2 public import static "ecere"
7 #ifndef MAKEFILE_GENERATOR
9 // We should have the .sln/.vcproj generation even on other platforms
10 // e.g. detect from an environment variable pointing to a Windows drive
16 import "ProjectConfig"
22 static void DummyFunction()
30 extern int __ecereVMethodID_class_OnCompare;
31 extern int __ecereVMethodID_class_OnFree;
33 IDESettings ideSettings;
35 IDESettingsContainer settingsContainer
38 dataOwner = &ideSettings;
39 dataClass = class(IDESettings);
41 void OnLoad(GlobalSettingsData data)
43 IDESettings settings = (IDESettings)data;
44 #ifndef MAKEFILE_GENERATOR
45 globalSettingsDialog.ideSettings = settings;
46 ide.UpdateRecentMenus();
47 // ide.UpdateMakefiles(); -- can't really regenerate on Load since all recent menus changes will happen
52 #ifdef MAKEFILE_GENERATOR
53 CompilerConfig defaultCompiler;
56 // LEGACY BINARY EPJ LOADING
58 SetBool ParseTrueFalseValue(char * string)
60 if(!strcmpi(string, "True")) return true;
64 void ParseArrayValue(Array<String> array, char * equal)
66 char * start, * comma;
68 string = CopyString(equal);
72 comma = strstr(start, ",");
75 array.Add(CopyString(start));
85 void ProjectNode::LegacyBinaryLoadNode(File f)
90 f.Read(&len, sizeof(len), 1);
91 name = new char[len+1];
93 f.Read(name, sizeof(char), len+1);
94 f.Read(&len, sizeof(len), 1);
96 path = new char[len+1];
97 f.Read(path, sizeof(char), len+1);
100 fileName = new char[fileNameLen+2];
101 strcpy(fileName, path);
102 if(fileName[0]) strcat(fileName, "/");
103 strcat(fileName, name);
106 f.Read(&type, sizeof(type), 1);
107 f.Read(&count, sizeof(count), 1);
112 icon = NodeIcons::SelectFileIcon(name);
117 icon = NodeIcons::SelectNodeIcon(type);
120 if(count && !files) files = { };
121 for(c = 0; c < count; c++)
123 ProjectNode child { };
126 child.indent = indent + 1;
127 LegacyBinaryLoadNode(child, f);
131 /*void LegacyBinarySaveNode(File f)
136 f.Write(&len, sizeof(len), 1);
137 f.Write(name, sizeof(char), len+1);
141 // Projects Absolute Path Are Not Saved
143 f.Write(&len, sizeof(len), 1);
144 f.Write(&len, sizeof(char), 1);
149 f.Write(&len, sizeof(len), 1);
150 f.Write(path, sizeof(char), len+1);
152 f.Write(&type, sizeof(type), 1);
153 f.Write(&children.count, sizeof(children.count), 1);
154 for(child = children.first; child; child.next)
158 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
161 char printPath[MAX_LOCATION];
163 if(type == project && (files.count /*|| preprocessorDefs.first*/))
165 f.Printf("\n Files\n");
167 else if(type == file)
169 if(!strcmp(path, insidePath))
170 f.Printf("%s - %s\n", indentation, name);
173 strcpy(printPath, path);
174 len = strlen(printPath);
176 if(printPath[len-1] != '/')
177 strcat(printPath, "/");
178 strcat(printPath, name);
179 f.Printf("%s = %s\n", indentation, printPath);
182 f.Printf("\nError\n\n");
184 else if(type == folder)
186 f.Printf("%s + %s\n", indentation, name);
188 else if(type == resources && files.count)
190 PathCatSlash(insidePath, path);
191 f.Printf("\n%sResources\n", indentation);
193 f.Printf("%s Path = %s\n", indentation, path);
196 /*if(buildExclusions.first && type != project)
198 for(item = buildExclusions.first; item; item = item.next)
200 if(item == buildExclusions.first)
201 f.Printf("%s Build Exclusions = %s", indentation, item.name);
203 f.Printf(", %s", item.name);
208 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
210 for(item = preprocessorDefs.first; item; item = item.next)
212 if(item == preprocessorDefs.first)
213 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
215 f.Printf(", %s", item.name);
221 if(type == project && (files.count /*|| preprocessorDefs.first*/))
225 LegacyAsciiSaveNode(child, f, indentation, insidePath);
227 else if(type == folder)
229 strcat(indentation, " ");
230 // WHAT WAS THIS: strcpy(printPath, path);
231 // TOCHECK: why is Unix/PathCat not used here
232 len = strlen(insidePath);
234 if(insidePath[len-1] != '/')
235 strcat(insidePath, "/");
236 strcat(insidePath, name);
239 LegacyAsciiSaveNode(child, f, indentation, insidePath);
240 f.Printf("%s -\n", indentation);
241 indentation[strlen(indentation) - 3] = '\0';
242 StripLastDirectory(insidePath, insidePath);
244 else if(type == resources && files.count)
248 LegacyAsciiSaveNode(child, f, indentation, insidePath);
249 StripLastDirectory(insidePath, insidePath);
254 void ProjectConfig::LegacyProjectConfigSave(File f)
256 char * indentation = " ";
258 //f.Printf("\n * Common\n");
260 f.Printf("\n + %s\n", name);
261 f.Printf("\n Compiler\n\n");
262 if(objDir.expression[0])
263 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
264 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
265 switch(options.optimization)
267 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
268 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
269 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
271 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
273 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
274 if(options.memoryGuard == true)
275 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
276 if(options.strictNameSpaces == true)
277 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
278 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
279 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
280 TOFIX: Compiler Bug {
281 if(options.preprocessorDefinitions.count)
284 for(item : options.preprocessorDefinitions)
288 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
292 f.Printf(", %s", item);
297 if(options.includeDirs.count)
299 f.Printf("\n%sInclude Directories\n", indentation);
300 for(item : options.includeDirs)
301 f.Printf("%s - %s\n", indentation, name);
305 f.Printf("\n%sLinker\n\n", indentation);
306 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
307 switch(options.targetType)
309 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
310 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
311 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
313 if(targetDir.expression[0])
314 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
316 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
318 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
319 if(options.libraries.count)
322 for(item : options.libraries)
326 f.Printf("\n%sLibraries = %s", indentation, name);
330 f.Printf(", %s", item);
334 if(options.libraryDirs.count)
336 f.Printf("\n%sLibrary Directories\n\n", indentation);
337 for(item : options.libraryDirs)
338 f.Printf(" - %s\n", indentation, item);
342 void LegacyAsciiSaveProject(File f, Project project)
344 char indentation[128*3];
345 char path[MAX_LOCATION];
347 f.Printf("\nECERE Project File : Format Version 0.1b\n");
348 f.Printf("\nDescription\n%s\n.\n", project.description);
349 f.Printf("\nLicense\n%s\n.\n", project.license);
350 f.Printf("\nModule Name = %s\n", project.moduleName);
351 f.Printf("\n Configurations\n");
352 //////////////////////////////////////commonConfig.Save(f, true);
353 for(cfg : project.configurations)
354 LegacyProjectConfigSave(cfg, f);
356 strcpy(indentation, " ");
358 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
364 // *** NEW JSON PROJECT FORMAT ***
365 public enum ProjectNodeType { file, folder };
367 // *******************************
369 define PEEK_RESOLUTION = (18.2 * 10);
375 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
377 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources };
379 define WorkspaceExtension = "ews";
380 define ProjectExtension = "epj";
382 define stringInFileIncludedFrom = "In file included from ";
384 void ReplaceSpaces(char * output, char * source)
389 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
391 if(ch == ' ') output[dc++] = '\\';
394 if(ch == '(' || ch == ')') output[dc++] = '\\';
404 void ReplaceUnwantedMakeChars(char * output, char * source)
409 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
413 if(ch == '(' || ch == ')') output[dc++] = '\\';
426 static void OutputNoSpace(File f, char * source)
428 char * output = new char[strlen(source)+1024];
429 ReplaceSpaces(output, source);
434 enum ListOutputMethod { inPlace, newLine, lineEach };
436 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
439 const int breakListLength = 1536;
440 const int breakLineLength = 78; // TODO: turn this into an option.
442 int c, len, itemCount = 0;
443 Array<int> breaks { };
447 MapNode<String, int> mn;
448 for(c=0; c<list.count; c++)
450 len = strlen(list[c]) + 3;
451 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
453 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
455 if(strstr(list[c], mn.key))
459 if(charCount + len > breakListLength)
461 breaks.Add(itemCount);
469 breaks.Add(itemCount);
470 numOfBreaks = breaks.count;
475 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
476 for(c=0; c<numOfBreaks; c++)
477 f.Printf(" $(%s%d)", name, c+1);
481 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
487 for(c=0; c<numOfBreaks; c++)
490 f.Printf("%s%d =", name, c+1);
493 itemCount = breaks[c];
494 for(n=offset; n<offset+itemCount; n++)
496 if(false) // TODO: turn this into an option.
498 int itemLen = strlen(list[n]);
499 if(len > 3 && len + itemLen > breakLineLength)
501 f.Printf(" \\\n\t%s", list[n]);
507 f.Printf(" %s", list[n]);
511 f.Printf(" \\\n\t%s", list[n]);
526 void OutputCleanActions(File f, char * name, int parts)
531 for(c=0; c<parts; c++)
532 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
535 f.Printf("\t$(call rmq,$(%s))\n", name);
538 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
542 if(method == newLine)
546 if(method == lineEach)
548 f.Printf(" -%s", option);
550 OutputNoSpace(f, item);
552 f.Printf("%s", item);
557 static void OutputLibraries(File f, Array<String> libraries)
559 for(item : libraries)
561 char ext[MAX_EXTENSION];
562 char temp[MAX_LOCATION];
564 bool usedFunction = false;
565 GetExtension(item, ext);
566 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
570 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
572 if(!strncmp(item, "lib", 3))
573 strcpy(temp, item + 3);
576 StripExtension(temp);
579 f.Printf(" \\\n\t$(call _L,");
588 void CamelCase(char * string)
590 int c, len = strlen(string);
591 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
592 string[c] = (char)tolower(string[c]);
595 CompilerConfig GetCompilerConfig()
597 #ifndef MAKEFILE_GENERATOR
598 CompilerConfig compiler = null;
599 if(ide && ide.workspace)
600 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
603 incref defaultCompiler;
604 return defaultCompiler;
608 define localTargetType = config && config.options && config.options.targetType ?
609 config.options.targetType : options && options.targetType ?
610 options.targetType : TargetTypes::executable;
611 define localWarnings = config && config.options && config.options.warnings ?
612 config.options.warnings : options && options.warnings ?
613 options.warnings : WarningsOption::unset;
614 define localDebug = config && config.options && config.options.debug ?
615 config.options.debug : options && options.debug ?
616 options.debug : SetBool::unset;
617 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
618 config.options.memoryGuard : options && options.memoryGuard ?
619 options.memoryGuard : SetBool::unset;
620 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
621 config.options.noLineNumbers : options && options.noLineNumbers ?
622 options.noLineNumbers : SetBool::unset;
623 define localProfile = config && config.options && config.options.profile ?
624 config.options.profile : options && options.profile ?
625 options.profile : SetBool::unset;
626 define localOptimization = config && config.options && config.options.optimization ?
627 config.options.optimization : options && options.optimization ?
628 options.optimization : OptimizationStrategy::none;
629 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
630 config.options.defaultNameSpace : options && options.defaultNameSpace ?
631 options.defaultNameSpace : null;
632 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
633 config.options.strictNameSpaces : options && options.strictNameSpaces ?
634 options.strictNameSpaces : SetBool::unset;
635 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
636 define localTargetFileName = config && config.options && config.options.targetFileName ?
637 config.options.targetFileName : options && options.targetFileName ?
638 options.targetFileName : "";
639 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
640 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
641 options.targetDirectory : null;
642 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
643 ideSettings.projectDefaultIntermediateObjDir[0] ?
644 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
645 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
646 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
647 options.objectsDirectory : null;
648 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
649 ideSettings.projectDefaultIntermediateObjDir[0] ?
650 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
651 define localConsole = config && config.options && config.options.console ?
652 config.options.console : options && options.console ?
653 options.console : SetBool::unset;
654 define localCompress = config && config.options && config.options.compress ?
655 config.options.compress : options && options.compress ?
656 options.compress : SetBool::unset;
658 define platformTargetType =
659 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
660 configPOs.options.targetType :
661 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
662 projectPOs.options.targetType : TargetTypes::unset;
665 // we should have some kind of direct mapping between a platform and it's makefile variable
666 char * PlatformToMakefileVariable(Platform platform)
668 return platform == win32 ? "WINDOWS" :
669 platform == tux ? "LINUX" :
670 platform == apple ? "OSX"/*"APPLE"*/ :
674 char * TargetTypeToMakefileVariable(TargetTypes targetType)
676 return targetType == executable ? "executable" :
677 targetType == sharedLibrary ? "sharedlib" :
678 targetType == staticLibrary ? "staticlib" :
682 // Move this to ProjectConfig? null vs Common to consider...
683 char * GetConfigName(ProjectConfig config)
685 return config ? config.name : "Common";
688 class Project : struct
690 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
691 // We might want to tweak this default behavior of regular classes ?
692 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
697 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
698 property Array<PlatformOptions> platforms
700 get { return platforms; }
703 if(platforms) { platforms.Free(); delete platforms; }
706 List<PlatformOptions> empty { };
707 Iterator<PlatformOptions> it { value };
709 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
710 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
720 if(p.options && !p.options.isEmpty)
727 List<ProjectConfig> configurations;
728 LinkList<ProjectNode> files;
729 String resourcesPath;
730 LinkList<ProjectNode> resources;
732 property char * description
734 set { delete description; if(value && value[0]) description = CopyString(value); }
735 get { return description ? description : ""; }
736 isset { return description != null && description[0]; }
739 property char * license
741 set { delete license; if(value && value[0]) license = CopyString(value); }
742 get { return license ? license : ""; }
743 isset { return license != null && license[0]; }
746 property char * compilerConfigsDir
748 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
749 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
750 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
754 // topNode.name holds the file name (.epj)
755 ProjectOptions options;
756 Array<PlatformOptions> platforms;
757 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
760 ProjectConfig config;
762 // This is the file name stripped of the epj extension
763 // It should NOT be edited, saved or loaded anywhere
768 String compilerConfigsDir;
769 #ifndef MAKEFILE_GENERATOR
770 FileMonitor fileMonitor
772 this, FileChange { modified = true };
773 bool OnFileNotify(FileChange action, char * param)
775 fileMonitor.StopMonitoring();
776 if(OnProjectModified(action, param))
777 fileMonitor.StartMonitoring();
782 bool StartMonitoring()
784 fileMonitor.fileName = filePath;
785 fileMonitor.StartMonitoring();
789 bool StopMonitoring()
791 fileMonitor.StopMonitoring();
795 bool OnProjectModified(FileChange fileChange, char * param)
798 sprintf(temp, $"The project %s was modified by another application.\n"
799 "Would you like to reload it and lose your changes?", name);
800 if(MessageBox { type = yesNo, master = ide,
801 text = $"Project has been modified", contents = temp }.Modal() == yes)
803 Project project = LoadProject(filePath);
806 ProjectView projectView = ide.projectView;
807 DataRow prev = topNode.row ? topNode.row.previous : null;
808 FileMonitor fm = fileMonitor;
810 if(projectView) projectView.DeleteNode(topNode);
815 topNode.project = this;
819 projectView.AddNode(topNode, null);
820 topNode.row.Move(prev);
822 eSystem_Delete(project);
831 // This frees contents without freeing the instance
832 // For use from destructor and for file monitor reloading
833 // (To work around JSON loader (LoadProject) always returning a new instance)
836 if(platforms) { platforms.Free(); delete platforms; }
837 if(configurations) { configurations.Free(); delete configurations; }
838 if(files) { files.Free(); delete files; }
839 if(resources) { resources.Free(); delete resources; }
841 delete resourcesPath;
845 delete compilerConfigsDir;
854 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
855 topNode.configurations = null;
856 topNode.platforms = null;
857 topNode.options = null;
862 property ProjectConfig config
868 topNode.info = CopyString(GetConfigName(config));
871 property char * filePath
877 char string[MAX_LOCATION];
878 GetLastDirectory(value, string);
880 topNode.name = CopyString(string);
881 StripExtension(string);
883 name = CopyString(string);
884 StripLastDirectory(value, string);
886 topNode.path = CopyString(string);
888 filePath = CopyString(value);
893 TargetTypes GetTargetType(ProjectConfig config)
895 TargetTypes targetType = localTargetType;
899 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
902 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
904 PlatformOptions projectPOs, configPOs;
905 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
906 if(platformTargetType)
913 char * GetObjDirExpression(ProjectConfig config)
915 // TODO: Support platform options
916 char * expression = localObjectsDirectory;
918 expression = settingsObjectsDirectory;
922 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config)
924 char * expression = GetObjDirExpression(config);
925 DirExpression objDir { type = intermediateObjectsDir };
926 objDir.Evaluate(expression, this, compiler, config);
930 char * GetTargetDirExpression(ProjectConfig config)
932 // TODO: Support platform options
933 char * expression = localTargetDirectory;
935 expression = settingsTargetDirectory;
939 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config)
941 char * expression = GetTargetDirExpression(config);
942 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
943 targetDir.Evaluate(expression, this, compiler, config);
947 WarningsOption GetWarnings(ProjectConfig config)
949 WarningsOption warnings = localWarnings;
953 bool GetDebug(ProjectConfig config)
955 SetBool debug = localDebug;
956 return debug == true;
959 bool GetMemoryGuard(ProjectConfig config)
961 SetBool memoryGuard = localMemoryGuard;
962 return memoryGuard == true;
965 bool GetNoLineNumbers(ProjectConfig config)
967 SetBool noLineNumbers = localNoLineNumbers;
968 return noLineNumbers == true;
971 bool GetProfile(ProjectConfig config)
973 SetBool profile = localProfile;
974 return profile == true;
977 OptimizationStrategy GetOptimization(ProjectConfig config)
979 OptimizationStrategy optimization = localOptimization;
983 String GetDefaultNameSpace(ProjectConfig config)
985 String defaultNameSpace = localDefaultNameSpace;
986 return defaultNameSpace;
989 bool GetStrictNameSpaces(ProjectConfig config)
991 SetBool strictNameSpaces = localStrictNameSpaces;
992 return strictNameSpaces == true;
995 String GetTargetFileName(ProjectConfig config)
997 String targetFileName = localTargetFileName;
998 return targetFileName;
1001 //String targetDirectory;
1002 //String objectsDirectory;
1003 bool GetConsole(ProjectConfig config)
1005 SetBool console = localConsole;
1006 return console == true;
1009 bool GetCompress(ProjectConfig config)
1011 SetBool compress = localCompress;
1012 return compress == true;
1014 //SetBool excludeFromBuild;
1016 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1018 #ifndef MAKEFILE_GENERATOR
1019 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1023 bool GetConfigIsInDebugSession(ProjectConfig config)
1025 #ifndef MAKEFILE_GENERATOR
1026 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1030 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config)
1032 #ifndef MAKEFILE_GENERATOR
1033 ide.SetPath(projectsDirs, compiler, config);
1037 #ifndef MAKEFILE_GENERATOR
1038 bool Save(char * fileName)
1041 /*char output[MAX_LOCATION];
1042 ChangeExtension(fileName, "json", output);
1043 f = FileOpen(output, write);*/
1044 f = FileOpen(fileName, write);
1047 files = topNode.files;
1048 resources = resNode.files;
1049 resourcesPath = resNode.path;
1051 files.Remove(resNode);
1054 WriteJSONObject(f, class(Project), this, 0);
1060 resourcesPath = null;
1067 // This method is only called from Debugger, should be moved to Debugger class?
1068 #ifndef MAKEFILE_GENERATOR
1069 bool GetRelativePath(char * filePath, char * relativePath)
1072 char moduleName[MAX_FILENAME];
1073 GetLastDirectory(filePath, moduleName);
1074 // try with workspace dir first?
1075 if((node = topNode.Find(moduleName, false)))
1077 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1078 PathCatSlash(relativePath, node.name);
1083 // Tweak for automatically resolving symbol loader modules
1084 char * sl = strstr(moduleName, ".main.ec");
1085 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1087 char objDir[MAX_LOCATION];
1088 DirExpression objDirExp;
1089 CompilerConfig compiler = ide.debugger.currentCompiler;
1090 ProjectConfig config = ide.debugger.prjConfig;
1091 // This is not perfect, as multiple source files exist for the symbol loader module...
1092 // We try to set it in the debug config object directory.
1093 if(!compiler || !config)
1095 // If we're not currently debugging, set a breakpoint in the active compiler/config
1096 compiler = GetCompilerConfig();
1097 config = this.config;
1098 // If the current config is not debuggable, set it in the first debuggable config found
1099 if(config && !config.options.debug)
1101 for(c : configurations; c.options.debug)
1108 objDirExp = GetObjDir(compiler, config);
1109 strcpy(objDir, objDirExp.dir);
1111 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1112 ReplaceSpaces(objDir, objDir);
1113 strcpy(relativePath, objDir);
1115 PathCatSlash(relativePath, moduleName);
1119 // WARNING: On failure, relative path is uninitialized
1124 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1126 TargetTypes targetType = GetTargetType(config);
1127 String targetFileName = GetTargetFileName(config);
1128 if(targetType == staticLibrary)
1130 PathCatSlash(string, "lib");
1131 strcat(string, targetFileName);
1133 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1135 PathCatSlash(string, "lib");
1136 strcat(string, targetFileName);
1139 PathCatSlash(string, targetFileName);
1144 if(compiler.targetPlatform == win32)
1145 strcat(string, ".exe");
1148 if(compiler.targetPlatform == win32)
1149 strcat(string, ".dll");
1150 else if(compiler.targetPlatform == apple)
1151 strcat(string, ".dylib");
1153 strcat(string, ".so");
1156 strcat(string, ".a");
1161 bool GetProjectCompilerConfigsDir(char * cfDir)
1163 bool result = false;
1164 strcpy(cfDir, topNode.path);
1165 if(compilerConfigsDir && compilerConfigsDir[0])
1167 PathCatSlash(cfDir, compilerConfigsDir);
1170 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1175 bool GetIDECompilerConfigsDir(char * cfDir)
1177 bool result = false;
1178 strcpy(cfDir, topNode.path);
1179 if(ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1181 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1186 // Default to <ProjectDir>/configs if unset
1187 PathCatSlash(cfDir, "configs");
1190 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1195 void CatMakeFileName(char * string, ProjectConfig config)
1197 char projectName[MAX_LOCATION];
1198 strcpy(projectName, name);
1199 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1202 #ifndef MAKEFILE_GENERATOR
1203 void MarkChanges(ProjectNode node)
1205 for(cfg : topNode.configurations)
1207 ProjectConfig c = null;
1208 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1210 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1211 (!c.options || !cfg.options)))
1212 cfg.symbolGenModified = true;
1214 cfg.makingModified = true;
1218 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1220 for(cfg : configurations)
1223 cfg.makingModified = true;
1225 cfg.compilingModified = true;
1227 cfg.linkingModified = true;
1229 cfg.symbolGenModified = true;
1231 if(compiling || linking)
1233 ide.projectView.modifiedDocument = true;
1234 ide.workspace.modified = true;
1238 void RotateActiveConfig(bool forward)
1240 if(configurations.first && configurations.last != configurations.first)
1242 Iterator<ProjectConfig> cfg { configurations };
1243 while(forward ? cfg.Next() : cfg.Prev())
1244 if(cfg.data == config)
1258 property::config = cfg.data;
1259 ide.workspace.modified = true;
1260 ide.projectView.Update(null);
1264 void ProcessPipeOutputRaw(DualPipe f)
1267 while(!f.Eof() && !ide.ShouldStopBuild())
1270 double lastTime = GetTime();
1274 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1276 ide.outputView.buildBox.Logf("%s\n", line);
1278 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1280 //printf("Processing Input...\n");
1281 if(app.ProcessInput(true))
1283 app.UpdateDisplay();
1286 //printf("Waiting...\n");
1289 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1291 if(ide.ShouldStopBuild())
1293 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1298 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode,
1299 CompilerConfig compiler, ProjectConfig config)
1302 bool compiling = false, linking = false, precompiling = false;
1303 int compilingEC = 0;
1304 int numErrors = 0, numWarnings = 0;
1305 bool loggedALine = false;
1306 char * configName = config.name;
1307 int lenMakeCommand = strlen(compiler.makeCommand);
1309 char cppCommand[MAX_LOCATION];
1310 char ccCommand[MAX_LOCATION];
1311 char cxxCommand[MAX_LOCATION];
1312 char ecpCommand[MAX_LOCATION];
1313 char eccCommand[MAX_LOCATION];
1314 char ecsCommand[MAX_LOCATION];
1315 char earCommand[MAX_LOCATION];
1317 char * cc = compiler.ccCommand;
1318 char * cxx = compiler.cxxCommand;
1319 char * cpp = compiler.cppCommand;
1320 sprintf(cppCommand, "%s%s%s%s ",
1321 compiler.ccacheEnabled ? "ccache " : "",
1322 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1323 compiler.distccEnabled ? "distcc " : "",
1324 compiler.cppCommand);
1325 sprintf(ccCommand, "%s%s%s%s ",
1326 compiler.ccacheEnabled ? "ccache " : "",
1327 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1328 compiler.distccEnabled ? "distcc " : "",
1329 compiler.ccCommand);
1330 sprintf(cxxCommand, "%s%s%s%s ",
1331 compiler.ccacheEnabled ? "ccache " : "",
1332 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1333 compiler.distccEnabled ? "distcc " : "",
1334 compiler.cxxCommand);
1335 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1336 sprintf(eccCommand, "%s ", compiler.eccCommand);
1337 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1338 sprintf(earCommand, "%s ", compiler.earCommand);
1340 while(!f.Eof() && !ide.ShouldStopBuild())
1343 double lastTime = GetTime();
1347 //printf("Peeking and GetLine...\n");
1348 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1350 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1351 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1353 char * module = strstr(line, "No rule to make target `");
1357 module = strchr(module, '`') + 1;
1358 end = strchr(module, '\'');
1362 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1363 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1369 //ide.outputView.buildBox.Logf("error: %s\n", line);
1373 else if(strstr(line, "ear ") == line);
1374 else if(strstr(line, "strip ") == line);
1375 else if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1377 char moduleName[MAX_FILENAME];
1380 bool isPrecomp = false;
1382 if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line)
1384 module = strstr(line, " -c ");
1385 if(module) module += 4;
1387 else if(strstr(line, eccCommand) == line)
1389 module = strstr(line, " -c ");
1390 if(module) module += 4;
1391 //module = line + 3;
1392 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1393 compilingEC = 3;//2;
1395 else if(strstr(line, ecpCommand) == line)
1397 // module = line + 8;
1398 module = strstr(line, " -c ");
1399 if(module) module += 4;
1408 if(!compiling && !isPrecomp)
1410 ide.outputView.buildBox.Logf($"Compiling...\n");
1413 else if(!precompiling && isPrecomp)
1415 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1416 precompiling = true;
1418 // Changed escapeBackSlashes here to handle paths with spaces
1419 Tokenize(module, 1, tokens, true); // false);
1420 GetLastDirectory(module, moduleName);
1421 ide.outputView.buildBox.Logf("%s\n", moduleName);
1423 else if((module = strstr(line, " -o ")))
1426 precompiling = false;
1428 ide.outputView.buildBox.Logf($"Linking...\n");
1432 ide.outputView.buildBox.Logf("%s\n", line);
1436 if(compilingEC) compilingEC--;
1438 else if(strstr(line, "ar rcs") == line)
1439 ide.outputView.buildBox.Logf($"Building library...\n");
1440 else if(strstr(line, ecsCommand) == line)
1441 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1444 if(linking || compiling || precompiling)
1446 char * colon = strstr(line, ":"); //, * bracket;
1447 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1448 colon = strstr(colon + 1, ":");
1451 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1454 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1455 int len = (int)(colon - start);
1456 len = Min(len, MAX_LOCATION-1);
1457 // Don't be mistaken by the drive letter colon
1459 // TODO: need to fix colon - line gives char *
1460 // warning: incompatible expression colon - line (char *); expected int
1462 strncpy(moduleName, line, (int)(colon - line));
1463 moduleName[colon - line] = '\0';
1465 strncpy(moduleName, start, len);
1466 moduleName[len] = '\0';
1467 // Remove stuff in brackets
1468 //bracket = strstr(moduleName, "(");
1469 //if(bracket) *bracket = '\0';
1471 GetLastDirectory(moduleName, temp);
1472 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1475 strcpy(moduleName, $"Linker Error");
1479 strcpy(temp, topNode.path);
1480 PathCatSlash(temp, moduleName);
1481 MakePathRelative(temp, topNode.path, moduleName);
1483 if(strstr(line, "error:"))
1487 // Silence warnings for compiled EC
1488 char * objDir = strstr(moduleName, objDirExp.dir);
1492 if((pointer = strstr(line, "undefined")) ||
1493 (pointer = strstr(line, "No such file")) ||
1494 (pointer = strstr(line, "token")))
1496 strncat(moduleName, colon, pointer - colon);
1497 strcat(moduleName, "error: ");
1502 else if((pointer = strstr(line, "No such file")))
1504 strncat(moduleName, colon, pointer - colon);
1505 strcat(moduleName, "error: ");
1509 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1511 else if(strstr(line, "warning:"))
1516 if(this == ide.workspace.projects.firstIterator.data)
1517 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1520 char fullModuleName[MAX_LOCATION];
1521 strcpy(fullModuleName, topNode.path);
1522 PathCat(fullModuleName, moduleName);
1523 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1524 MakeSystemPath(fullModuleName);
1525 ide.outputView.buildBox.Logf(" %s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : "", fullModuleName, colon);
1530 ide.outputView.buildBox.Logf("%s\n", line);
1531 linking = compiling = precompiling = false;
1535 ide.outputView.buildBox.Logf("%s\n", line);
1539 //printf("Done getting line\n");
1540 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1542 //printf("Processing Input...\n");
1543 if(app.ProcessInput(true))
1545 app.UpdateDisplay();
1548 //printf("Waiting...\n");
1551 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1553 if(ide.ShouldStopBuild())
1555 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1558 else if(loggedALine || !isARun)
1560 if(f.GetExitCode() && !numErrors)
1562 bool result = f.GetLine(line, sizeof(line)-1);
1563 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1568 ide.outputView.buildBox.Logf("\n%s (%s) - ", GetTargetFileName(config), configName);
1570 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1572 ide.outputView.buildBox.Logf($"no error, ");
1575 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1577 ide.outputView.buildBox.Logf($"no warning\n");
1580 return numErrors == 0;
1583 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1586 int lenMakeCommand = strlen(compiler.makeCommand);
1591 double lastTime = GetTime();
1594 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1596 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1597 else if(strstr(line, "del") == line);
1598 else if(strstr(line, "rm") == line);
1599 else if(strstr(line, "Could Not Find") == line);
1602 ide.outputView.buildBox.Logf(line);
1603 ide.outputView.buildBox.Logf("\n");
1607 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1609 if(app.ProcessInput(true))
1611 app.UpdateDisplay();
1614 //Sleep(1.0 / PEEK_RESOLUTION);
1618 bool Build(bool isARun, ProjectNode onlyNode, CompilerConfig compiler, ProjectConfig config)
1620 bool result = false;
1622 char targetFileName[MAX_LOCATION] = "";
1623 char makeTarget[MAX_LOCATION] = "";
1624 char makeFile[MAX_LOCATION];
1625 char makeFilePath[MAX_LOCATION];
1626 char configName[MAX_LOCATION];
1627 DirExpression objDirExp = GetObjDir(compiler, config);
1628 PathBackup pathBackup { };
1630 int numJobs = compiler.numJobs;
1631 char command[MAX_LOCATION];
1632 char * compilerName;
1634 compilerName = CopyString(compiler.name);
1635 CamelCase(compilerName);
1637 strcpy(configName, config ? config.name : "Common");
1639 SetPath(false, compiler, config); //true
1640 CatTargetFileName(targetFileName, compiler, config);
1642 strcpy(makeFilePath, topNode.path);
1643 CatMakeFileName(makeFile, config);
1644 PathCatSlash(makeFilePath, makeFile);
1646 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1649 if(compiler.type.isVC)
1651 PrintLn("compiling a single file is not yet supported");
1656 char pushD[MAX_LOCATION];
1657 char cfDir[MAX_LOCATION];
1658 GetIDECompilerConfigsDir(cfDir);
1659 GetWorkingDir(pushD, sizeof(pushD));
1660 ChangeWorkingDir(topNode.path);
1661 // Create object dir if it does not exist already
1662 if(!FileExists(objDirExp.dir).isDirectory)
1663 Execute("%s CF_DIR=%s COMPILER=%s objdir -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, topNode.path, makeFilePath);
1664 ChangeWorkingDir(pushD);
1666 PathCatSlash(makeTarget+1, objDirExp.dir);
1667 PathCatSlash(makeTarget+1, onlyNode.name);
1668 StripExtension(makeTarget+1);
1669 strcat(makeTarget+1, ".o");
1670 makeTarget[0] = '\"';
1671 len = strlen(makeTarget);
1672 makeTarget[len++] = '\"';
1673 makeTarget[len++] = '\0';
1677 if(compiler.type.isVC)
1679 bool result = false;
1680 char oldwd[MAX_LOCATION];
1681 GetWorkingDir(oldwd, sizeof(oldwd));
1682 ChangeWorkingDir(topNode.path);
1684 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1685 ide.outputView.buildBox.Logf("command: %s\n", command);
1686 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1688 ProcessPipeOutputRaw(f);
1692 ChangeWorkingDir(oldwd);
1696 char cfDir[MAX_LOCATION];
1697 GetIDECompilerConfigsDir(cfDir);
1698 sprintf(command, "%s CF_DIR=%s COMPILER=%s -j%d %s%s%s -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, numJobs,
1699 compiler.ccacheEnabled ? "CCACHE=y " : "",
1700 compiler.distccEnabled ? "DISTCC=y " : "",
1701 makeTarget, topNode.path, makeFilePath);
1702 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1704 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode, compiler, config);
1708 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
1713 delete compilerName;
1717 void Clean(CompilerConfig compiler, ProjectConfig config, bool realclean)
1719 char makeFile[MAX_LOCATION];
1720 char makeFilePath[MAX_LOCATION];
1721 char command[MAX_LOCATION];
1722 char * compilerName;
1724 PathBackup pathBackup { };
1726 compilerName = CopyString(compiler.name);
1727 CamelCase(compilerName);
1729 SetPath(false, compiler, config);
1731 strcpy(makeFilePath, topNode.path);
1732 CatMakeFileName(makeFile, config);
1733 PathCatSlash(makeFilePath, makeFile);
1735 if(compiler.type.isVC)
1737 bool result = false;
1738 char oldwd[MAX_LOCATION];
1739 GetWorkingDir(oldwd, sizeof(oldwd));
1740 ChangeWorkingDir(topNode.path);
1742 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1743 ide.outputView.buildBox.Logf("command: %s\n", command);
1744 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1746 ProcessPipeOutputRaw(f);
1750 ChangeWorkingDir(oldwd);
1755 char cfDir[MAX_LOCATION];
1756 GetIDECompilerConfigsDir(cfDir);
1757 sprintf(command, "%s CF_DIR=%s COMPILER=%s %sclean -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, realclean ? "real" : "", topNode.path, makeFilePath);
1758 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1760 ide.outputView.buildBox.Tell($"Deleting target and object files...");
1761 ProcessCleanPipeOutput(f, compiler, config);
1764 ide.outputView.buildBox.Logf($"Target and object files deleted\n");
1769 delete compilerName;
1772 void Run(char * args, CompilerConfig compiler, ProjectConfig config)
1774 String target = new char[maxPathLen];
1775 char oldDirectory[MAX_LOCATION];
1776 DirExpression targetDirExp = GetTargetDir(compiler, config);
1777 PathBackup pathBackup { };
1779 // Build(project, ideMain, true, null);
1781 #if defined(__WIN32__)
1782 strcpy(target, topNode.path);
1786 PathCatSlash(target, targetDirExp.dir);
1787 CatTargetFileName(target, compiler, config);
1788 sprintf(target, "%s %s", target, args);
1789 GetWorkingDir(oldDirectory, MAX_LOCATION);
1791 if(strlen(ide.workspace.debugDir))
1793 char temp[MAX_LOCATION];
1794 strcpy(temp, topNode.path);
1795 PathCatSlash(temp, ide.workspace.debugDir);
1796 ChangeWorkingDir(temp);
1799 ChangeWorkingDir(topNode.path);
1800 // ChangeWorkingDir(topNode.path);
1801 SetPath(true, compiler, config);
1802 if(compiler.execPrefixCommand)
1804 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1805 prefixedTarget[0] = '\0';
1806 strcat(prefixedTarget, compiler.execPrefixCommand);
1807 strcat(prefixedTarget, " ");
1808 strcat(prefixedTarget, target);
1809 Execute(prefixedTarget);
1810 delete prefixedTarget;
1815 ChangeWorkingDir(oldDirectory);
1818 delete targetDirExp;
1822 void Compile(ProjectNode node, CompilerConfig compiler, ProjectConfig config)
1824 Build(false, node, compiler, config);
1828 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
1831 if(targetType == staticLibrary || targetType == sharedLibrary)
1832 strcat(fileName, "$(LP)");
1833 // !!! ReplaceSpaces must be done after all PathCat calls !!!
1834 // ReplaceSpaces(s, GetTargetFileName(config));
1835 strcat(fileName, GetTargetFileName(config));
1839 strcat(fileName, "$(E)");
1842 strcat(fileName, "$(SO)");
1845 strcat(fileName, "$(A)");
1850 bool GenerateCrossPlatformCf()
1852 bool result = false;
1853 char path[MAX_LOCATION];
1855 if(!GetProjectCompilerConfigsDir(path))
1856 GetIDECompilerConfigsDir(path);
1858 if(!FileExists(path).isDirectory)
1860 PathCatSlash(path, "crossplatform.mk");
1862 if(FileExists(path))
1865 File include = FileOpen(":crossplatform.mk", read);
1868 File f = FileOpen(path, write);
1871 for(; !include.Eof(); )
1874 int count = include.Read(buffer, 1, 4096);
1875 f.Write(buffer, 1, count);
1887 bool GenerateCompilerMk(CompilerConfig compiler)
1889 bool result = false;
1890 char path[MAX_LOCATION];
1892 char * compilerName;
1893 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
1894 Platform platform = GetRuntimePlatform();
1896 compilerName = CopyString(compiler.name);
1897 CamelCase(compilerName);
1898 name = PrintString(platform, "-", compilerName, ".cf");
1900 if(!GetProjectCompilerConfigsDir(path))
1901 GetIDECompilerConfigsDir(path);
1903 if(!FileExists(path).isDirectory)
1905 PathCatSlash(path, name);
1907 if(FileExists(path))
1910 File f = FileOpen(path, write);
1913 bool crossCompiling = compiler.targetPlatform != platform;
1915 f.Printf("# TOOLCHAIN\n\n");
1917 //f.Printf("SHELL := %s\n", "ar"/*compiler.arCommand*/); // is this really needed?
1918 f.Printf("CPP := %s\n", compiler.cppCommand);
1919 f.Printf("CC := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.ccCommand);
1920 f.Printf("CXX := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.cxxCommand);
1921 f.Printf("ECP := %s\n", compiler.ecpCommand);
1922 f.Printf("ECC := %s\n", compiler.eccCommand);
1923 f.Printf("ECS := %s%s%s\n", compiler.ecsCommand,
1924 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1925 f.Printf("EAR := %s\n", compiler.earCommand);
1927 f.Printf("AS := as\n");
1928 f.Printf("LD := ld\n");
1929 f.Printf("AR := ar\n");
1930 f.Printf("STRIP := strip\n");
1931 f.Printf("UPX := upx\n");
1935 f.Printf("UPXFLAGS = -9\n\n"); // TOFEAT: Compression Level Option? Other UPX Options?
1937 f.Printf("# HARD CODED PLATFORM-SPECIFIC OPTIONS\n");
1938 f.Printf("ifdef %s\n", PlatformToMakefileVariable(tux));
1939 f.Printf("OFLAGS += -Wl,--no-undefined\n");
1940 f.Printf("endif\n\n");
1943 f.Printf("ifdef %s\n", PlatformToMakefileVariable(apple));
1944 f.Printf("OFLAGS += -framework cocoa -framework OpenGL\n");
1945 f.Printf("endif\n");
1949 f.Printf("\nPLATFORM = %s\n", (char *)compiler.targetPlatform);
1954 f.Printf("\nCFLAGS += -fmessage-length=0\n");
1957 if(compiler.includeDirs && compiler.includeDirs.count)
1959 f.Printf("\nCFLAGS +=");
1960 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
1963 if(compiler.prepDirectives && compiler.prepDirectives.count)
1965 f.Printf("\nCFLAGS +=");
1966 OutputListOption(f, "D", compiler.prepDirectives, inPlace, true);
1969 if(compiler.libraryDirs && compiler.libraryDirs.count)
1971 f.Printf("\nOFLAGS +=");
1972 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
1975 if(compiler.excludeLibs && compiler.excludeLibs.count)
1977 f.Puts("\nEXCLUDED_LIBS =");
1978 for(l : compiler.excludeLibs)
1989 delete compilerName;
1993 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
1995 bool result = false;
1996 char filePath[MAX_LOCATION];
1997 char makeFile[MAX_LOCATION];
1998 // PathBackup pathBackup { };
1999 // char oldDirectory[MAX_LOCATION];
2002 if(!altMakefilePath)
2004 strcpy(filePath, topNode.path);
2005 CatMakeFileName(makeFile, config);
2006 PathCatSlash(filePath, makeFile);
2009 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2011 /*SetPath(false, compiler, config);
2012 GetWorkingDir(oldDirectory, MAX_LOCATION);
2013 ChangeWorkingDir(topNode.path);*/
2020 Platform runtimePlatform = GetRuntimePlatform();
2021 char targetDir[MAX_LOCATION];
2022 char objDirExpNoSpaces[MAX_LOCATION];
2023 char objDirNoSpaces[MAX_LOCATION];
2024 char resDirNoSpaces[MAX_LOCATION];
2025 char targetDirExpNoSpaces[MAX_LOCATION];
2026 char fixedModuleName[MAX_FILENAME];
2027 char fixedConfigName[MAX_FILENAME];
2029 // Non-zero if we're building eC code
2030 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2031 int numCObjects = 0;
2032 bool containsCXX = false; // True if the project contains a C++ file
2033 bool sameObjTargetDirs;
2034 String objDirExp = GetObjDirExpression(config);
2035 TargetTypes targetType = GetTargetType(config);
2037 char cfDir[MAX_LOCATION];
2038 int objectsParts, eCsourcesParts;
2039 Array<String> listItems { };
2040 Map<String, int> varStringLenDiffs { };
2041 Map<String, NameCollisionInfo> namesInfo { };
2042 bool forceBitDepth = false;
2044 ReplaceSpaces(objDirNoSpaces, objDirExp);
2045 strcpy(targetDir, GetTargetDirExpression(config));
2046 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2048 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2049 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2050 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
2051 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2052 ReplaceSpaces(fixedModuleName, moduleName);
2053 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2054 CamelCase(fixedConfigName);
2056 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2058 f.Printf(".PHONY: all objdir%s clean realclean\n\n", sameObjTargetDirs ? "" : " targetdir");
2060 f.Printf("# CONTENT\n\n");
2062 f.Printf("MODULE := %s\n", fixedModuleName);
2063 //f.Printf("VERSION = %s\n", version);
2064 f.Printf("CONFIG := %s\n", fixedConfigName);
2065 f.Printf("ifndef COMPILER\n");
2066 f.Printf("COMPILER := default\n");
2067 f.Printf("endif\n");
2070 if(compilerConfigsDir && compilerConfigsDir[0])
2072 strcpy(cfDir, compilerConfigsDir);
2073 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2077 strcpy(cfDir, "$(CF_DIR)");
2079 f.Printf("_CF_DIR = %s\n", cfDir);
2082 f.Printf("ifndef DEBUG\n");
2083 f.Printf("OPTIMIZE :=");
2084 switch(GetOptimization(config))
2088 f.Printf(" -ffast-math");
2094 if(GetDebug(config))
2098 f.Printf("OPTIMIZE := -g\n");
2099 f.Printf("NOSTRIP := y\n");
2100 f.Printf("endif\n");
2102 test = GetTargetTypeIsSetByPlatform(config);
2106 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2108 TargetTypes targetType;
2109 PlatformOptions projectPOs, configPOs;
2110 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2111 targetType = platformTargetType;
2117 f.Printf("ifdef %s\n", PlatformToMakefileVariable(platform));
2119 f.Printf("TARGET_TYPE = ");
2120 f.Printf(TargetTypeToMakefileVariable(targetType));
2124 f.Printf("else\n"); // ifCount should always be > 0
2126 f.Printf("TARGET_TYPE = ");
2127 f.Printf(TargetTypeToMakefileVariable(targetType));
2133 for(c = 0; c < ifCount; c++)
2134 f.Printf("endif\n");
2139 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2140 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2141 f.Printf("endif\n\n");
2143 f.Printf("# FLAGS\n\n");
2145 f.Printf("CFLAGS =\n");
2146 f.Printf("CECFLAGS =\n");
2147 f.Printf("ECFLAGS =\n");
2148 f.Printf("OFLAGS =\n");
2149 f.Printf("LIBS =\n");
2152 f.Printf("# INCLUDES\n\n");
2154 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2155 f.Printf("include $(_CF_DIR)$(PLATFORM)-$(COMPILER).cf\n");
2158 f.Printf("# VARIABLES\n\n");
2160 f.Printf("OBJ = %s%s\n\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2162 f.Printf("ifdef DEBUG\n");
2163 f.Printf("CFLAGS += -D_DEBUG\n");
2164 f.Printf("endif\n\n");
2166 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2168 // test = GetTargetTypeIsSetByPlatform(config);
2170 char target[MAX_LOCATION];
2171 char targetNoSpaces[MAX_LOCATION];
2176 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2178 if(type != targetType)
2183 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2185 GetMakefileTargetFileName(type, target, config);
2186 strcpy(targetNoSpaces, targetDir);
2187 PathCatSlash(targetNoSpaces, target);
2188 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2189 f.Printf("TARGET = %s\n", targetNoSpaces);
2192 f.Printf("else\n"); // ifCount should always be > 0
2194 GetMakefileTargetFileName(targetType, target, config);
2195 strcpy(targetNoSpaces, targetDir);
2196 PathCatSlash(targetNoSpaces, target);
2197 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2198 f.Printf("TARGET = %s\n", targetNoSpaces);
2204 for(c = 0; c < ifCount; c++)
2205 f.Printf("endif\n");
2211 // Use something fixed here, to not cause Makefile differences across compilers...
2212 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2213 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2215 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2217 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2219 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
2220 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs, null);
2224 char * map[4][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "BOWLS", "B" } };
2226 topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2227 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2229 f.Printf("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2230 if(eCsourcesParts > 1)
2232 for(c = 1; c <= eCsourcesParts; c++)
2233 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2237 for(c = 0; c < 3; c++)
2239 if(eCsourcesParts > 1)
2242 f.Printf("%s =", map[c][0]);
2243 for(n = 1; n <= eCsourcesParts; n++)
2244 f.Printf(" $(%s%d)", map[c][0], n);
2246 for(n = 1; n <= eCsourcesParts; n++)
2247 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2249 else if(eCsourcesParts == 1)
2250 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2255 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2256 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, "$(ECSOURCES)");
2259 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2260 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2262 f.Printf("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
2263 if((config && config.options && config.options.libraries) ||
2264 (options && options.libraries))
2266 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2267 f.Printf("LIBS +=");
2268 if(config && config.options && config.options.libraries)
2269 OutputLibraries(f, config.options.libraries);
2270 else if(options && options.libraries)
2271 OutputLibraries(f, options.libraries);
2273 f.Printf("endif\n");
2277 if(platforms || (config && config.platforms))
2280 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2281 //for(platform = win32; platform <= apple; platform++)
2283 f.Printf("# PLATFORM-SPECIFIC OPTIONS\n\n");
2284 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2286 PlatformOptions projectPlatformOptions, configPlatformOptions;
2287 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2289 if(projectPlatformOptions || configPlatformOptions)
2295 f.Printf(PlatformToMakefileVariable(platform));
2298 if((projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions && projectPlatformOptions.options.preprocessorDefinitions.count) ||
2299 (configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions && configPlatformOptions.options.preprocessorDefinitions.count) ||
2300 (projectPlatformOptions && projectPlatformOptions.options.includeDirs && projectPlatformOptions.options.includeDirs.count) ||
2301 (configPlatformOptions && configPlatformOptions.options.includeDirs && configPlatformOptions.options.includeDirs.count))
2303 f.Printf("CFLAGS +=");
2304 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2306 f.Printf(" \\\n\t -Wl");
2307 for(s : projectPlatformOptions.options.linkerOptions)
2310 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2312 f.Printf(" \\\n\t -Wl");
2313 for(s : configPlatformOptions.options.linkerOptions)
2316 if(projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions)
2317 OutputListOption(f, "D", projectPlatformOptions.options.preprocessorDefinitions, newLine, false);
2318 if(configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions)
2319 OutputListOption(f, "D", configPlatformOptions.options.preprocessorDefinitions, newLine, false );
2320 if(configPlatformOptions && configPlatformOptions.options.includeDirs)
2321 OutputListOption(f, "I", configPlatformOptions.options.includeDirs, lineEach, true);
2322 if(projectPlatformOptions && projectPlatformOptions.options.includeDirs)
2323 OutputListOption(f, "I", projectPlatformOptions.options.includeDirs, lineEach, true);
2327 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2328 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2329 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2330 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2332 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2333 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2334 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2336 f.Printf("OFLAGS +=");
2337 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2338 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2339 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2340 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2344 if((configPlatformOptions && configPlatformOptions.options.libraries))
2346 if(configPlatformOptions.options.libraries.count)
2348 f.Printf("LIBS +=");
2349 OutputLibraries(f, configPlatformOptions.options.libraries);
2353 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
2355 if(projectPlatformOptions.options.libraries.count)
2357 f.Printf("LIBS +=");
2358 OutputLibraries(f, projectPlatformOptions.options.libraries);
2362 f.Printf("endif\n\n");
2368 for(c = 0; c < ifCount; c++)
2369 f.Printf("endif\n");
2374 f.Printf("CFLAGS +=");
2377 f.Printf(" $(OPTIMIZE)");
2378 forceBitDepth = (options && options.buildBitDepth) || numCObjects;
2380 f.Printf((!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? " -m32" : " -m64");
2381 f.Printf(" $(FPIC)");
2383 switch(GetWarnings(config))
2385 case all: f.Printf(" -Wall"); break;
2386 case none: f.Printf(" -w"); break;
2388 if(GetProfile(config))
2390 if(options && options.linkerOptions && options.linkerOptions.count)
2392 f.Printf(" \\\n\t -Wl");
2393 for(s : options.linkerOptions)
2397 if(options && options.preprocessorDefinitions)
2398 OutputListOption(f, "D", options.preprocessorDefinitions, newLine, false);
2399 if(config && config.options && config.options.preprocessorDefinitions)
2400 OutputListOption(f, "D", config.options.preprocessorDefinitions, newLine, false);
2401 if(config && config.options && config.options.includeDirs)
2402 OutputListOption(f, "I", config.options.includeDirs, lineEach, true);
2403 if(options && options.includeDirs)
2404 OutputListOption(f, "I", options.includeDirs, lineEach, true);
2407 f.Printf("CECFLAGS += -cpp $(call escspace,$(CPP)) -t $(PLATFORM)");
2410 f.Printf("ECFLAGS +=");
2411 if(GetMemoryGuard(config))
2412 f.Printf(" -memguard");
2413 if(GetStrictNameSpaces(config))
2414 f.Printf(" -strictns");
2415 if(GetNoLineNumbers(config))
2416 f.Printf(" -nolinenumbers");
2419 if((s = GetDefaultNameSpace(config)) && s[0])
2420 f.Printf(" -defaultns %s", s);
2424 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2425 f.Printf("OFLAGS +=");
2427 f.Printf((!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? " -m32" : " -m64 \\\n");
2429 if(GetProfile(config))
2431 if(config && config.options && config.options.libraryDirs)
2432 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
2433 if(options && options.libraryDirs)
2434 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
2436 f.Printf("endif\n\n");
2438 f.Printf("# TARGETS\n\n");
2440 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
2442 f.Printf("objdir:\n");
2443 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2444 //f.Printf("# PRE-BUILD COMMANDS\n");
2445 if(options && options.prebuildCommands)
2447 for(s : options.prebuildCommands)
2448 if(s && s[0]) f.Printf("\t%s\n", s);
2450 if(config && config.options && config.options.prebuildCommands)
2452 for(s : config.options.prebuildCommands)
2453 if(s && s[0]) f.Printf("\t%s\n", s);
2455 if(platforms || (config && config.platforms))
2458 //f.Printf("# PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2459 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2461 PlatformOptions projectPOs, configPOs;
2462 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2464 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2465 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2471 f.Printf(PlatformToMakefileVariable(platform));
2474 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2476 for(s : projectPOs.options.prebuildCommands)
2477 if(s && s[0]) f.Printf("\t%s\n", s);
2479 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2481 for(s : configPOs.options.prebuildCommands)
2482 if(s && s[0]) f.Printf("\t%s\n", s);
2489 for(c = 0; c < ifCount; c++)
2490 f.Printf("endif\n");
2495 if(!sameObjTargetDirs)
2497 f.Printf("targetdir:\n");
2498 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2503 // Main Module (Linking) for ECERE C modules
2504 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2505 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2506 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2507 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
2508 // Main Module (Linking) for ECERE C modules
2509 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2510 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2511 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2512 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2513 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2518 // This would not rebuild the target on updated objects
2519 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2521 // This should fix it for good!
2522 f.Printf("$(SYMBOLS): | objdir\n");
2523 f.Printf("$(OBJECTS): | objdir\n");
2525 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2526 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2528 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2529 f.Printf("\t$(%s) $(OFLAGS) $(OBJECTS) $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
2530 if(!GetDebug(config))
2532 f.Printf("ifndef NOSTRIP\n");
2533 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2534 f.Printf("endif\n");
2536 if(GetCompress(config))
2538 f.Printf("ifndef WINDOWS\n");
2539 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2540 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2541 f.Printf("endif\n");
2543 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2544 f.Printf("endif\n");
2547 if(resNode.files && resNode.files.count && !noResources)
2548 resNode.GenMakefileAddResources(f, resNode.path, config);
2550 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2551 f.Printf("endif\n");
2553 //f.Printf("# POST-BUILD COMMANDS\n");
2554 if(options && options.postbuildCommands)
2556 for(s : options.postbuildCommands)
2557 if(s && s[0]) f.Printf("\t%s\n", s);
2559 if(config && config.options && config.options.postbuildCommands)
2561 for(s : config.options.postbuildCommands)
2562 if(s && s[0]) f.Printf("\t%s\n", s);
2564 if(platforms || (config && config.platforms))
2567 //f.Printf("# PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2568 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2570 PlatformOptions projectPOs, configPOs;
2571 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2573 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2574 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2580 f.Printf(PlatformToMakefileVariable(platform));
2583 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2585 for(s : projectPOs.options.postbuildCommands)
2586 if(s && s[0]) f.Printf("\t%s\n", s);
2588 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2590 for(s : configPOs.options.postbuildCommands)
2591 if(s && s[0]) f.Printf("\t%s\n", s);
2598 for(c = 0; c < ifCount; c++)
2599 f.Printf("endif\n");
2604 f.Printf("# SYMBOL RULES\n\n");
2606 Map<Platform, bool> excludedPlatforms { };
2607 topNode.GenMakefilePrintSymbolRules(f, this, config, excludedPlatforms);
2608 delete excludedPlatforms;
2611 f.Printf("# C OBJECT RULES\n\n");
2613 Map<Platform, bool> excludedPlatforms { };
2614 topNode.GenMakefilePrintCObjectRules(f, this, config, excludedPlatforms);
2615 delete excludedPlatforms;
2618 f.Printf("# OBJECT RULES\n\n");
2619 // todo call this still but only generate rules whith specific options
2620 // see we-have-file-specific-options in ProjectNode.ec
2622 Map<Platform, bool> excludedPlatforms { };
2623 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, excludedPlatforms);
2624 delete excludedPlatforms;
2628 GenMakefilePrintMainObjectRule(f, config);
2630 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2631 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) " : "");
2632 OutputCleanActions(f, "OBJECTS", objectsParts);
2635 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
2636 OutputCleanActions(f, "BOWLS", eCsourcesParts);
2637 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
2638 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
2642 f.Printf("realclean: clean\n");
2643 f.Printf("\t$(call rmrq,$(OBJ))\n");
2644 if(!sameObjTargetDirs)
2645 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2652 varStringLenDiffs.Free();
2653 delete varStringLenDiffs;
2660 // ChangeWorkingDir(oldDirectory);
2661 // delete pathBackup;
2664 config.makingModified = false;
2668 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
2670 char extension[MAX_EXTENSION] = "c";
2671 char modulePath[MAX_LOCATION];
2672 char fixedModuleName[MAX_FILENAME];
2675 char objDirNoSpaces[MAX_LOCATION];
2676 String objDirExp = GetObjDirExpression(config);
2678 ReplaceSpaces(objDirNoSpaces, objDirExp);
2679 ReplaceSpaces(fixedModuleName, moduleName);
2681 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2682 //strcat(fixedModuleName, ".main");
2684 #if 0 // TODO: Fix nospaces stuff
2685 // *** Dependency command ***
2686 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2688 // System Includes (from global settings)
2689 for(item : compiler.dirs[Includes])
2691 strcat(command, " -isystem ");
2692 if(strchr(item.name, ' '))
2694 strcat(command, "\"");
2695 strcat(command, item);
2696 strcat(command, "\"");
2699 strcat(command, item);
2702 for(item = includeDirs.first; item; item = item.next)
2704 strcat(command, " -I");
2705 if(strchr(item.name, ' '))
2707 strcat(command, "\"");
2708 strcat(command, item.name);
2709 strcat(command, "\"");
2712 strcat(command, item.name);
2714 for(item = preprocessorDefs.first; item; item = item.next)
2716 strcat(command, " -D");
2717 strcat(command, item.name);
2721 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2725 bool firstLine = true;
2727 // To do some time: auto save external dependencies?
2730 if(dep.GetLine(line, sizeof(line)-1))
2734 char * colon = strstr(line, ":");
2735 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2749 // If we failed to generate dependencies...
2753 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2759 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2762 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
2763 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
2765 *projectPlatformOptions = null;
2766 *configPlatformOptions = null;
2771 if(!strcmpi(p.name, platform))
2773 *projectPlatformOptions = p;
2778 if(config && config.platforms)
2780 for(p : config.platforms)
2782 if(!strcmpi(p.name, platform))
2784 *configPlatformOptions = p;
2792 Project LegacyBinaryLoadProject(File f, char * filePath)
2794 Project project = null;
2795 char signature[sizeof(epjSignature)];
2797 f.Read(signature, sizeof(signature), 1);
2798 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2800 char topNodePath[MAX_LOCATION];
2801 /*ProjectConfig newConfig
2803 name = CopyString("Default");
2804 makingModified = true;
2805 compilingModified = true;
2806 linkingModified = true;
2810 project = Project { options = { } };
2811 LegacyBinaryLoadNode(project.topNode, f);
2812 delete project.topNode.path;
2813 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2814 MakeSlashPath(topNodePath);
2816 PathCatSlash(topNodePath, filePath);
2817 project.filePath = topNodePath;
2819 /* THIS IS ALREADY DONE BY filePath property
2820 StripLastDirectory(topNodePath, topNodePath);
2821 project.topNode.path = CopyString(topNodePath);
2823 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2825 // newConfig.options.defaultNameSpace = "";
2826 /*newConfig.objDir.dir = "obj";
2827 newConfig.targetDir.dir = "";*/
2829 //project.configurations = { [ newConfig ] };
2830 //project.config = newConfig;
2837 String targetFileName, targetDirectory, objectsDirectory;
2839 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2840 f.Read(&temp, sizeof(int),1);
2843 case 0: project.options.targetType = executable; break;
2844 case 1: project.options.targetType = sharedLibrary; break;
2845 case 2: project.options.targetType = staticLibrary; break;
2848 f.Read(&len, sizeof(int),1);
2849 targetFileName = new char[len+1];
2850 f.Read(targetFileName, sizeof(char), len+1);
2851 project.options.targetFileName = targetFileName;
2852 delete targetFileName;
2854 f.Read(&len, sizeof(int),1);
2855 targetDirectory = new char[len+1];
2856 f.Read(targetDirectory, sizeof(char), len+1);
2857 project.options.targetDirectory = targetDirectory;
2858 delete targetDirectory;
2860 f.Read(&len, sizeof(int),1);
2861 objectsDirectory = new byte[len+1];
2862 f.Read(objectsDirectory, sizeof(char), len+1);
2863 project.options.objectsDirectory = objectsDirectory;
2864 delete objectsDirectory;
2866 f.Read(&temp, sizeof(int),1);
2867 project./*config.*/options.debug = temp ? true : false;
2868 f.Read(&temp, sizeof(int),1);
2869 project./*config.*/options.optimization = temp ? speed : none;
2870 f.Read(&temp, sizeof(int),1);
2871 project./*config.*/options.profile = temp ? true : false;
2872 f.Read(&temp, sizeof(int),1);
2873 project.options.warnings = temp ? all : unset;
2875 f.Read(&count, sizeof(int),1);
2878 project.options.includeDirs = { };
2879 for(c = 0; c < count; c++)
2882 f.Read(&len, sizeof(int),1);
2883 name = new char[len+1];
2884 f.Read(name, sizeof(char), len+1);
2885 project.options.includeDirs.Add(name);
2889 f.Read(&count, sizeof(int),1);
2892 project.options.libraryDirs = { };
2893 for(c = 0; c < count; c++)
2896 f.Read(&len, sizeof(int),1);
2897 name = new char[len+1];
2898 f.Read(name, sizeof(char), len+1);
2899 project.options.libraryDirs.Add(name);
2903 f.Read(&count, sizeof(int),1);
2906 project.options.libraries = { };
2907 for(c = 0; c < count; c++)
2910 f.Read(&len, sizeof(int),1);
2911 name = new char[len+1];
2912 f.Read(name, sizeof(char), len+1);
2913 project.options.libraries.Add(name);
2917 f.Read(&count, sizeof(int),1);
2920 project.options.preprocessorDefinitions = { };
2921 for(c = 0; c < count; c++)
2924 f.Read(&len, sizeof(int),1);
2925 name = new char[len+1];
2926 f.Read(name, sizeof(char), len+1);
2927 project.options.preprocessorDefinitions.Add(name);
2931 f.Read(&temp, sizeof(int),1);
2932 project.options.console = temp ? true : false;
2935 for(node : project.topNode.files)
2937 if(node.type == resources)
2939 project.resNode = node;
2949 void ProjectConfig::LegacyProjectConfigLoad(File f)
2957 char subSection[128];
2963 f.GetLine(buffer, 65536 - 1);
2964 TrimLSpaces(buffer, buffer);
2965 TrimRSpaces(buffer, buffer);
2968 if(buffer[0] == '-')
2972 TrimLSpaces(equal, equal);
2973 if(!strcmpi(subSection, "LibraryDirs"))
2975 if(!options.libraryDirs)
2976 options.libraryDirs = { [ CopyString(equal) ] };
2978 options.libraryDirs.Add(CopyString(equal));
2980 else if(!strcmpi(subSection, "IncludeDirs"))
2982 if(!options.includeDirs)
2983 options.includeDirs = { [ CopyString(equal) ] };
2985 options.includeDirs.Add(CopyString(equal));
2988 else if(buffer[0] == '+')
2999 TrimLSpaces(equal, equal);
3000 delete name; name = CopyString(equal); // property::name = equal;
3003 else if(!strcmpi(buffer, "Compiler Options"))
3004 strcpy(section, buffer);
3005 else if(!strcmpi(buffer, "IncludeDirs"))
3006 strcpy(subSection, buffer);
3007 else if(!strcmpi(buffer, "Linker Options"))
3008 strcpy(section, buffer);
3009 else if(!strcmpi(buffer, "LibraryDirs"))
3010 strcpy(subSection, buffer);
3011 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3018 equal = strstr(buffer, "=");
3022 TrimRSpaces(buffer, buffer);
3024 TrimLSpaces(equal, equal);
3025 if(!strcmpi(buffer, "Target Name"))
3026 options.targetFileName = /*CopyString(*/equal/*)*/;
3027 else if(!strcmpi(buffer, "Target Type"))
3029 if(!strcmpi(equal, "Executable"))
3030 options.targetType = executable;
3031 else if(!strcmpi(equal, "Shared"))
3032 options.targetType = sharedLibrary;
3033 else if(!strcmpi(equal, "Static"))
3034 options.targetType = staticLibrary;
3036 options.targetType = executable;
3038 else if(!strcmpi(buffer, "Target Directory"))
3039 options.targetDirectory = /*CopyString(*/equal/*)*/;
3040 else if(!strcmpi(buffer, "Console"))
3041 options.console = ParseTrueFalseValue(equal);
3042 else if(!strcmpi(buffer, "Libraries"))
3044 if(!options.libraries) options.libraries = { };
3045 ParseArrayValue(options.libraries, equal);
3047 else if(!strcmpi(buffer, "Intermediate Directory"))
3048 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3049 else if(!strcmpi(buffer, "Debug"))
3050 options.debug = ParseTrueFalseValue(equal);
3051 else if(!strcmpi(buffer, "Optimize"))
3053 if(!strcmpi(equal, "None"))
3054 options.optimization = none;
3055 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3056 options.optimization = speed;
3057 else if(!strcmpi(equal, "Size"))
3058 options.optimization = size;
3060 options.optimization = none;
3062 else if(!strcmpi(buffer, "Compress"))
3063 options.compress = ParseTrueFalseValue(equal);
3064 else if(!strcmpi(buffer, "Profile"))
3065 options.profile = ParseTrueFalseValue(equal);
3066 else if(!strcmpi(buffer, "AllWarnings"))
3067 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3068 else if(!strcmpi(buffer, "MemoryGuard"))
3069 options.memoryGuard = ParseTrueFalseValue(equal);
3070 else if(!strcmpi(buffer, "Default Name Space"))
3071 options.defaultNameSpace = CopyString(equal);
3072 else if(!strcmpi(buffer, "Strict Name Spaces"))
3073 options.strictNameSpaces = ParseTrueFalseValue(equal);
3074 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3076 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3077 ParseArrayValue(options.preprocessorDefinitions, equal);
3083 if(!options.targetDirectory && options.objectsDirectory)
3084 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3085 //if(!objDir.dir) objDir.dir = "obj";
3086 //if(!targetDir.dir) targetDir.dir = "";
3087 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3088 // if(!defaultNameSpace) property::defaultNameSpace = "";
3089 makingModified = true;
3092 Project LegacyAsciiLoadProject(File f, char * filePath)
3094 Project project = null;
3095 ProjectNode node = null;
3097 char parentPath[MAX_LOCATION];
3098 char section[128] = "";
3099 char subSection[128] = "";
3101 bool configurationsPresent = false;
3111 f.GetLine(buffer, 65536 - 1);
3112 TrimLSpaces(buffer, buffer);
3113 TrimRSpaces(buffer, buffer);
3116 if(buffer[0] == '-' || buffer[0] == '=')
3118 bool simple = buffer[0] == '-';
3121 TrimLSpaces(equal, equal);
3122 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3124 if(!project.config.options.libraryDirs) project.config.options.libraryDirs = { };
3125 project.config.options.libraryDirs.Add(CopyString(equal));
3127 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3129 if(!project.config.options.includeDirs) project.config.options.includeDirs = { };
3130 project.config.options.includeDirs.Add(CopyString(equal));
3132 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3134 len = strlen(equal);
3137 char temp[MAX_LOCATION];
3138 ProjectNode child { };
3139 // We don't need to do this anymore, fileName is just a property that sets name & path
3140 // child.fileName = CopyString(equal);
3143 child.name = CopyString(equal);
3144 child.path = CopyString(parentPath);
3148 GetLastDirectory(equal, temp);
3149 child.name = CopyString(temp);
3150 StripLastDirectory(equal, temp);
3151 child.path = CopyString(temp);
3153 child.nodeType = file;
3154 child.parent = parent;
3155 child.indent = parent.indent + 1;
3157 child.icon = NodeIcons::SelectFileIcon(child.name);
3158 parent.files.Add(child);
3164 StripLastDirectory(parentPath, parentPath);
3165 parent = parent.parent;
3169 else if(buffer[0] == '+')
3173 TrimLSpaces(equal, equal);
3174 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3176 char temp[MAX_LOCATION];
3177 ProjectNode child { };
3178 // NEW: Folders now have a path set like files
3179 child.name = CopyString(equal);
3180 strcpy(temp, parentPath);
3181 PathCatSlash(temp, child.name);
3182 child.path = CopyString(temp);
3184 child.parent = parent;
3185 child.indent = parent.indent + 1;
3186 child.type = folder;
3187 child.nodeType = folder;
3189 child.icon = folder;
3190 PathCatSlash(parentPath, child.name);
3191 parent.files.Add(child);
3196 else if(!strcmpi(section, "Configurations"))
3198 ProjectConfig newConfig
3200 makingModified = true;
3204 LegacyProjectConfigLoad(newConfig, f);
3205 project.configurations.Add(newConfig);
3208 else if(!strcmpi(buffer, "ECERE Project File"));
3209 else if(!strcmpi(buffer, "Version 0a"))
3210 ; //strcpy(version, "0a");
3211 else if(!strcmpi(buffer, "Version 0.1a"))
3212 ; //strcpy(version, "0.1a");
3213 else if(!strcmpi(buffer, "Configurations"))
3215 project.configurations.Free();
3216 project.config = null;
3217 strcpy(section, buffer);
3218 configurationsPresent = true;
3220 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3222 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3223 char topNodePath[MAX_LOCATION];
3224 // newConfig.defaultNameSpace = "";
3225 //newConfig.objDir.dir = "obj";
3226 //newConfig.targetDir.dir = "";
3227 project = Project { /*options = { }*/ };
3228 project.configurations = { [ newConfig ] };
3229 project.config = newConfig;
3230 // if(project.topNode.path) delete project.topNode.path;
3231 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3232 MakeSlashPath(topNodePath);
3233 PathCatSlash(topNodePath, filePath);
3234 project.filePath = topNodePath;
3235 parentPath[0] = '\0';
3236 parent = project.topNode;
3238 strcpy(section, "Target");
3243 if(equal[0] == '\"')
3245 StripQuotes(equal, equal);
3246 delete project.moduleName; project.moduleName = CopyString(equal);
3250 else if(!strcmpi(buffer, "Compiler Options"));
3251 else if(!strcmpi(buffer, "IncludeDirs"))
3252 strcpy(subSection, buffer);
3253 else if(!strcmpi(buffer, "Linker Options"));
3254 else if(!strcmpi(buffer, "LibraryDirs"))
3255 strcpy(subSection, buffer);
3256 else if(!strcmpi(buffer, "Files"))
3258 strcpy(section, "Target");
3259 strcpy(subSection, buffer);
3261 else if(!strcmpi(buffer, "Resources"))
3263 ProjectNode child { };
3264 parent.files.Add(child);
3265 child.parent = parent;
3266 child.indent = parent.indent + 1;
3267 child.name = CopyString(buffer);
3268 child.path = CopyString("");
3269 child.type = resources;
3271 child.icon = archiveFile;
3272 project.resNode = child;
3275 strcpy(subSection, buffer);
3279 equal = strstr(buffer, "=");
3283 TrimRSpaces(buffer, buffer);
3285 TrimLSpaces(equal, equal);
3287 if(!strcmpi(section, "Target"))
3289 if(!strcmpi(buffer, "Build Exclusions"))
3291 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3293 /*if(node && node.type != NodeTypes::project)
3294 ParseListValue(node.buildExclusions, equal);*/
3297 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
3299 delete project.resNode.path;
3300 project.resNode.path = CopyString(equal);
3301 PathCatSlash(parentPath, equal);
3305 else if(!strcmpi(buffer, "Intermediate Directory"))
3306 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3307 else if(!strcmpi(buffer, "Debug"))
3308 project.config.options.debug = ParseTrueFalseValue(equal);
3309 else if(!strcmpi(buffer, "Optimize"))
3311 if(!strcmpi(equal, "None"))
3312 project.config.options.optimization = none;
3313 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3314 project.config.options.optimization = speed;
3315 else if(!strcmpi(equal, "Size"))
3316 project.config.options.optimization = size;
3318 project.config.options.optimization = none;
3320 else if(!strcmpi(buffer, "Profile"))
3321 project.config.options.profile = ParseTrueFalseValue(equal);
3322 else if(!strcmpi(buffer, "MemoryGuard"))
3323 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
3326 if(!project.options) project.options = { };
3328 // Project Wide Settings (All configs)
3329 if(!strcmpi(buffer, "Target Name"))
3330 project.options.targetFileName = /*CopyString(*/equal/*)*/;
3331 else if(!strcmpi(buffer, "Target Type"))
3333 if(!strcmpi(equal, "Executable"))
3334 project.options.targetType = executable;
3335 else if(!strcmpi(equal, "Shared"))
3336 project.options.targetType = sharedLibrary;
3337 else if(!strcmpi(equal, "Static"))
3338 project.options.targetType = staticLibrary;
3340 project.options.targetType = executable;
3342 else if(!strcmpi(buffer, "Target Directory"))
3343 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
3344 else if(!strcmpi(buffer, "Console"))
3345 project.options.console = ParseTrueFalseValue(equal);
3346 else if(!strcmpi(buffer, "Libraries"))
3348 if(!project.options.libraries) project.options.libraries = { };
3349 ParseArrayValue(project.options.libraries, equal);
3351 else if(!strcmpi(buffer, "AllWarnings"))
3352 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3353 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3355 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3357 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
3358 ParseListValue(node.preprocessorDefs, equal);*/
3362 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
3363 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3374 SplitPlatformLibraries(project);
3376 if(configurationsPresent)
3377 CombineIdenticalConfigOptions(project);
3381 void SplitPlatformLibraries(Project project)
3383 if(project && project.configurations)
3385 for(cfg : project.configurations)
3387 if(cfg.options.libraries && cfg.options.libraries.count)
3389 Iterator<String> it { cfg.options.libraries };
3393 char * platformName = strstr(l, ":");
3396 PlatformOptions platform = null;
3398 if(!cfg.platforms) cfg.platforms = { };
3399 for(p : cfg.platforms)
3401 if(!strcmpi(platformName, p.name))
3409 platform = { name = CopyString(platformName), options = { libraries = { } } };
3410 cfg.platforms.Add(platform);
3412 *(platformName-1) = 0;
3413 platform.options.libraries.Add(CopyString(l));
3415 cfg.options.libraries.Delete(it.pointer);
3424 void CombineIdenticalConfigOptions(Project project)
3426 if(project && project.configurations && project.configurations.count)
3429 ProjectOptions nullOptions { };
3430 ProjectConfig firstConfig = null;
3431 for(cfg : project.configurations)
3433 if(cfg.options.targetType != staticLibrary)
3440 firstConfig = project.configurations.firstIterator.data;
3442 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3444 if(!member.isProperty)
3446 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3451 for(cfg : project.configurations)
3453 if(cfg != firstConfig)
3455 if(cfg.options.targetType != staticLibrary)
3459 if(type.type == noHeadClass || type.type == normalClass)
3461 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3462 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3463 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3467 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3468 (byte *)firstConfig.options + member.offset + member._class.offset,
3469 (byte *)cfg.options + member.offset + member._class.offset);
3481 if(type.type == noHeadClass || type.type == normalClass)
3483 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3484 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3485 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3490 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3491 (byte *)firstConfig.options + member.offset + member._class.offset,
3492 (byte *)nullOptions + member.offset + member._class.offset))
3496 if(!project.options) project.options = { };
3498 /*if(type.type == noHeadClass || type.type == normalClass)
3500 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3501 (byte *)project.options + member.offset + member._class.offset,
3502 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3506 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3507 // TOFIX: ListBox::SetData / OnCopy mess
3508 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3509 (byte *)project.options + member.offset + member._class.offset,
3510 (type.typeSize > 4) ? address :
3511 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3512 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3513 (void *)*(byte *)address )));
3516 (byte *)project.options + member.offset + member._class.offset,
3517 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3519 for(cfg : project.configurations)
3521 if(cfg.options.targetType == staticLibrary)
3525 if(type.type == noHeadClass || type.type == normalClass)
3527 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3528 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3529 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3533 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3534 (byte *)firstConfig.options + member.offset + member._class.offset,
3535 (byte *)cfg.options + member.offset + member._class.offset);
3540 if(cfg != firstConfig)
3542 if(type.type == noHeadClass || type.type == normalClass)
3544 type._vTbl[__ecereVMethodID_class_OnFree](type,
3545 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3549 type._vTbl[__ecereVMethodID_class_OnFree](type,
3550 (byte *)cfg.options + member.offset + member._class.offset);
3552 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3555 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3562 // Compare Platform Specific Settings
3565 for(cfg : project.configurations)
3567 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3568 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3574 if(same && firstConfig.platforms)
3576 for(cfg : project.configurations)
3578 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3580 if(cfg != firstConfig)
3582 cfg.platforms.Free();
3583 delete cfg.platforms;
3586 project.platforms = firstConfig.platforms;
3587 firstConfig.platforms = null;
3591 // Static libraries can't contain libraries
3592 for(cfg : project.configurations)
3594 if(cfg.options.targetType == staticLibrary)
3596 if(!cfg.options.libraries) cfg.options.libraries = { };
3597 cfg.options.libraries.Free();
3603 Project LoadProject(char * filePath)
3605 Project project = null;
3606 File f = FileOpen(filePath, read);
3609 project = LegacyBinaryLoadProject(f, filePath);
3612 JSONParser parser { f = f };
3613 JSONResult result = parser.GetObject(class(Project), &project);
3616 char insidePath[MAX_LOCATION];
3618 delete project.topNode.files;
3619 if(!project.files) project.files = { };
3620 project.topNode.files = project.files;
3621 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3622 delete project.resNode.path;
3623 project.resNode.path = project.resourcesPath;
3624 project.resourcesPath = null;
3625 project.resNode.nodeType = (ProjectNodeType)-1;
3626 delete project.resNode.files;
3627 project.resNode.files = project.resources;
3628 project.files = null;
3629 project.resources = null;
3630 if(!project.configurations) project.configurations = { };
3633 char topNodePath[MAX_LOCATION];
3634 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3635 MakeSlashPath(topNodePath);
3636 PathCatSlash(topNodePath, filePath);
3637 project.filePath = topNodePath;//filePath;
3640 project.topNode.FixupNode(insidePath);
3645 project = LegacyAsciiLoadProject(f, filePath);
3651 if(!project.options) project.options = { };
3652 if(!project.config && project.configurations)
3653 project.config = project.configurations.firstIterator.data;
3655 if(!project.resNode)
3657 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3660 if(!project.moduleName)
3661 project.moduleName = CopyString(project.name);
3662 if(project.config &&
3663 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3664 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3666 //delete project.config.options.targetFileName;
3668 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
3669 project.config.options.optimization = none;
3670 project.config.options.debug = true;
3671 //project.config.options.warnings = unset;
3672 project.config.options.memoryGuard = false;
3673 project.config.compilingModified = true;
3674 project.config.linkingModified = true;
3676 else if(!project.topNode.name && project.config)
3678 project.topNode.name = CopyString(project.config.options.targetFileName);
3681 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3682 project.topNode.configurations = project.configurations;
3683 project.topNode.platforms = project.platforms;
3684 project.topNode.options = project.options;*/