2 public import static "ecere"
9 #ifndef MAKEFILE_GENERATOR
11 // We should have the .sln/.vcproj generation even on other platforms
12 // e.g. detect from an environment variable pointing to a Windows drive
18 import "ProjectConfig"
24 static void DummyFunction()
32 extern int __ecereVMethodID_class_OnCompare;
33 extern int __ecereVMethodID_class_OnFree;
35 IDESettings ideSettings;
37 IDESettingsContainer settingsContainer
40 dataOwner = &ideSettings;
41 dataClass = class(IDESettings);
43 void OnLoad(GlobalSettingsData data)
45 IDESettings settings = (IDESettings)data;
46 #ifndef MAKEFILE_GENERATOR
47 globalSettingsDialog.ideSettings = settings;
48 ide.UpdateRecentMenus();
49 ide.UpdateCompilerConfigs(true);
54 #ifdef MAKEFILE_GENERATOR
55 CompilerConfig defaultCompiler;
58 // LEGACY BINARY EPJ LOADING
60 SetBool ParseTrueFalseValue(char * string)
62 if(!strcmpi(string, "True")) return true;
66 void ParseArrayValue(Array<String> array, char * equal)
68 char * start, * comma;
70 string = CopyString(equal);
74 comma = strstr(start, ",");
77 array.Add(CopyString(start));
87 void ProjectNode::LegacyBinaryLoadNode(File f)
92 f.Read(&len, sizeof(len), 1);
93 name = new char[len+1];
95 f.Read(name, sizeof(char), len+1);
96 f.Read(&len, sizeof(len), 1);
98 path = new char[len+1];
99 f.Read(path, sizeof(char), len+1);
102 fileName = new char[fileNameLen+2];
103 strcpy(fileName, path);
104 if(fileName[0]) strcat(fileName, "/");
105 strcat(fileName, name);
108 f.Read(&type, sizeof(type), 1);
109 f.Read(&count, sizeof(count), 1);
114 icon = NodeIcons::SelectFileIcon(name);
119 icon = NodeIcons::SelectNodeIcon(type);
122 if(count && !files) files = { };
123 for(c = 0; c < count; c++)
125 ProjectNode child { };
128 child.indent = indent + 1;
129 LegacyBinaryLoadNode(child, f);
133 /*void LegacyBinarySaveNode(File f)
138 f.Write(&len, sizeof(len), 1);
139 f.Write(name, sizeof(char), len+1);
143 // Projects Absolute Path Are Not Saved
145 f.Write(&len, sizeof(len), 1);
146 f.Write(&len, sizeof(char), 1);
151 f.Write(&len, sizeof(len), 1);
152 f.Write(path, sizeof(char), len+1);
154 f.Write(&type, sizeof(type), 1);
155 f.Write(&children.count, sizeof(children.count), 1);
156 for(child = children.first; child; child.next)
160 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
163 char printPath[MAX_LOCATION];
165 if(type == project && (files.count /*|| preprocessorDefs.first*/))
167 f.Printf("\n Files\n");
169 else if(type == file)
171 if(!strcmp(path, insidePath))
172 f.Printf("%s - %s\n", indentation, name);
175 strcpy(printPath, path);
176 len = strlen(printPath);
178 if(printPath[len-1] != '/')
179 strcat(printPath, "/");
180 strcat(printPath, name);
181 f.Printf("%s = %s\n", indentation, printPath);
184 f.Printf("\nError\n\n");
186 else if(type == folder)
188 f.Printf("%s + %s\n", indentation, name);
190 else if(type == resources && files.count)
192 PathCatSlash(insidePath, path);
193 f.Printf("\n%sResources\n", indentation);
195 f.Printf("%s Path = %s\n", indentation, path);
198 /*if(buildExclusions.first && type != project)
200 for(item = buildExclusions.first; item; item = item.next)
202 if(item == buildExclusions.first)
203 f.Printf("%s Build Exclusions = %s", indentation, item.name);
205 f.Printf(", %s", item.name);
210 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
212 for(item = preprocessorDefs.first; item; item = item.next)
214 if(item == preprocessorDefs.first)
215 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
217 f.Printf(", %s", item.name);
223 if(type == project && (files.count /*|| preprocessorDefs.first*/))
227 LegacyAsciiSaveNode(child, f, indentation, insidePath);
229 else if(type == folder)
231 strcat(indentation, " ");
232 // WHAT WAS THIS: strcpy(printPath, path);
233 // TOCHECK: why is Unix/PathCat not used here
234 len = strlen(insidePath);
236 if(insidePath[len-1] != '/')
237 strcat(insidePath, "/");
238 strcat(insidePath, name);
241 LegacyAsciiSaveNode(child, f, indentation, insidePath);
242 f.Printf("%s -\n", indentation);
243 indentation[strlen(indentation) - 3] = '\0';
244 StripLastDirectory(insidePath, insidePath);
246 else if(type == resources && files.count)
250 LegacyAsciiSaveNode(child, f, indentation, insidePath);
251 StripLastDirectory(insidePath, insidePath);
256 void ProjectConfig::LegacyProjectConfigSave(File f)
258 char * indentation = " ";
260 //f.Printf("\n * Common\n");
262 f.Printf("\n + %s\n", name);
263 f.Printf("\n Compiler\n\n");
264 if(objDir.expression[0])
265 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
266 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
267 switch(options.optimization)
269 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
270 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
271 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
273 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
275 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
276 if(options.memoryGuard == true)
277 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
278 if(options.strictNameSpaces == true)
279 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
280 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
281 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
282 TOFIX: Compiler Bug {
283 if(options.preprocessorDefinitions.count)
286 for(item : options.preprocessorDefinitions)
290 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
294 f.Printf(", %s", item);
299 if(options.includeDirs.count)
301 f.Printf("\n%sInclude Directories\n", indentation);
302 for(item : options.includeDirs)
303 f.Printf("%s - %s\n", indentation, name);
307 f.Printf("\n%sLinker\n\n", indentation);
308 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
309 switch(options.targetType)
311 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
312 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
313 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
315 if(targetDir.expression[0])
316 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
318 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
320 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
321 if(options.libraries.count)
324 for(item : options.libraries)
328 f.Printf("\n%sLibraries = %s", indentation, name);
332 f.Printf(", %s", item);
336 if(options.libraryDirs.count)
338 f.Printf("\n%sLibrary Directories\n\n", indentation);
339 for(item : options.libraryDirs)
340 f.Printf(" - %s\n", indentation, item);
344 void LegacyAsciiSaveProject(File f, Project project)
346 char indentation[128*3];
347 char path[MAX_LOCATION];
349 f.Printf("\nECERE Project File : Format Version 0.1b\n");
350 f.Printf("\nDescription\n%s\n.\n", project.description);
351 f.Printf("\nLicense\n%s\n.\n", project.license);
352 f.Printf("\nModule Name = %s\n", project.moduleName);
353 f.Printf("\n Configurations\n");
354 //////////////////////////////////////commonConfig.Save(f, true);
355 for(cfg : project.configurations)
356 LegacyProjectConfigSave(cfg, f);
358 strcpy(indentation, " ");
360 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
366 // *** NEW JSON PROJECT FORMAT ***
367 public enum ProjectNodeType { file, folder };
369 // *******************************
371 define PEEK_RESOLUTION = (18.2 * 10);
377 static Array<String> notLinkerOptions
399 static bool IsLinkerOption(String s)
401 for(i : notLinkerOptions)
402 if(strstr(s, "-Wl,") || !strcmp(s, i))
407 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
409 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources, rcSources };
411 define WorkspaceExtension = "ews";
412 define ProjectExtension = "epj";
414 define stringInFileIncludedFrom = "In file included from ";
415 define stringFrom = " from ";
417 // This function cannot accept same pointer for source and output
418 // todo: rename ReplaceSpaces to EscapeSpaceAndSpecialChars or something
419 void ReplaceSpaces(char * output, char * source)
424 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
426 if(ch == ' ') output[dc++] = '\\';
427 if(ch == '\"') output[dc++] = '\\';
428 if(ch == '&') output[dc++] = '\\';
431 if(ch == '(' || ch == ')') output[dc++] = '\\';
441 // chars refused for project name: windowsFileNameCharsNotAllowed + " &,."
443 //define gnuMakeCharsNeedEscaping = "$%";
445 //define windowsFileNameCharsNotAllowed = "*/:<>?\\\"|";
446 //define linuxFileNameCharsNotAllowed = "/";
448 //define windowsFileNameCharsNeedEscaping = " !%&'()+,;=[]^`{}~"; // "#$-.@_" are ok
449 //define linuxFileNameCharsNeedEscaping = " !\"$&'()*:;<=>?[\\`{|"; // "#%+,-.@]^_}~" are ok
451 // NOTES: - this function should get only unescaped unix style paths
452 // - paths with literal $(somestring) in them are not supported
453 // my_$(messed_up)_path would likely become my__path
454 void EscapeForMake(char * output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
456 char ch, *i = input, *o = output;
459 int len = strlen(input);
460 if(len && ((input[0] == '"' && input[len-1] == '"') || strchr(input, '\\') || strchr(input, 127) || (!allowDblQuote && strchr(input, '"'))))
461 PrintLn("Invalid input for EscapeForMake! -- ", input);
467 if(i-1 != input && *(i-2) == '$' && allowVars)
474 if(inVar == true && allowVars)
479 else if(ch == '$' && *i != '(')
501 void EscapeForMakeToFile(File output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
503 char * buf = new char[strlen(input)*2+1];
504 EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
509 void EscapeForMakeToDynString(DynamicString output, char * input, bool hideSpace, bool allowVars, bool allowDblQuote)
511 char * buf = new char[strlen(input)*2+1];
512 EscapeForMake(buf, input, hideSpace, allowVars, allowDblQuote);
517 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
520 const int breakListLength = 1536;
521 const int breakLineLength = 78; // TODO: turn this into an option.
523 int c, len, itemCount = 0;
524 Array<int> breaks { };
528 MapNode<String, int> mn;
529 for(c=0; c<list.count; c++)
531 len = strlen(list[c]) + 3;
532 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
534 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
536 if(strstr(list[c], mn.key))
540 if(charCount + len > breakListLength)
542 breaks.Add(itemCount);
550 breaks.Add(itemCount);
551 numOfBreaks = breaks.count;
556 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
557 for(c=0; c<numOfBreaks; c++)
558 f.Printf(" $(%s%d)", name, c+1);
562 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
568 for(c=0; c<numOfBreaks; c++)
571 f.Printf("%s%d =", name, c+1);
574 itemCount = breaks[c];
575 for(n=offset; n<offset+itemCount; n++)
577 if(false) // TODO: turn this into an option.
579 int itemLen = strlen(list[n]);
580 if(len > 3 && len + itemLen > breakLineLength)
582 f.Printf(" \\\n\t%s", list[n]);
588 f.Printf(" %s", list[n]);
592 f.Printf(" \\\n\t%s", list[n]);
607 void OutputLinkObjectActions(File f, char * name, int parts)
612 for(c=0; c<parts; c++)
613 f.Printf("\t@$(call echo,$(%s%d)) >> $(OBJ)linkobjects.lst\n", name, c+1);
615 f.Printf("\t@$(call echo,$(%s)) >> $(OBJ)linkobjects.lst\n", name);
619 void OutputCleanActions(File f, char * name, int parts)
624 for(c=0; c<parts; c++)
625 f.Printf("\t$(call rmq,$(_%s%d))\n", name, c+1);
628 f.Printf("\t$(call rmq,$(_%s))\n", name);
631 enum LineOutputMethod { inPlace, newLine, lineEach };
632 enum StringOutputMethod { asIs, escape, escapePath};
634 enum ToolchainFlag { any, _D, _I, _isystem, _Wl, _L/*, _Wl-rpath*/ };
635 String flagNames[ToolchainFlag] = { "", "-D", "-I", "-isystem ", "-Wl,", /*"-Wl,--library-path="*/"-L"/*, "-Wl,-rpath "*/ };
636 void OutputFlags(File f, ToolchainFlag flag, Array<String> list, LineOutputMethod lineMethod)
640 if(lineMethod == newLine)
644 if(lineMethod == lineEach)
646 f.Printf(" %s", flagNames[flag]);
647 if(flag != _D && flag != _Wl && flag != any)
649 char * tmp = new char[strlen(item)*2+1];
650 EscapeForMake(tmp, item, false, true, false);
651 f.Printf("$(call quote_path,%s)", tmp);
655 EscapeForMakeToFile(f, item, false, true, true);
660 static void OutputLibraries(File f, Array<String> libraries)
662 for(item : libraries)
664 char ext[MAX_EXTENSION];
665 char temp[MAX_LOCATION];
667 bool usedFunction = false;
668 GetExtension(item, ext);
669 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
673 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
675 if(!strncmp(item, "lib", 3))
676 strcpy(temp, item + 3);
679 StripExtension(temp);
682 f.Puts(" \\\n\t$(call _L,");
685 EscapeForMakeToFile(f, s, false, false, false);
691 void CamelCase(char * string)
693 int c, len = strlen(string);
694 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
695 string[c] = (char)tolower(string[c]);
698 CompilerConfig GetCompilerConfig()
700 #ifndef MAKEFILE_GENERATOR
701 CompilerConfig compiler = null;
702 if(ide && ide.workspace)
703 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
706 incref defaultCompiler;
707 return defaultCompiler;
711 define localTargetType = config && config.options && config.options.targetType ?
712 config.options.targetType : options && options.targetType ?
713 options.targetType : TargetTypes::executable;
714 define localWarnings = config && config.options && config.options.warnings ?
715 config.options.warnings : options && options.warnings ?
716 options.warnings : WarningsOption::unset;
717 define localDebug = config && config.options && config.options.debug ?
718 config.options.debug : options && options.debug ?
719 options.debug : SetBool::unset;
720 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
721 config.options.memoryGuard : options && options.memoryGuard ?
722 options.memoryGuard : SetBool::unset;
723 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
724 config.options.noLineNumbers : options && options.noLineNumbers ?
725 options.noLineNumbers : SetBool::unset;
726 define localProfile = config && config.options && config.options.profile ?
727 config.options.profile : options && options.profile ?
728 options.profile : SetBool::unset;
729 define localOptimization = config && config.options && config.options.optimization ?
730 config.options.optimization : options && options.optimization ?
731 options.optimization : OptimizationStrategy::none;
732 define localFastMath = config && config.options && config.options.fastMath ?
733 config.options.fastMath : options && options.fastMath ?
734 options.fastMath : SetBool::unset;
735 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
736 config.options.defaultNameSpace : options && options.defaultNameSpace ?
737 options.defaultNameSpace : null;
738 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
739 config.options.strictNameSpaces : options && options.strictNameSpaces ?
740 options.strictNameSpaces : SetBool::unset;
741 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
742 define localTargetFileName = config && config.options && config.options.targetFileName ?
743 config.options.targetFileName : options && options.targetFileName ?
744 options.targetFileName : "";
745 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
746 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
747 options.targetDirectory : null;
748 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
749 ideSettings.projectDefaultIntermediateObjDir[0] ?
750 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
751 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
752 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
753 options.objectsDirectory : null;
754 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
755 ideSettings.projectDefaultIntermediateObjDir[0] ?
756 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
757 define localConsole = config && config.options && config.options.console ?
758 config.options.console : options && options.console ?
759 options.console : SetBool::unset;
760 define localCompress = config && config.options && config.options.compress ?
761 config.options.compress : options && options.compress ?
762 options.compress : SetBool::unset;
764 define platformTargetType =
765 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
766 configPOs.options.targetType :
767 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
768 projectPOs.options.targetType : TargetTypes::unset;
771 char * PlatformToMakefileTargetVariable(Platform platform)
773 return platform == win32 ? "WINDOWS_TARGET" :
774 platform == tux ? "LINUX_TARGET" :
775 platform == apple ? "OSX_TARGET" :
779 char * TargetTypeToMakefileVariable(TargetTypes targetType)
781 return targetType == executable ? "executable" :
782 targetType == sharedLibrary ? "sharedlib" :
783 targetType == staticLibrary ? "staticlib" :
787 // Move this to ProjectConfig? null vs Common to consider...
788 char * GetConfigName(ProjectConfig config)
790 return config ? config.name : "Common";
793 public enum SingleFileCompileMode
795 normal, debugPrecompile, debugCompile, debugGenerateSymbols, cObject;
797 property bool eC_ToolsDebug { get { return this == debugCompile || this == debugGenerateSymbols || this == debugPrecompile; } }
800 class Project : struct
802 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
803 // We might want to tweak this default behavior of regular classes ?
804 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
809 property char * moduleVersion
811 set { delete moduleVersion; if(value && value[0]) moduleVersion = CopyString(value); } // TODO: use CopyString function that filters chars
812 get { return moduleVersion ? moduleVersion : ""; } // version number should only use digits and dots
813 isset { return moduleVersion != null && moduleVersion[0]; } // add leading/trailing 0 if value start/ends with dot(s)
816 property char * description
818 set { delete description; if(value && value[0]) description = CopyString(value); }
819 get { return description ? description : ""; }
820 isset { return description != null && description[0]; }
823 property char * license
825 set { delete license; if(value && value[0]) license = CopyString(value); }
826 get { return license ? license : ""; }
827 isset { return license != null && license[0]; }
830 property char * compilerConfigsDir
832 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
833 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
834 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
837 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
838 property Array<PlatformOptions> platforms
840 get { return platforms; }
843 if(platforms) { platforms.Free(); delete platforms; }
846 List<PlatformOptions> empty { };
847 Iterator<PlatformOptions> it { value };
849 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
850 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
860 if(p.options && !p.options.isEmpty)
867 List<ProjectConfig> configurations;
868 LinkList<ProjectNode> files;
869 String resourcesPath;
870 LinkList<ProjectNode> resources;
873 // topNode.name holds the file name (.epj)
874 ProjectOptions options;
875 Array<PlatformOptions> platforms;
876 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
879 ProjectConfig config;
881 // This is the file name stripped of the epj extension
882 // It should NOT be edited, saved or loaded anywhere
887 String compilerConfigsDir;
888 String moduleVersion;
890 String lastBuildConfigName;
891 String lastBuildCompilerName;
893 Map<String, Map<String, NameCollisionInfo>> configsNameCollisions { };
895 #ifndef MAKEFILE_GENERATOR
896 FileMonitor fileMonitor
898 this, FileChange { modified = true };
899 bool OnFileNotify(FileChange action, char * param)
901 fileMonitor.StopMonitoring();
902 if(OnProjectModified(action, param))
903 fileMonitor.StartMonitoring();
908 bool StartMonitoring()
910 fileMonitor.fileName = filePath;
911 fileMonitor.StartMonitoring();
915 bool StopMonitoring()
917 fileMonitor.StopMonitoring();
921 bool OnProjectModified(FileChange fileChange, char * param)
924 sprintf(temp, $"The project %s was modified by another application.\n"
925 "Would you like to reload it and lose your changes?", name);
926 if(MessageBox { type = yesNo, master = ide,
927 text = $"Project has been modified", contents = temp }.Modal() == yes)
929 Project project = LoadProject(filePath, config ? config.name : null);
932 ProjectView projectView = ide.projectView;
933 DataRow prev = topNode.row ? topNode.row.previous : null;
934 FileMonitor fm = fileMonitor;
935 bool confirmation = true;
939 if(projectView.projectSettingsDialog)
941 confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
943 projectView.projectSettingsDialog.Destroy(0);
946 projectView.DeleteNode(topNode);
953 topNode.project = this;
957 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
958 projectView.AddNode(topNode, null);
959 topNode.row.Move(prev);
961 projectView.ShowOutputBuildLog(true);
962 projectView.DisplayCompiler(compiler, false);
963 projectView.ProjectUpdateMakefileForAllConfigs(this);
966 eSystem_Delete(project);
978 // This frees contents without freeing the instance
979 // For use from destructor and for file monitor reloading
980 // (To work around JSON loader (LoadProject) always returning a new instance)
983 if(platforms) { platforms.Free(); delete platforms; }
984 if(configurations) { configurations.Free(); delete configurations; }
985 if(files) { files.Free(); delete files; }
986 if(resources) { resources.Free(); delete resources; }
988 delete resourcesPath;
992 delete compilerConfigsDir;
994 delete moduleVersion;
998 delete lastBuildConfigName;
999 delete lastBuildCompilerName;
1000 for(map : configsNameCollisions)
1002 configsNameCollisions.Free();
1007 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
1008 topNode.configurations = null;
1009 topNode.platforms = null;
1010 topNode.options = null;
1015 property ProjectConfig config
1020 delete topNode.info;
1021 topNode.info = CopyString(GetConfigName(config));
1025 property char * filePath
1031 char string[MAX_LOCATION];
1032 GetLastDirectory(value, string);
1033 delete topNode.name;
1034 topNode.name = CopyString(string);
1035 StripExtension(string);
1037 name = CopyString(string);
1038 StripLastDirectory(value, string);
1039 delete topNode.path;
1040 topNode.path = CopyString(string);
1042 filePath = CopyString(value);
1047 ProjectConfig GetConfig(char * configName)
1049 ProjectConfig result = null;
1050 if(configName && configName[0] && configurations.count)
1052 for(cfg : configurations; !strcmpi(cfg.name, configName))
1061 ProjectNode FindNodeByObjectFileName(char * fileName, IntermediateFileType type, bool dotMain, ProjectConfig config)
1066 config = this.config;
1067 cfgName = config ? config.name : "";
1068 if(!configsNameCollisions[cfgName])
1069 ProjectLoadLastBuildNamesInfo(this, config);
1070 result = topNode.FindByObjectFileName(fileName, type, dotMain, configsNameCollisions[cfgName]);
1074 TargetTypes GetTargetType(ProjectConfig config)
1076 TargetTypes targetType = localTargetType;
1080 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
1083 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1085 PlatformOptions projectPOs, configPOs;
1086 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1087 if(platformTargetType)
1093 char * GetObjDirExpression(ProjectConfig config)
1095 // TODO: Support platform options
1096 char * expression = localObjectsDirectory;
1098 expression = settingsObjectsDirectory;
1102 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1104 char * expression = GetObjDirExpression(config);
1105 DirExpression objDir { type = intermediateObjectsDir };
1106 objDir.Evaluate(expression, this, compiler, config, bitDepth);
1110 char * GetTargetDirExpression(ProjectConfig config)
1112 // TODO: Support platform options
1113 char * expression = localTargetDirectory;
1115 expression = settingsTargetDirectory;
1119 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1121 char * expression = GetTargetDirExpression(config);
1122 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
1123 targetDir.Evaluate(expression, this, compiler, config, bitDepth);
1127 WarningsOption GetWarnings(ProjectConfig config)
1129 WarningsOption warnings = localWarnings;
1133 bool GetDebug(ProjectConfig config)
1135 SetBool debug = localDebug;
1136 return debug == true;
1139 bool GetMemoryGuard(ProjectConfig config)
1141 SetBool memoryGuard = localMemoryGuard;
1142 return memoryGuard == true;
1145 bool GetNoLineNumbers(ProjectConfig config)
1147 SetBool noLineNumbers = localNoLineNumbers;
1148 return noLineNumbers == true;
1151 bool GetProfile(ProjectConfig config)
1153 SetBool profile = localProfile;
1154 return profile == true;
1157 OptimizationStrategy GetOptimization(ProjectConfig config)
1159 OptimizationStrategy optimization = localOptimization;
1160 return optimization;
1163 bool GetFastMath(ProjectConfig config)
1165 SetBool fastMath = localFastMath;
1166 return fastMath == true;
1169 String GetDefaultNameSpace(ProjectConfig config)
1171 String defaultNameSpace = localDefaultNameSpace;
1172 return defaultNameSpace;
1175 bool GetStrictNameSpaces(ProjectConfig config)
1177 SetBool strictNameSpaces = localStrictNameSpaces;
1178 return strictNameSpaces == true;
1181 String GetTargetFileName(ProjectConfig config)
1183 String targetFileName = localTargetFileName;
1184 return targetFileName;
1187 //String targetDirectory;
1188 //String objectsDirectory;
1189 bool GetConsole(ProjectConfig config)
1191 SetBool console = localConsole;
1192 return console == true;
1195 bool GetCompress(ProjectConfig config)
1197 SetBool compress = localCompress;
1198 return compress == true;
1200 //SetBool excludeFromBuild;
1202 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1204 #ifndef MAKEFILE_GENERATOR
1205 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1209 bool GetConfigIsInDebugSession(ProjectConfig config)
1211 #ifndef MAKEFILE_GENERATOR
1212 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1216 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
1218 #ifndef MAKEFILE_GENERATOR
1219 ide.SetPath(projectsDirs, compiler, config, bitDepth);
1223 #ifndef MAKEFILE_GENERATOR
1224 bool Save(char * fileName)
1227 /*char output[MAX_LOCATION];
1228 ChangeExtension(fileName, "json", output);
1229 f = FileOpen(output, write);*/
1230 f = FileOpen(fileName, write);
1233 files = topNode.files;
1234 resources = resNode.files;
1235 resourcesPath = resNode.path;
1237 files.Remove(resNode);
1240 WriteJSONObject(f, class(Project), this, 0);
1246 resourcesPath = null;
1253 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1255 TargetTypes targetType = GetTargetType(config);
1256 String targetFileName = GetTargetFileName(config);
1257 if(targetType == staticLibrary)
1259 PathCatSlash(string, "lib");
1260 strcat(string, targetFileName);
1262 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1264 PathCatSlash(string, "lib");
1265 strcat(string, targetFileName);
1268 PathCatSlash(string, targetFileName);
1273 if(compiler.targetPlatform == win32)
1274 strcat(string, ".exe");
1277 if(compiler.targetPlatform == win32)
1278 strcat(string, ".dll");
1279 else if(compiler.targetPlatform == apple)
1280 strcat(string, ".dylib");
1282 strcat(string, ".so");
1283 if(compiler.targetPlatform == tux && GetRuntimePlatform() == tux && moduleVersion && moduleVersion[0])
1285 strcat(string, ".");
1286 strcat(string, moduleVersion);
1290 strcat(string, ".a");
1295 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1297 bool result = false;
1298 char temp[MAX_LOCATION];
1299 strcpy(cfDir, topNode.path);
1300 if(compilerConfigsDir && compilerConfigsDir[0])
1302 PathCatSlash(cfDir, compilerConfigsDir);
1307 strcpy(temp, cfDir);
1308 // Using a relative path makes it less likely to run into spaces issues
1309 // Even with escaped spaces, there still seems to be issues including a config file
1310 // in a path containing spaces
1312 MakePathRelative(temp, topNode.path, cfDir);
1315 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1319 strcpy(temp, cfDir);
1320 ReplaceSpaces(cfDir, temp);
1325 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1327 char temp[MAX_LOCATION];
1328 bool result = false;
1329 strcpy(cfDir, topNode.path);
1330 if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1332 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1337 // Default to <ProjectDir>/.configs if unset
1338 PathCatSlash(cfDir, ".configs");
1343 strcpy(temp, cfDir);
1344 // Using a relative path makes it less likely to run into spaces issues
1345 // Even with escaped spaces, there still seems to be issues including a config file
1346 // in a path containing spaces
1347 if(IsPathInsideOf(cfDir, topNode.path))
1348 MakePathRelative(temp, topNode.path, cfDir);
1350 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1354 strcpy(temp, cfDir);
1355 ReplaceSpaces(cfDir, temp);
1360 void CatMakeFileName(char * string, ProjectConfig config)
1362 char projectName[MAX_LOCATION];
1363 strcpy(projectName, name);
1364 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1367 #ifndef MAKEFILE_GENERATOR
1368 void MarkChanges(ProjectNode node)
1370 for(cfg : topNode.configurations)
1372 ProjectConfig c = null;
1373 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1375 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1376 (!c.options || !cfg.options)))
1377 cfg.symbolGenModified = true;
1378 if(c && ((c.options && cfg.options &&
1379 ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) )
1380 || (!c.options || !cfg.options)))
1381 cfg.linkingModified = true;
1383 cfg.makingModified = true;
1387 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1389 Map<String, NameCollisionInfo> cfgNameCollision = configsNameCollisions[""];
1390 if(cfgNameCollision)
1392 cfgNameCollision.Free();
1393 delete cfgNameCollision;
1394 configsNameCollisions[""] = null;
1396 for(cfg : configurations)
1400 cfg.makingModified = true;
1401 cfgNameCollision = configsNameCollisions[cfg.name];
1402 if(cfgNameCollision)
1404 cfgNameCollision.Free();
1405 delete cfgNameCollision;
1406 configsNameCollisions[cfg.name] = null;
1410 cfg.compilingModified = true;
1412 cfg.linkingModified = true;
1414 cfg.symbolGenModified = true;
1416 if(compiling || linking)
1418 ide.projectView.modifiedDocument = true;
1419 ide.workspace.modified = true;
1423 void RotateActiveConfig(bool forward, bool syncAllProjects)
1425 if(configurations.first && configurations.last != configurations.first)
1427 Iterator<ProjectConfig> cfg { configurations };
1428 while(forward ? cfg.Next() : cfg.Prev())
1429 if(cfg.data == config)
1444 ide.workspace.SelectActiveConfig(cfg.data.name);
1447 property::config = cfg.data;
1448 ide.UpdateToolBarActiveConfigs(true);
1449 ide.workspace.modified = true;
1450 ide.projectView.Update(null);
1455 bool ProcessPipeOutputRaw(DualPipe f)
1458 while(!f.Eof() && !ide.projectView.stopBuild)
1461 double lastTime = GetTime();
1465 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1467 ide.outputView.buildBox.Logf("%s\n", line);
1469 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1471 //printf("Processing Input...\n");
1472 if(app.ProcessInput(true))
1474 app.UpdateDisplay();
1477 //printf("Waiting...\n");
1480 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1482 if(ide.projectView.stopBuild)
1484 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1487 return !ide.projectView.stopBuild;
1490 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, BuildType buildType, List<ProjectNode> onlyNodes,
1491 CompilerConfig compiler, ProjectConfig config, int bitDepth)
1494 bool compiling = false, linking = false, precompiling = false;
1495 int compilingEC = 0;
1496 int numErrors = 0, numWarnings = 0;
1497 bool loggedALine = false;
1498 int lenMakeCommand = strlen(compiler.makeCommand);
1501 char moduleName[MAX_FILENAME];
1502 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1504 DynamicString test { };
1505 DynamicString ecp { };
1506 DynamicString ecc { };
1507 DynamicString ecs { };
1508 DynamicString ear { };
1509 DynamicString prefix { };
1510 DynamicString cpp { };
1511 DynamicString cc { };
1512 DynamicString cxx { };
1513 DynamicString strip { };
1514 DynamicString ar { };
1515 DynamicString windres { };
1518 if(bitDepth == 64 && compiler.targetPlatform == win32)
1519 gnuToolchainPrefix = "x86_64-w64-mingw32-";
1520 else if(bitDepth == 32 && compiler.targetPlatform == win32)
1521 gnuToolchainPrefix = "i686-w64-mingw32-";
1523 ecp.concatx(compiler.ecpCommand, " ");
1524 ecc.concatx(compiler.eccCommand, " ");
1525 ecs.concatx(compiler.ecsCommand, " ");
1526 ear.concatx(compiler.earCommand, " ");
1529 compiler.ccacheEnabled ? "ccache " : "",
1530 compiler.distccEnabled ? "distcc " : "",
1531 gnuToolchainPrefix);
1533 cpp.concatx((String)prefix, compiler.cppCommand, " ");
1534 cc.concatx((String)prefix, compiler.ccCommand, " ");
1535 cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1537 strip.concatx(gnuToolchainPrefix, "strip ");
1538 ar.concatx(gnuToolchainPrefix, "ar rcs");
1539 windres.concatx(gnuToolchainPrefix, "windres ");
1541 testLen = Max(testLen, ecp.size);
1542 testLen = Max(testLen, ecc.size);
1543 testLen = Max(testLen, ecs.size);
1544 testLen = Max(testLen, ear.size);
1545 testLen = Max(testLen, cpp.size);
1546 testLen = Max(testLen, cc.size);
1547 testLen = Max(testLen, cxx.size);
1548 testLen = Max(testLen, strip.size);
1549 testLen = Max(testLen, ar.size);
1550 testLen = Max(testLen, windres.size);
1551 testLen = Max(testLen, strlen("mkdir "));
1554 while(!f.Eof() && !ide.projectView.stopBuild)
1557 double lastTime = GetTime();
1561 //printf("Peeking and GetLine...\n");
1562 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1564 char * message = null;
1565 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1566 char * from = strstr(line, stringFrom);
1567 test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1568 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1570 char * module = strstr(line, "No rule to make target `");
1574 module = strchr(module, '`') + 1;
1575 end = strchr(module, '\'');
1579 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1580 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1586 //ide.outputView.buildBox.Logf("error: %s\n", line);
1590 else if(strstr(test, "mkdir ") == test);
1591 else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
1592 else if(strstr(test, ear) == test);
1593 else if(strstr(test, strip) == test);
1594 else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1597 bool isPrecomp = false;
1600 if(strstr(test, cc) == test || strstr(test, cxx) == test)
1602 module = strstr(line, " -c ");
1603 if(module) module += 4;
1606 else if(strstr(test, ecc) == test)
1608 module = strstr(line, " -c ");
1609 if(module) module += 4;
1610 //module = line + 3;
1611 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1612 compilingEC = 3;//2;
1615 else if(strstr(test, ecp) == test)
1617 // module = line + 8;
1618 module = strstr(line, " -c ");
1619 if(module) module += 4;
1630 if(!compiling && !isPrecomp)
1632 ide.outputView.buildBox.Logf($"Compiling...\n");
1635 else if(!precompiling && isPrecomp)
1637 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1638 precompiling = true;
1640 Tokenize(module, 1, tokens, forArgsPassing/*(BackSlashEscaping)true*/);
1641 GetLastDirectory(tokens[0], moduleName);
1642 ide.outputView.buildBox.Logf("%s\n", moduleName);
1644 else if((module = strstr(line, " -o ")))
1647 precompiling = false;
1649 ide.outputView.buildBox.Logf($"Linking...\n");
1653 ide.outputView.buildBox.Logf("%s\n", line);
1654 if(strstr(line, "warning:") || strstr(line, "note:"))
1656 else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
1660 if(compilingEC) compilingEC--;
1662 else if(strstr(test, windres) == test)
1665 module = strstr(line, " ");
1666 if(module) module++;
1670 char * dashF = strstr(module, "-F ");
1674 while(*dashF && *dashF != ' ') dashF++;
1675 while(*dashF && *dashF == ' ') dashF++;
1678 Tokenize(module, 1, tokens, forArgsPassing/*(BackSlashEscaping)true*/);
1679 GetLastDirectory(module, moduleName);
1680 ide.outputView.buildBox.Logf("%s\n", moduleName);
1683 else if(strstr(test, ar) == test)
1684 ide.outputView.buildBox.Logf($"Building library...\n");
1685 else if(strstr(test, ecs) == test)
1686 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1689 if(linking || compiling || precompiling)
1691 char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
1692 char * colon = strstr(start, ":"); //, * bracket;
1693 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1694 colon = strstr(colon + 1, ":");
1697 char * sayError = "";
1698 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1701 int len = (int)(colon - start);
1702 char ext[MAX_EXTENSION];
1703 len = Min(len, MAX_LOCATION-1);
1704 // Don't be mistaken by the drive letter colon
1706 // TODO: need to fix colon - line gives char *
1707 // warning: incompatible expression colon - line (char *); expected int
1709 strncpy(moduleName, line, (int)(colon - line));
1710 moduleName[colon - line] = '\0';
1712 strncpy(moduleName, start, len);
1713 moduleName[len] = '\0';
1714 // Remove stuff in brackets
1715 //bracket = strstr(moduleName, "(");
1716 //if(bracket) *bracket = '\0';
1718 GetLastDirectory(moduleName, temp);
1719 GetExtension(temp, ext);
1721 if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
1723 char * cColon = strstr(colon+1, ":");
1724 if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
1725 cColon = strstr(cColon + 1, ":");
1728 int len = (int)(cColon - (colon+1));
1729 char mName[MAX_LOCATION];
1730 len = Min(len, MAX_LOCATION-1);
1731 strncpy(mName, colon+1, len);
1733 GetLastDirectory(mName, temp);
1734 GetExtension(temp, ext);
1735 if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
1738 strcpy(moduleName, mName);
1742 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1745 if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1747 message = $"Linker Message: ";
1753 message = $"Linker Error: ";
1756 else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
1760 if(strstr(colon, "Warning:") == colon)
1762 message = $"Linker ";
1765 else if(!strstr(line, "error:"))
1767 message = $"Linker Error: ";
1773 strcpy(temp, topNode.path);
1774 PathCatSlash(temp, moduleName);
1775 MakePathRelative(temp, topNode.path, moduleName);
1777 error = strstr(line, "error:");
1778 if(!message && error && error > colon)
1782 // Silence warnings for compiled eC
1783 char * objDir = strstr(moduleName, objDirExp.dir);
1787 if((pointer = strstr(line, "undefined")) ||
1788 (pointer = strstr(line, "multiple definition")) ||
1789 (pointer = strstr(line, "No such file")) ||
1790 (pointer = strstr(line, "token")))
1792 strncat(moduleName, colon, pointer - colon);
1793 sayError = "error: ";
1798 else if((pointer = strstr(line, "No such file")))
1800 strncat(moduleName, colon, pointer - colon);
1801 sayError = "error: ";
1805 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1807 else if(strstr(line, "warning:"))
1813 ide.outputView.buildBox.Logf(" %s%s\n", message, colon);
1814 /*else if(this == ide.workspace.projects.firstIterator.data)
1815 ide.outputView.buildBox.Logf(" %s%s%s\n", moduleName, sayError, colon);*/
1818 char fullModuleName[MAX_LOCATION];
1819 FileAttribs found = 0;
1820 Project foundProject = this;
1823 char * loc = strstr(moduleName, ":");
1825 strcpy(fullModuleName, topNode.path);
1826 PathCat(fullModuleName, moduleName);
1827 found = FileExists(fullModuleName);
1828 if(!found && !strcmp(ext, "c"))
1830 char ecName[MAX_LOCATION];
1831 ChangeExtension(fullModuleName, "ec", ecName);
1832 found = FileExists(ecName);
1836 char path[MAX_LOCATION];
1837 if(ide && ide.workspace)
1839 for(prj : ide.workspace.projects)
1842 MakePathRelative(fullModuleName, prj.topNode.path, path);
1844 if((node = prj.topNode.FindWithPath(path, false)))
1846 strcpy(fullModuleName, prj.topNode.path);
1847 PathCatSlash(fullModuleName, node.path);
1848 PathCatSlash(fullModuleName, node.name);
1849 found = FileExists(fullModuleName);
1857 if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1859 for(prj : ide.workspace.projects)
1862 if((node = prj.topNode.Find(moduleName, false)))
1864 strcpy(fullModuleName, prj.topNode.path);
1865 PathCatSlash(fullModuleName, node.path);
1866 PathCatSlash(fullModuleName, node.name);
1867 found = FileExists(fullModuleName);
1880 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1881 MakeSystemPath(fullModuleName);
1884 strcpy(fullModuleName, moduleName);
1887 strcat(fullModuleName, ":");
1888 strcat(fullModuleName, loc + 1);
1892 fullModuleName[0] = 0;
1893 ide.outputView.buildBox.Logf(" %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
1898 ide.outputView.buildBox.Logf("%s\n", line);
1899 linking = compiling = precompiling = false;
1903 ide.outputView.buildBox.Logf("%s\n", line);
1907 //printf("Done getting line\n");
1908 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1910 //printf("Processing Input...\n");
1911 if(app.ProcessInput(true))
1913 app.UpdateDisplay();
1916 //printf("Waiting...\n");
1919 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1921 if(ide.projectView.stopBuild)
1923 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1926 else if(loggedALine || buildType != run)
1928 if(f.GetExitCode() && !numErrors)
1930 bool result = f.GetLine(line, sizeof(line)-1);
1931 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1933 else if(buildType != install)
1937 char targetFileName[MAX_LOCATION];
1938 targetFileName[0] = '\0';
1939 CatTargetFileName(targetFileName, compiler, config);
1940 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, lastBuildConfigName);
1943 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1945 ide.outputView.buildBox.Logf($"no error, ");
1948 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1950 ide.outputView.buildBox.Logf($"no warning\n");
1967 return numErrors == 0 && !ide.projectView.stopBuild;
1970 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1973 int lenMakeCommand = strlen(compiler.makeCommand);
1978 double lastTime = GetTime();
1981 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1983 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1984 else if(strstr(line, "mkdir") == line);
1985 else if(strstr(line, "del") == line);
1986 else if(strstr(line, "rm") == line);
1987 else if(strstr(line, "Could Not Find") == line);
1990 ide.outputView.buildBox.Logf(line);
1991 ide.outputView.buildBox.Logf("\n");
1995 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1997 if(app.ProcessInput(true))
1999 app.UpdateDisplay();
2002 //Sleep(1.0 / PEEK_RESOLUTION);
2006 bool Build(BuildType buildType, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2008 bool result = false;
2010 char targetFileName[MAX_LOCATION] = "";
2011 DynamicString makeTargets { };
2012 char makeFile[MAX_LOCATION];
2013 char makeFilePath[MAX_LOCATION];
2014 char configName[MAX_LOCATION];
2015 DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
2016 PathBackup pathBackup { };
2017 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
2018 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2020 bool eC_Debug = mode.eC_ToolsDebug;
2021 bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
2022 int numJobs = compiler.numJobs;
2023 char command[MAX_F_STRING*4];
2024 char * compilerName = CopyString(compiler.name);
2025 Map<String, NameCollisionInfo> cfgNameCollisions;
2027 delete lastBuildConfigName;
2028 lastBuildConfigName = CopyString(config ? config.name : "Common");
2029 delete lastBuildCompilerName;
2030 lastBuildCompilerName = CopyString(compiler.name);
2031 ProjectLoadLastBuildNamesInfo(this, config);
2032 cfgNameCollisions = configsNameCollisions[config ? config.name : ""];
2034 CamelCase(compilerName);
2036 strcpy(configName, config ? config.name : "Common");
2038 SetPath(false, compiler, config, bitDepth); //true
2039 CatTargetFileName(targetFileName, compiler, config);
2041 strcpy(makeFilePath, topNode.path);
2042 CatMakeFileName(makeFile, config);
2043 PathCatSlash(makeFilePath, makeFile);
2045 // TODO: TEST ON UNIX IF \" around makeTarget is ok
2046 if(buildType == install)
2047 makeTargets.concat(" install");
2050 if(compiler.type.isVC)
2052 PrintLn("compiling a single file is not yet supported");
2057 char pushD[MAX_LOCATION];
2058 char cfDir[MAX_LOCATION];
2059 GetIDECompilerConfigsDir(cfDir, true, true);
2060 GetWorkingDir(pushD, sizeof(pushD));
2061 ChangeWorkingDir(topNode.path);
2062 // Create object dir if it does not exist already
2063 if(!FileExists(objDirExp.dir).isDirectory)
2065 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
2066 compiler.makeCommand, cfDir,
2067 crossCompiling ? " TARGET_PLATFORM=" : "",
2069 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2070 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
2072 compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
2074 ide.outputView.buildBox.Logf("%s\n", command);
2078 ChangeWorkingDir(pushD);
2080 for(node : onlyNodes)
2082 if(node.GetIsExcluded(config))
2083 ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
2087 node.DeleteIntermediateFiles(compiler, config, bitDepth, cfgNameCollisions, mode == cObject ? true : false);
2088 node.GetTargets(config, cfgNameCollisions, objDirExp.dir, makeTargets);
2094 if(compiler.type.isVC)
2096 bool result = false;
2097 char oldwd[MAX_LOCATION];
2098 GetWorkingDir(oldwd, sizeof(oldwd));
2099 ChangeWorkingDir(topNode.path);
2101 // TODO: support justPrint
2102 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2104 ide.outputView.buildBox.Logf("%s\n", command);
2105 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
2107 ProcessPipeOutputRaw(f);
2111 ChangeWorkingDir(oldwd);
2113 else if(onlyNodes && strlen(makeTargets) == 0)
2115 ide.outputView.buildBox.Log("No targets to compile.\n");
2119 char cfDir[MAX_LOCATION];
2120 GetIDECompilerConfigsDir(cfDir, true, true);
2121 sprintf(command, "%s%s %sCF_DIR=\"%s\"%s%s%s%s%s%s COMPILER=%s %s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
2122 #if defined(__WIN32__)
2125 buildType == install ? "pkexec --user root " : "",
2127 compiler.makeCommand,
2128 mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
2130 crossCompiling ? " TARGET_PLATFORM=" : "",
2132 bitDepth ? " ARCH=" : "",
2133 bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2134 ide.workspace.useValgrind ? " DISABLED_POOLING=1" : "",
2135 /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
2136 compilerName, eC_Debug ? "--always-make " : "", numJobs,
2137 (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
2138 (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
2139 (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
2141 ide.outputView.buildBox.Logf("%s\n", command);
2143 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2151 ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
2157 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2160 ide.outputView.buildBox.Logf("%s\n", line);
2161 if(!error && !found && strstr(line, "echo ") == line)
2163 strcpy(command, line+5);
2166 if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
2168 strcpy(command, line);
2178 result = ProcessPipeOutputRaw(f);
2180 result = ProcessBuildPipeOutput(f, objDirExp, buildType, onlyNodes, compiler, config, bitDepth);
2183 ide.outputView.buildBox.Logf("%s\n", command);
2184 else if(justPrint && found)
2185 ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
2190 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
2195 delete compilerName;
2200 void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint)
2202 char makeFile[MAX_LOCATION];
2203 char makeFilePath[MAX_LOCATION];
2204 char command[MAX_LOCATION];
2205 char * compilerName;
2207 PathBackup pathBackup { };
2208 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
2209 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2211 compilerName = CopyString(compiler.name);
2212 CamelCase(compilerName);
2214 SetPath(false, compiler, config, bitDepth);
2216 strcpy(makeFilePath, topNode.path);
2217 CatMakeFileName(makeFile, config);
2218 PathCatSlash(makeFilePath, makeFile);
2220 if(compiler.type.isVC)
2222 bool result = false;
2223 char oldwd[MAX_LOCATION];
2224 GetWorkingDir(oldwd, sizeof(oldwd));
2225 ChangeWorkingDir(topNode.path);
2227 // TODO: justPrint support
2228 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2230 ide.outputView.buildBox.Logf("%s\n", command);
2231 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2233 ProcessPipeOutputRaw(f);
2237 ChangeWorkingDir(oldwd);
2242 char cfDir[MAX_LOCATION];
2243 GetIDECompilerConfigsDir(cfDir, true, true);
2244 sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s %sclean%s -C \"%s\"%s -f \"%s\"",
2245 compiler.makeCommand, cfDir,
2246 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2247 bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2249 cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2250 topNode.path, justPrint ? " -n": "", makeFilePath);
2252 ide.outputView.buildBox.Logf("%s\n", command);
2253 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2255 ide.outputView.buildBox.Tellf($"Deleting %s%s...",
2256 cleanType == realClean ? $"intermediate objects directory" : $"target",
2257 cleanType == clean ? $" and object files" : "");
2259 ProcessPipeOutputRaw(f);
2261 ProcessCleanPipeOutput(f, compiler, config);
2262 ide.outputView.buildBox.Logf($"%s%s deleted\n",
2263 cleanType == realClean ? $"Intermediate objects directory" : $"Target",
2264 cleanType == clean ? $" and object files" : "");
2270 delete compilerName;
2273 void Run(char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2275 String target = new char[maxPathLen];
2276 char oldDirectory[MAX_LOCATION];
2277 char * executableLauncher = compiler.executableLauncher;
2278 DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2279 PathBackup pathBackup { };
2281 // Build(project, ideMain, true, null, false);
2283 strcpy(target, topNode.path);
2284 PathCatSlash(target, targetDirExp.dir);
2285 CatTargetFileName(target, compiler, config);
2286 sprintf(target, "%s %s", target, args);
2287 GetWorkingDir(oldDirectory, MAX_LOCATION);
2289 if(strlen(ide.workspace.debugDir))
2291 char temp[MAX_LOCATION];
2292 strcpy(temp, topNode.path);
2293 PathCatSlash(temp, ide.workspace.debugDir);
2294 ChangeWorkingDir(temp);
2297 ChangeWorkingDir(topNode.path);
2298 SetPath(true, compiler, config, bitDepth);
2299 if(executableLauncher)
2301 char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 8];
2302 prefixedTarget[0] = '\0';
2303 strcat(prefixedTarget, executableLauncher);
2304 strcat(prefixedTarget, " ");
2305 strcat(prefixedTarget, target);
2306 Execute(prefixedTarget);
2307 delete prefixedTarget;
2312 ChangeWorkingDir(oldDirectory);
2315 delete targetDirExp;
2319 bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2321 return Build(build, nodes, compiler, config, bitDepth, justPrint, mode);
2325 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2328 if(targetType == staticLibrary || targetType == sharedLibrary)
2329 strcat(fileName, "$(LP)");
2330 strcat(fileName, GetTargetFileName(config));
2334 strcat(fileName, "$(E)");
2337 strcat(fileName, "$(SO)$(VER)");
2340 strcat(fileName, "$(A)");
2345 bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2347 bool result = false;
2348 char path[MAX_LOCATION];
2350 if(!GetProjectCompilerConfigsDir(path, false, false))
2351 GetIDECompilerConfigsDir(path, false, false);
2353 if(!FileExists(path).isDirectory)
2357 char dirName[MAX_FILENAME];
2358 GetLastDirectory(path, dirName);
2359 if(!strcmp(dirName, ".configs"))
2360 FileSetAttribs(path, FileAttribs { isHidden = true });
2363 PathCatSlash(path, "crossplatform.mk");
2365 if(FileExists(path))
2368 File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2371 File f = FileOpen(path, write);
2374 include.Seek(0, start);
2375 for(; !include.Eof(); )
2378 int count = include.Read(buffer, 1, 4096);
2379 f.Write(buffer, 1, count);
2385 if(!altCrossPlatformMk)
2392 bool GenerateCompilerCf(CompilerConfig compiler)
2394 bool result = false;
2395 char path[MAX_LOCATION];
2397 char * compilerName;
2398 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2399 char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2400 Platform platform = compiler.targetPlatform;
2402 compilerName = CopyString(compiler.name);
2403 CamelCase(compilerName);
2404 name = PrintString(platform, "-", compilerName, ".cf");
2406 if(!GetProjectCompilerConfigsDir(path, false, false))
2407 GetIDECompilerConfigsDir(path, false, false);
2409 if(!FileExists(path).isDirectory)
2413 char dirName[MAX_FILENAME];
2414 GetLastDirectory(path, dirName);
2415 if(!strcmp(dirName, ".configs"))
2416 FileSetAttribs(path, FileAttribs { isHidden = true });
2419 PathCatSlash(path, name);
2421 if(FileExists(path))
2424 File f = FileOpen(path, write);
2427 if(compiler.environmentVars && compiler.environmentVars.count)
2429 f.Puts("# ENVIRONMENT VARIABLES\n");
2431 for(e : compiler.environmentVars)
2433 f.Printf("export %s := %s\n", e.name, e.string);
2438 f.Puts("# TOOLCHAIN\n");
2441 if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2443 f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2446 if(compiler.sysroot && compiler.sysroot[0])
2448 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2449 // Moved this to crossplatform.mk
2450 //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2454 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2455 f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2456 f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.ccCommand);
2457 f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cxxCommand);
2458 f.Printf("ECP := $(if $(ECP_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecp/ecp.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)\n", compiler.ecpCommand);
2459 f.Printf("ECC := $(if $(ECC_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecc/ecc.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.eccCommand);
2460 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);
2461 f.Printf("EAR := %s\n", compiler.earCommand);
2463 f.Puts("AS := $(GCC_PREFIX)as\n");
2464 f.Puts("LD := $(GCC_PREFIX)ld\n");
2465 f.Puts("AR := $(GCC_PREFIX)ar\n");
2466 f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2467 f.Puts("ifdef WINDOWS_TARGET\n");
2468 f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
2469 f.Puts(" ifdef ARCH\n");
2470 f.Puts(" ifeq \"$(ARCH)\" \"x32\"\n");
2471 f.Puts("WINDRES_FLAGS := -F pe-i386\n");
2473 f.Puts(" ifeq \"$(ARCH)\" \"x64\"\n");
2474 f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
2479 f.Puts("UPX := upx\n");
2482 f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2485 f.Puts("EARFLAGS = \n");
2488 f.Puts("ifndef ARCH\n");
2489 f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2490 f.Puts(" ifdef WINDOWS_HOST\n");
2491 f.Puts(" ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2492 f.Puts(" TARGET_ARCH := x86_64\n");
2494 f.Puts(" TARGET_ARCH := i386\n");
2497 f.Puts("endif\n\n");
2499 f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2500 f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2504 f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2508 f.Puts("\nCFLAGS += -fmessage-length=0\n");
2511 if(compiler.includeDirs && compiler.includeDirs.count)
2513 f.Puts("\nCFLAGS +=");
2514 OutputFlags(f, gccCompiler ? _isystem : _I, compiler.includeDirs, lineEach);
2517 if(compiler.prepDirectives && compiler.prepDirectives.count)
2519 f.Puts("\nCFLAGS +=");
2520 OutputFlags(f, _D, compiler.prepDirectives, inPlace);
2523 if(compiler.libraryDirs && compiler.libraryDirs.count)
2525 f.Puts("\nLDFLAGS +=");
2526 OutputFlags(f, _L, compiler.libraryDirs, lineEach);
2527 // We would need a bool option to know whether we want to add to rpath as well...
2528 // OutputFlags(f, _Wl-rpath, compiler.libraryDirs, lineEach);
2531 if(compiler.excludeLibs && compiler.excludeLibs.count)
2533 f.Puts("\nEXCLUDED_LIBS =");
2534 for(l : compiler.excludeLibs)
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,
2924 cflagsVariations, nodeCFlagsMapping,
2925 ecflagsVariations, nodeECFlagsMapping, null);
2927 GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
2928 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2930 if(platforms || (config && config.platforms))
2933 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2934 //for(platform = win32; platform <= apple; platform++)
2936 f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
2937 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2939 PlatformOptions projectPlatformOptions, configPlatformOptions;
2940 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2942 if(projectPlatformOptions || configPlatformOptions)
2947 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2950 if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
2951 (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
2953 f.Puts("CFLAGS +=");
2954 if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
2957 for(s : projectPlatformOptions.options.compilerOptions)
2960 if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
2963 for(s : configPlatformOptions.options.compilerOptions)
2970 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
2971 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
2973 f.Puts("OFLAGS +=");
2974 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2976 bool needWl = false;
2978 for(s : projectPlatformOptions.options.linkerOptions)
2980 if(!IsLinkerOption(s))
2988 for(s : projectPlatformOptions.options.linkerOptions)
2989 if(IsLinkerOption(s))
2993 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2995 bool needWl = false;
2997 for(s : configPlatformOptions.options.linkerOptions)
2999 if(IsLinkerOption(s))
3007 for(s : configPlatformOptions.options.linkerOptions)
3008 if(!IsLinkerOption(s))
3016 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3017 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
3018 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
3019 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
3021 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3022 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
3023 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
3025 f.Puts("OFLAGS +=");
3026 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
3027 OutputFlags(f, _L, configPlatformOptions.options.libraryDirs, lineEach);
3028 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
3029 OutputFlags(f, _L, projectPlatformOptions.options.libraryDirs, lineEach);
3033 if(configPlatformOptions && configPlatformOptions.options.libraries)
3035 if(configPlatformOptions.options.libraries.count)
3038 OutputLibraries(f, configPlatformOptions.options.libraries);
3042 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
3044 if(projectPlatformOptions.options.libraries.count)
3047 OutputLibraries(f, projectPlatformOptions.options.libraries);
3058 for(c = 0; c < ifCount; c++)
3064 if((config && config.options && config.options.compilerOptions && config.options.compilerOptions.count) ||
3065 (options && options.compilerOptions && options.compilerOptions.count))
3067 f.Puts("CFLAGS +=");
3070 if(config && config.options && config.options.compilerOptions && config.options.compilerOptions.count)
3072 for(s : config.options.compilerOptions)
3075 if(options && options.compilerOptions && options.compilerOptions.count)
3077 for(s : options.compilerOptions)
3084 if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
3085 (options && options.linkerOptions && options.linkerOptions.count))
3087 f.Puts("OFLAGS +=");
3090 if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
3092 bool needWl = false;
3093 for(s : config.options.linkerOptions)
3095 if(!IsLinkerOption(s))
3103 for(s : config.options.linkerOptions)
3104 if(IsLinkerOption(s))
3108 if(options && options.linkerOptions && options.linkerOptions.count)
3110 bool needWl = false;
3111 for(s : options.linkerOptions)
3113 if(!IsLinkerOption(s))
3121 for(s : options.linkerOptions)
3122 if(IsLinkerOption(s))
3130 f.Puts("CECFLAGS += -cpp $(_CPP)");
3134 if(GetProfile(config))
3135 f.Puts("OFLAGS += -pg\n\n");
3137 if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
3139 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3140 f.Puts("OFLAGS +=");
3141 if(config && config.options && config.options.libraryDirs)
3142 OutputFlags(f, _L, config.options.libraryDirs, lineEach);
3143 if(options && options.libraryDirs)
3144 OutputFlags(f, _L, options.libraryDirs, lineEach);
3150 f.Puts("# TARGETS\n");
3153 f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3156 f.Puts("objdir:\n");
3158 f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
3160 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");
3161 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");
3162 //f.Puts("# PRE-BUILD COMMANDS\n");
3163 if(options && options.prebuildCommands)
3165 for(s : options.prebuildCommands)
3166 if(s && s[0]) f.Printf("\t%s\n", s);
3168 if(config && config.options && config.options.prebuildCommands)
3170 for(s : config.options.prebuildCommands)
3171 if(s && s[0]) f.Printf("\t%s\n", s);
3173 if(platforms || (config && config.platforms))
3176 //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
3177 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3179 PlatformOptions projectPOs, configPOs;
3180 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3182 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
3183 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
3188 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3190 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
3192 for(s : projectPOs.options.prebuildCommands)
3193 if(s && s[0]) f.Printf("\t%s\n", s);
3195 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
3197 for(s : configPOs.options.prebuildCommands)
3198 if(s && s[0]) f.Printf("\t%s\n", s);
3205 for(c = 0; c < ifCount; c++)
3211 if(!sameOrRelObjTargetDirs)
3213 f.Puts("targetdir:\n");
3214 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
3220 // Main Module (Linking) for ECERE C modules
3221 f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
3222 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
3223 f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(call quote_path,$@)\n",
3224 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
3226 // Main Module (Linking) for ECERE C modules
3227 f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
3228 f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
3229 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
3230 f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
3231 " -c $(OBJ)$(MODULE).main.ec -o $(call quote_path,$@) -symbols $(OBJ)\n");
3237 // This would not rebuild the target on updated objects
3238 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3240 // This should fix it for good!
3241 f.Puts("$(SYMBOLS): | objdir\n");
3242 f.Puts("$(OBJECTS): | objdir\n");
3244 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
3245 f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
3246 rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
3248 f.Printf("\t@$(call rmq,$(OBJ)linkobjects.lst)\n");
3249 f.Printf("\t@$(call touch,$(OBJ)linkobjects.lst)\n");
3250 OutputLinkObjectActions(f, "_OBJECTS", objectsParts);
3253 f.Puts("ifdef WINDOWS_TARGET\n");
3254 OutputLinkObjectActions(f, "RCOBJECTS", rcSourcesParts);
3259 f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)linkobjects.lst\n");
3260 OutputLinkObjectActions(f, "ECOBJECTS", eCsourcesParts);
3263 f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3265 f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)linkobjects.lst $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
3266 if(!GetDebug(config))
3268 f.Puts("ifndef NOSTRIP\n");
3269 f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
3272 if(GetCompress(config))
3274 f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
3275 f.Puts("ifdef EXECUTABLE_TARGET\n");
3276 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3279 f.Puts("ifneq \"$(TARGET_ARCH)\" \"x86_64\"\n");
3280 f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3285 if(resNode.files && resNode.files.count && !noResources)
3286 resNode.GenMakefileAddResources(f, resNode.path, config);
3288 f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)linkobjects.lst $(LIBS)\n");
3290 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3291 f.Puts("ifdef LINUX_TARGET\n");
3292 f.Puts("ifdef LINUX_HOST\n");
3293 // TODO?: support symlinks for longer version numbers
3294 f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
3295 f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
3300 //f.Puts("# POST-BUILD COMMANDS\n");
3301 if(options && options.postbuildCommands)
3303 for(s : options.postbuildCommands)
3304 if(s && s[0]) f.Printf("\t%s\n", s);
3306 if(config && config.options && config.options.postbuildCommands)
3308 for(s : config.options.postbuildCommands)
3309 if(s && s[0]) f.Printf("\t%s\n", s);
3311 if(platforms || (config && config.platforms))
3314 //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
3315 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3317 PlatformOptions projectPOs, configPOs;
3318 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3320 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
3321 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
3326 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3328 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
3330 for(s : projectPOs.options.postbuildCommands)
3331 if(s && s[0]) f.Printf("\t%s\n", s);
3333 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
3335 for(s : configPOs.options.postbuildCommands)
3336 if(s && s[0]) f.Printf("\t%s\n", s);
3343 for(c = 0; c < ifCount; c++)
3350 if(platforms || (config && config.platforms))
3352 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3354 PlatformOptions projectPOs, configPOs;
3355 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3357 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3358 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3365 if(test || (options && options.installCommands) ||
3366 (config && config.options && config.options.installCommands))
3368 f.Puts("install:\n");
3369 if(options && options.installCommands)
3371 for(s : options.installCommands)
3372 if(s && s[0]) f.Printf("\t%s\n", s);
3374 if(config && config.options && config.options.installCommands)
3376 for(s : config.options.installCommands)
3377 if(s && s[0]) f.Printf("\t%s\n", s);
3379 if(platforms || (config && config.platforms))
3382 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3384 PlatformOptions projectPOs, configPOs;
3385 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3387 if((projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count) ||
3388 (configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count))
3393 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3395 if(projectPOs && projectPOs.options.installCommands && projectPOs.options.installCommands.count)
3397 for(s : projectPOs.options.installCommands)
3398 if(s && s[0]) f.Printf("\t%s\n", s);
3400 if(configPOs && configPOs.options.installCommands && configPOs.options.installCommands.count)
3402 for(s : configPOs.options.installCommands)
3403 if(s && s[0]) f.Printf("\t%s\n", s);
3410 for(c = 0; c < ifCount; c++)
3417 f.Puts("# SYMBOL RULES\n");
3420 topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3422 f.Puts("# C OBJECT RULES\n");
3425 topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3427 f.Puts("# OBJECT RULES\n");
3429 // todo call this still but only generate rules whith specific options
3430 // see we-have-file-specific-options in ProjectNode.ec
3431 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
3434 GenMakefilePrintMainObjectRule(f, config);
3436 f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3437 f.Puts("\t$(call rmq,$(TARGET))\n");
3439 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)");
3440 f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3441 f.Puts("ifdef LINUX_TARGET\n");
3442 f.Puts("ifdef LINUX_HOST\n");
3443 // TODO?: support symlinks for longer version numbers
3444 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
3445 f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
3451 f.Puts("clean: cleantarget\n");
3452 f.Printf("\t$(call rmq,$(OBJ)linkobjects.lst)\n");
3453 OutputCleanActions(f, "OBJECTS", objectsParts);
3456 f.Puts("ifdef WINDOWS_TARGET\n");
3457 OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
3462 OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3463 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3464 OutputCleanActions(f, "BOWLS", eCsourcesParts);
3465 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3466 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3470 f.Puts("realclean: cleantarget\n");
3471 f.Puts("\t$(call rmrq,$(OBJ))\n");
3472 if(!sameOrRelObjTargetDirs)
3473 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3476 f.Puts("distclean: cleantarget\n");
3477 if(!sameOrRelObjTargetDirs)
3478 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3480 f.Puts("\t$(call rmrq,obj/)\n");
3486 varStringLenDiffs.Free();
3487 delete varStringLenDiffs;
3491 delete cflagsVariations;
3492 delete nodeCFlagsMapping;
3493 delete ecflagsVariations;
3494 delete nodeECFlagsMapping;
3499 // ChangeWorkingDir(oldDirectory);
3500 // delete pathBackup;
3503 config.makingModified = false;
3507 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3509 char extension[MAX_EXTENSION] = "c";
3510 char modulePath[MAX_LOCATION];
3511 char fixedModuleName[MAX_FILENAME];
3514 char objDirNoSpaces[MAX_LOCATION];
3515 String objDirExp = GetObjDirExpression(config);
3517 ReplaceSpaces(objDirNoSpaces, objDirExp);
3518 ReplaceSpaces(fixedModuleName, moduleName);
3520 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3521 //strcat(fixedModuleName, ".main");
3523 #if 0 // TODO: Fix nospaces stuff
3524 // *** Dependency command ***
3525 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3527 // System Includes (from global settings)
3528 for(item : compiler.dirs[Includes])
3530 strcat(command, " -isystem ");
3531 if(strchr(item.name, ' '))
3533 strcat(command, "\"");
3534 strcat(command, item);
3535 strcat(command, "\"");
3538 strcat(command, item);
3541 for(item = includeDirs.first; item; item = item.next)
3543 strcat(command, " -I");
3544 if(strchr(item.name, ' '))
3546 strcat(command, "\"");
3547 strcat(command, item.name);
3548 strcat(command, "\"");
3551 strcat(command, item.name);
3553 for(item = preprocessorDefs.first; item; item = item.next)
3555 strcat(command, " -D");
3556 strcat(command, item.name);
3560 if((dep = DualPipeOpen(PipeOpenMode { output = true, error = true/*, input = true*/ }, command)))
3564 bool firstLine = true;
3566 // To do some time: auto save external dependencies?
3569 if(dep.GetLine(line, sizeof(line)-1))
3573 char * colon = strstr(line, ":");
3574 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3588 // If we failed to generate dependencies...
3592 f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3593 f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(call quote_path,$@)\n", extension);
3601 void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3604 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3606 for(v : cflagsVariations)
3611 f.Printf("%s +=", variableName);
3613 f.Printf("CUSTOM%d_%s =", v-1, variableName);
3614 f.Puts(&v ? &v : "");
3622 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3623 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3625 *projectPlatformOptions = null;
3626 *configPlatformOptions = null;
3631 if(!strcmpi(p.name, platform))
3633 *projectPlatformOptions = p;
3638 if(config && config.platforms)
3640 for(p : config.platforms)
3642 if(!strcmpi(p.name, platform))
3644 *configPlatformOptions = p;
3652 static inline void ProjectLoadLastBuildNamesInfo(Project prj, ProjectConfig cfg)
3654 char * cfgName = cfg ? cfg.name : "";
3655 Map<String, NameCollisionInfo> cfgNameCollisions = prj.configsNameCollisions[cfgName];
3656 if(cfgNameCollisions)
3658 cfgNameCollisions.Free();
3659 delete cfgNameCollisions;
3661 prj.configsNameCollisions[cfgName] = cfgNameCollisions = { };
3662 prj.topNode.GenMakefileGetNameCollisionInfo(cfgNameCollisions, cfg);
3665 Project LegacyBinaryLoadProject(File f, char * filePath)
3667 Project project = null;
3668 char signature[sizeof(epjSignature)];
3670 f.Read(signature, sizeof(signature), 1);
3671 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3673 char topNodePath[MAX_LOCATION];
3674 /*ProjectConfig newConfig
3676 name = CopyString("Default");
3677 makingModified = true;
3678 compilingModified = true;
3679 linkingModified = true;
3683 project = Project { options = { } };
3684 LegacyBinaryLoadNode(project.topNode, f);
3685 delete project.topNode.path;
3686 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3687 MakeSlashPath(topNodePath);
3689 PathCatSlash(topNodePath, filePath);
3690 project.filePath = topNodePath;
3692 /* THIS IS ALREADY DONE BY filePath property
3693 StripLastDirectory(topNodePath, topNodePath);
3694 project.topNode.path = CopyString(topNodePath);
3696 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3698 // newConfig.options.defaultNameSpace = "";
3699 /*newConfig.objDir.dir = "obj";
3700 newConfig.targetDir.dir = "";*/
3702 //project.configurations = { [ newConfig ] };
3703 //project.config = newConfig;
3710 String targetFileName, targetDirectory, objectsDirectory;
3712 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3713 f.Read(&temp, sizeof(int),1);
3716 case 0: project.options.targetType = executable; break;
3717 case 1: project.options.targetType = sharedLibrary; break;
3718 case 2: project.options.targetType = staticLibrary; break;
3721 f.Read(&len, sizeof(int),1);
3722 targetFileName = new char[len+1];
3723 f.Read(targetFileName, sizeof(char), len+1);
3724 project.options.targetFileName = targetFileName;
3725 delete targetFileName;
3727 f.Read(&len, sizeof(int),1);
3728 targetDirectory = new char[len+1];
3729 f.Read(targetDirectory, sizeof(char), len+1);
3730 project.options.targetDirectory = targetDirectory;
3731 delete targetDirectory;
3733 f.Read(&len, sizeof(int),1);
3734 objectsDirectory = new byte[len+1];
3735 f.Read(objectsDirectory, sizeof(char), len+1);
3736 project.options.objectsDirectory = objectsDirectory;
3737 delete objectsDirectory;
3739 f.Read(&temp, sizeof(int),1);
3740 project./*config.*/options.debug = temp ? true : false;
3741 f.Read(&temp, sizeof(int),1);
3742 project./*config.*/options.optimization = temp ? speed : none;
3743 f.Read(&temp, sizeof(int),1);
3744 project./*config.*/options.profile = temp ? true : false;
3745 f.Read(&temp, sizeof(int),1);
3746 project.options.warnings = temp ? all : unset;
3748 f.Read(&count, sizeof(int),1);
3751 project.options.includeDirs = { };
3752 for(c = 0; c < count; c++)
3755 f.Read(&len, sizeof(int),1);
3756 name = new char[len+1];
3757 f.Read(name, sizeof(char), len+1);
3758 project.options.includeDirs.Add(name);
3762 f.Read(&count, sizeof(int),1);
3765 project.options.libraryDirs = { };
3766 for(c = 0; c < count; c++)
3769 f.Read(&len, sizeof(int),1);
3770 name = new char[len+1];
3771 f.Read(name, sizeof(char), len+1);
3772 project.options.libraryDirs.Add(name);
3776 f.Read(&count, sizeof(int),1);
3779 project.options.libraries = { };
3780 for(c = 0; c < count; c++)
3783 f.Read(&len, sizeof(int),1);
3784 name = new char[len+1];
3785 f.Read(name, sizeof(char), len+1);
3786 project.options.libraries.Add(name);
3790 f.Read(&count, sizeof(int),1);
3793 project.options.preprocessorDefinitions = { };
3794 for(c = 0; c < count; c++)
3797 f.Read(&len, sizeof(int),1);
3798 name = new char[len+1];
3799 f.Read(name, sizeof(char), len+1);
3800 project.options.preprocessorDefinitions.Add(name);
3804 f.Read(&temp, sizeof(int),1);
3805 project.options.console = temp ? true : false;
3808 for(node : project.topNode.files)
3810 if(node.type == resources)
3812 project.resNode = node;
3822 void ProjectConfig::LegacyProjectConfigLoad(File f)
3830 char subSection[128];
3836 f.GetLine(buffer, 65536 - 1);
3837 TrimLSpaces(buffer, buffer);
3838 TrimRSpaces(buffer, buffer);
3841 if(buffer[0] == '-')
3845 TrimLSpaces(equal, equal);
3846 if(!strcmpi(subSection, "LibraryDirs"))
3848 if(!options.libraryDirs)
3849 options.libraryDirs = { [ CopyString(equal) ] };
3851 options.libraryDirs.Add(CopyString(equal));
3853 else if(!strcmpi(subSection, "IncludeDirs"))
3855 if(!options.includeDirs)
3856 options.includeDirs = { [ CopyString(equal) ] };
3858 options.includeDirs.Add(CopyString(equal));
3861 else if(buffer[0] == '+')
3872 TrimLSpaces(equal, equal);
3873 delete name; name = CopyString(equal); // property::name = equal;
3876 else if(!strcmpi(buffer, "Compiler Options"))
3877 strcpy(section, buffer);
3878 else if(!strcmpi(buffer, "IncludeDirs"))
3879 strcpy(subSection, buffer);
3880 else if(!strcmpi(buffer, "Linker Options"))
3881 strcpy(section, buffer);
3882 else if(!strcmpi(buffer, "LibraryDirs"))
3883 strcpy(subSection, buffer);
3884 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3891 equal = strstr(buffer, "=");
3895 TrimRSpaces(buffer, buffer);
3897 TrimLSpaces(equal, equal);
3898 if(!strcmpi(buffer, "Target Name"))
3899 options.targetFileName = /*CopyString(*/equal/*)*/;
3900 else if(!strcmpi(buffer, "Target Type"))
3902 if(!strcmpi(equal, "Executable"))
3903 options.targetType = executable;
3904 else if(!strcmpi(equal, "Shared"))
3905 options.targetType = sharedLibrary;
3906 else if(!strcmpi(equal, "Static"))
3907 options.targetType = staticLibrary;
3909 options.targetType = executable;
3911 else if(!strcmpi(buffer, "Target Directory"))
3912 options.targetDirectory = /*CopyString(*/equal/*)*/;
3913 else if(!strcmpi(buffer, "Console"))
3914 options.console = ParseTrueFalseValue(equal);
3915 else if(!strcmpi(buffer, "Libraries"))
3917 if(!options.libraries) options.libraries = { };
3918 ParseArrayValue(options.libraries, equal);
3920 else if(!strcmpi(buffer, "Intermediate Directory"))
3921 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3922 else if(!strcmpi(buffer, "Debug"))
3923 options.debug = ParseTrueFalseValue(equal);
3924 else if(!strcmpi(buffer, "Optimize"))
3926 if(!strcmpi(equal, "None"))
3927 options.optimization = none;
3928 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3929 options.optimization = speed;
3930 else if(!strcmpi(equal, "Size"))
3931 options.optimization = size;
3933 options.optimization = none;
3935 else if(!strcmpi(buffer, "Compress"))
3936 options.compress = ParseTrueFalseValue(equal);
3937 else if(!strcmpi(buffer, "Profile"))
3938 options.profile = ParseTrueFalseValue(equal);
3939 else if(!strcmpi(buffer, "AllWarnings"))
3940 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3941 else if(!strcmpi(buffer, "MemoryGuard"))
3942 options.memoryGuard = ParseTrueFalseValue(equal);
3943 else if(!strcmpi(buffer, "Default Name Space"))
3944 options.defaultNameSpace = CopyString(equal);
3945 else if(!strcmpi(buffer, "Strict Name Spaces"))
3946 options.strictNameSpaces = ParseTrueFalseValue(equal);
3947 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3949 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3950 ParseArrayValue(options.preprocessorDefinitions, equal);
3956 if(!options.targetDirectory && options.objectsDirectory)
3957 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3958 //if(!objDir.dir) objDir.dir = "obj";
3959 //if(!targetDir.dir) targetDir.dir = "";
3960 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3961 // if(!defaultNameSpace) property::defaultNameSpace = "";
3962 makingModified = true;
3965 Project LegacyAsciiLoadProject(File f, char * filePath)
3967 Project project = null;
3968 ProjectNode node = null;
3970 char parentPath[MAX_LOCATION];
3971 char section[128] = "";
3972 char subSection[128] = "";
3974 bool configurationsPresent = false;
3984 f.GetLine(buffer, 65536 - 1);
3985 TrimLSpaces(buffer, buffer);
3986 TrimRSpaces(buffer, buffer);
3989 if(buffer[0] == '-' || buffer[0] == '=')
3991 bool simple = buffer[0] == '-';
3994 TrimLSpaces(equal, equal);
3995 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3997 if(!project.config.options.libraryDirs)
3998 project.config.options.libraryDirs = { [ CopyString(equal) ] };
4000 project.config.options.libraryDirs.Add(CopyString(equal));
4002 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
4004 if(!project.config.options.includeDirs)
4005 project.config.options.includeDirs = { [ CopyString(equal) ] };
4007 project.config.options.includeDirs.Add(CopyString(equal));
4009 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4011 len = strlen(equal);
4014 char temp[MAX_LOCATION];
4015 ProjectNode child { };
4016 // We don't need to do this anymore, fileName is just a property that sets name & path
4017 // child.fileName = CopyString(equal);
4020 child.name = CopyString(equal);
4021 child.path = CopyString(parentPath);
4025 GetLastDirectory(equal, temp);
4026 child.name = CopyString(temp);
4027 StripLastDirectory(equal, temp);
4028 child.path = CopyString(temp);
4030 child.nodeType = file;
4031 child.parent = parent;
4032 child.indent = parent.indent + 1;
4034 child.icon = NodeIcons::SelectFileIcon(child.name);
4035 parent.files.Add(child);
4041 StripLastDirectory(parentPath, parentPath);
4042 parent = parent.parent;
4046 else if(buffer[0] == '+')
4050 TrimLSpaces(equal, equal);
4051 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
4053 char temp[MAX_LOCATION];
4054 ProjectNode child { };
4055 // NEW: Folders now have a path set like files
4056 child.name = CopyString(equal);
4057 strcpy(temp, parentPath);
4058 PathCatSlash(temp, child.name);
4059 child.path = CopyString(temp);
4061 child.parent = parent;
4062 child.indent = parent.indent + 1;
4063 child.type = folder;
4064 child.nodeType = folder;
4066 child.icon = folder;
4067 PathCatSlash(parentPath, child.name);
4068 parent.files.Add(child);
4073 else if(!strcmpi(section, "Configurations"))
4075 ProjectConfig newConfig
4077 makingModified = true;
4081 LegacyProjectConfigLoad(newConfig, f);
4082 project.configurations.Add(newConfig);
4085 else if(!strcmpi(buffer, "ECERE Project File"));
4086 else if(!strcmpi(buffer, "Version 0a"))
4087 ; //strcpy(version, "0a");
4088 else if(!strcmpi(buffer, "Version 0.1a"))
4089 ; //strcpy(version, "0.1a");
4090 else if(!strcmpi(buffer, "Configurations"))
4092 project.configurations.Free();
4093 project.config = null;
4094 strcpy(section, buffer);
4095 configurationsPresent = true;
4097 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
4099 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
4100 char topNodePath[MAX_LOCATION];
4101 // newConfig.defaultNameSpace = "";
4102 //newConfig.objDir.dir = "obj";
4103 //newConfig.targetDir.dir = "";
4104 project = Project { /*options = { }*/ };
4105 project.configurations = { [ newConfig ] };
4106 project.config = newConfig;
4107 // if(project.topNode.path) delete project.topNode.path;
4108 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4109 MakeSlashPath(topNodePath);
4110 PathCatSlash(topNodePath, filePath);
4111 project.filePath = topNodePath;
4112 parentPath[0] = '\0';
4113 parent = project.topNode;
4115 strcpy(section, "Target");
4120 if(equal[0] == '\"')
4122 StripQuotes(equal, equal);
4123 delete project.moduleName; project.moduleName = CopyString(equal);
4127 else if(!strcmpi(buffer, "Compiler Options"));
4128 else if(!strcmpi(buffer, "IncludeDirs"))
4129 strcpy(subSection, buffer);
4130 else if(!strcmpi(buffer, "Linker Options"));
4131 else if(!strcmpi(buffer, "LibraryDirs"))
4132 strcpy(subSection, buffer);
4133 else if(!strcmpi(buffer, "Files"))
4135 strcpy(section, "Target");
4136 strcpy(subSection, buffer);
4138 else if(!strcmpi(buffer, "Resources"))
4140 ProjectNode child { };
4141 parent.files.Add(child);
4142 child.parent = parent;
4143 child.indent = parent.indent + 1;
4144 child.name = CopyString(buffer);
4145 child.path = CopyString("");
4146 child.type = resources;
4148 child.icon = archiveFile;
4149 project.resNode = child;
4152 strcpy(subSection, buffer);
4156 equal = strstr(buffer, "=");
4160 TrimRSpaces(buffer, buffer);
4162 TrimLSpaces(equal, equal);
4164 if(!strcmpi(section, "Target"))
4166 if(!strcmpi(buffer, "Build Exclusions"))
4168 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4170 /*if(node && node.type != NodeTypes::project)
4171 ParseListValue(node.buildExclusions, equal);*/
4174 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
4176 delete project.resNode.path;
4177 project.resNode.path = CopyString(equal);
4178 PathCatSlash(parentPath, equal);
4182 else if(!strcmpi(buffer, "Intermediate Directory"))
4183 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4184 else if(!strcmpi(buffer, "Debug"))
4185 project.config.options.debug = ParseTrueFalseValue(equal);
4186 else if(!strcmpi(buffer, "Optimize"))
4188 if(!strcmpi(equal, "None"))
4189 project.config.options.optimization = none;
4190 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4191 project.config.options.optimization = speed;
4192 else if(!strcmpi(equal, "Size"))
4193 project.config.options.optimization = size;
4195 project.config.options.optimization = none;
4197 else if(!strcmpi(buffer, "Profile"))
4198 project.config.options.profile = ParseTrueFalseValue(equal);
4199 else if(!strcmpi(buffer, "MemoryGuard"))
4200 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
4203 if(!project.options) project.options = { };
4205 // Project Wide Settings (All configs)
4206 if(!strcmpi(buffer, "Target Name"))
4207 project.options.targetFileName = /*CopyString(*/equal/*)*/;
4208 else if(!strcmpi(buffer, "Target Type"))
4210 if(!strcmpi(equal, "Executable"))
4211 project.options.targetType = executable;
4212 else if(!strcmpi(equal, "Shared"))
4213 project.options.targetType = sharedLibrary;
4214 else if(!strcmpi(equal, "Static"))
4215 project.options.targetType = staticLibrary;
4217 project.options.targetType = executable;
4219 else if(!strcmpi(buffer, "Target Directory"))
4220 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
4221 else if(!strcmpi(buffer, "Console"))
4222 project.options.console = ParseTrueFalseValue(equal);
4223 else if(!strcmpi(buffer, "Libraries"))
4225 if(!project.options.libraries) project.options.libraries = { };
4226 ParseArrayValue(project.options.libraries, equal);
4228 else if(!strcmpi(buffer, "AllWarnings"))
4229 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4230 else if(!strcmpi(buffer, "Preprocessor Definitions"))
4232 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4234 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
4235 ParseListValue(node.preprocessorDefs, equal);*/
4239 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
4240 ParseArrayValue(project.options.preprocessorDefinitions, equal);
4251 SplitPlatformLibraries(project);
4253 if(configurationsPresent)
4254 CombineIdenticalConfigOptions(project);
4258 void SplitPlatformLibraries(Project project)
4260 if(project && project.configurations)
4262 for(cfg : project.configurations)
4264 if(cfg.options.libraries && cfg.options.libraries.count)
4266 Iterator<String> it { cfg.options.libraries };
4270 char * platformName = strstr(l, ":");
4273 PlatformOptions platform = null;
4275 if(!cfg.platforms) cfg.platforms = { };
4276 for(p : cfg.platforms)
4278 if(!strcmpi(platformName, p.name))
4286 platform = { name = CopyString(platformName), options = { libraries = { } } };
4287 cfg.platforms.Add(platform);
4289 *(platformName-1) = 0;
4290 platform.options.libraries.Add(CopyString(l));
4292 cfg.options.libraries.Delete(it.pointer);
4301 void CombineIdenticalConfigOptions(Project project)
4303 if(project && project.configurations && project.configurations.count)
4306 ProjectOptions nullOptions { };
4307 ProjectConfig firstConfig = null;
4308 for(cfg : project.configurations)
4310 if(cfg.options.targetType != staticLibrary)
4317 firstConfig = project.configurations.firstIterator.data;
4319 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
4321 if(!member.isProperty)
4323 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
4328 for(cfg : project.configurations)
4330 if(cfg != firstConfig)
4332 if(cfg.options.targetType != staticLibrary)
4336 if(type.type == noHeadClass || type.type == normalClass)
4338 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4339 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4340 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4344 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4345 (byte *)firstConfig.options + member.offset + member._class.offset,
4346 (byte *)cfg.options + member.offset + member._class.offset);
4358 if(type.type == noHeadClass || type.type == normalClass)
4360 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4361 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4362 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
4367 if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4368 (byte *)firstConfig.options + member.offset + member._class.offset,
4369 (byte *)nullOptions + member.offset + member._class.offset))
4373 if(!project.options) project.options = { };
4375 /*if(type.type == noHeadClass || type.type == normalClass)
4377 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4378 (byte *)project.options + member.offset + member._class.offset,
4379 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
4383 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
4384 // TOFIX: ListBox::SetData / OnCopy mess
4385 ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type,
4386 (byte *)project.options + member.offset + member._class.offset,
4387 (type.typeSize > 4) ? address :
4388 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
4389 ((type.typeSize == 2) ? (void *)*(uint16*)address :
4390 (void *)*(byte *)address )));
4393 (byte *)project.options + member.offset + member._class.offset,
4394 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
4396 for(cfg : project.configurations)
4398 if(cfg.options.targetType == staticLibrary)
4402 if(type.type == noHeadClass || type.type == normalClass)
4404 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4405 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4406 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4410 result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type,
4411 (byte *)firstConfig.options + member.offset + member._class.offset,
4412 (byte *)cfg.options + member.offset + member._class.offset);
4417 if(cfg != firstConfig)
4419 if(type.type == noHeadClass || type.type == normalClass)
4421 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4422 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4426 ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type,
4427 (byte *)cfg.options + member.offset + member._class.offset);
4429 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
4432 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
4439 // Compare Platform Specific Settings
4442 for(cfg : project.configurations)
4444 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
4445 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
4451 if(same && firstConfig.platforms)
4453 for(cfg : project.configurations)
4455 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
4457 if(cfg != firstConfig)
4459 cfg.platforms.Free();
4460 delete cfg.platforms;
4463 project.platforms = firstConfig.platforms;
4464 firstConfig.platforms = null;
4468 // Static libraries can't contain libraries
4469 for(cfg : project.configurations)
4471 if(cfg.options.targetType == staticLibrary)
4473 if(!cfg.options.libraries) cfg.options.libraries = { };
4474 cfg.options.libraries.Free();
4480 Project LoadProject(char * filePath, char * activeConfigName)
4482 Project project = null;
4483 File f = FileOpen(filePath, read);
4486 project = LegacyBinaryLoadProject(f, filePath);
4489 JSONParser parser { f = f };
4490 JSONResult result = parser.GetObject(class(Project), &project);
4493 char insidePath[MAX_LOCATION];
4495 delete project.topNode.files;
4496 if(!project.files) project.files = { };
4497 project.topNode.files = project.files;
4500 char topNodePath[MAX_LOCATION];
4501 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4502 MakeSlashPath(topNodePath);
4503 PathCatSlash(topNodePath, filePath);
4504 project.filePath = topNodePath;//filePath;
4507 project.topNode.FixupNode(insidePath);
4509 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4510 delete project.resNode.path;
4511 project.resNode.path = project.resourcesPath;
4512 project.resourcesPath = null;
4513 project.resNode.nodeType = (ProjectNodeType)-1;
4514 delete project.resNode.files;
4515 project.resNode.files = project.resources;
4516 project.files = null;
4517 project.resources = null;
4518 if(!project.configurations) project.configurations = { };
4520 project.resNode.FixupNode(insidePath);
4525 project = LegacyAsciiLoadProject(f, filePath);
4531 if(!project.options) project.options = { };
4532 if(activeConfigName && activeConfigName[0] && project.configurations)
4533 project.config = project.GetConfig(activeConfigName);
4534 if(!project.config && project.configurations)
4535 project.config = project.configurations.firstIterator.data;
4537 if(!project.resNode)
4539 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4542 if(!project.moduleName)
4543 project.moduleName = CopyString(project.name);
4544 if(project.config &&
4545 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4546 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4548 //delete project.config.options.targetFileName;
4550 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4551 project.config.options.optimization = none;
4552 project.config.options.debug = true;
4553 //project.config.options.warnings = unset;
4554 project.config.options.memoryGuard = false;
4555 project.config.compilingModified = true;
4556 project.config.linkingModified = true;
4558 else if(!project.topNode.name && project.config)
4560 project.topNode.name = CopyString(project.config.options.targetFileName);
4563 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4564 project.topNode.configurations = project.configurations;
4565 project.topNode.platforms = project.platforms;
4566 project.topNode.options = project.options;*/