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();
53 #ifdef MAKEFILE_GENERATOR
54 CompilerConfig defaultCompiler;
57 // LEGACY BINARY EPJ LOADING
59 SetBool ParseTrueFalseValue(char * string)
61 if(!strcmpi(string, "True")) return true;
65 void ParseArrayValue(Array<String> array, char * equal)
67 char * start, * comma;
69 string = CopyString(equal);
73 comma = strstr(start, ",");
76 array.Add(CopyString(start));
86 void ProjectNode::LegacyBinaryLoadNode(File f)
91 f.Read(&len, sizeof(len), 1);
92 name = new char[len+1];
94 f.Read(name, sizeof(char), len+1);
95 f.Read(&len, sizeof(len), 1);
97 path = new char[len+1];
98 f.Read(path, sizeof(char), len+1);
101 fileName = new char[fileNameLen+2];
102 strcpy(fileName, path);
103 if(fileName[0]) strcat(fileName, "/");
104 strcat(fileName, name);
107 f.Read(&type, sizeof(type), 1);
108 f.Read(&count, sizeof(count), 1);
113 icon = NodeIcons::SelectFileIcon(name);
118 icon = NodeIcons::SelectNodeIcon(type);
121 if(count && !files) files = { };
122 for(c = 0; c < count; c++)
124 ProjectNode child { };
127 child.indent = indent + 1;
128 LegacyBinaryLoadNode(child, f);
132 /*void LegacyBinarySaveNode(File f)
137 f.Write(&len, sizeof(len), 1);
138 f.Write(name, sizeof(char), len+1);
142 // Projects Absolute Path Are Not Saved
144 f.Write(&len, sizeof(len), 1);
145 f.Write(&len, sizeof(char), 1);
150 f.Write(&len, sizeof(len), 1);
151 f.Write(path, sizeof(char), len+1);
153 f.Write(&type, sizeof(type), 1);
154 f.Write(&children.count, sizeof(children.count), 1);
155 for(child = children.first; child; child.next)
159 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
162 char printPath[MAX_LOCATION];
164 if(type == project && (files.count /*|| preprocessorDefs.first*/))
166 f.Printf("\n Files\n");
168 else if(type == file)
170 if(!strcmp(path, insidePath))
171 f.Printf("%s - %s\n", indentation, name);
174 strcpy(printPath, path);
175 len = strlen(printPath);
177 if(printPath[len-1] != '/')
178 strcat(printPath, "/");
179 strcat(printPath, name);
180 f.Printf("%s = %s\n", indentation, printPath);
183 f.Printf("\nError\n\n");
185 else if(type == folder)
187 f.Printf("%s + %s\n", indentation, name);
189 else if(type == resources && files.count)
191 PathCatSlash(insidePath, path);
192 f.Printf("\n%sResources\n", indentation);
194 f.Printf("%s Path = %s\n", indentation, path);
197 /*if(buildExclusions.first && type != project)
199 for(item = buildExclusions.first; item; item = item.next)
201 if(item == buildExclusions.first)
202 f.Printf("%s Build Exclusions = %s", indentation, item.name);
204 f.Printf(", %s", item.name);
209 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
211 for(item = preprocessorDefs.first; item; item = item.next)
213 if(item == preprocessorDefs.first)
214 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
216 f.Printf(", %s", item.name);
222 if(type == project && (files.count /*|| preprocessorDefs.first*/))
226 LegacyAsciiSaveNode(child, f, indentation, insidePath);
228 else if(type == folder)
230 strcat(indentation, " ");
231 // WHAT WAS THIS: strcpy(printPath, path);
232 // TOCHECK: why is Unix/PathCat not used here
233 len = strlen(insidePath);
235 if(insidePath[len-1] != '/')
236 strcat(insidePath, "/");
237 strcat(insidePath, name);
240 LegacyAsciiSaveNode(child, f, indentation, insidePath);
241 f.Printf("%s -\n", indentation);
242 indentation[strlen(indentation) - 3] = '\0';
243 StripLastDirectory(insidePath, insidePath);
245 else if(type == resources && files.count)
249 LegacyAsciiSaveNode(child, f, indentation, insidePath);
250 StripLastDirectory(insidePath, insidePath);
255 void ProjectConfig::LegacyProjectConfigSave(File f)
257 char * indentation = " ";
259 //f.Printf("\n * Common\n");
261 f.Printf("\n + %s\n", name);
262 f.Printf("\n Compiler\n\n");
263 if(objDir.expression[0])
264 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
265 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
266 switch(options.optimization)
268 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
269 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
270 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
272 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
274 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
275 if(options.memoryGuard == true)
276 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
277 if(options.strictNameSpaces == true)
278 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
279 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
280 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
281 TOFIX: Compiler Bug {
282 if(options.preprocessorDefinitions.count)
285 for(item : options.preprocessorDefinitions)
289 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
293 f.Printf(", %s", item);
298 if(options.includeDirs.count)
300 f.Printf("\n%sInclude Directories\n", indentation);
301 for(item : options.includeDirs)
302 f.Printf("%s - %s\n", indentation, name);
306 f.Printf("\n%sLinker\n\n", indentation);
307 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
308 switch(options.targetType)
310 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
311 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
312 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
314 if(targetDir.expression[0])
315 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
317 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
319 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
320 if(options.libraries.count)
323 for(item : options.libraries)
327 f.Printf("\n%sLibraries = %s", indentation, name);
331 f.Printf(", %s", item);
335 if(options.libraryDirs.count)
337 f.Printf("\n%sLibrary Directories\n\n", indentation);
338 for(item : options.libraryDirs)
339 f.Printf(" - %s\n", indentation, item);
343 void LegacyAsciiSaveProject(File f, Project project)
345 char indentation[128*3];
346 char path[MAX_LOCATION];
348 f.Printf("\nECERE Project File : Format Version 0.1b\n");
349 f.Printf("\nDescription\n%s\n.\n", project.description);
350 f.Printf("\nLicense\n%s\n.\n", project.license);
351 f.Printf("\nModule Name = %s\n", project.moduleName);
352 f.Printf("\n Configurations\n");
353 //////////////////////////////////////commonConfig.Save(f, true);
354 for(cfg : project.configurations)
355 LegacyProjectConfigSave(cfg, f);
357 strcpy(indentation, " ");
359 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
365 // *** NEW JSON PROJECT FORMAT ***
366 public enum ProjectNodeType { file, folder };
368 // *******************************
370 define PEEK_RESOLUTION = (18.2 * 10);
376 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
378 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources };
380 define WorkspaceExtension = "ews";
381 define ProjectExtension = "epj";
383 define stringInFileIncludedFrom = "In file included from ";
385 void ReplaceSpaces(char * output, char * source)
390 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
392 if(ch == ' ') output[dc++] = '\\';
395 if(ch == '(' || ch == ')') output[dc++] = '\\';
405 void ReplaceUnwantedMakeChars(char * output, char * source)
410 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
414 if(ch == '(' || ch == ')') output[dc++] = '\\';
427 static void OutputNoSpace(File f, char * source)
429 char * output = new char[strlen(source)+1024];
430 ReplaceSpaces(output, source);
435 enum ListOutputMethod { inPlace, newLine, lineEach };
437 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
440 const int breakListLength = 1536;
441 const int breakLineLength = 78; // TODO: turn this into an option.
443 int c, len, itemCount = 0;
444 Array<int> breaks { };
448 MapNode<String, int> mn;
449 for(c=0; c<list.count; c++)
451 len = strlen(list[c]) + 3;
452 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
454 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
456 if(strstr(list[c], mn.key))
460 if(charCount + len > breakListLength)
462 breaks.Add(itemCount);
470 breaks.Add(itemCount);
471 numOfBreaks = breaks.count;
476 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
477 for(c=0; c<numOfBreaks; c++)
478 f.Printf(" $(%s%d)", name, c+1);
482 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
488 for(c=0; c<numOfBreaks; c++)
491 f.Printf("%s%d =", name, c+1);
494 itemCount = breaks[c];
495 for(n=offset; n<offset+itemCount; n++)
497 if(false) // TODO: turn this into an option.
499 int itemLen = strlen(list[n]);
500 if(len > 3 && len + itemLen > breakLineLength)
502 f.Printf(" \\\n\t%s", list[n]);
508 f.Printf(" %s", list[n]);
512 f.Printf(" \\\n\t%s", list[n]);
527 void OutputCleanActions(File f, char * name, int parts)
532 for(c=0; c<parts; c++)
533 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
536 f.Printf("\t$(call rmq,$(%s))\n", name);
539 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
543 if(method == newLine)
547 if(method == lineEach)
549 f.Printf(" -%s", option);
551 OutputNoSpace(f, item);
553 f.Printf("%s", item);
558 void StringNoSpaceToDynamicString(DynamicString s, char * path)
560 char * output = new char[strlen(path)+1024];
561 ReplaceSpaces(output, path);
566 static void OutputLibraries(File f, Array<String> libraries)
568 for(item : libraries)
570 char ext[MAX_EXTENSION];
571 char temp[MAX_LOCATION];
573 bool usedFunction = false;
574 GetExtension(item, ext);
575 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
579 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
581 if(!strncmp(item, "lib", 3))
582 strcpy(temp, item + 3);
585 StripExtension(temp);
588 f.Printf(" \\\n\t$(call _L,");
597 void CamelCase(char * string)
599 int c, len = strlen(string);
600 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
601 string[c] = (char)tolower(string[c]);
604 CompilerConfig GetCompilerConfig()
606 #ifndef MAKEFILE_GENERATOR
607 CompilerConfig compiler = null;
608 if(ide && ide.workspace)
609 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
612 incref defaultCompiler;
613 return defaultCompiler;
617 define localTargetType = config && config.options && config.options.targetType ?
618 config.options.targetType : options && options.targetType ?
619 options.targetType : TargetTypes::executable;
620 define localWarnings = config && config.options && config.options.warnings ?
621 config.options.warnings : options && options.warnings ?
622 options.warnings : WarningsOption::unset;
623 define localDebug = config && config.options && config.options.debug ?
624 config.options.debug : options && options.debug ?
625 options.debug : SetBool::unset;
626 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
627 config.options.memoryGuard : options && options.memoryGuard ?
628 options.memoryGuard : SetBool::unset;
629 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
630 config.options.noLineNumbers : options && options.noLineNumbers ?
631 options.noLineNumbers : SetBool::unset;
632 define localProfile = config && config.options && config.options.profile ?
633 config.options.profile : options && options.profile ?
634 options.profile : SetBool::unset;
635 define localOptimization = config && config.options && config.options.optimization ?
636 config.options.optimization : options && options.optimization ?
637 options.optimization : OptimizationStrategy::none;
638 define localFastMath = config && config.options && config.options.fastMath ?
639 config.options.fastMath : options && options.fastMath ?
640 options.fastMath : SetBool::unset;
641 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
642 config.options.defaultNameSpace : options && options.defaultNameSpace ?
643 options.defaultNameSpace : null;
644 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
645 config.options.strictNameSpaces : options && options.strictNameSpaces ?
646 options.strictNameSpaces : SetBool::unset;
647 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
648 define localTargetFileName = config && config.options && config.options.targetFileName ?
649 config.options.targetFileName : options && options.targetFileName ?
650 options.targetFileName : "";
651 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
652 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
653 options.targetDirectory : null;
654 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
655 ideSettings.projectDefaultIntermediateObjDir[0] ?
656 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
657 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
658 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
659 options.objectsDirectory : null;
660 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
661 ideSettings.projectDefaultIntermediateObjDir[0] ?
662 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
663 define localConsole = config && config.options && config.options.console ?
664 config.options.console : options && options.console ?
665 options.console : SetBool::unset;
666 define localCompress = config && config.options && config.options.compress ?
667 config.options.compress : options && options.compress ?
668 options.compress : SetBool::unset;
670 define platformTargetType =
671 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
672 configPOs.options.targetType :
673 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
674 projectPOs.options.targetType : TargetTypes::unset;
677 char * PlatformToMakefileTargetVariable(Platform platform)
679 return platform == win32 ? "WINDOWS_TARGET" :
680 platform == tux ? "LINUX_TARGET" :
681 platform == apple ? "OSX_TARGET" :
685 char * TargetTypeToMakefileVariable(TargetTypes targetType)
687 return targetType == executable ? "executable" :
688 targetType == sharedLibrary ? "sharedlib" :
689 targetType == staticLibrary ? "staticlib" :
693 // Move this to ProjectConfig? null vs Common to consider...
694 char * GetConfigName(ProjectConfig config)
696 return config ? config.name : "Common";
699 class Project : struct
701 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
702 // We might want to tweak this default behavior of regular classes ?
703 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
708 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
709 property Array<PlatformOptions> platforms
711 get { return platforms; }
714 if(platforms) { platforms.Free(); delete platforms; }
717 List<PlatformOptions> empty { };
718 Iterator<PlatformOptions> it { value };
720 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
721 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
731 if(p.options && !p.options.isEmpty)
738 List<ProjectConfig> configurations;
739 LinkList<ProjectNode> files;
740 String resourcesPath;
741 LinkList<ProjectNode> resources;
743 property char * description
745 set { delete description; if(value && value[0]) description = CopyString(value); }
746 get { return description ? description : ""; }
747 isset { return description != null && description[0]; }
750 property char * license
752 set { delete license; if(value && value[0]) license = CopyString(value); }
753 get { return license ? license : ""; }
754 isset { return license != null && license[0]; }
757 property char * compilerConfigsDir
759 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
760 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
761 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
765 // topNode.name holds the file name (.epj)
766 ProjectOptions options;
767 Array<PlatformOptions> platforms;
768 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
771 ProjectConfig config;
773 // This is the file name stripped of the epj extension
774 // It should NOT be edited, saved or loaded anywhere
779 String compilerConfigsDir;
780 #ifndef MAKEFILE_GENERATOR
781 FileMonitor fileMonitor
783 this, FileChange { modified = true };
784 bool OnFileNotify(FileChange action, char * param)
786 fileMonitor.StopMonitoring();
787 if(OnProjectModified(action, param))
788 fileMonitor.StartMonitoring();
793 bool StartMonitoring()
795 fileMonitor.fileName = filePath;
796 fileMonitor.StartMonitoring();
800 bool StopMonitoring()
802 fileMonitor.StopMonitoring();
806 bool OnProjectModified(FileChange fileChange, char * param)
809 sprintf(temp, $"The project %s was modified by another application.\n"
810 "Would you like to reload it and lose your changes?", name);
811 if(MessageBox { type = yesNo, master = ide,
812 text = $"Project has been modified", contents = temp }.Modal() == yes)
814 Project project = LoadProject(filePath, config.name);
817 ProjectView projectView = ide.projectView;
818 DataRow prev = topNode.row ? topNode.row.previous : null;
819 FileMonitor fm = fileMonitor;
821 if(projectView) projectView.DeleteNode(topNode);
826 topNode.project = this;
830 CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
831 projectView.AddNode(topNode, null);
832 topNode.row.Move(prev);
834 projectView.ShowOutputBuildLog(true);
835 projectView.DisplayCompiler(compiler, false);
836 projectView.ProjectUpdateMakefileForAllConfigs(this);
839 eSystem_Delete(project);
848 // This frees contents without freeing the instance
849 // For use from destructor and for file monitor reloading
850 // (To work around JSON loader (LoadProject) always returning a new instance)
853 if(platforms) { platforms.Free(); delete platforms; }
854 if(configurations) { configurations.Free(); delete configurations; }
855 if(files) { files.Free(); delete files; }
856 if(resources) { resources.Free(); delete resources; }
858 delete resourcesPath;
862 delete compilerConfigsDir;
871 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
872 topNode.configurations = null;
873 topNode.platforms = null;
874 topNode.options = null;
879 property ProjectConfig config
885 topNode.info = CopyString(GetConfigName(config));
888 property char * filePath
894 char string[MAX_LOCATION];
895 GetLastDirectory(value, string);
897 topNode.name = CopyString(string);
898 StripExtension(string);
900 name = CopyString(string);
901 StripLastDirectory(value, string);
903 topNode.path = CopyString(string);
905 filePath = CopyString(value);
910 TargetTypes GetTargetType(ProjectConfig config)
912 TargetTypes targetType = localTargetType;
916 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
919 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
921 PlatformOptions projectPOs, configPOs;
922 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
923 if(platformTargetType)
930 char * GetObjDirExpression(ProjectConfig config)
932 // TODO: Support platform options
933 char * expression = localObjectsDirectory;
935 expression = settingsObjectsDirectory;
939 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config)
941 char * expression = GetObjDirExpression(config);
942 DirExpression objDir { type = intermediateObjectsDir };
943 objDir.Evaluate(expression, this, compiler, config);
947 char * GetTargetDirExpression(ProjectConfig config)
949 // TODO: Support platform options
950 char * expression = localTargetDirectory;
952 expression = settingsTargetDirectory;
956 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config)
958 char * expression = GetTargetDirExpression(config);
959 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
960 targetDir.Evaluate(expression, this, compiler, config);
964 WarningsOption GetWarnings(ProjectConfig config)
966 WarningsOption warnings = localWarnings;
970 bool GetDebug(ProjectConfig config)
972 SetBool debug = localDebug;
973 return debug == true;
976 bool GetMemoryGuard(ProjectConfig config)
978 SetBool memoryGuard = localMemoryGuard;
979 return memoryGuard == true;
982 bool GetNoLineNumbers(ProjectConfig config)
984 SetBool noLineNumbers = localNoLineNumbers;
985 return noLineNumbers == true;
988 bool GetProfile(ProjectConfig config)
990 SetBool profile = localProfile;
991 return profile == true;
994 OptimizationStrategy GetOptimization(ProjectConfig config)
996 OptimizationStrategy optimization = localOptimization;
1000 bool GetFastMath(ProjectConfig config)
1002 SetBool fastMath = localFastMath;
1003 return fastMath == true;
1006 String GetDefaultNameSpace(ProjectConfig config)
1008 String defaultNameSpace = localDefaultNameSpace;
1009 return defaultNameSpace;
1012 bool GetStrictNameSpaces(ProjectConfig config)
1014 SetBool strictNameSpaces = localStrictNameSpaces;
1015 return strictNameSpaces == true;
1018 String GetTargetFileName(ProjectConfig config)
1020 String targetFileName = localTargetFileName;
1021 return targetFileName;
1024 //String targetDirectory;
1025 //String objectsDirectory;
1026 bool GetConsole(ProjectConfig config)
1028 SetBool console = localConsole;
1029 return console == true;
1032 bool GetCompress(ProjectConfig config)
1034 SetBool compress = localCompress;
1035 return compress == true;
1037 //SetBool excludeFromBuild;
1039 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1041 #ifndef MAKEFILE_GENERATOR
1042 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1046 bool GetConfigIsInDebugSession(ProjectConfig config)
1048 #ifndef MAKEFILE_GENERATOR
1049 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1053 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config)
1055 #ifndef MAKEFILE_GENERATOR
1056 ide.SetPath(projectsDirs, compiler, config);
1060 #ifndef MAKEFILE_GENERATOR
1061 bool Save(char * fileName)
1064 /*char output[MAX_LOCATION];
1065 ChangeExtension(fileName, "json", output);
1066 f = FileOpen(output, write);*/
1067 f = FileOpen(fileName, write);
1070 files = topNode.files;
1071 resources = resNode.files;
1072 resourcesPath = resNode.path;
1074 files.Remove(resNode);
1077 WriteJSONObject(f, class(Project), this, 0);
1083 resourcesPath = null;
1090 // This method is only called from Debugger, should be moved to Debugger class?
1091 #ifndef MAKEFILE_GENERATOR
1092 bool GetRelativePath(char * filePath, char * relativePath)
1095 char moduleName[MAX_FILENAME];
1096 GetLastDirectory(filePath, moduleName);
1097 // try with workspace dir first?
1098 if((node = topNode.Find(moduleName, false)))
1100 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1101 PathCatSlash(relativePath, node.name);
1106 // Tweak for automatically resolving symbol loader modules
1107 char * sl = strstr(moduleName, ".main.ec");
1108 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1110 char objDir[MAX_LOCATION];
1111 DirExpression objDirExp;
1112 CompilerConfig compiler = ide.debugger.currentCompiler;
1113 ProjectConfig config = ide.debugger.prjConfig;
1114 // This is not perfect, as multiple source files exist for the symbol loader module...
1115 // We try to set it in the debug config object directory.
1116 if(!compiler || !config)
1118 // If we're not currently debugging, set a breakpoint in the active compiler/config
1119 compiler = GetCompilerConfig();
1120 config = this.config;
1121 // If the current config is not debuggable, set it in the first debuggable config found
1122 if(config && !config.options.debug)
1124 for(c : configurations; c.options.debug)
1131 objDirExp = GetObjDir(compiler, config);
1132 strcpy(objDir, objDirExp.dir);
1134 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1135 ReplaceSpaces(objDir, objDir);
1136 strcpy(relativePath, objDir);
1138 PathCatSlash(relativePath, moduleName);
1142 // WARNING: On failure, relative path is uninitialized
1147 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1149 TargetTypes targetType = GetTargetType(config);
1150 String targetFileName = GetTargetFileName(config);
1151 if(targetType == staticLibrary)
1153 PathCatSlash(string, "lib");
1154 strcat(string, targetFileName);
1156 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1158 PathCatSlash(string, "lib");
1159 strcat(string, targetFileName);
1162 PathCatSlash(string, targetFileName);
1167 if(compiler.targetPlatform == win32)
1168 strcat(string, ".exe");
1171 if(compiler.targetPlatform == win32)
1172 strcat(string, ".dll");
1173 else if(compiler.targetPlatform == apple)
1174 strcat(string, ".dylib");
1176 strcat(string, ".so");
1179 strcat(string, ".a");
1184 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1186 bool result = false;
1187 char temp[MAX_LOCATION];
1188 strcpy(cfDir, topNode.path);
1189 if(compilerConfigsDir && compilerConfigsDir[0])
1191 PathCatSlash(cfDir, compilerConfigsDir);
1196 strcpy(temp, cfDir);
1197 // Using a relative path makes it less likely to run into spaces issues
1198 // Even with escaped spaces, there still seems to be issues including a config file
1199 // in a path containing spaces
1201 MakePathRelative(temp, topNode.path, cfDir);
1204 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1208 strcpy(temp, cfDir);
1209 ReplaceSpaces(cfDir, temp);
1214 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1216 char temp[MAX_LOCATION];
1217 bool result = false;
1218 strcpy(cfDir, topNode.path);
1219 if(ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1221 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1226 // Default to <ProjectDir>/.configs if unset
1227 PathCatSlash(cfDir, ".configs");
1232 strcpy(temp, cfDir);
1233 // Using a relative path makes it less likely to run into spaces issues
1234 // Even with escaped spaces, there still seems to be issues including a config file
1235 // in a path containing spaces
1236 if(IsPathInsideOf(cfDir, topNode.path))
1237 MakePathRelative(temp, topNode.path, cfDir);
1239 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1243 strcpy(temp, cfDir);
1244 ReplaceSpaces(cfDir, temp);
1249 void CatMakeFileName(char * string, ProjectConfig config)
1251 char projectName[MAX_LOCATION];
1252 strcpy(projectName, name);
1253 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1256 #ifndef MAKEFILE_GENERATOR
1257 void MarkChanges(ProjectNode node)
1259 for(cfg : topNode.configurations)
1261 ProjectConfig c = null;
1262 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1264 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1265 (!c.options || !cfg.options)))
1266 cfg.symbolGenModified = true;
1268 cfg.makingModified = true;
1272 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1274 for(cfg : configurations)
1277 cfg.makingModified = true;
1279 cfg.compilingModified = true;
1281 cfg.linkingModified = true;
1283 cfg.symbolGenModified = true;
1285 if(compiling || linking)
1287 ide.projectView.modifiedDocument = true;
1288 ide.workspace.modified = true;
1292 void RotateActiveConfig(bool forward)
1294 if(configurations.first && configurations.last != configurations.first)
1296 Iterator<ProjectConfig> cfg { configurations };
1297 while(forward ? cfg.Next() : cfg.Prev())
1298 if(cfg.data == config)
1312 property::config = cfg.data;
1313 ide.workspace.modified = true;
1314 ide.projectView.Update(null);
1318 void ProcessPipeOutputRaw(DualPipe f)
1321 while(!f.Eof() && !ide.ShouldStopBuild())
1324 double lastTime = GetTime();
1328 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1330 ide.outputView.buildBox.Logf("%s\n", line);
1332 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1334 //printf("Processing Input...\n");
1335 if(app.ProcessInput(true))
1337 app.UpdateDisplay();
1340 //printf("Waiting...\n");
1343 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1345 if(ide.ShouldStopBuild())
1347 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1352 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode,
1353 CompilerConfig compiler, ProjectConfig config)
1356 bool compiling = false, linking = false, precompiling = false;
1357 int compilingEC = 0;
1358 int numErrors = 0, numWarnings = 0;
1359 bool loggedALine = false;
1360 char * configName = config.name;
1361 int lenMakeCommand = strlen(compiler.makeCommand);
1363 char cppCommand[MAX_LOCATION];
1364 char ccCommand[MAX_LOCATION];
1365 char cxxCommand[MAX_LOCATION];
1366 char stripCommand[MAX_LOCATION];
1367 char ecpCommand[MAX_LOCATION];
1368 char eccCommand[MAX_LOCATION];
1369 char ecsCommand[MAX_LOCATION];
1370 char earCommand[MAX_LOCATION];
1372 char * cc = compiler.ccCommand;
1373 char * cxx = compiler.cxxCommand;
1374 char * cpp = compiler.cppCommand;
1375 char * strip = compiler.cppCommand;
1376 sprintf(cppCommand, "%s%s%s%s%s ",
1377 compiler.ccacheEnabled ? "ccache " : "",
1378 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1379 compiler.distccEnabled ? "distcc " : "",
1380 compiler.gccPrefix ? compiler.gccPrefix : "",
1381 compiler.cppCommand);
1382 sprintf(ccCommand, "%s%s%s%s%s ",
1383 compiler.ccacheEnabled ? "ccache " : "",
1384 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1385 compiler.distccEnabled ? "distcc " : "",
1386 compiler.gccPrefix ? compiler.gccPrefix : "",
1387 compiler.ccCommand);
1388 sprintf(cxxCommand, "%s%s%s%s%s ",
1389 compiler.ccacheEnabled ? "ccache " : "",
1390 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1391 compiler.distccEnabled ? "distcc " : "",
1392 compiler.gccPrefix ? compiler.gccPrefix : "",
1393 compiler.cxxCommand);
1395 sprintf(stripCommand, "%sstrip ",
1396 compiler.gccPrefix ? compiler.gccPrefix : "");
1398 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1399 sprintf(eccCommand, "%s ", compiler.eccCommand);
1400 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1401 sprintf(earCommand, "%s ", compiler.earCommand);
1403 while(!f.Eof() && !ide.ShouldStopBuild())
1406 double lastTime = GetTime();
1410 //printf("Peeking and GetLine...\n");
1411 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1413 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1414 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1416 char * module = strstr(line, "No rule to make target `");
1420 module = strchr(module, '`') + 1;
1421 end = strchr(module, '\'');
1425 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1426 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1432 //ide.outputView.buildBox.Logf("error: %s\n", line);
1436 else if(strstr(line, "ear ") == line);
1437 else if(strstr(line, stripCommand) == line);
1438 else if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1440 char moduleName[MAX_FILENAME];
1443 bool isPrecomp = false;
1445 if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line)
1447 module = strstr(line, " -c ");
1448 if(module) module += 4;
1450 else if(strstr(line, eccCommand) == line)
1452 module = strstr(line, " -c ");
1453 if(module) module += 4;
1454 //module = line + 3;
1455 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1456 compilingEC = 3;//2;
1458 else if(strstr(line, ecpCommand) == line)
1460 // module = line + 8;
1461 module = strstr(line, " -c ");
1462 if(module) module += 4;
1471 if(!compiling && !isPrecomp)
1473 ide.outputView.buildBox.Logf($"Compiling...\n");
1476 else if(!precompiling && isPrecomp)
1478 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1479 precompiling = true;
1481 // Changed escapeBackSlashes here to handle paths with spaces
1482 Tokenize(module, 1, tokens, true); // false);
1483 GetLastDirectory(module, moduleName);
1484 ide.outputView.buildBox.Logf("%s\n", moduleName);
1486 else if((module = strstr(line, " -o ")))
1489 precompiling = false;
1491 ide.outputView.buildBox.Logf($"Linking...\n");
1495 ide.outputView.buildBox.Logf("%s\n", line);
1499 if(compilingEC) compilingEC--;
1501 else if(strstr(line, "ar rcs") == line)
1502 ide.outputView.buildBox.Logf($"Building library...\n");
1503 else if(strstr(line, ecsCommand) == line)
1504 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1507 if(linking || compiling || precompiling)
1509 char * colon = strstr(line, ":"); //, * bracket;
1510 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1511 colon = strstr(colon + 1, ":");
1514 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1517 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1518 int len = (int)(colon - start);
1519 len = Min(len, MAX_LOCATION-1);
1520 // Don't be mistaken by the drive letter colon
1522 // TODO: need to fix colon - line gives char *
1523 // warning: incompatible expression colon - line (char *); expected int
1525 strncpy(moduleName, line, (int)(colon - line));
1526 moduleName[colon - line] = '\0';
1528 strncpy(moduleName, start, len);
1529 moduleName[len] = '\0';
1530 // Remove stuff in brackets
1531 //bracket = strstr(moduleName, "(");
1532 //if(bracket) *bracket = '\0';
1534 GetLastDirectory(moduleName, temp);
1535 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1538 strcpy(moduleName, $"Linker Error");
1542 strcpy(temp, topNode.path);
1543 PathCatSlash(temp, moduleName);
1544 MakePathRelative(temp, topNode.path, moduleName);
1546 if(strstr(line, "error:"))
1550 // Silence warnings for compiled EC
1551 char * objDir = strstr(moduleName, objDirExp.dir);
1555 if((pointer = strstr(line, "undefined")) ||
1556 (pointer = strstr(line, "No such file")) ||
1557 (pointer = strstr(line, "token")))
1559 strncat(moduleName, colon, pointer - colon);
1560 strcat(moduleName, "error: ");
1565 else if((pointer = strstr(line, "No such file")))
1567 strncat(moduleName, colon, pointer - colon);
1568 strcat(moduleName, "error: ");
1572 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1574 else if(strstr(line, "warning:"))
1579 if(this == ide.workspace.projects.firstIterator.data)
1580 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1583 char fullModuleName[MAX_LOCATION];
1584 strcpy(fullModuleName, topNode.path);
1585 PathCat(fullModuleName, moduleName);
1586 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1587 MakeSystemPath(fullModuleName);
1588 ide.outputView.buildBox.Logf(" %s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : "", fullModuleName, colon);
1593 ide.outputView.buildBox.Logf("%s\n", line);
1594 linking = compiling = precompiling = false;
1598 ide.outputView.buildBox.Logf("%s\n", line);
1602 //printf("Done getting line\n");
1603 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1605 //printf("Processing Input...\n");
1606 if(app.ProcessInput(true))
1608 app.UpdateDisplay();
1611 //printf("Waiting...\n");
1614 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1616 if(ide.ShouldStopBuild())
1618 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1621 else if(loggedALine || !isARun)
1623 if(f.GetExitCode() && !numErrors)
1625 bool result = f.GetLine(line, sizeof(line)-1);
1626 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1631 ide.outputView.buildBox.Logf("\n%s (%s) - ", GetTargetFileName(config), configName);
1633 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1635 ide.outputView.buildBox.Logf($"no error, ");
1638 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1640 ide.outputView.buildBox.Logf($"no warning\n");
1643 return numErrors == 0;
1646 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1649 int lenMakeCommand = strlen(compiler.makeCommand);
1654 double lastTime = GetTime();
1657 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1659 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1660 else if(strstr(line, "del") == line);
1661 else if(strstr(line, "rm") == line);
1662 else if(strstr(line, "Could Not Find") == line);
1665 ide.outputView.buildBox.Logf(line);
1666 ide.outputView.buildBox.Logf("\n");
1670 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1672 if(app.ProcessInput(true))
1674 app.UpdateDisplay();
1677 //Sleep(1.0 / PEEK_RESOLUTION);
1681 bool Build(bool isARun, ProjectNode onlyNode, CompilerConfig compiler, ProjectConfig config)
1683 bool result = false;
1685 char targetFileName[MAX_LOCATION] = "";
1686 char makeTarget[MAX_LOCATION] = "";
1687 char makeFile[MAX_LOCATION];
1688 char makeFilePath[MAX_LOCATION];
1689 char configName[MAX_LOCATION];
1690 DirExpression objDirExp = GetObjDir(compiler, config);
1691 PathBackup pathBackup { };
1692 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1693 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1695 int numJobs = compiler.numJobs;
1696 char command[MAX_LOCATION];
1697 char * compilerName;
1699 compilerName = CopyString(compiler.name);
1700 CamelCase(compilerName);
1702 strcpy(configName, config ? config.name : "Common");
1704 SetPath(false, compiler, config); //true
1705 CatTargetFileName(targetFileName, compiler, config);
1707 strcpy(makeFilePath, topNode.path);
1708 CatMakeFileName(makeFile, config);
1709 PathCatSlash(makeFilePath, makeFile);
1711 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1714 if(compiler.type.isVC)
1716 PrintLn("compiling a single file is not yet supported");
1721 char pushD[MAX_LOCATION];
1722 char cfDir[MAX_LOCATION];
1723 GetIDECompilerConfigsDir(cfDir, true, true);
1724 GetWorkingDir(pushD, sizeof(pushD));
1725 ChangeWorkingDir(topNode.path);
1726 // Create object dir if it does not exist already
1727 if(!FileExists(objDirExp.dir).isDirectory)
1729 sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s objdir -C \"%s\" -f \"%s\"",
1730 compiler.makeCommand, cfDir,
1731 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
1732 compilerName, topNode.path, makeFilePath);
1735 ide.outputView.buildBox.Logf("command: %s\n", command);
1740 ChangeWorkingDir(pushD);
1742 PathCatSlash(makeTarget+1, objDirExp.dir);
1743 PathCatSlash(makeTarget+1, onlyNode.name);
1744 StripExtension(makeTarget+1);
1745 strcat(makeTarget+1, ".o");
1746 makeTarget[0] = '\"';
1747 len = strlen(makeTarget);
1748 makeTarget[len++] = '\"';
1749 makeTarget[len++] = '\0';
1753 if(compiler.type.isVC)
1755 bool result = false;
1756 char oldwd[MAX_LOCATION];
1757 GetWorkingDir(oldwd, sizeof(oldwd));
1758 ChangeWorkingDir(topNode.path);
1760 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1761 ide.outputView.buildBox.Logf("command: %s\n", command);
1764 ide.outputView.buildBox.Logf("command: %s\n", command);
1766 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1768 ProcessPipeOutputRaw(f);
1772 ChangeWorkingDir(oldwd);
1776 char cfDir[MAX_LOCATION];
1777 GetIDECompilerConfigsDir(cfDir, true, true);
1778 sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s -j%d %s%s%s -C \"%s\" -f \"%s\"",
1779 compiler.makeCommand, cfDir,
1780 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
1781 compilerName, numJobs,
1782 compiler.ccacheEnabled ? "CCACHE=y " : "",
1783 compiler.distccEnabled ? "DISTCC=y " : "",
1784 makeTarget, topNode.path, makeFilePath);
1787 ide.outputView.buildBox.Logf("command: %s\n", command);
1789 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1791 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode, compiler, config);
1796 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
1798 ide.outputView.buildBox.Logf("command: %s\n", command);
1805 delete compilerName;
1809 void Clean(CompilerConfig compiler, ProjectConfig config, bool realclean)
1811 char makeFile[MAX_LOCATION];
1812 char makeFilePath[MAX_LOCATION];
1813 char command[MAX_LOCATION];
1814 char * compilerName;
1816 PathBackup pathBackup { };
1817 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1818 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1820 compilerName = CopyString(compiler.name);
1821 CamelCase(compilerName);
1823 SetPath(false, compiler, config);
1825 strcpy(makeFilePath, topNode.path);
1826 CatMakeFileName(makeFile, config);
1827 PathCatSlash(makeFilePath, makeFile);
1829 if(compiler.type.isVC)
1831 bool result = false;
1832 char oldwd[MAX_LOCATION];
1833 GetWorkingDir(oldwd, sizeof(oldwd));
1834 ChangeWorkingDir(topNode.path);
1836 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1837 ide.outputView.buildBox.Logf("command: %s\n", command);
1840 ide.outputView.buildBox.Logf("command: %s\n", command);
1842 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1844 ProcessPipeOutputRaw(f);
1848 ChangeWorkingDir(oldwd);
1853 char cfDir[MAX_LOCATION];
1854 GetIDECompilerConfigsDir(cfDir, true, true);
1855 sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s %sclean -C \"%s\" -f \"%s\"",
1856 compiler.makeCommand, cfDir,
1857 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
1858 compilerName, realclean ? "real" : "", topNode.path, makeFilePath);
1861 ide.outputView.buildBox.Logf("command: %s\n", command);
1863 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1865 ide.outputView.buildBox.Tell($"Deleting target and object files...");
1866 ProcessCleanPipeOutput(f, compiler, config);
1869 ide.outputView.buildBox.Logf($"Target and object files deleted\n");
1874 delete compilerName;
1877 void Run(char * args, CompilerConfig compiler, ProjectConfig config)
1879 String target = new char[maxPathLen];
1880 char oldDirectory[MAX_LOCATION];
1881 DirExpression targetDirExp = GetTargetDir(compiler, config);
1882 PathBackup pathBackup { };
1884 // Build(project, ideMain, true, null);
1886 #if defined(__WIN32__)
1887 strcpy(target, topNode.path);
1891 PathCatSlash(target, targetDirExp.dir);
1892 CatTargetFileName(target, compiler, config);
1893 sprintf(target, "%s %s", target, args);
1894 GetWorkingDir(oldDirectory, MAX_LOCATION);
1896 if(strlen(ide.workspace.debugDir))
1898 char temp[MAX_LOCATION];
1899 strcpy(temp, topNode.path);
1900 PathCatSlash(temp, ide.workspace.debugDir);
1901 ChangeWorkingDir(temp);
1904 ChangeWorkingDir(topNode.path);
1905 // ChangeWorkingDir(topNode.path);
1906 SetPath(true, compiler, config);
1907 if(compiler.execPrefixCommand)
1909 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1910 prefixedTarget[0] = '\0';
1911 strcat(prefixedTarget, compiler.execPrefixCommand);
1912 strcat(prefixedTarget, " ");
1913 strcat(prefixedTarget, target);
1914 Execute(prefixedTarget);
1915 delete prefixedTarget;
1920 ChangeWorkingDir(oldDirectory);
1923 delete targetDirExp;
1927 void Compile(ProjectNode node, CompilerConfig compiler, ProjectConfig config)
1929 Build(false, node, compiler, config);
1933 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
1936 if(targetType == staticLibrary || targetType == sharedLibrary)
1937 strcat(fileName, "$(LP)");
1938 // !!! ReplaceSpaces must be done after all PathCat calls !!!
1939 // ReplaceSpaces(s, GetTargetFileName(config));
1940 strcat(fileName, GetTargetFileName(config));
1944 strcat(fileName, "$(E)");
1947 strcat(fileName, "$(SO)");
1950 strcat(fileName, "$(A)");
1955 bool GenerateCrossPlatformMk()
1957 bool result = false;
1958 char path[MAX_LOCATION];
1960 if(!GetProjectCompilerConfigsDir(path, false, false))
1961 GetIDECompilerConfigsDir(path, false, false);
1963 if(!FileExists(path).isDirectory)
1967 char dirName[MAX_FILENAME];
1968 GetLastDirectory(path, dirName);
1969 if(!strcmp(dirName, ".configs"))
1970 FileSetAttribs(path, FileAttribs { isHidden = true });
1973 PathCatSlash(path, "crossplatform.mk");
1975 if(FileExists(path))
1978 File include = FileOpen(":crossplatform.mk", read);
1981 File f = FileOpen(path, write);
1984 for(; !include.Eof(); )
1987 int count = include.Read(buffer, 1, 4096);
1988 f.Write(buffer, 1, count);
2000 bool GenerateCompilerCf(CompilerConfig compiler)
2002 bool result = false;
2003 char path[MAX_LOCATION];
2005 char * compilerName;
2006 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2007 Platform platform = compiler.targetPlatform;
2009 compilerName = CopyString(compiler.name);
2010 CamelCase(compilerName);
2011 name = PrintString(platform, "-", compilerName, ".cf");
2013 if(!GetProjectCompilerConfigsDir(path, false, false))
2014 GetIDECompilerConfigsDir(path, false, false);
2016 if(!FileExists(path).isDirectory)
2020 char dirName[MAX_FILENAME];
2021 GetLastDirectory(path, dirName);
2022 if(!strcmp(dirName, ".configs"))
2023 FileSetAttribs(path, FileAttribs { isHidden = true });
2026 PathCatSlash(path, name);
2028 if(FileExists(path))
2031 File f = FileOpen(path, write);
2034 f.Printf("# TOOLCHAIN\n");
2037 if(compiler.gccPrefix && compiler.gccPrefix[0])
2039 f.Printf("GCC_PREFIX := %s\n", compiler.gccPrefix);
2042 if(compiler.sysroot && compiler.sysroot[0])
2044 f.Printf("SYSROOT := %s\n", compiler.sysroot);
2045 f.Printf("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2049 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2050 f.Printf("CPP := $(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2051 f.Printf("CC := $(CCACHE_COMPILE) $(DISTCC_COMPILE) $(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.ccCommand);
2052 f.Printf("CXX := $(CCACHE_COMPILE) $(DISTCC_COMPILE) $(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cxxCommand);
2053 f.Printf("ECP := %s\n", compiler.ecpCommand);
2054 f.Printf("ECC := %s\n", compiler.eccCommand);
2055 f.Printf("ifeq \"$(TARGET_PLATFORM)\" \"$(HOST_PLATFORM)\"\n");
2056 f.Printf("ECS := %s\n", compiler.ecsCommand);
2058 f.Printf("ECS := %s -t $(TARGET_PLATFORM)\n", compiler.ecsCommand);
2059 f.Printf("endif\n");
2060 f.Printf("EAR := %s\n", compiler.earCommand);
2062 f.Printf("AS := $(GCC_PREFIX)as\n");
2063 f.Printf("LD := $(GCC_PREFIX)ld\n");
2064 f.Printf("AR := $(GCC_PREFIX)ar\n");
2065 f.Printf("STRIP := $(GCC_PREFIX)strip\n");
2066 f.Printf("UPX := upx\n");
2069 if(compiler.environmentVars && compiler.environmentVars.count)
2071 f.Printf("# ENVIRONMENT VARIABLES\n");
2072 for(e : compiler.environmentVars)
2074 f.Printf("export %s := %s\n", e.name, e.string);
2078 f.Printf("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2081 f.Printf("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2082 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(tux));
2083 f.Printf("LDFLAGS += -Wl,--no-undefined\n");
2084 f.Printf("endif\n");
2088 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(apple));
2089 f.Printf("LDFLAGS += -framework cocoa -framework OpenGL\n");
2090 f.Printf("endif\n");
2094 f.Printf("\nCFLAGS += -fmessage-length=0\n");
2097 if(compiler.includeDirs && compiler.includeDirs.count)
2099 f.Printf("\nCFLAGS +=");
2100 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
2103 if(compiler.prepDirectives && compiler.prepDirectives.count)
2105 f.Printf("\nCFLAGS +=");
2106 OutputListOption(f, "D", compiler.prepDirectives, inPlace, true);
2109 if(compiler.libraryDirs && compiler.libraryDirs.count)
2111 f.Printf("\nLDFLAGS +=");
2112 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
2113 // We would need a bool option to know whether we want to add to rpath as well...
2114 // OutputListOption(f, "Wl,-rpath ", compiler.libraryDirs, lineEach, true);
2117 if(compiler.excludeLibs && compiler.excludeLibs.count)
2119 f.Puts("\nEXCLUDED_LIBS =");
2120 for(l : compiler.excludeLibs)
2126 if(compiler.linkerFlags && compiler.linkerFlags.count)
2128 f.Printf("\nLDFLAGS +=");
2129 OutputListOption(f, "Wl,", compiler.linkerFlags, inPlace, true);
2132 f.Printf("\nFORCE_64_BIT := %s", compiler.supportsBitDepth ? "-m64" : "");
2133 f.Printf("\nFORCE_32_BIT := %s", compiler.supportsBitDepth ? "-m32" : "");
2140 delete compilerName;
2144 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2146 bool result = false;
2147 char filePath[MAX_LOCATION];
2148 char makeFile[MAX_LOCATION];
2149 // PathBackup pathBackup { };
2150 // char oldDirectory[MAX_LOCATION];
2153 if(!altMakefilePath)
2155 strcpy(filePath, topNode.path);
2156 CatMakeFileName(makeFile, config);
2157 PathCatSlash(filePath, makeFile);
2160 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2162 /*SetPath(false, compiler, config);
2163 GetWorkingDir(oldDirectory, MAX_LOCATION);
2164 ChangeWorkingDir(topNode.path);*/
2171 char targetDir[MAX_LOCATION];
2172 char objDirExpNoSpaces[MAX_LOCATION];
2173 char objDirNoSpaces[MAX_LOCATION];
2174 char resDirNoSpaces[MAX_LOCATION];
2175 char targetDirExpNoSpaces[MAX_LOCATION];
2176 char fixedModuleName[MAX_FILENAME];
2177 char fixedConfigName[MAX_FILENAME];
2179 // Non-zero if we're building eC code
2180 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2181 int numCObjects = 0;
2182 bool containsCXX = false; // True if the project contains a C++ file
2183 bool sameObjTargetDirs;
2184 String objDirExp = GetObjDirExpression(config);
2185 TargetTypes targetType = GetTargetType(config);
2187 char cfDir[MAX_LOCATION];
2188 int objectsParts, eCsourcesParts;
2189 Array<String> listItems { };
2190 Map<String, int> varStringLenDiffs { };
2191 Map<String, NameCollisionInfo> namesInfo { };
2192 bool forceBitDepth = false;
2194 Map<String, int> cflagsVariations { };
2195 Map<int, int> nodeCFlagsMapping { };
2197 Map<String, int> ecflagsVariations { };
2198 Map<int, int> nodeECFlagsMapping { };
2200 ReplaceSpaces(objDirNoSpaces, objDirExp);
2201 strcpy(targetDir, GetTargetDirExpression(config));
2202 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2204 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2205 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2206 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
2207 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2208 ReplaceSpaces(fixedModuleName, moduleName);
2209 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2210 CamelCase(fixedConfigName);
2212 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2214 f.Printf(".PHONY: all objdir%s clean realclean\n\n", sameObjTargetDirs ? "" : " targetdir");
2216 f.Printf("# CONTENT\n\n");
2218 f.Printf("MODULE := %s\n", fixedModuleName);
2219 //f.Printf("VERSION = %s\n", version);
2220 f.Printf("CONFIG := %s\n", fixedConfigName);
2221 f.Printf("ifndef COMPILER\n");
2222 f.Printf("COMPILER := default\n");
2223 f.Printf("endif\n");
2226 if(compilerConfigsDir && compilerConfigsDir[0])
2228 strcpy(cfDir, compilerConfigsDir);
2229 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2234 GetIDECompilerConfigsDir(cfDir, true, true);
2235 // Use CF_DIR environment variable for absolute paths only
2236 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2237 strcpy(cfDir, "$(CF_DIR)");
2240 f.Printf("_CF_DIR = %s\n", cfDir);
2243 f.Printf("ifdef DEBUG\n");
2244 f.Printf("NOSTRIP := y\n");
2245 f.Printf("endif\n");
2247 test = GetTargetTypeIsSetByPlatform(config);
2251 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2253 TargetTypes targetType;
2254 PlatformOptions projectPOs, configPOs;
2255 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2256 targetType = platformTargetType;
2262 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2264 f.Printf("TARGET_TYPE = ");
2265 f.Printf(TargetTypeToMakefileVariable(targetType));
2269 f.Printf("else\n"); // ifCount should always be > 0
2271 f.Printf("TARGET_TYPE = ");
2272 f.Printf(TargetTypeToMakefileVariable(targetType));
2278 for(c = 0; c < ifCount; c++)
2279 f.Printf("endif\n");
2284 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2285 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2286 f.Printf("endif\n\n");
2288 f.Printf("# FLAGS\n\n");
2290 f.Printf("ECFLAGS =\n");
2291 f.Printf("ifndef DEBIAN_PACKAGE\n");
2292 f.Printf("CFLAGS =\n");
2293 f.Printf("endif\n");
2294 f.Printf("CECFLAGS =\n");
2295 f.Printf("OFLAGS =\n");
2296 f.Printf("LDFLAGS =\n");
2297 f.Printf("LIBS =\n");
2300 f.Printf("# INCLUDES\n\n");
2302 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2303 f.Printf("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2306 f.Printf("# VARIABLES\n\n");
2308 f.Printf("OBJ = %s%s\n\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2310 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2312 // test = GetTargetTypeIsSetByPlatform(config);
2314 char target[MAX_LOCATION];
2315 char targetNoSpaces[MAX_LOCATION];
2320 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2322 if(type != targetType)
2327 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2329 GetMakefileTargetFileName(type, target, config);
2330 strcpy(targetNoSpaces, targetDir);
2331 PathCatSlash(targetNoSpaces, target);
2332 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2333 f.Printf("TARGET = %s\n", targetNoSpaces);
2336 f.Printf("else\n"); // ifCount should always be > 0
2338 GetMakefileTargetFileName(targetType, target, config);
2339 strcpy(targetNoSpaces, targetDir);
2340 PathCatSlash(targetNoSpaces, target);
2341 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2342 f.Printf("TARGET = %s\n", targetNoSpaces);
2348 for(c = 0; c < ifCount; c++)
2349 f.Printf("endif\n");
2355 // Use something fixed here, to not cause Makefile differences across compilers...
2356 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2357 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2359 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2361 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2363 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
2364 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs, null);
2368 char * map[4][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "BOWLS", "B" } };
2370 topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2371 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2373 f.Printf("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2374 if(eCsourcesParts > 1)
2376 for(c = 1; c <= eCsourcesParts; c++)
2377 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2381 for(c = 0; c < 3; c++)
2383 if(eCsourcesParts > 1)
2386 f.Printf("%s =", map[c][0]);
2387 for(n = 1; n <= eCsourcesParts; n++)
2388 f.Printf(" $(%s%d)", map[c][0], n);
2390 for(n = 1; n <= eCsourcesParts; n++)
2391 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2393 else if(eCsourcesParts == 1)
2394 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2399 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2400 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, "$(ECSOURCES)");
2403 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2404 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2406 f.Printf("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
2407 if((config && config.options && config.options.libraries) ||
2408 (options && options.libraries))
2410 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2411 f.Printf("LIBS +=");
2412 if(config && config.options && config.options.libraries)
2413 OutputLibraries(f, config.options.libraries);
2414 else if(options && options.libraries)
2415 OutputLibraries(f, options.libraries);
2417 f.Printf("endif\n");
2421 topNode.GenMakeCollectAssignNodeFlags(config, numCObjects,
2422 cflagsVariations, nodeCFlagsMapping,
2423 ecflagsVariations, nodeECFlagsMapping, null);
2425 GenMakePrintCustomFlags(f, "CFLAGS", false, cflagsVariations);
2426 GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2428 if(platforms || (config && config.platforms))
2431 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2432 //for(platform = win32; platform <= apple; platform++)
2434 f.Printf("# TARGET_PLATFORM-SPECIFIC OPTIONS\n\n");
2435 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2437 PlatformOptions projectPlatformOptions, configPlatformOptions;
2438 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2440 if(projectPlatformOptions || configPlatformOptions)
2445 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2448 if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
2449 (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
2451 f.Printf("CFLAGS +=");
2452 // tocheck: does any of that -Wl stuff from linkerOptions have any business being in CFLAGS?
2453 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2455 f.Printf(" \\\n\t -Wl");
2456 for(s : projectPlatformOptions.options.linkerOptions)
2459 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2461 f.Printf(" \\\n\t -Wl");
2462 for(s : configPlatformOptions.options.linkerOptions)
2468 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2469 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2470 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2471 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2473 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2474 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2475 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2477 f.Printf("OFLAGS +=");
2478 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2479 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2480 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2481 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2485 if((configPlatformOptions && configPlatformOptions.options.libraries))
2487 if(configPlatformOptions.options.libraries.count)
2489 f.Printf("LIBS +=");
2490 OutputLibraries(f, configPlatformOptions.options.libraries);
2494 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
2496 if(projectPlatformOptions.options.libraries.count)
2498 f.Printf("LIBS +=");
2499 OutputLibraries(f, projectPlatformOptions.options.libraries);
2503 f.Printf("endif\n\n");
2509 for(c = 0; c < ifCount; c++)
2510 f.Printf("endif\n");
2515 // tocheck: does any of that -Wl stuff from linkerOptions have any business being in CFLAGS?
2516 if(options && options.linkerOptions && options.linkerOptions.count)
2518 f.Printf("CFLAGS +=");
2519 f.Printf(" \\\n\t -Wl");
2520 for(s : options.linkerOptions)
2525 f.Printf("CECFLAGS += -cpp $(call escspace,$(CPP)) -t $(TARGET_PLATFORM)");
2528 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2529 f.Printf("OFLAGS +=");
2530 forceBitDepth = (options && options.buildBitDepth) || numCObjects;
2532 f.Printf((!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? " $(FORCE_32_BIT)" : " $(FORCE_64_BIT) \\\n");
2534 if(GetProfile(config))
2536 if(config && config.options && config.options.libraryDirs)
2537 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
2538 if(options && options.libraryDirs)
2539 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
2541 f.Printf("OFLAGS += $(LDFLAGS)\n");
2542 f.Printf("endif\n\n");
2544 f.Printf("# TARGETS\n\n");
2546 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
2548 f.Printf("objdir:\n");
2549 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2550 //f.Printf("# PRE-BUILD COMMANDS\n");
2551 if(options && options.prebuildCommands)
2553 for(s : options.prebuildCommands)
2554 if(s && s[0]) f.Printf("\t%s\n", s);
2556 if(config && config.options && config.options.prebuildCommands)
2558 for(s : config.options.prebuildCommands)
2559 if(s && s[0]) f.Printf("\t%s\n", s);
2561 if(platforms || (config && config.platforms))
2564 //f.Printf("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2565 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2567 PlatformOptions projectPOs, configPOs;
2568 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2570 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2571 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2577 f.Printf(PlatformToMakefileTargetVariable(platform));
2580 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2582 for(s : projectPOs.options.prebuildCommands)
2583 if(s && s[0]) f.Printf("\t%s\n", s);
2585 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2587 for(s : configPOs.options.prebuildCommands)
2588 if(s && s[0]) f.Printf("\t%s\n", s);
2595 for(c = 0; c < ifCount; c++)
2596 f.Printf("endif\n");
2601 if(!sameObjTargetDirs)
2603 f.Printf("targetdir:\n");
2604 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2609 // Main Module (Linking) for ECERE C modules
2610 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2611 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2612 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2613 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
2614 // Main Module (Linking) for ECERE C modules
2615 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2616 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2617 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2618 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2619 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2624 // This would not rebuild the target on updated objects
2625 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2627 // This should fix it for good!
2628 f.Printf("$(SYMBOLS): | objdir\n");
2629 f.Printf("$(OBJECTS): | objdir\n");
2631 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2632 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2634 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2635 f.Printf("\t$(%s) $(OFLAGS) $(OBJECTS) $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
2636 if(!GetDebug(config))
2638 f.Printf("ifndef NOSTRIP\n");
2639 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2640 f.Printf("endif\n");
2642 if(GetCompress(config))
2644 f.Printf("ifndef WINDOWS\n");
2645 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2646 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2647 f.Printf("endif\n");
2649 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2650 f.Printf("endif\n");
2653 if(resNode.files && resNode.files.count && !noResources)
2654 resNode.GenMakefileAddResources(f, resNode.path, config);
2656 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2657 f.Printf("endif\n");
2659 //f.Printf("# POST-BUILD COMMANDS\n");
2660 if(options && options.postbuildCommands)
2662 for(s : options.postbuildCommands)
2663 if(s && s[0]) f.Printf("\t%s\n", s);
2665 if(config && config.options && config.options.postbuildCommands)
2667 for(s : config.options.postbuildCommands)
2668 if(s && s[0]) f.Printf("\t%s\n", s);
2670 if(platforms || (config && config.platforms))
2673 //f.Printf("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2674 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2676 PlatformOptions projectPOs, configPOs;
2677 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2679 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2680 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2686 f.Printf(PlatformToMakefileTargetVariable(platform));
2689 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2691 for(s : projectPOs.options.postbuildCommands)
2692 if(s && s[0]) f.Printf("\t%s\n", s);
2694 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2696 for(s : configPOs.options.postbuildCommands)
2697 if(s && s[0]) f.Printf("\t%s\n", s);
2704 for(c = 0; c < ifCount; c++)
2705 f.Printf("endif\n");
2710 f.Printf("# SYMBOL RULES\n\n");
2712 Map<Platform, bool> excludedPlatforms { };
2713 topNode.GenMakefilePrintSymbolRules(f, this, config, excludedPlatforms,
2714 nodeCFlagsMapping, nodeECFlagsMapping);
2715 delete excludedPlatforms;
2718 f.Printf("# C OBJECT RULES\n\n");
2720 Map<Platform, bool> excludedPlatforms { };
2721 topNode.GenMakefilePrintCObjectRules(f, this, config, excludedPlatforms,
2722 nodeCFlagsMapping, nodeECFlagsMapping);
2723 delete excludedPlatforms;
2726 f.Printf("# OBJECT RULES\n\n");
2727 // todo call this still but only generate rules whith specific options
2728 // see we-have-file-specific-options in ProjectNode.ec
2730 Map<Platform, bool> excludedPlatforms { };
2731 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, excludedPlatforms,
2732 nodeCFlagsMapping, nodeECFlagsMapping);
2733 delete excludedPlatforms;
2737 GenMakefilePrintMainObjectRule(f, config);
2739 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2740 f.Printf("\t$(call rmq,%s$(TARGET))\n", numCObjects ? "$(OBJ)$(MODULE).main.c $(OBJ)$(MODULE).main.ec $(OBJ)$(MODULE).main$(I) $(OBJ)$(MODULE).main$(S) " : "");
2741 OutputCleanActions(f, "OBJECTS", objectsParts);
2744 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
2745 OutputCleanActions(f, "BOWLS", eCsourcesParts);
2746 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
2747 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
2751 f.Printf("realclean: clean\n");
2752 f.Printf("\t$(call rmrq,$(OBJ))\n");
2753 if(!sameObjTargetDirs)
2754 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2761 varStringLenDiffs.Free();
2762 delete varStringLenDiffs;
2766 delete cflagsVariations;
2767 delete nodeCFlagsMapping;
2768 delete ecflagsVariations;
2769 delete nodeECFlagsMapping;
2774 // ChangeWorkingDir(oldDirectory);
2775 // delete pathBackup;
2778 config.makingModified = false;
2782 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
2784 char extension[MAX_EXTENSION] = "c";
2785 char modulePath[MAX_LOCATION];
2786 char fixedModuleName[MAX_FILENAME];
2789 char objDirNoSpaces[MAX_LOCATION];
2790 String objDirExp = GetObjDirExpression(config);
2792 ReplaceSpaces(objDirNoSpaces, objDirExp);
2793 ReplaceSpaces(fixedModuleName, moduleName);
2795 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2796 //strcat(fixedModuleName, ".main");
2798 #if 0 // TODO: Fix nospaces stuff
2799 // *** Dependency command ***
2800 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2802 // System Includes (from global settings)
2803 for(item : compiler.dirs[Includes])
2805 strcat(command, " -isystem ");
2806 if(strchr(item.name, ' '))
2808 strcat(command, "\"");
2809 strcat(command, item);
2810 strcat(command, "\"");
2813 strcat(command, item);
2816 for(item = includeDirs.first; item; item = item.next)
2818 strcat(command, " -I");
2819 if(strchr(item.name, ' '))
2821 strcat(command, "\"");
2822 strcat(command, item.name);
2823 strcat(command, "\"");
2826 strcat(command, item.name);
2828 for(item = preprocessorDefs.first; item; item = item.next)
2830 strcat(command, " -D");
2831 strcat(command, item.name);
2835 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2839 bool firstLine = true;
2841 // To do some time: auto save external dependencies?
2844 if(dep.GetLine(line, sizeof(line)-1))
2848 char * colon = strstr(line, ":");
2849 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2863 // If we failed to generate dependencies...
2867 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2873 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2876 void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
2879 for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
2881 for(v : cflagsVariations)
2886 f.Printf("%s +=", variableName);
2888 f.Printf("CUSTOM%d_%s =", v-1, variableName);
2889 f.Puts(&v ? &v : "");
2898 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
2899 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
2901 *projectPlatformOptions = null;
2902 *configPlatformOptions = null;
2907 if(!strcmpi(p.name, platform))
2909 *projectPlatformOptions = p;
2914 if(config && config.platforms)
2916 for(p : config.platforms)
2918 if(!strcmpi(p.name, platform))
2920 *configPlatformOptions = p;
2928 Project LegacyBinaryLoadProject(File f, char * filePath)
2930 Project project = null;
2931 char signature[sizeof(epjSignature)];
2933 f.Read(signature, sizeof(signature), 1);
2934 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2936 char topNodePath[MAX_LOCATION];
2937 /*ProjectConfig newConfig
2939 name = CopyString("Default");
2940 makingModified = true;
2941 compilingModified = true;
2942 linkingModified = true;
2946 project = Project { options = { } };
2947 LegacyBinaryLoadNode(project.topNode, f);
2948 delete project.topNode.path;
2949 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2950 MakeSlashPath(topNodePath);
2952 PathCatSlash(topNodePath, filePath);
2953 project.filePath = topNodePath;
2955 /* THIS IS ALREADY DONE BY filePath property
2956 StripLastDirectory(topNodePath, topNodePath);
2957 project.topNode.path = CopyString(topNodePath);
2959 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2961 // newConfig.options.defaultNameSpace = "";
2962 /*newConfig.objDir.dir = "obj";
2963 newConfig.targetDir.dir = "";*/
2965 //project.configurations = { [ newConfig ] };
2966 //project.config = newConfig;
2973 String targetFileName, targetDirectory, objectsDirectory;
2975 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2976 f.Read(&temp, sizeof(int),1);
2979 case 0: project.options.targetType = executable; break;
2980 case 1: project.options.targetType = sharedLibrary; break;
2981 case 2: project.options.targetType = staticLibrary; break;
2984 f.Read(&len, sizeof(int),1);
2985 targetFileName = new char[len+1];
2986 f.Read(targetFileName, sizeof(char), len+1);
2987 project.options.targetFileName = targetFileName;
2988 delete targetFileName;
2990 f.Read(&len, sizeof(int),1);
2991 targetDirectory = new char[len+1];
2992 f.Read(targetDirectory, sizeof(char), len+1);
2993 project.options.targetDirectory = targetDirectory;
2994 delete targetDirectory;
2996 f.Read(&len, sizeof(int),1);
2997 objectsDirectory = new byte[len+1];
2998 f.Read(objectsDirectory, sizeof(char), len+1);
2999 project.options.objectsDirectory = objectsDirectory;
3000 delete objectsDirectory;
3002 f.Read(&temp, sizeof(int),1);
3003 project./*config.*/options.debug = temp ? true : false;
3004 f.Read(&temp, sizeof(int),1);
3005 project./*config.*/options.optimization = temp ? speed : none;
3006 f.Read(&temp, sizeof(int),1);
3007 project./*config.*/options.profile = temp ? true : false;
3008 f.Read(&temp, sizeof(int),1);
3009 project.options.warnings = temp ? all : unset;
3011 f.Read(&count, sizeof(int),1);
3014 project.options.includeDirs = { };
3015 for(c = 0; c < count; c++)
3018 f.Read(&len, sizeof(int),1);
3019 name = new char[len+1];
3020 f.Read(name, sizeof(char), len+1);
3021 project.options.includeDirs.Add(name);
3025 f.Read(&count, sizeof(int),1);
3028 project.options.libraryDirs = { };
3029 for(c = 0; c < count; c++)
3032 f.Read(&len, sizeof(int),1);
3033 name = new char[len+1];
3034 f.Read(name, sizeof(char), len+1);
3035 project.options.libraryDirs.Add(name);
3039 f.Read(&count, sizeof(int),1);
3042 project.options.libraries = { };
3043 for(c = 0; c < count; c++)
3046 f.Read(&len, sizeof(int),1);
3047 name = new char[len+1];
3048 f.Read(name, sizeof(char), len+1);
3049 project.options.libraries.Add(name);
3053 f.Read(&count, sizeof(int),1);
3056 project.options.preprocessorDefinitions = { };
3057 for(c = 0; c < count; c++)
3060 f.Read(&len, sizeof(int),1);
3061 name = new char[len+1];
3062 f.Read(name, sizeof(char), len+1);
3063 project.options.preprocessorDefinitions.Add(name);
3067 f.Read(&temp, sizeof(int),1);
3068 project.options.console = temp ? true : false;
3071 for(node : project.topNode.files)
3073 if(node.type == resources)
3075 project.resNode = node;
3085 void ProjectConfig::LegacyProjectConfigLoad(File f)
3093 char subSection[128];
3099 f.GetLine(buffer, 65536 - 1);
3100 TrimLSpaces(buffer, buffer);
3101 TrimRSpaces(buffer, buffer);
3104 if(buffer[0] == '-')
3108 TrimLSpaces(equal, equal);
3109 if(!strcmpi(subSection, "LibraryDirs"))
3111 if(!options.libraryDirs)
3112 options.libraryDirs = { [ CopyString(equal) ] };
3114 options.libraryDirs.Add(CopyString(equal));
3116 else if(!strcmpi(subSection, "IncludeDirs"))
3118 if(!options.includeDirs)
3119 options.includeDirs = { [ CopyString(equal) ] };
3121 options.includeDirs.Add(CopyString(equal));
3124 else if(buffer[0] == '+')
3135 TrimLSpaces(equal, equal);
3136 delete name; name = CopyString(equal); // property::name = equal;
3139 else if(!strcmpi(buffer, "Compiler Options"))
3140 strcpy(section, buffer);
3141 else if(!strcmpi(buffer, "IncludeDirs"))
3142 strcpy(subSection, buffer);
3143 else if(!strcmpi(buffer, "Linker Options"))
3144 strcpy(section, buffer);
3145 else if(!strcmpi(buffer, "LibraryDirs"))
3146 strcpy(subSection, buffer);
3147 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3154 equal = strstr(buffer, "=");
3158 TrimRSpaces(buffer, buffer);
3160 TrimLSpaces(equal, equal);
3161 if(!strcmpi(buffer, "Target Name"))
3162 options.targetFileName = /*CopyString(*/equal/*)*/;
3163 else if(!strcmpi(buffer, "Target Type"))
3165 if(!strcmpi(equal, "Executable"))
3166 options.targetType = executable;
3167 else if(!strcmpi(equal, "Shared"))
3168 options.targetType = sharedLibrary;
3169 else if(!strcmpi(equal, "Static"))
3170 options.targetType = staticLibrary;
3172 options.targetType = executable;
3174 else if(!strcmpi(buffer, "Target Directory"))
3175 options.targetDirectory = /*CopyString(*/equal/*)*/;
3176 else if(!strcmpi(buffer, "Console"))
3177 options.console = ParseTrueFalseValue(equal);
3178 else if(!strcmpi(buffer, "Libraries"))
3180 if(!options.libraries) options.libraries = { };
3181 ParseArrayValue(options.libraries, equal);
3183 else if(!strcmpi(buffer, "Intermediate Directory"))
3184 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3185 else if(!strcmpi(buffer, "Debug"))
3186 options.debug = ParseTrueFalseValue(equal);
3187 else if(!strcmpi(buffer, "Optimize"))
3189 if(!strcmpi(equal, "None"))
3190 options.optimization = none;
3191 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3192 options.optimization = speed;
3193 else if(!strcmpi(equal, "Size"))
3194 options.optimization = size;
3196 options.optimization = none;
3198 else if(!strcmpi(buffer, "Compress"))
3199 options.compress = ParseTrueFalseValue(equal);
3200 else if(!strcmpi(buffer, "Profile"))
3201 options.profile = ParseTrueFalseValue(equal);
3202 else if(!strcmpi(buffer, "AllWarnings"))
3203 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3204 else if(!strcmpi(buffer, "MemoryGuard"))
3205 options.memoryGuard = ParseTrueFalseValue(equal);
3206 else if(!strcmpi(buffer, "Default Name Space"))
3207 options.defaultNameSpace = CopyString(equal);
3208 else if(!strcmpi(buffer, "Strict Name Spaces"))
3209 options.strictNameSpaces = ParseTrueFalseValue(equal);
3210 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3212 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3213 ParseArrayValue(options.preprocessorDefinitions, equal);
3219 if(!options.targetDirectory && options.objectsDirectory)
3220 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3221 //if(!objDir.dir) objDir.dir = "obj";
3222 //if(!targetDir.dir) targetDir.dir = "";
3223 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3224 // if(!defaultNameSpace) property::defaultNameSpace = "";
3225 makingModified = true;
3228 Project LegacyAsciiLoadProject(File f, char * filePath)
3230 Project project = null;
3231 ProjectNode node = null;
3233 char parentPath[MAX_LOCATION];
3234 char section[128] = "";
3235 char subSection[128] = "";
3237 bool configurationsPresent = false;
3247 f.GetLine(buffer, 65536 - 1);
3248 TrimLSpaces(buffer, buffer);
3249 TrimRSpaces(buffer, buffer);
3252 if(buffer[0] == '-' || buffer[0] == '=')
3254 bool simple = buffer[0] == '-';
3257 TrimLSpaces(equal, equal);
3258 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3260 if(!project.config.options.libraryDirs)
3261 project.config.options.libraryDirs = { [ CopyString(equal) ] };
3263 project.config.options.libraryDirs.Add(CopyString(equal));
3265 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3267 if(!project.config.options.includeDirs)
3268 project.config.options.includeDirs = { [ CopyString(equal) ] };
3270 project.config.options.includeDirs.Add(CopyString(equal));
3272 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3274 len = strlen(equal);
3277 char temp[MAX_LOCATION];
3278 ProjectNode child { };
3279 // We don't need to do this anymore, fileName is just a property that sets name & path
3280 // child.fileName = CopyString(equal);
3283 child.name = CopyString(equal);
3284 child.path = CopyString(parentPath);
3288 GetLastDirectory(equal, temp);
3289 child.name = CopyString(temp);
3290 StripLastDirectory(equal, temp);
3291 child.path = CopyString(temp);
3293 child.nodeType = file;
3294 child.parent = parent;
3295 child.indent = parent.indent + 1;
3297 child.icon = NodeIcons::SelectFileIcon(child.name);
3298 parent.files.Add(child);
3304 StripLastDirectory(parentPath, parentPath);
3305 parent = parent.parent;
3309 else if(buffer[0] == '+')
3313 TrimLSpaces(equal, equal);
3314 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3316 char temp[MAX_LOCATION];
3317 ProjectNode child { };
3318 // NEW: Folders now have a path set like files
3319 child.name = CopyString(equal);
3320 strcpy(temp, parentPath);
3321 PathCatSlash(temp, child.name);
3322 child.path = CopyString(temp);
3324 child.parent = parent;
3325 child.indent = parent.indent + 1;
3326 child.type = folder;
3327 child.nodeType = folder;
3329 child.icon = folder;
3330 PathCatSlash(parentPath, child.name);
3331 parent.files.Add(child);
3336 else if(!strcmpi(section, "Configurations"))
3338 ProjectConfig newConfig
3340 makingModified = true;
3344 LegacyProjectConfigLoad(newConfig, f);
3345 project.configurations.Add(newConfig);
3348 else if(!strcmpi(buffer, "ECERE Project File"));
3349 else if(!strcmpi(buffer, "Version 0a"))
3350 ; //strcpy(version, "0a");
3351 else if(!strcmpi(buffer, "Version 0.1a"))
3352 ; //strcpy(version, "0.1a");
3353 else if(!strcmpi(buffer, "Configurations"))
3355 project.configurations.Free();
3356 project.config = null;
3357 strcpy(section, buffer);
3358 configurationsPresent = true;
3360 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3362 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3363 char topNodePath[MAX_LOCATION];
3364 // newConfig.defaultNameSpace = "";
3365 //newConfig.objDir.dir = "obj";
3366 //newConfig.targetDir.dir = "";
3367 project = Project { /*options = { }*/ };
3368 project.configurations = { [ newConfig ] };
3369 project.config = newConfig;
3370 // if(project.topNode.path) delete project.topNode.path;
3371 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3372 MakeSlashPath(topNodePath);
3373 PathCatSlash(topNodePath, filePath);
3374 project.filePath = topNodePath;
3375 parentPath[0] = '\0';
3376 parent = project.topNode;
3378 strcpy(section, "Target");
3383 if(equal[0] == '\"')
3385 StripQuotes(equal, equal);
3386 delete project.moduleName; project.moduleName = CopyString(equal);
3390 else if(!strcmpi(buffer, "Compiler Options"));
3391 else if(!strcmpi(buffer, "IncludeDirs"))
3392 strcpy(subSection, buffer);
3393 else if(!strcmpi(buffer, "Linker Options"));
3394 else if(!strcmpi(buffer, "LibraryDirs"))
3395 strcpy(subSection, buffer);
3396 else if(!strcmpi(buffer, "Files"))
3398 strcpy(section, "Target");
3399 strcpy(subSection, buffer);
3401 else if(!strcmpi(buffer, "Resources"))
3403 ProjectNode child { };
3404 parent.files.Add(child);
3405 child.parent = parent;
3406 child.indent = parent.indent + 1;
3407 child.name = CopyString(buffer);
3408 child.path = CopyString("");
3409 child.type = resources;
3411 child.icon = archiveFile;
3412 project.resNode = child;
3415 strcpy(subSection, buffer);
3419 equal = strstr(buffer, "=");
3423 TrimRSpaces(buffer, buffer);
3425 TrimLSpaces(equal, equal);
3427 if(!strcmpi(section, "Target"))
3429 if(!strcmpi(buffer, "Build Exclusions"))
3431 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3433 /*if(node && node.type != NodeTypes::project)
3434 ParseListValue(node.buildExclusions, equal);*/
3437 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
3439 delete project.resNode.path;
3440 project.resNode.path = CopyString(equal);
3441 PathCatSlash(parentPath, equal);
3445 else if(!strcmpi(buffer, "Intermediate Directory"))
3446 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3447 else if(!strcmpi(buffer, "Debug"))
3448 project.config.options.debug = ParseTrueFalseValue(equal);
3449 else if(!strcmpi(buffer, "Optimize"))
3451 if(!strcmpi(equal, "None"))
3452 project.config.options.optimization = none;
3453 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3454 project.config.options.optimization = speed;
3455 else if(!strcmpi(equal, "Size"))
3456 project.config.options.optimization = size;
3458 project.config.options.optimization = none;
3460 else if(!strcmpi(buffer, "Profile"))
3461 project.config.options.profile = ParseTrueFalseValue(equal);
3462 else if(!strcmpi(buffer, "MemoryGuard"))
3463 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
3466 if(!project.options) project.options = { };
3468 // Project Wide Settings (All configs)
3469 if(!strcmpi(buffer, "Target Name"))
3470 project.options.targetFileName = /*CopyString(*/equal/*)*/;
3471 else if(!strcmpi(buffer, "Target Type"))
3473 if(!strcmpi(equal, "Executable"))
3474 project.options.targetType = executable;
3475 else if(!strcmpi(equal, "Shared"))
3476 project.options.targetType = sharedLibrary;
3477 else if(!strcmpi(equal, "Static"))
3478 project.options.targetType = staticLibrary;
3480 project.options.targetType = executable;
3482 else if(!strcmpi(buffer, "Target Directory"))
3483 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
3484 else if(!strcmpi(buffer, "Console"))
3485 project.options.console = ParseTrueFalseValue(equal);
3486 else if(!strcmpi(buffer, "Libraries"))
3488 if(!project.options.libraries) project.options.libraries = { };
3489 ParseArrayValue(project.options.libraries, equal);
3491 else if(!strcmpi(buffer, "AllWarnings"))
3492 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3493 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3495 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3497 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
3498 ParseListValue(node.preprocessorDefs, equal);*/
3502 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
3503 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3514 SplitPlatformLibraries(project);
3516 if(configurationsPresent)
3517 CombineIdenticalConfigOptions(project);
3521 void SplitPlatformLibraries(Project project)
3523 if(project && project.configurations)
3525 for(cfg : project.configurations)
3527 if(cfg.options.libraries && cfg.options.libraries.count)
3529 Iterator<String> it { cfg.options.libraries };
3533 char * platformName = strstr(l, ":");
3536 PlatformOptions platform = null;
3538 if(!cfg.platforms) cfg.platforms = { };
3539 for(p : cfg.platforms)
3541 if(!strcmpi(platformName, p.name))
3549 platform = { name = CopyString(platformName), options = { libraries = { } } };
3550 cfg.platforms.Add(platform);
3552 *(platformName-1) = 0;
3553 platform.options.libraries.Add(CopyString(l));
3555 cfg.options.libraries.Delete(it.pointer);
3564 void CombineIdenticalConfigOptions(Project project)
3566 if(project && project.configurations && project.configurations.count)
3569 ProjectOptions nullOptions { };
3570 ProjectConfig firstConfig = null;
3571 for(cfg : project.configurations)
3573 if(cfg.options.targetType != staticLibrary)
3580 firstConfig = project.configurations.firstIterator.data;
3582 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3584 if(!member.isProperty)
3586 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3591 for(cfg : project.configurations)
3593 if(cfg != firstConfig)
3595 if(cfg.options.targetType != staticLibrary)
3599 if(type.type == noHeadClass || type.type == normalClass)
3601 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3602 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3603 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3607 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3608 (byte *)firstConfig.options + member.offset + member._class.offset,
3609 (byte *)cfg.options + member.offset + member._class.offset);
3621 if(type.type == noHeadClass || type.type == normalClass)
3623 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3624 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3625 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3630 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3631 (byte *)firstConfig.options + member.offset + member._class.offset,
3632 (byte *)nullOptions + member.offset + member._class.offset))
3636 if(!project.options) project.options = { };
3638 /*if(type.type == noHeadClass || type.type == normalClass)
3640 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3641 (byte *)project.options + member.offset + member._class.offset,
3642 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3646 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3647 // TOFIX: ListBox::SetData / OnCopy mess
3648 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3649 (byte *)project.options + member.offset + member._class.offset,
3650 (type.typeSize > 4) ? address :
3651 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3652 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3653 (void *)*(byte *)address )));
3656 (byte *)project.options + member.offset + member._class.offset,
3657 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3659 for(cfg : project.configurations)
3661 if(cfg.options.targetType == staticLibrary)
3665 if(type.type == noHeadClass || type.type == normalClass)
3667 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3668 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3669 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3673 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3674 (byte *)firstConfig.options + member.offset + member._class.offset,
3675 (byte *)cfg.options + member.offset + member._class.offset);
3680 if(cfg != firstConfig)
3682 if(type.type == noHeadClass || type.type == normalClass)
3684 type._vTbl[__ecereVMethodID_class_OnFree](type,
3685 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3689 type._vTbl[__ecereVMethodID_class_OnFree](type,
3690 (byte *)cfg.options + member.offset + member._class.offset);
3692 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3695 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3702 // Compare Platform Specific Settings
3705 for(cfg : project.configurations)
3707 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3708 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3714 if(same && firstConfig.platforms)
3716 for(cfg : project.configurations)
3718 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3720 if(cfg != firstConfig)
3722 cfg.platforms.Free();
3723 delete cfg.platforms;
3726 project.platforms = firstConfig.platforms;
3727 firstConfig.platforms = null;
3731 // Static libraries can't contain libraries
3732 for(cfg : project.configurations)
3734 if(cfg.options.targetType == staticLibrary)
3736 if(!cfg.options.libraries) cfg.options.libraries = { };
3737 cfg.options.libraries.Free();
3743 Project LoadProject(char * filePath, char * activeConfigName)
3745 Project project = null;
3746 File f = FileOpen(filePath, read);
3749 project = LegacyBinaryLoadProject(f, filePath);
3752 JSONParser parser { f = f };
3753 JSONResult result = parser.GetObject(class(Project), &project);
3756 char insidePath[MAX_LOCATION];
3758 delete project.topNode.files;
3759 if(!project.files) project.files = { };
3760 project.topNode.files = project.files;
3761 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3762 delete project.resNode.path;
3763 project.resNode.path = project.resourcesPath;
3764 project.resourcesPath = null;
3765 project.resNode.nodeType = (ProjectNodeType)-1;
3766 delete project.resNode.files;
3767 project.resNode.files = project.resources;
3768 project.files = null;
3769 project.resources = null;
3770 if(!project.configurations) project.configurations = { };
3773 char topNodePath[MAX_LOCATION];
3774 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3775 MakeSlashPath(topNodePath);
3776 PathCatSlash(topNodePath, filePath);
3777 project.filePath = topNodePath;//filePath;
3780 project.topNode.FixupNode(insidePath);
3785 project = LegacyAsciiLoadProject(f, filePath);
3791 if(!project.options) project.options = { };
3792 if(activeConfigName && activeConfigName[0] && project.configurations)
3794 for(cfg : project.configurations)
3796 if(!strcmpi(cfg.name, activeConfigName))
3798 project.config = cfg;
3803 if(!project.config && project.configurations)
3804 project.config = project.configurations.firstIterator.data;
3806 if(!project.resNode)
3808 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3811 if(!project.moduleName)
3812 project.moduleName = CopyString(project.name);
3813 if(project.config &&
3814 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3815 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3817 //delete project.config.options.targetFileName;
3819 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
3820 project.config.options.optimization = none;
3821 project.config.options.debug = true;
3822 //project.config.options.warnings = unset;
3823 project.config.options.memoryGuard = false;
3824 project.config.compilingModified = true;
3825 project.config.linkingModified = true;
3827 else if(!project.topNode.name && project.config)
3829 project.topNode.name = CopyString(project.config.options.targetFileName);
3832 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3833 project.topNode.configurations = project.configurations;
3834 project.topNode.platforms = project.platforms;
3835 project.topNode.options = project.options;*/