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 GetExtension(item, ext);
565 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
569 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
571 if(!strncmp(item, "lib", 3))
572 strcpy(temp, item + 3);
575 StripExtension(temp);
584 void CamelCase(char * string)
586 int c, len = strlen(string);
587 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
588 string[c] = (char)tolower(string[c]);
591 CompilerConfig GetCompilerConfig()
593 #ifndef MAKEFILE_GENERATOR
594 CompilerConfig compiler = null;
595 if(ide && ide.workspace)
596 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
599 incref defaultCompiler;
600 return defaultCompiler;
604 define localTargetType = config && config.options && config.options.targetType ?
605 config.options.targetType : options && options.targetType ?
606 options.targetType : TargetTypes::executable;
607 define localWarnings = config && config.options && config.options.warnings ?
608 config.options.warnings : options && options.warnings ?
609 options.warnings : WarningsOption::unset;
610 define localDebug = config && config.options && config.options.debug ?
611 config.options.debug : options && options.debug ?
612 options.debug : SetBool::unset;
613 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
614 config.options.memoryGuard : options && options.memoryGuard ?
615 options.memoryGuard : SetBool::unset;
616 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
617 config.options.noLineNumbers : options && options.noLineNumbers ?
618 options.noLineNumbers : SetBool::unset;
619 define localProfile = config && config.options && config.options.profile ?
620 config.options.profile : options && options.profile ?
621 options.profile : SetBool::unset;
622 define localOptimization = config && config.options && config.options.optimization ?
623 config.options.optimization : options && options.optimization ?
624 options.optimization : OptimizationStrategy::none;
625 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
626 config.options.defaultNameSpace : options && options.defaultNameSpace ?
627 options.defaultNameSpace : null;
628 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
629 config.options.strictNameSpaces : options && options.strictNameSpaces ?
630 options.strictNameSpaces : SetBool::unset;
631 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
632 define localTargetFileName = config && config.options && config.options.targetFileName ?
633 config.options.targetFileName : options && options.targetFileName ?
634 options.targetFileName : "";
635 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
636 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
637 options.targetDirectory : null;
638 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
639 ideSettings.projectDefaultIntermediateObjDir[0] ?
640 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
641 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
642 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
643 options.objectsDirectory : null;
644 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
645 ideSettings.projectDefaultIntermediateObjDir[0] ?
646 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
647 define localConsole = config && config.options && config.options.console ?
648 config.options.console : options && options.console ?
649 options.console : SetBool::unset;
650 define localCompress = config && config.options && config.options.compress ?
651 config.options.compress : options && options.compress ?
652 options.compress : SetBool::unset;
654 define platformTargetType =
655 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
656 configPOs.options.targetType :
657 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
658 projectPOs.options.targetType : TargetTypes::unset;
661 // we should have some kind of direct mapping between a platform and it's makefile variable
662 char * PlatformToMakefileVariable(Platform platform)
664 return platform == win32 ? "WINDOWS" :
665 platform == tux ? "LINUX" :
666 platform == apple ? "OSX"/*"APPLE"*/ :
670 char * TargetTypeToMakefileVariable(TargetTypes targetType)
672 return targetType == executable ? "executable" :
673 targetType == sharedLibrary ? "sharedlib" :
674 targetType == staticLibrary ? "staticlib" :
678 // Move this to ProjectConfig? null vs Common to consider...
679 char * GetConfigName(ProjectConfig config)
681 return config ? config.name : "Common";
684 class Project : struct
686 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
687 // We might want to tweak this default behavior of regular classes ?
688 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
693 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
694 property Array<PlatformOptions> platforms
696 get { return platforms; }
699 if(platforms) { platforms.Free(); delete platforms; }
702 List<PlatformOptions> empty { };
703 Iterator<PlatformOptions> it { value };
705 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
706 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
716 if(p.options && !p.options.isEmpty)
723 List<ProjectConfig> configurations;
724 LinkList<ProjectNode> files;
725 String resourcesPath;
726 LinkList<ProjectNode> resources;
728 property char * description
730 set { delete description; if(value && value[0]) description = CopyString(value); }
731 get { return description ? description : ""; }
732 isset { return description != null && description[0]; }
735 property char * license
737 set { delete license; if(value && value[0]) license = CopyString(value); }
738 get { return license ? license : ""; }
739 isset { return license != null && license[0]; }
743 // topNode.name holds the file name (.epj)
744 ProjectOptions options;
745 Array<PlatformOptions> platforms;
746 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
749 ProjectConfig config;
751 // This is the file name stripped of the epj extension
752 // It should NOT be edited, saved or loaded anywhere
760 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
761 topNode.configurations = null;
762 topNode.platforms = null;
763 topNode.options = null;
766 if(platforms) { platforms.Free(); delete platforms; }
767 if(configurations) { configurations.Free(); delete configurations; }
768 if(files) { files.Free(); delete files; }
769 if(resources) { resources.Free(); delete resources; }
771 delete resourcesPath;
781 property ProjectConfig config
787 topNode.info = CopyString(GetConfigName(config));
790 property char * filePath
796 char string[MAX_LOCATION];
797 GetLastDirectory(value, string);
799 topNode.name = CopyString(string);
800 StripExtension(string);
802 name = CopyString(string);
803 StripLastDirectory(value, string);
805 topNode.path = CopyString(string);
807 filePath = CopyString(value);
812 TargetTypes GetTargetType(ProjectConfig config)
814 TargetTypes targetType = localTargetType;
818 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
821 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
823 PlatformOptions projectPOs, configPOs;
824 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
825 if(platformTargetType)
832 char * GetObjDirExpression(CompilerConfig compiler, ProjectConfig config)
834 // TODO: Support platform options
835 char * expression = localObjectsDirectory;
837 expression = settingsObjectsDirectory;
841 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config)
843 char * expression = GetObjDirExpression(compiler, config);
844 DirExpression objDir { type = intermediateObjectsDir };
845 objDir.Evaluate(expression, this, compiler, config);
849 char * GetTargetDirExpression(CompilerConfig compiler, ProjectConfig config)
851 // TODO: Support platform options
852 char * expression = localTargetDirectory;
854 expression = settingsTargetDirectory;
858 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config)
860 char * expression = GetTargetDirExpression(compiler, config);
861 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
862 targetDir.Evaluate(expression, this, compiler, config);
866 WarningsOption GetWarnings(ProjectConfig config)
868 WarningsOption warnings = localWarnings;
872 bool GetDebug(ProjectConfig config)
874 SetBool debug = localDebug;
875 return debug == true;
878 bool GetMemoryGuard(ProjectConfig config)
880 SetBool memoryGuard = localMemoryGuard;
881 return memoryGuard == true;
884 bool GetNoLineNumbers(ProjectConfig config)
886 SetBool noLineNumbers = localNoLineNumbers;
887 return noLineNumbers == true;
890 bool GetProfile(ProjectConfig config)
892 SetBool profile = localProfile;
893 return profile == true;
896 OptimizationStrategy GetOptimization(ProjectConfig config)
898 OptimizationStrategy optimization = localOptimization;
902 String GetDefaultNameSpace(ProjectConfig config)
904 String defaultNameSpace = localDefaultNameSpace;
905 return defaultNameSpace;
908 bool GetStrictNameSpaces(ProjectConfig config)
910 SetBool strictNameSpaces = localStrictNameSpaces;
911 return strictNameSpaces == true;
914 String GetTargetFileName(ProjectConfig config)
916 String targetFileName = localTargetFileName;
917 return targetFileName;
920 //String targetDirectory;
921 //String objectsDirectory;
922 bool GetConsole(ProjectConfig config)
924 SetBool console = localConsole;
925 return console == true;
928 bool GetCompress(ProjectConfig config)
930 SetBool compress = localCompress;
931 return compress == true;
933 //SetBool excludeFromBuild;
935 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
937 #ifndef MAKEFILE_GENERATOR
938 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
942 bool GetConfigIsInDebugSession(ProjectConfig config)
944 #ifndef MAKEFILE_GENERATOR
945 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
949 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config)
951 #ifndef MAKEFILE_GENERATOR
952 ide.SetPath(projectsDirs, compiler, config);
956 #ifndef MAKEFILE_GENERATOR
957 bool Save(char * fileName)
960 /*char output[MAX_LOCATION];
961 ChangeExtension(fileName, "json", output);
962 f = FileOpen(output, write);*/
963 f = FileOpen(fileName, write);
966 files = topNode.files;
967 resources = resNode.files;
968 resourcesPath = resNode.path;
970 files.Remove(resNode);
973 WriteJSONObject(f, class(Project), this, 0);
979 resourcesPath = null;
986 #ifndef MAKEFILE_GENERATOR
987 bool GetRelativePath(char * filePath, char * relativePath)
990 char moduleName[MAX_FILENAME];
991 GetLastDirectory(filePath, moduleName);
992 // try with workspace dir first?
993 if((node = topNode.Find(moduleName, false)))
995 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
996 PathCatSlash(relativePath, node.name);
999 // WARNING: On failure, relative path is uninitialized
1004 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1006 TargetTypes targetType = GetTargetType(config);
1007 String targetFileName = GetTargetFileName(config);
1008 if(targetType == staticLibrary)
1010 PathCatSlash(string, "lib");
1011 strcat(string, targetFileName);
1013 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1015 PathCatSlash(string, "lib");
1016 strcat(string, targetFileName);
1019 PathCatSlash(string, targetFileName);
1024 if(compiler.targetPlatform == win32)
1025 strcat(string, ".exe");
1028 if(compiler.targetPlatform == win32)
1029 strcat(string, ".dll");
1030 else if(compiler.targetPlatform == apple)
1031 strcat(string, ".dylib");
1033 strcat(string, ".so");
1036 strcat(string, ".a");
1041 void GetCompilerConfigsDir(char * cfDir)
1043 strcpy(cfDir, topNode.path);
1044 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1045 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1049 void CatMakeFileName(char * string, ProjectConfig config)
1051 char projectName[MAX_LOCATION];
1052 strcpy(projectName, name);
1053 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1056 #ifndef MAKEFILE_GENERATOR
1057 void MarkChanges(ProjectNode node)
1059 for(cfg : topNode.configurations)
1061 ProjectConfig c = null;
1062 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1064 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1065 (!c.options || !cfg.options)))
1066 cfg.symbolGenModified = true;
1068 cfg.makingModified = true;
1072 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1074 for(cfg : configurations)
1077 cfg.makingModified = true;
1079 cfg.compilingModified = true;
1081 cfg.linkingModified = true;
1083 cfg.symbolGenModified = true;
1085 if(compiling || linking)
1087 ide.projectView.modifiedDocument = true;
1088 ide.workspace.modified = true;
1092 void RotateActiveConfig(bool forward)
1094 if(configurations.first && configurations.last != configurations.first)
1096 Iterator<ProjectConfig> cfg { configurations };
1097 while(forward ? cfg.Next() : cfg.Prev())
1098 if(cfg.data == config)
1112 property::config = cfg.data;
1113 ide.workspace.modified = true;
1114 ide.projectView.Update(null);
1118 void ProcessPipeOutputRaw(DualPipe f)
1121 while(!f.Eof() && !ide.ShouldStopBuild())
1124 double lastTime = GetTime();
1128 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1130 ide.outputView.buildBox.Logf("%s\n", line);
1132 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1134 //printf("Processing Input...\n");
1135 if(app.ProcessInput(true))
1137 app.UpdateDisplay();
1140 //printf("Waiting...\n");
1143 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1145 if(ide.ShouldStopBuild())
1147 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1152 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode,
1153 CompilerConfig compiler, ProjectConfig config)
1156 bool compiling = false, linking = false, precompiling = false;
1157 int compilingEC = 0;
1158 int numErrors = 0, numWarnings = 0;
1159 bool loggedALine = false;
1160 char * configName = config.name;
1161 int lenMakeCommand = strlen(compiler.makeCommand);
1163 char cppCommand[MAX_LOCATION];
1164 char ccCommand[MAX_LOCATION];
1165 char ecpCommand[MAX_LOCATION];
1166 char eccCommand[MAX_LOCATION];
1167 char ecsCommand[MAX_LOCATION];
1168 char earCommand[MAX_LOCATION];
1170 char * cc = compiler.ccCommand;
1171 char * cpp = compiler.cppCommand;
1172 sprintf(cppCommand, "%s%s%s%s ",
1173 compiler.ccacheEnabled ? "ccache " : "",
1174 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1175 compiler.distccEnabled ? "distcc " : "",
1176 compiler.cppCommand);
1177 sprintf(ccCommand, "%s%s%s%s ",
1178 compiler.ccacheEnabled ? "ccache " : "",
1179 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1180 compiler.distccEnabled ? "distcc " : "",
1181 compiler.ccCommand);
1182 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1183 sprintf(eccCommand, "%s ", compiler.eccCommand);
1184 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1185 sprintf(earCommand, "%s ", compiler.earCommand);
1187 while(!f.Eof() && !ide.ShouldStopBuild())
1190 double lastTime = GetTime();
1194 //printf("Peeking and GetLine...\n");
1195 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1197 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1198 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1200 char * module = strstr(line, "No rule to make target `");
1204 module = strchr(module, '`') + 1;
1205 end = strchr(module, '\'');
1209 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1210 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1216 //ide.outputView.buildBox.Logf("error: %s\n", line);
1220 else if(strstr(line, "ear ") == line);
1221 else if(strstr(line, "strip ") == line);
1222 else if(strstr(line, ccCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1224 char moduleName[MAX_FILENAME];
1227 bool isPrecomp = false;
1229 if(strstr(line, ccCommand) == line)
1231 module = strstr(line, " -c ");
1232 if(module) module += 4;
1234 else if(strstr(line, eccCommand) == line)
1236 module = strstr(line, " -c ");
1237 if(module) module += 4;
1238 //module = line + 3;
1239 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1240 compilingEC = 3;//2;
1242 else if(strstr(line, ecpCommand) == line)
1244 // module = line + 8;
1245 module = strstr(line, " -c ");
1246 if(module) module += 4;
1255 if(!compiling && !isPrecomp)
1257 ide.outputView.buildBox.Logf($"Compiling...\n");
1260 else if(!precompiling && isPrecomp)
1262 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1263 precompiling = true;
1265 // Changed escapeBackSlashes here to handle paths with spaces
1266 Tokenize(module, 1, tokens, true); // false);
1267 GetLastDirectory(module, moduleName);
1268 ide.outputView.buildBox.Logf("%s\n", moduleName);
1270 else if((module = strstr(line, " -o ")))
1273 precompiling = false;
1275 ide.outputView.buildBox.Logf($"Linking...\n");
1279 ide.outputView.buildBox.Logf("%s\n", line);
1283 if(compilingEC) compilingEC--;
1285 else if(strstr(line, "ar rcs") == line)
1286 ide.outputView.buildBox.Logf($"Building library...\n");
1287 else if(strstr(line, ecsCommand) == line)
1288 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1291 if(linking || compiling || precompiling)
1293 char * colon = strstr(line, ":"); //, * bracket;
1294 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1295 colon = strstr(colon + 1, ":");
1298 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1301 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1302 int len = (int)(colon - start);
1303 len = Min(len, MAX_LOCATION-1);
1304 // Don't be mistaken by the drive letter colon
1306 // TODO: need to fix colon - line gives char *
1307 // warning: incompatible expression colon - line (char *); expected int
1309 strncpy(moduleName, line, (int)(colon - line));
1310 moduleName[colon - line] = '\0';
1312 strncpy(moduleName, start, len);
1313 moduleName[len] = '\0';
1314 // Remove stuff in brackets
1315 //bracket = strstr(moduleName, "(");
1316 //if(bracket) *bracket = '\0';
1318 GetLastDirectory(moduleName, temp);
1319 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1322 strcpy(moduleName, $"Linker Error");
1326 strcpy(temp, topNode.path);
1327 PathCatSlash(temp, moduleName);
1328 MakePathRelative(temp, topNode.path, moduleName);
1330 if(strstr(line, "error:"))
1334 // Silence warnings for compiled EC
1335 char * objDir = strstr(moduleName, objDirExp.dir);
1339 if((pointer = strstr(line, "undefined")) ||
1340 (pointer = strstr(line, "No such file")) ||
1341 (pointer = strstr(line, "token")))
1343 strncat(moduleName, colon, pointer - colon);
1344 strcat(moduleName, "error: ");
1349 else if((pointer = strstr(line, "No such file")))
1351 strncat(moduleName, colon, pointer - colon);
1352 strcat(moduleName, "error: ");
1356 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1358 else if(strstr(line, "warning:"))
1363 if(this == ide.workspace.projects.firstIterator.data)
1364 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1367 char fullModuleName[MAX_LOCATION];
1368 strcpy(fullModuleName, topNode.path);
1369 PathCat(fullModuleName, moduleName);
1370 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1371 MakeSystemPath(fullModuleName);
1372 ide.outputView.buildBox.Logf(" %s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : "", fullModuleName, colon);
1377 ide.outputView.buildBox.Logf("%s\n", line);
1378 linking = compiling = precompiling = false;
1382 ide.outputView.buildBox.Logf("%s\n", line);
1386 //printf("Done getting line\n");
1387 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1389 //printf("Processing Input...\n");
1390 if(app.ProcessInput(true))
1392 app.UpdateDisplay();
1395 //printf("Waiting...\n");
1398 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1400 if(ide.ShouldStopBuild())
1402 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1405 else if(loggedALine || !isARun)
1407 if(f.GetExitCode() && !numErrors)
1409 bool result = f.GetLine(line, sizeof(line)-1);
1410 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1415 ide.outputView.buildBox.Logf("\n%s (%s) - ", GetTargetFileName(config), configName);
1417 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1419 ide.outputView.buildBox.Logf($"no error, ");
1422 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1424 ide.outputView.buildBox.Logf($"no warning\n");
1427 return numErrors == 0;
1430 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1433 int lenMakeCommand = strlen(compiler.makeCommand);
1438 double lastTime = GetTime();
1441 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1443 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1444 else if(strstr(line, "del") == line);
1445 else if(strstr(line, "rm") == line);
1446 else if(strstr(line, "Could Not Find") == line);
1449 ide.outputView.buildBox.Logf(line);
1450 ide.outputView.buildBox.Logf("\n");
1454 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1456 if(app.ProcessInput(true))
1458 app.UpdateDisplay();
1461 //Sleep(1.0 / PEEK_RESOLUTION);
1465 bool Build(bool isARun, ProjectNode onlyNode, CompilerConfig compiler, ProjectConfig config)
1467 bool result = false;
1469 char targetFileName[MAX_LOCATION] = "";
1470 char makeTarget[MAX_LOCATION] = "";
1471 char makeFile[MAX_LOCATION];
1472 char makeFilePath[MAX_LOCATION];
1473 char configName[MAX_LOCATION];
1474 DirExpression objDirExp = GetObjDir(compiler, config);
1475 PathBackup pathBackup { };
1477 int numJobs = compiler.numJobs;
1478 char command[MAX_LOCATION];
1479 char * compilerName;
1481 compilerName = CopyString(compiler.name);
1482 CamelCase(compilerName);
1484 strcpy(configName, config ? config.name : "Common");
1486 SetPath(false, compiler, config); //true
1487 CatTargetFileName(targetFileName, compiler, config);
1489 strcpy(makeFilePath, topNode.path);
1490 CatMakeFileName(makeFile, config);
1491 PathCatSlash(makeFilePath, makeFile);
1493 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1496 if(compiler.type.isVC)
1498 PrintLn("compiling a single file is not yet supported");
1503 char pushD[MAX_LOCATION];
1504 char cfDir[MAX_LOCATION];
1505 GetCompilerConfigsDir(cfDir);
1506 GetWorkingDir(pushD, sizeof(pushD));
1507 ChangeWorkingDir(topNode.path);
1508 // Create object dir if it does not exist already
1509 if(!FileExists(objDirExp.dir).isDirectory)
1510 Execute("%s E_IDE_CF_DIR=%s COMPILER=%s objdir -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, topNode.path, makeFilePath);
1511 ChangeWorkingDir(pushD);
1513 PathCatSlash(makeTarget+1, objDirExp.dir);
1514 PathCatSlash(makeTarget+1, onlyNode.name);
1515 StripExtension(makeTarget+1);
1516 strcat(makeTarget+1, ".o");
1517 makeTarget[0] = '\"';
1518 len = strlen(makeTarget);
1519 makeTarget[len++] = '\"';
1520 makeTarget[len++] = '\0';
1524 if(compiler.type.isVC)
1526 bool result = false;
1527 char oldwd[MAX_LOCATION];
1528 GetWorkingDir(oldwd, sizeof(oldwd));
1529 ChangeWorkingDir(topNode.path);
1531 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1532 ide.outputView.buildBox.Logf("command: %s\n", command);
1533 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1535 ProcessPipeOutputRaw(f);
1539 ChangeWorkingDir(oldwd);
1543 char cfDir[MAX_LOCATION];
1544 GetCompilerConfigsDir(cfDir);
1545 sprintf(command, "%s E_IDE_CF_DIR=%s COMPILER=%s -j%d %s%s%s -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, numJobs,
1546 compiler.ccacheEnabled ? "CCACHE=y " : "",
1547 compiler.distccEnabled ? "DISTCC=y " : "",
1548 makeTarget, topNode.path, makeFilePath);
1549 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1551 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode, compiler, config);
1555 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
1560 delete compilerName;
1564 void Clean(CompilerConfig compiler, ProjectConfig config, bool realclean)
1566 char makeFile[MAX_LOCATION];
1567 char makeFilePath[MAX_LOCATION];
1568 char command[MAX_LOCATION];
1569 char * compilerName;
1571 PathBackup pathBackup { };
1573 compilerName = CopyString(compiler.name);
1574 CamelCase(compilerName);
1576 SetPath(false, compiler, config);
1578 strcpy(makeFilePath, topNode.path);
1579 CatMakeFileName(makeFile, config);
1580 PathCatSlash(makeFilePath, makeFile);
1582 if(compiler.type.isVC)
1584 bool result = false;
1585 char oldwd[MAX_LOCATION];
1586 GetWorkingDir(oldwd, sizeof(oldwd));
1587 ChangeWorkingDir(topNode.path);
1589 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1590 ide.outputView.buildBox.Logf("command: %s\n", command);
1591 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1593 ProcessPipeOutputRaw(f);
1597 ChangeWorkingDir(oldwd);
1602 char cfDir[MAX_LOCATION];
1603 GetCompilerConfigsDir(cfDir);
1604 sprintf(command, "%s E_IDE_CF_DIR=%s COMPILER=%s %sclean -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, realclean ? "real" : "", topNode.path, makeFilePath);
1605 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1607 ide.outputView.buildBox.Tell($"Deleting target and object files...");
1608 ProcessCleanPipeOutput(f, compiler, config);
1611 ide.outputView.buildBox.Logf($"Target and object files deleted\n");
1616 delete compilerName;
1619 void Run(char * args, CompilerConfig compiler, ProjectConfig config)
1621 String target = new char[maxPathLen];
1622 char oldDirectory[MAX_LOCATION];
1623 DirExpression targetDirExp = GetTargetDir(compiler, config);
1624 PathBackup pathBackup { };
1626 // Build(project, ideMain, true, null);
1628 #if defined(__WIN32__)
1629 strcpy(target, topNode.path);
1633 PathCatSlash(target, targetDirExp.dir);
1634 CatTargetFileName(target, compiler, config);
1635 sprintf(target, "%s %s", target, args);
1636 GetWorkingDir(oldDirectory, MAX_LOCATION);
1638 if(strlen(ide.workspace.debugDir))
1640 char temp[MAX_LOCATION];
1641 strcpy(temp, topNode.path);
1642 PathCatSlash(temp, ide.workspace.debugDir);
1643 ChangeWorkingDir(temp);
1646 ChangeWorkingDir(topNode.path);
1647 // ChangeWorkingDir(topNode.path);
1648 SetPath(true, compiler, config);
1649 if(compiler.execPrefixCommand)
1651 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1652 prefixedTarget[0] = '\0';
1653 strcat(prefixedTarget, compiler.execPrefixCommand);
1654 strcat(prefixedTarget, " ");
1655 strcat(prefixedTarget, target);
1656 Execute(prefixedTarget);
1657 delete prefixedTarget;
1662 ChangeWorkingDir(oldDirectory);
1665 delete targetDirExp;
1669 void Compile(ProjectNode node, CompilerConfig compiler, ProjectConfig config)
1671 Build(false, node, compiler, config);
1675 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
1678 if(targetType == staticLibrary || targetType == sharedLibrary)
1679 strcat(fileName, "$(LP)");
1680 // !!! ReplaceSpaces must be done after all PathCat calls !!!
1681 // ReplaceSpaces(s, GetTargetFileName(config));
1682 strcat(fileName, GetTargetFileName(config));
1686 strcat(fileName, "$(E)");
1689 strcat(fileName, "$(SO)");
1692 strcat(fileName, "$(A)");
1697 bool GenerateDebugCf(CompilerConfig compiler)
1699 bool result = false;
1700 char path[MAX_LOCATION];
1702 GetCompilerConfigsDir(path);
1703 if(!FileExists(path).isDirectory)
1705 PathCatSlash(path, "debug.cf");
1707 if(FileExists(path))
1710 File f = FileOpen(path, write);
1713 f.Printf(".PHONY: debug_lists\n");
1716 f.Printf("ifdef WINDOWS\n");
1717 f.Printf(".PHONY: debug_openssl\n");
1718 f.Printf("debug_openssl:\n");
1719 f.Printf(" @$(call echo,OPENSSL_CONF = $(OPENSSL_CONF))\n");
1720 f.Printf(" @$(call echo,_OPENSSL_CONF = $(_OPENSSL_CONF))\n");
1721 f.Printf(" @$(call echo,OPENSSL_INCLUDE_DIR = $(OPENSSL_INCLUDE_DIR))\n");
1722 f.Printf(" @$(call echo,OPENSSL_LIB_DIR = $(OPENSSL_LIB_DIR))\n");
1723 f.Printf(" @$(call echo,OPENSSL_BIN_DIR = $(OPENSSL_BIN_DIR))\n");
1724 f.Printf("endif\n");
1727 f.Printf("debug_lists:\n");
1728 f.Printf(" @$(call echo,ECSOURCES = $(ECSOURCES))\n");
1729 f.Printf(" @$(call echo,SYMBOLS = $(SYMBOLS))\n");
1730 f.Printf(" @$(call echo,IMPORTS = $(IMPORTS))\n");
1731 f.Printf(" @$(call echo,COBJECTS = $(COBJECTS))\n");
1739 bool GenerateCrossPlatformCf()
1741 bool result = false;
1742 char path[MAX_LOCATION];
1744 GetCompilerConfigsDir(path);
1745 if(!FileExists(path).isDirectory)
1747 PathCatSlash(path, "crossplatform.cf");
1749 if(FileExists(path))
1752 File include = FileOpen(":crossplatform.cf", read);
1755 File f = FileOpen(path, write);
1758 for(; !include.Eof(); )
1761 int count = include.Read(buffer, 1, 4096);
1762 f.Write(buffer, 1, count);
1774 bool GenerateCompilerMk(CompilerConfig compiler)
1776 bool result = false;
1777 char path[MAX_LOCATION];
1779 char * compilerName;
1780 bool gccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "gcc") != null;
1781 Platform platform = GetRuntimePlatform();
1783 compilerName = CopyString(compiler.name);
1784 CamelCase(compilerName);
1785 name = PrintString(platform, "-", compilerName, ".cf");
1787 GetCompilerConfigsDir(path);
1788 if(!FileExists(path).isDirectory)
1790 PathCatSlash(path, name);
1792 if(FileExists(path))
1795 File f = FileOpen(path, write);
1798 bool crossCompiling = compiler.targetPlatform != platform;
1800 f.Printf("# TOOLCHAIN\n\n");
1802 //f.Printf("SHELL := %s\n", "ar"/*compiler.arCommand*/); // is this really needed?
1803 f.Printf("CPP := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.cppCommand);
1804 f.Printf("CC := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.ccCommand);
1805 f.Printf("ECP := %s\n", compiler.ecpCommand);
1806 f.Printf("ECC := %s\n", compiler.eccCommand);
1807 f.Printf("ECS := %s%s%s\n", compiler.ecsCommand,
1808 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1809 f.Printf("EAR := %s\n", compiler.earCommand);
1811 f.Printf("AS := as\n");
1812 f.Printf("LD := ld\n");
1813 f.Printf("AR := ar\n");
1814 f.Printf("STRIP := strip\n");
1815 f.Printf("UPX := upx\n");
1819 f.Printf("UPXFLAGS = -9\n\n"); // TOFEAT: Compression Level Option? Other UPX Options?
1821 f.Printf("# HARD CODED PLATFORM-SPECIFIC OPTIONS\n");
1822 f.Printf("ifdef %s\n", PlatformToMakefileVariable(tux));
1823 f.Printf("OFLAGS += -Wl,--no-undefined\n");
1824 f.Printf("endif\n\n");
1827 f.Printf("ifdef %s\n", PlatformToMakefileVariable(apple));
1828 f.Printf("OFLAGS += -framework cocoa -framework OpenGL\n");
1829 f.Printf("endif\n\n");
1832 f.Printf("PLATFORM = %s\n", (char *)compiler.targetPlatform);
1834 if((compiler.includeDirs && compiler.includeDirs.count) ||
1835 (compiler.libraryDirs && compiler.libraryDirs.count))
1837 if(compiler.includeDirs && compiler.includeDirs.count)
1839 f.Printf("CFLAGS +=");
1840 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
1843 if(compiler.libraryDirs && compiler.libraryDirs.count)
1845 f.Printf("OFLAGS +=");
1846 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
1856 delete compilerName;
1860 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath,
1861 CompilerConfig compiler, ProjectConfig config)
1863 bool result = false;
1864 char filePath[MAX_LOCATION];
1865 char makeFile[MAX_LOCATION];
1866 // PathBackup pathBackup { };
1867 // char oldDirectory[MAX_LOCATION];
1870 if(!altMakefilePath)
1872 strcpy(filePath, topNode.path);
1873 CatMakeFileName(makeFile, config);
1874 PathCatSlash(filePath, makeFile);
1877 #if defined(__WIN32__) && !defined(MAKEFILE_GENERATOR)
1878 if(compiler.type.isVC)
1880 GenerateVSSolutionFile(this, compiler);
1881 GenerateVCProjectFile(this, compiler);
1885 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
1887 /*SetPath(false, compiler, config);
1888 GetWorkingDir(oldDirectory, MAX_LOCATION);
1889 ChangeWorkingDir(topNode.path);*/
1896 Platform runtimePlatform = GetRuntimePlatform();
1897 char targetDir[MAX_LOCATION];
1898 char objDirExpNoSpaces[MAX_LOCATION];
1899 char objDirNoSpaces[MAX_LOCATION];
1900 char resDirNoSpaces[MAX_LOCATION];
1901 char targetDirExpNoSpaces[MAX_LOCATION];
1902 char fixedModuleName[MAX_FILENAME];
1903 char fixedConfigName[MAX_FILENAME];
1904 char fixedCompilerName[MAX_FILENAME];
1906 int numCObjects = 0;
1907 bool sameObjTargetDirs;
1908 DirExpression objDirExp = GetObjDir(compiler, config);
1909 TargetTypes targetType = GetTargetType(config);
1911 bool crossCompiling = compiler.targetPlatform != runtimePlatform;
1912 bool gccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "gcc") != null;
1913 bool tccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "tcc") != null;
1914 bool defaultPreprocessor = compiler.cppCommand && (strstr(compiler.cppCommand, "gcc") != null || compiler.cppCommand && strstr(compiler.cppCommand, "cpp") != null);
1916 int objectsParts, eCsourcesParts;
1917 Array<String> listItems { };
1918 Map<String, int> varStringLenDiffs { };
1919 Map<String, NameCollisionInfo> namesInfo { };
1921 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
1922 strcpy(targetDir, GetTargetDirExpression(compiler, config));
1923 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
1925 strcpy(objDirExpNoSpaces, GetObjDirExpression(compiler, config));
1926 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1927 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
1928 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
1929 //ReplaceSpaces(fixedPrjName, name);
1930 ReplaceSpaces(fixedModuleName, moduleName);
1931 ReplaceSpaces(fixedConfigName, GetConfigName(config));
1932 ReplaceSpaces(fixedCompilerName, compiler.name);
1933 //CamelCase(fixedModuleName); // case is important for static linking
1934 CamelCase(fixedConfigName);
1935 CamelCase(fixedCompilerName);
1937 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
1939 f.Printf(".PHONY: all objdir%s clean realclean\n\n", sameObjTargetDirs ? "" : " targetdir");
1941 f.Printf("# CONTENT\n\n");
1943 f.Printf("MODULE := %s\n", fixedModuleName);
1944 //f.Printf("VERSION = %s\n", version);
1945 f.Printf("CONFIG := %s\n", fixedConfigName);
1946 f.Printf("ifndef COMPILER\n");
1947 f.Printf("COMPILER := %s\n", fixedCompilerName);
1948 f.Printf("endif\n");
1949 test = GetTargetTypeIsSetByPlatform(config);
1953 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1955 TargetTypes targetType;
1956 PlatformOptions projectPOs, configPOs;
1957 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1958 targetType = platformTargetType;
1964 f.Printf("ifdef %s\n", PlatformToMakefileVariable(platform));
1966 f.Printf("TARGET_TYPE = ");
1967 f.Printf(TargetTypeToMakefileVariable(targetType));
1971 f.Printf("else\n"); // ifCount should always be > 0
1973 f.Printf("TARGET_TYPE = ");
1974 f.Printf(TargetTypeToMakefileVariable(targetType));
1980 for(c = 0; c < ifCount; c++)
1981 f.Printf("endif\n");
1986 f.Printf("# FLAGS\n\n");
1988 f.Printf("CFLAGS =\n");
1989 f.Printf("CECFLAGS =\n");
1990 f.Printf("ECFLAGS =\n");
1991 f.Printf("OFLAGS =\n");
1992 f.Printf("LIBS =\n");
1995 f.Printf("# INCLUDES\n\n");
1997 f.Printf("include %s\n", includemkPath ? includemkPath : "$(E_IDE_CF_DIR)crossplatform.cf");
1998 f.Printf("include $(E_IDE_CF_DIR)%s-%s.cf\n", (char*)runtimePlatform, fixedCompilerName);
2001 f.Printf("# VARIABLES\n\n");
2003 f.Printf("OBJ = %s%s\n\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2005 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2007 // test = GetTargetTypeIsSetByPlatform(config);
2009 char target[MAX_LOCATION];
2010 char targetNoSpaces[MAX_LOCATION];
2015 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2017 if(type != targetType)
2022 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2024 GetMakefileTargetFileName(type, target, config);
2025 strcpy(targetNoSpaces, targetDir);
2026 PathCatSlash(targetNoSpaces, target);
2027 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2028 f.Printf("TARGET = %s\n", targetNoSpaces);
2031 f.Printf("else\n"); // ifCount should always be > 0
2033 GetMakefileTargetFileName(targetType, target, config);
2034 strcpy(targetNoSpaces, targetDir);
2035 PathCatSlash(targetNoSpaces, target);
2036 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2037 f.Printf("TARGET = %s\n", targetNoSpaces);
2042 for(c = 0; c < ifCount; c++)
2043 f.Printf("endif\n");
2049 varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2051 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2053 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config);
2055 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
2056 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs, null);
2060 char * map[3][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" } };
2062 topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config);
2063 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2065 f.Printf("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2066 if(eCsourcesParts > 1)
2068 for(c = 1; c <= eCsourcesParts; c++)
2069 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2073 for(c = 0; c < 3; c++)
2075 if(eCsourcesParts > 1)
2078 f.Printf("%s =", map[c][0]);
2079 for(n = 1; n <= eCsourcesParts; n++)
2080 f.Printf(" $(%s%d)", map[c][0], n);
2082 for(n = 1; n <= eCsourcesParts; n++)
2083 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2085 else if(eCsourcesParts == 1)
2086 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2091 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config);
2092 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, "$(ECSOURCES)");
2095 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config);
2096 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2098 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2099 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2100 f.Printf("endif\n\n");
2102 if((config && config.options && config.options.libraries) ||
2103 (options && options.libraries))
2105 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2106 f.Printf("LIBS +=");
2107 if(config && config.options && config.options.libraries)
2108 OutputLibraries(f, config.options.libraries);
2109 else if(options && options.libraries)
2110 OutputLibraries(f, options.libraries);
2112 f.Printf("endif\n");
2115 f.Printf("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
2117 if(platforms || (config && config.platforms))
2120 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2121 //for(platform = win32; platform <= apple; platform++)
2123 f.Printf("# PLATFORM-SPECIFIC OPTIONS\n\n");
2124 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2126 PlatformOptions projectPlatformOptions, configPlatformOptions;
2127 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2129 if(projectPlatformOptions || configPlatformOptions)
2135 f.Printf(PlatformToMakefileVariable(platform));
2138 if((projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions && projectPlatformOptions.options.preprocessorDefinitions.count) ||
2139 (configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions && configPlatformOptions.options.preprocessorDefinitions.count) ||
2140 (projectPlatformOptions && projectPlatformOptions.options.includeDirs && projectPlatformOptions.options.includeDirs.count) ||
2141 (configPlatformOptions && configPlatformOptions.options.includeDirs && configPlatformOptions.options.includeDirs.count))
2143 f.Printf("CFLAGS +=");
2144 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2146 f.Printf(" \\\n\t -Wl");
2147 for(s : projectPlatformOptions.options.linkerOptions)
2150 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2152 f.Printf(" \\\n\t -Wl");
2153 for(s : configPlatformOptions.options.linkerOptions)
2156 if(projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions)
2157 OutputListOption(f, "D", projectPlatformOptions.options.preprocessorDefinitions, newLine, false);
2158 if(configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions)
2159 OutputListOption(f, "D", configPlatformOptions.options.preprocessorDefinitions, newLine, false );
2160 if(configPlatformOptions && configPlatformOptions.options.includeDirs)
2161 OutputListOption(f, "I", configPlatformOptions.options.includeDirs, lineEach, true);
2162 if(projectPlatformOptions && projectPlatformOptions.options.includeDirs)
2163 OutputListOption(f, "I", projectPlatformOptions.options.includeDirs, lineEach, true);
2167 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2168 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2169 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2170 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2172 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2173 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2174 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2176 f.Printf("OFLAGS +=");
2177 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2178 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2179 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2180 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2184 if(projectPlatformOptions && projectPlatformOptions.options.libraries &&
2185 projectPlatformOptions.options.libraries.count)
2187 f.Printf("LIBS +=");
2188 OutputLibraries(f, projectPlatformOptions.options.libraries);
2191 if((configPlatformOptions && configPlatformOptions.options.libraries &&
2192 configPlatformOptions.options.libraries.count))
2194 f.Printf("LIBS +=");
2195 OutputLibraries(f, configPlatformOptions.options.libraries);
2198 f.Printf("endif\n\n");
2204 for(c = 0; c < ifCount; c++)
2205 f.Printf("endif\n");
2210 f.Printf("CFLAGS +=");
2213 f.Printf(" -fmessage-length=0");
2214 switch(GetOptimization(config))
2218 f.Printf(" -ffast-math");
2224 //if(compiler.targetPlatform.is32Bits)
2226 //else if(compiler.targetPlatform.is64Bits)
2227 // f.Printf(" -m64");
2228 f.Printf(" $(FPIC)");
2229 //f.Printf(" -fpack-struct");
2231 switch(GetWarnings(config))
2233 case all: f.Printf(" -Wall"); break;
2234 case none: f.Printf(" -w"); break;
2236 if(GetDebug(config))
2238 if(GetProfile(config))
2240 if(options && options.linkerOptions && options.linkerOptions.count)
2242 f.Printf(" \\\n\t -Wl");
2243 for(s : options.linkerOptions)
2247 if(options && options.preprocessorDefinitions)
2248 OutputListOption(f, "D", options.preprocessorDefinitions, newLine, false);
2249 if(config && config.options && config.options.preprocessorDefinitions)
2250 OutputListOption(f, "D", config.options.preprocessorDefinitions, newLine, false);
2251 if(config && config.options && config.options.includeDirs)
2252 OutputListOption(f, "I", config.options.includeDirs, lineEach, true);
2253 if(options && options.includeDirs)
2254 OutputListOption(f, "I", options.includeDirs, lineEach, true);
2257 f.Printf("CECFLAGS +=%s%s%s%s", defaultPreprocessor ? "" : " -cpp ", defaultPreprocessor ? "" : compiler.cppCommand,
2258 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
2261 f.Printf("ECFLAGS +=");
2262 if(GetMemoryGuard(config))
2263 f.Printf(" -memguard");
2264 if(GetStrictNameSpaces(config))
2265 f.Printf(" -strictns");
2266 if(GetNoLineNumbers(config))
2267 f.Printf(" -nolinenumbers");
2270 if((s = GetDefaultNameSpace(config)) && s[0])
2271 f.Printf(" -defaultns %s", s);
2275 f.Printf("OFLAGS +=\n");
2276 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2277 f.Printf("OFLAGS += -m32");
2278 if(GetProfile(config))
2280 if(config && config.options && config.options.libraryDirs)
2281 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
2282 if(options && options.libraryDirs)
2283 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
2285 f.Printf("endif\n\n");
2287 f.Printf("# TARGETS\n\n");
2289 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
2291 f.Printf("objdir:\n");
2292 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2293 //f.Printf("# PRE-BUILD COMMANDS\n");
2294 if(options && options.prebuildCommands)
2296 for(s : options.prebuildCommands)
2297 if(s && s[0]) f.Printf("\t%s\n", s);
2299 if(config && config.options && config.options.prebuildCommands)
2301 for(s : config.options.prebuildCommands)
2302 if(s && s[0]) f.Printf("\t%s\n", s);
2304 if(platforms || (config && config.platforms))
2307 //f.Printf("# PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2308 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2310 PlatformOptions projectPOs, configPOs;
2311 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2313 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2314 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2320 f.Printf(PlatformToMakefileVariable(platform));
2323 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2325 for(s : projectPOs.options.prebuildCommands)
2326 if(s && s[0]) f.Printf("\t%s\n", s);
2328 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2330 for(s : configPOs.options.prebuildCommands)
2331 if(s && s[0]) f.Printf("\t%s\n", s);
2338 for(c = 0; c < ifCount; c++)
2339 f.Printf("endif\n");
2344 if(!sameObjTargetDirs)
2346 f.Printf("targetdir:\n");
2347 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2352 // Main Module (Linking) for ECERE C modules
2353 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2354 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2355 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2356 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
2357 // Main Module (Linking) for ECERE C modules
2358 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2359 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2360 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2361 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2362 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2367 // This would not rebuild the target on updated objects
2368 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2370 // This should fix it for good!
2371 f.Printf("$(SYMBOLS): | objdir\n");
2372 f.Printf("$(OBJECTS): | objdir\n");
2374 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2375 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2377 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2378 f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET) $(INSTALLNAME)\n");
2379 if(!GetDebug(config))
2381 f.Printf("ifndef NOSTRIP\n");
2382 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2383 f.Printf("endif\n");
2385 if(GetCompress(config))
2387 f.Printf("ifndef WINDOWS\n");
2388 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2389 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2390 f.Printf("endif\n");
2392 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2393 f.Printf("endif\n");
2396 if(resNode.files && resNode.files.count && !noResources)
2397 resNode.GenMakefileAddResources(f, resNode.path, config);
2399 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2400 f.Printf("endif\n");
2402 //f.Printf("# POST-BUILD COMMANDS\n");
2403 if(options && options.postbuildCommands)
2405 for(s : options.postbuildCommands)
2406 if(s && s[0]) f.Printf("\t%s\n", s);
2408 if(config && config.options && config.options.postbuildCommands)
2410 for(s : config.options.postbuildCommands)
2411 if(s && s[0]) f.Printf("\t%s\n", s);
2413 if(platforms || (config && config.platforms))
2416 //f.Printf("# PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2417 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2419 PlatformOptions projectPOs, configPOs;
2420 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2422 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2423 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2429 f.Printf(PlatformToMakefileVariable(platform));
2432 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2434 for(s : projectPOs.options.postbuildCommands)
2435 if(s && s[0]) f.Printf("\t%s\n", s);
2437 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2439 for(s : configPOs.options.postbuildCommands)
2440 if(s && s[0]) f.Printf("\t%s\n", s);
2447 for(c = 0; c < ifCount; c++)
2448 f.Printf("endif\n");
2453 f.Printf("# SYMBOL RULES\n\n");
2455 Map<Platform, bool> excludedPlatforms { };
2456 topNode.GenMakefilePrintSymbolRules(f, this, compiler, config, excludedPlatforms);
2457 delete excludedPlatforms;
2460 f.Printf("# C OBJECT RULES\n\n");
2462 Map<Platform, bool> excludedPlatforms { };
2463 topNode.GenMakefilePrintCObjectRules(f, this, compiler, config, excludedPlatforms);
2464 delete excludedPlatforms;
2467 f.Printf("# OBJECT RULES\n\n");
2468 // todo call this still but only generate rules whith specific options
2469 // see we-have-file-specific-options in ProjectNode.ec
2471 Map<Platform, bool> excludedPlatforms { };
2472 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, compiler, config, excludedPlatforms);
2473 delete excludedPlatforms;
2477 GenMakefilePrintMainObjectRule(f, compiler, config);
2479 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2480 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) " : "");
2481 OutputCleanActions(f, "OBJECTS", objectsParts);
2482 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
2485 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
2486 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
2490 f.Printf("realclean: clean\n");
2491 f.Printf("\t$(call rmrq,$(OBJ))\n");
2492 if(!sameObjTargetDirs)
2493 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2496 f.Printf("include $(E_IDE_CF_DIR)debug.cf\n");
2502 varStringLenDiffs.Free();
2503 delete varStringLenDiffs;
2510 // ChangeWorkingDir(oldDirectory);
2511 // delete pathBackup;
2514 config.makingModified = false;
2518 void GenMakefilePrintMainObjectRule(File f, CompilerConfig compiler, ProjectConfig config)
2520 char extension[MAX_EXTENSION] = "c";
2521 char modulePath[MAX_LOCATION];
2522 char fixedModuleName[MAX_FILENAME];
2525 char objDirNoSpaces[MAX_LOCATION];
2526 DirExpression objDirExp = GetObjDir(compiler, config);
2528 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
2529 ReplaceSpaces(fixedModuleName, moduleName);
2531 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2532 //strcat(fixedModuleName, ".main");
2534 #if 0 // TODO: Fix nospaces stuff
2535 // *** Dependency command ***
2536 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2538 // System Includes (from global settings)
2539 for(item : compiler.dirs[Includes])
2541 strcat(command, " -isystem ");
2542 if(strchr(item.name, ' '))
2544 strcat(command, "\"");
2545 strcat(command, item);
2546 strcat(command, "\"");
2549 strcat(command, item);
2552 for(item = includeDirs.first; item; item = item.next)
2554 strcat(command, " -I");
2555 if(strchr(item.name, ' '))
2557 strcat(command, "\"");
2558 strcat(command, item.name);
2559 strcat(command, "\"");
2562 strcat(command, item.name);
2564 for(item = preprocessorDefs.first; item; item = item.next)
2566 strcat(command, " -D");
2567 strcat(command, item.name);
2571 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2575 bool firstLine = true;
2577 // To do some time: auto save external dependencies?
2580 if(dep.GetLine(line, sizeof(line)-1))
2584 char * colon = strstr(line, ":");
2585 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2599 // If we failed to generate dependencies...
2603 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2609 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2614 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
2615 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
2617 *projectPlatformOptions = null;
2618 *configPlatformOptions = null;
2623 if(!strcmpi(p.name, platform))
2625 *projectPlatformOptions = p;
2630 if(config && config.platforms)
2632 for(p : config.platforms)
2634 if(!strcmpi(p.name, platform))
2636 *configPlatformOptions = p;
2644 Project LegacyBinaryLoadProject(File f, char * filePath)
2646 Project project = null;
2647 char signature[sizeof(epjSignature)];
2649 f.Read(signature, sizeof(signature), 1);
2650 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2652 char topNodePath[MAX_LOCATION];
2653 /*ProjectConfig newConfig
2655 name = CopyString("Default");
2656 makingModified = true;
2657 compilingModified = true;
2658 linkingModified = true;
2662 project = Project { options = { } };
2663 LegacyBinaryLoadNode(project.topNode, f);
2664 delete project.topNode.path;
2665 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2666 MakeSlashPath(topNodePath);
2668 PathCatSlash(topNodePath, filePath);
2669 project.filePath = topNodePath;
2671 /* THIS IS ALREADY DONE BY filePath property
2672 StripLastDirectory(topNodePath, topNodePath);
2673 project.topNode.path = CopyString(topNodePath);
2675 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2677 // newConfig.options.defaultNameSpace = "";
2678 /*newConfig.objDir.dir = "obj";
2679 newConfig.targetDir.dir = "";*/
2681 //project.configurations = { [ newConfig ] };
2682 //project.config = newConfig;
2689 String targetFileName, targetDirectory, objectsDirectory;
2691 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2692 f.Read(&temp, sizeof(int),1);
2695 case 0: project.options.targetType = executable; break;
2696 case 1: project.options.targetType = sharedLibrary; break;
2697 case 2: project.options.targetType = staticLibrary; break;
2700 f.Read(&len, sizeof(int),1);
2701 targetFileName = new char[len+1];
2702 f.Read(targetFileName, sizeof(char), len+1);
2703 project.options.targetFileName = targetFileName;
2704 delete targetFileName;
2706 f.Read(&len, sizeof(int),1);
2707 targetDirectory = new char[len+1];
2708 f.Read(targetDirectory, sizeof(char), len+1);
2709 project.options.targetDirectory = targetDirectory;
2710 delete targetDirectory;
2712 f.Read(&len, sizeof(int),1);
2713 objectsDirectory = new byte[len+1];
2714 f.Read(objectsDirectory, sizeof(char), len+1);
2715 project.options.objectsDirectory = objectsDirectory;
2716 delete objectsDirectory;
2718 f.Read(&temp, sizeof(int),1);
2719 project./*config.*/options.debug = temp ? true : false;
2720 f.Read(&temp, sizeof(int),1);
2721 project./*config.*/options.optimization = temp ? speed : none;
2722 f.Read(&temp, sizeof(int),1);
2723 project./*config.*/options.profile = temp ? true : false;
2724 f.Read(&temp, sizeof(int),1);
2725 project.options.warnings = temp ? all : unset;
2727 f.Read(&count, sizeof(int),1);
2730 project.options.includeDirs = { };
2731 for(c = 0; c < count; c++)
2734 f.Read(&len, sizeof(int),1);
2735 name = new char[len+1];
2736 f.Read(name, sizeof(char), len+1);
2737 project.options.includeDirs.Add(name);
2741 f.Read(&count, sizeof(int),1);
2744 project.options.libraryDirs = { };
2745 for(c = 0; c < count; c++)
2748 f.Read(&len, sizeof(int),1);
2749 name = new char[len+1];
2750 f.Read(name, sizeof(char), len+1);
2751 project.options.libraryDirs.Add(name);
2755 f.Read(&count, sizeof(int),1);
2758 project.options.libraries = { };
2759 for(c = 0; c < count; c++)
2762 f.Read(&len, sizeof(int),1);
2763 name = new char[len+1];
2764 f.Read(name, sizeof(char), len+1);
2765 project.options.libraries.Add(name);
2769 f.Read(&count, sizeof(int),1);
2772 project.options.preprocessorDefinitions = { };
2773 for(c = 0; c < count; c++)
2776 f.Read(&len, sizeof(int),1);
2777 name = new char[len+1];
2778 f.Read(name, sizeof(char), len+1);
2779 project.options.preprocessorDefinitions.Add(name);
2783 f.Read(&temp, sizeof(int),1);
2784 project.options.console = temp ? true : false;
2787 for(node : project.topNode.files)
2789 if(node.type == resources)
2791 project.resNode = node;
2801 void ProjectConfig::LegacyProjectConfigLoad(File f)
2809 char subSection[128];
2815 f.GetLine(buffer, 65536 - 1);
2816 TrimLSpaces(buffer, buffer);
2817 TrimRSpaces(buffer, buffer);
2820 if(buffer[0] == '-')
2824 TrimLSpaces(equal, equal);
2825 if(!strcmpi(subSection, "LibraryDirs"))
2827 if(!options.libraryDirs)
2828 options.libraryDirs = { [ CopyString(equal) ] };
2830 options.libraryDirs.Add(CopyString(equal));
2832 else if(!strcmpi(subSection, "IncludeDirs"))
2834 if(!options.includeDirs)
2835 options.includeDirs = { [ CopyString(equal) ] };
2837 options.includeDirs.Add(CopyString(equal));
2840 else if(buffer[0] == '+')
2851 TrimLSpaces(equal, equal);
2852 delete name; name = CopyString(equal); // property::name = equal;
2855 else if(!strcmpi(buffer, "Compiler Options"))
2856 strcpy(section, buffer);
2857 else if(!strcmpi(buffer, "IncludeDirs"))
2858 strcpy(subSection, buffer);
2859 else if(!strcmpi(buffer, "Linker Options"))
2860 strcpy(section, buffer);
2861 else if(!strcmpi(buffer, "LibraryDirs"))
2862 strcpy(subSection, buffer);
2863 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
2870 equal = strstr(buffer, "=");
2874 TrimRSpaces(buffer, buffer);
2876 TrimLSpaces(equal, equal);
2877 if(!strcmpi(buffer, "Target Name"))
2878 options.targetFileName = /*CopyString(*/equal/*)*/;
2879 else if(!strcmpi(buffer, "Target Type"))
2881 if(!strcmpi(equal, "Executable"))
2882 options.targetType = executable;
2883 else if(!strcmpi(equal, "Shared"))
2884 options.targetType = sharedLibrary;
2885 else if(!strcmpi(equal, "Static"))
2886 options.targetType = staticLibrary;
2888 options.targetType = executable;
2890 else if(!strcmpi(buffer, "Target Directory"))
2891 options.targetDirectory = /*CopyString(*/equal/*)*/;
2892 else if(!strcmpi(buffer, "Console"))
2893 options.console = ParseTrueFalseValue(equal);
2894 else if(!strcmpi(buffer, "Libraries"))
2896 if(!options.libraries) options.libraries = { };
2897 ParseArrayValue(options.libraries, equal);
2899 else if(!strcmpi(buffer, "Intermediate Directory"))
2900 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
2901 else if(!strcmpi(buffer, "Debug"))
2902 options.debug = ParseTrueFalseValue(equal);
2903 else if(!strcmpi(buffer, "Optimize"))
2905 if(!strcmpi(equal, "None"))
2906 options.optimization = none;
2907 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
2908 options.optimization = speed;
2909 else if(!strcmpi(equal, "Size"))
2910 options.optimization = size;
2912 options.optimization = none;
2914 else if(!strcmpi(buffer, "Compress"))
2915 options.compress = ParseTrueFalseValue(equal);
2916 else if(!strcmpi(buffer, "Profile"))
2917 options.profile = ParseTrueFalseValue(equal);
2918 else if(!strcmpi(buffer, "AllWarnings"))
2919 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
2920 else if(!strcmpi(buffer, "MemoryGuard"))
2921 options.memoryGuard = ParseTrueFalseValue(equal);
2922 else if(!strcmpi(buffer, "Default Name Space"))
2923 options.defaultNameSpace = CopyString(equal);
2924 else if(!strcmpi(buffer, "Strict Name Spaces"))
2925 options.strictNameSpaces = ParseTrueFalseValue(equal);
2926 else if(!strcmpi(buffer, "Preprocessor Definitions"))
2928 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
2929 ParseArrayValue(options.preprocessorDefinitions, equal);
2935 if(!options.targetDirectory && options.objectsDirectory)
2936 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
2937 //if(!objDir.dir) objDir.dir = "obj";
2938 //if(!targetDir.dir) targetDir.dir = "";
2939 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
2940 // if(!defaultNameSpace) property::defaultNameSpace = "";
2941 makingModified = true;
2944 Project LegacyAsciiLoadProject(File f, char * filePath)
2946 Project project = null;
2947 ProjectNode node = null;
2949 char parentPath[MAX_LOCATION];
2950 char section[128] = "";
2951 char subSection[128] = "";
2953 bool configurationsPresent = false;
2963 f.GetLine(buffer, 65536 - 1);
2964 TrimLSpaces(buffer, buffer);
2965 TrimRSpaces(buffer, buffer);
2968 if(buffer[0] == '-' || buffer[0] == '=')
2970 bool simple = buffer[0] == '-';
2973 TrimLSpaces(equal, equal);
2974 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
2976 if(!project.config.options.libraryDirs) project.config.options.libraryDirs = { };
2977 project.config.options.libraryDirs.Add(CopyString(equal));
2979 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
2981 if(!project.config.options.includeDirs) project.config.options.includeDirs = { };
2982 project.config.options.includeDirs.Add(CopyString(equal));
2984 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
2986 len = strlen(equal);
2989 char temp[MAX_LOCATION];
2990 ProjectNode child { };
2991 // We don't need to do this anymore, fileName is just a property that sets name & path
2992 // child.fileName = CopyString(equal);
2995 child.name = CopyString(equal);
2996 child.path = CopyString(parentPath);
3000 GetLastDirectory(equal, temp);
3001 child.name = CopyString(temp);
3002 StripLastDirectory(equal, temp);
3003 child.path = CopyString(temp);
3005 child.nodeType = file;
3006 child.parent = parent;
3007 child.indent = parent.indent + 1;
3009 child.icon = NodeIcons::SelectFileIcon(child.name);
3010 parent.files.Add(child);
3016 StripLastDirectory(parentPath, parentPath);
3017 parent = parent.parent;
3021 else if(buffer[0] == '+')
3025 TrimLSpaces(equal, equal);
3026 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3028 char temp[MAX_LOCATION];
3029 ProjectNode child { };
3030 // NEW: Folders now have a path set like files
3031 child.name = CopyString(equal);
3032 strcpy(temp, parentPath);
3033 PathCatSlash(temp, child.name);
3034 child.path = CopyString(temp);
3036 child.parent = parent;
3037 child.indent = parent.indent + 1;
3038 child.type = folder;
3039 child.nodeType = folder;
3041 child.icon = folder;
3042 PathCatSlash(parentPath, child.name);
3043 parent.files.Add(child);
3048 else if(!strcmpi(section, "Configurations"))
3050 ProjectConfig newConfig
3052 makingModified = true;
3056 LegacyProjectConfigLoad(newConfig, f);
3057 project.configurations.Add(newConfig);
3060 else if(!strcmpi(buffer, "ECERE Project File"));
3061 else if(!strcmpi(buffer, "Version 0a"))
3062 ; //strcpy(version, "0a");
3063 else if(!strcmpi(buffer, "Version 0.1a"))
3064 ; //strcpy(version, "0.1a");
3065 else if(!strcmpi(buffer, "Configurations"))
3067 project.configurations.Free();
3068 project.config = null;
3069 strcpy(section, buffer);
3070 configurationsPresent = true;
3072 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3074 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3075 char topNodePath[MAX_LOCATION];
3076 // newConfig.defaultNameSpace = "";
3077 //newConfig.objDir.dir = "obj";
3078 //newConfig.targetDir.dir = "";
3079 project = Project { /*options = { }*/ };
3080 project.configurations = { [ newConfig ] };
3081 project.config = newConfig;
3082 // if(project.topNode.path) delete project.topNode.path;
3083 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3084 MakeSlashPath(topNodePath);
3085 PathCatSlash(topNodePath, filePath);
3086 project.filePath = topNodePath;
3087 parentPath[0] = '\0';
3088 parent = project.topNode;
3090 strcpy(section, "Target");
3095 if(equal[0] == '\"')
3097 StripQuotes(equal, equal);
3098 delete project.moduleName; project.moduleName = CopyString(equal);
3102 else if(!strcmpi(buffer, "Compiler Options"));
3103 else if(!strcmpi(buffer, "IncludeDirs"))
3104 strcpy(subSection, buffer);
3105 else if(!strcmpi(buffer, "Linker Options"));
3106 else if(!strcmpi(buffer, "LibraryDirs"))
3107 strcpy(subSection, buffer);
3108 else if(!strcmpi(buffer, "Files"))
3110 strcpy(section, "Target");
3111 strcpy(subSection, buffer);
3113 else if(!strcmpi(buffer, "Resources"))
3115 ProjectNode child { };
3116 parent.files.Add(child);
3117 child.parent = parent;
3118 child.indent = parent.indent + 1;
3119 child.name = CopyString(buffer);
3120 child.path = CopyString("");
3121 child.type = resources;
3123 child.icon = archiveFile;
3124 project.resNode = child;
3127 strcpy(subSection, buffer);
3131 equal = strstr(buffer, "=");
3135 TrimRSpaces(buffer, buffer);
3137 TrimLSpaces(equal, equal);
3139 if(!strcmpi(section, "Target"))
3141 if(!strcmpi(buffer, "Build Exclusions"))
3143 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3145 /*if(node && node.type != NodeTypes::project)
3146 ParseListValue(node.buildExclusions, equal);*/
3149 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
3151 delete project.resNode.path;
3152 project.resNode.path = CopyString(equal);
3153 PathCatSlash(parentPath, equal);
3157 else if(!strcmpi(buffer, "Intermediate Directory"))
3158 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3159 else if(!strcmpi(buffer, "Debug"))
3160 project.config.options.debug = ParseTrueFalseValue(equal);
3161 else if(!strcmpi(buffer, "Optimize"))
3163 if(!strcmpi(equal, "None"))
3164 project.config.options.optimization = none;
3165 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3166 project.config.options.optimization = speed;
3167 else if(!strcmpi(equal, "Size"))
3168 project.config.options.optimization = size;
3170 project.config.options.optimization = none;
3172 else if(!strcmpi(buffer, "Profile"))
3173 project.config.options.profile = ParseTrueFalseValue(equal);
3174 else if(!strcmpi(buffer, "MemoryGuard"))
3175 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
3178 if(!project.options) project.options = { };
3180 // Project Wide Settings (All configs)
3181 if(!strcmpi(buffer, "Target Name"))
3182 project.options.targetFileName = /*CopyString(*/equal/*)*/;
3183 else if(!strcmpi(buffer, "Target Type"))
3185 if(!strcmpi(equal, "Executable"))
3186 project.options.targetType = executable;
3187 else if(!strcmpi(equal, "Shared"))
3188 project.options.targetType = sharedLibrary;
3189 else if(!strcmpi(equal, "Static"))
3190 project.options.targetType = staticLibrary;
3192 project.options.targetType = executable;
3194 else if(!strcmpi(buffer, "Target Directory"))
3195 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
3196 else if(!strcmpi(buffer, "Console"))
3197 project.options.console = ParseTrueFalseValue(equal);
3198 else if(!strcmpi(buffer, "Libraries"))
3200 if(!project.options.libraries) project.options.libraries = { };
3201 ParseArrayValue(project.options.libraries, equal);
3203 else if(!strcmpi(buffer, "AllWarnings"))
3204 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3205 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3207 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3209 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
3210 ParseListValue(node.preprocessorDefs, equal);*/
3214 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
3215 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3226 SplitPlatformLibraries(project);
3228 if(configurationsPresent)
3229 CombineIdenticalConfigOptions(project);
3233 void SplitPlatformLibraries(Project project)
3235 if(project && project.configurations)
3237 for(cfg : project.configurations)
3239 if(cfg.options.libraries && cfg.options.libraries.count)
3241 Iterator<String> it { cfg.options.libraries };
3245 char * platformName = strstr(l, ":");
3248 PlatformOptions platform = null;
3250 if(!cfg.platforms) cfg.platforms = { };
3251 for(p : cfg.platforms)
3253 if(!strcmpi(platformName, p.name))
3261 platform = { name = CopyString(platformName), options = { libraries = { } } };
3262 cfg.platforms.Add(platform);
3264 *(platformName-1) = 0;
3265 platform.options.libraries.Add(CopyString(l));
3267 cfg.options.libraries.Delete(it.pointer);
3276 void CombineIdenticalConfigOptions(Project project)
3278 if(project && project.configurations && project.configurations.count)
3281 ProjectOptions nullOptions { };
3282 ProjectConfig firstConfig = null;
3283 for(cfg : project.configurations)
3285 if(cfg.options.targetType != staticLibrary)
3292 firstConfig = project.configurations.firstIterator.data;
3294 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3296 if(!member.isProperty)
3298 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3303 for(cfg : project.configurations)
3305 if(cfg != firstConfig)
3307 if(cfg.options.targetType != staticLibrary)
3311 if(type.type == noHeadClass || type.type == normalClass)
3313 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3314 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3315 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3319 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3320 (byte *)firstConfig.options + member.offset + member._class.offset,
3321 (byte *)cfg.options + member.offset + member._class.offset);
3333 if(type.type == noHeadClass || type.type == normalClass)
3335 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3336 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3337 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3342 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3343 (byte *)firstConfig.options + member.offset + member._class.offset,
3344 (byte *)nullOptions + member.offset + member._class.offset))
3348 if(!project.options) project.options = { };
3350 /*if(type.type == noHeadClass || type.type == normalClass)
3352 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3353 (byte *)project.options + member.offset + member._class.offset,
3354 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3358 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3359 // TOFIX: ListBox::SetData / OnCopy mess
3360 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3361 (byte *)project.options + member.offset + member._class.offset,
3362 (type.typeSize > 4) ? address :
3363 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3364 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3365 (void *)*(byte *)address )));
3368 (byte *)project.options + member.offset + member._class.offset,
3369 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3371 for(cfg : project.configurations)
3373 if(cfg.options.targetType == staticLibrary)
3377 if(type.type == noHeadClass || type.type == normalClass)
3379 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3380 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3381 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3385 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3386 (byte *)firstConfig.options + member.offset + member._class.offset,
3387 (byte *)cfg.options + member.offset + member._class.offset);
3392 if(cfg != firstConfig)
3394 if(type.type == noHeadClass || type.type == normalClass)
3396 type._vTbl[__ecereVMethodID_class_OnFree](type,
3397 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3401 type._vTbl[__ecereVMethodID_class_OnFree](type,
3402 (byte *)cfg.options + member.offset + member._class.offset);
3404 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3407 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3414 // Compare Platform Specific Settings
3417 for(cfg : project.configurations)
3419 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3420 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3426 if(same && firstConfig.platforms)
3428 for(cfg : project.configurations)
3430 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3432 if(cfg != firstConfig)
3434 cfg.platforms.Free();
3435 delete cfg.platforms;
3438 project.platforms = firstConfig.platforms;
3439 firstConfig.platforms = null;
3443 // Static libraries can't contain libraries
3444 for(cfg : project.configurations)
3446 if(cfg.options.targetType == staticLibrary)
3448 if(!cfg.options.libraries) cfg.options.libraries = { };
3449 cfg.options.libraries.Free();
3455 Project LoadProject(char * filePath)
3457 Project project = null;
3458 File f = FileOpen(filePath, read);
3461 project = LegacyBinaryLoadProject(f, filePath);
3464 JSONParser parser { f = f };
3465 JSONResult result = parser.GetObject(class(Project), &project);
3468 char insidePath[MAX_LOCATION];
3470 delete project.topNode.files;
3471 if(!project.files) project.files = { };
3472 project.topNode.files = project.files;
3473 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3474 delete project.resNode.path;
3475 project.resNode.path = project.resourcesPath;
3476 project.resourcesPath = null;
3477 project.resNode.nodeType = (ProjectNodeType)-1;
3478 delete project.resNode.files;
3479 project.resNode.files = project.resources;
3480 project.files = null;
3481 project.resources = null;
3482 if(!project.configurations) project.configurations = { };
3485 char topNodePath[MAX_LOCATION];
3486 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3487 MakeSlashPath(topNodePath);
3488 PathCatSlash(topNodePath, filePath);
3489 project.filePath = topNodePath;//filePath;
3492 project.topNode.FixupNode(insidePath);
3497 project = LegacyAsciiLoadProject(f, filePath);
3503 if(!project.options) project.options = { };
3504 if(!project.config && project.configurations)
3505 project.config = project.configurations.firstIterator.data;
3507 if(!project.resNode)
3509 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3512 if(!project.moduleName)
3513 project.moduleName = CopyString(project.name);
3514 if(project.config &&
3515 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3516 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3518 //delete project.config.options.targetFileName;
3520 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
3521 project.config.options.optimization = none;
3522 project.config.options.debug = true;
3523 //project.config.options.warnings = unset;
3524 project.config.options.memoryGuard = false;
3525 project.config.compilingModified = true;
3526 project.config.linkingModified = true;
3528 else if(!project.topNode.name && project.config)
3530 project.topNode.name = CopyString(project.config.options.targetFileName);
3533 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3534 project.topNode.configurations = project.configurations;
3535 project.topNode.platforms = project.platforms;
3536 project.topNode.options = project.options;*/