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]; }
742 property char * compilerConfigsDir
744 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
745 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
746 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
750 // topNode.name holds the file name (.epj)
751 ProjectOptions options;
752 Array<PlatformOptions> platforms;
753 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
756 ProjectConfig config;
758 // This is the file name stripped of the epj extension
759 // It should NOT be edited, saved or loaded anywhere
764 String compilerConfigsDir;
765 #ifndef MAKEFILE_GENERATOR
766 FileMonitor fileMonitor
768 this, FileChange { modified = true };
769 bool OnFileNotify(FileChange action, char * param)
771 fileMonitor.StopMonitoring();
772 if(OnProjectModified(action, param))
773 fileMonitor.StartMonitoring();
778 bool StartMonitoring()
780 fileMonitor.fileName = filePath;
781 fileMonitor.StartMonitoring();
785 bool StopMonitoring()
787 fileMonitor.StopMonitoring();
791 bool OnProjectModified(FileChange fileChange, char * param)
794 sprintf(temp, $"The project %s was modified by another application.\n"
795 "Would you like to reload it and lose your changes?", name);
796 if(MessageBox { type = yesNo, master = ide,
797 text = $"Project has been modified", contents = temp }.Modal() == yes)
799 Project project = LoadProject(filePath);
802 ProjectView projectView = ide.projectView;
803 DataRow prev = topNode.row ? topNode.row.previous : null;
804 FileMonitor fm = fileMonitor;
806 if(projectView) projectView.DeleteNode(topNode);
811 topNode.project = this;
815 projectView.AddNode(topNode, null);
816 topNode.row.Move(prev);
818 eSystem_Delete(project);
827 // This frees contents without freeing the instance
828 // For use from destructor and for file monitor reloading
829 // (To work around JSON loader (LoadProject) always returning a new instance)
832 if(platforms) { platforms.Free(); delete platforms; }
833 if(configurations) { configurations.Free(); delete configurations; }
834 if(files) { files.Free(); delete files; }
835 if(resources) { resources.Free(); delete resources; }
837 delete resourcesPath;
841 delete compilerConfigsDir;
850 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
851 topNode.configurations = null;
852 topNode.platforms = null;
853 topNode.options = null;
858 property ProjectConfig config
864 topNode.info = CopyString(GetConfigName(config));
867 property char * filePath
873 char string[MAX_LOCATION];
874 GetLastDirectory(value, string);
876 topNode.name = CopyString(string);
877 StripExtension(string);
879 name = CopyString(string);
880 StripLastDirectory(value, string);
882 topNode.path = CopyString(string);
884 filePath = CopyString(value);
889 TargetTypes GetTargetType(ProjectConfig config)
891 TargetTypes targetType = localTargetType;
895 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
898 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
900 PlatformOptions projectPOs, configPOs;
901 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
902 if(platformTargetType)
909 char * GetObjDirExpression(CompilerConfig compiler, ProjectConfig config)
911 // TODO: Support platform options
912 char * expression = localObjectsDirectory;
914 expression = settingsObjectsDirectory;
918 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config)
920 char * expression = GetObjDirExpression(compiler, config);
921 DirExpression objDir { type = intermediateObjectsDir };
922 objDir.Evaluate(expression, this, compiler, config);
926 char * GetTargetDirExpression(CompilerConfig compiler, ProjectConfig config)
928 // TODO: Support platform options
929 char * expression = localTargetDirectory;
931 expression = settingsTargetDirectory;
935 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config)
937 char * expression = GetTargetDirExpression(compiler, config);
938 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
939 targetDir.Evaluate(expression, this, compiler, config);
943 WarningsOption GetWarnings(ProjectConfig config)
945 WarningsOption warnings = localWarnings;
949 bool GetDebug(ProjectConfig config)
951 SetBool debug = localDebug;
952 return debug == true;
955 bool GetMemoryGuard(ProjectConfig config)
957 SetBool memoryGuard = localMemoryGuard;
958 return memoryGuard == true;
961 bool GetNoLineNumbers(ProjectConfig config)
963 SetBool noLineNumbers = localNoLineNumbers;
964 return noLineNumbers == true;
967 bool GetProfile(ProjectConfig config)
969 SetBool profile = localProfile;
970 return profile == true;
973 OptimizationStrategy GetOptimization(ProjectConfig config)
975 OptimizationStrategy optimization = localOptimization;
979 String GetDefaultNameSpace(ProjectConfig config)
981 String defaultNameSpace = localDefaultNameSpace;
982 return defaultNameSpace;
985 bool GetStrictNameSpaces(ProjectConfig config)
987 SetBool strictNameSpaces = localStrictNameSpaces;
988 return strictNameSpaces == true;
991 String GetTargetFileName(ProjectConfig config)
993 String targetFileName = localTargetFileName;
994 return targetFileName;
997 //String targetDirectory;
998 //String objectsDirectory;
999 bool GetConsole(ProjectConfig config)
1001 SetBool console = localConsole;
1002 return console == true;
1005 bool GetCompress(ProjectConfig config)
1007 SetBool compress = localCompress;
1008 return compress == true;
1010 //SetBool excludeFromBuild;
1012 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1014 #ifndef MAKEFILE_GENERATOR
1015 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1019 bool GetConfigIsInDebugSession(ProjectConfig config)
1021 #ifndef MAKEFILE_GENERATOR
1022 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1026 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config)
1028 #ifndef MAKEFILE_GENERATOR
1029 ide.SetPath(projectsDirs, compiler, config);
1033 #ifndef MAKEFILE_GENERATOR
1034 bool Save(char * fileName)
1037 /*char output[MAX_LOCATION];
1038 ChangeExtension(fileName, "json", output);
1039 f = FileOpen(output, write);*/
1040 f = FileOpen(fileName, write);
1043 files = topNode.files;
1044 resources = resNode.files;
1045 resourcesPath = resNode.path;
1047 files.Remove(resNode);
1050 WriteJSONObject(f, class(Project), this, 0);
1056 resourcesPath = null;
1063 // This method is only called from Debugger, should be moved to Debugger class?
1064 #ifndef MAKEFILE_GENERATOR
1065 bool GetRelativePath(char * filePath, char * relativePath)
1068 char moduleName[MAX_FILENAME];
1069 GetLastDirectory(filePath, moduleName);
1070 // try with workspace dir first?
1071 if((node = topNode.Find(moduleName, false)))
1073 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1074 PathCatSlash(relativePath, node.name);
1079 // Tweak for automatically resolving symbol loader modules
1080 char * sl = strstr(moduleName, ".main.ec");
1081 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1083 char objDir[MAX_LOCATION];
1084 DirExpression objDirExp;
1085 CompilerConfig compiler = ide.debugger.currentCompiler;
1086 ProjectConfig config = ide.debugger.prjConfig;
1087 // This is not perfect, as multiple source files exist for the symbol loader module...
1088 // We try to set it in the debug config object directory.
1089 if(!compiler || !config)
1091 // If we're not currently debugging, set a breakpoint in the active compiler/config
1092 compiler = GetCompilerConfig();
1093 config = this.config;
1094 // If the current config is not debuggable, set it in the first debuggable config found
1095 if(config && !config.options.debug)
1097 for(c : configurations; c.options.debug)
1104 objDirExp = GetObjDir(compiler, config);
1105 strcpy(objDir, objDirExp.dir);
1107 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1108 ReplaceSpaces(objDir, objDir);
1109 strcpy(relativePath, objDir);
1111 PathCatSlash(relativePath, moduleName);
1115 // WARNING: On failure, relative path is uninitialized
1120 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1122 TargetTypes targetType = GetTargetType(config);
1123 String targetFileName = GetTargetFileName(config);
1124 if(targetType == staticLibrary)
1126 PathCatSlash(string, "lib");
1127 strcat(string, targetFileName);
1129 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1131 PathCatSlash(string, "lib");
1132 strcat(string, targetFileName);
1135 PathCatSlash(string, targetFileName);
1140 if(compiler.targetPlatform == win32)
1141 strcat(string, ".exe");
1144 if(compiler.targetPlatform == win32)
1145 strcat(string, ".dll");
1146 else if(compiler.targetPlatform == apple)
1147 strcat(string, ".dylib");
1149 strcat(string, ".so");
1152 strcat(string, ".a");
1157 bool GetProjectCompilerConfigsDir(char * cfDir)
1159 bool result = false;
1160 strcpy(cfDir, topNode.path);
1161 if(compilerConfigsDir && compilerConfigsDir[0])
1163 PathCatSlash(cfDir, compilerConfigsDir);
1166 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1171 bool GetIDECompilerConfigsDir(char * cfDir)
1173 bool result = false;
1174 strcpy(cfDir, topNode.path);
1175 if(ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1177 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1180 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1185 void CatMakeFileName(char * string, ProjectConfig config)
1187 char projectName[MAX_LOCATION];
1188 strcpy(projectName, name);
1189 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1192 #ifndef MAKEFILE_GENERATOR
1193 void MarkChanges(ProjectNode node)
1195 for(cfg : topNode.configurations)
1197 ProjectConfig c = null;
1198 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1200 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1201 (!c.options || !cfg.options)))
1202 cfg.symbolGenModified = true;
1204 cfg.makingModified = true;
1208 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1210 for(cfg : configurations)
1213 cfg.makingModified = true;
1215 cfg.compilingModified = true;
1217 cfg.linkingModified = true;
1219 cfg.symbolGenModified = true;
1221 if(compiling || linking)
1223 ide.projectView.modifiedDocument = true;
1224 ide.workspace.modified = true;
1228 void RotateActiveConfig(bool forward)
1230 if(configurations.first && configurations.last != configurations.first)
1232 Iterator<ProjectConfig> cfg { configurations };
1233 while(forward ? cfg.Next() : cfg.Prev())
1234 if(cfg.data == config)
1248 property::config = cfg.data;
1249 ide.workspace.modified = true;
1250 ide.projectView.Update(null);
1254 void ProcessPipeOutputRaw(DualPipe f)
1257 while(!f.Eof() && !ide.ShouldStopBuild())
1260 double lastTime = GetTime();
1264 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1266 ide.outputView.buildBox.Logf("%s\n", line);
1268 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1270 //printf("Processing Input...\n");
1271 if(app.ProcessInput(true))
1273 app.UpdateDisplay();
1276 //printf("Waiting...\n");
1279 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1281 if(ide.ShouldStopBuild())
1283 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1288 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode,
1289 CompilerConfig compiler, ProjectConfig config)
1292 bool compiling = false, linking = false, precompiling = false;
1293 int compilingEC = 0;
1294 int numErrors = 0, numWarnings = 0;
1295 bool loggedALine = false;
1296 char * configName = config.name;
1297 int lenMakeCommand = strlen(compiler.makeCommand);
1299 char cppCommand[MAX_LOCATION];
1300 char ccCommand[MAX_LOCATION];
1301 char cxxCommand[MAX_LOCATION];
1302 char ecpCommand[MAX_LOCATION];
1303 char eccCommand[MAX_LOCATION];
1304 char ecsCommand[MAX_LOCATION];
1305 char earCommand[MAX_LOCATION];
1307 char * cc = compiler.ccCommand;
1308 char * cxx = compiler.cxxCommand;
1309 char * cpp = compiler.cppCommand;
1310 sprintf(cppCommand, "%s%s%s%s ",
1311 compiler.ccacheEnabled ? "ccache " : "",
1312 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1313 compiler.distccEnabled ? "distcc " : "",
1314 compiler.cppCommand);
1315 sprintf(ccCommand, "%s%s%s%s ",
1316 compiler.ccacheEnabled ? "ccache " : "",
1317 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1318 compiler.distccEnabled ? "distcc " : "",
1319 compiler.ccCommand);
1320 sprintf(cxxCommand, "%s%s%s%s ",
1321 compiler.ccacheEnabled ? "ccache " : "",
1322 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1323 compiler.distccEnabled ? "distcc " : "",
1324 compiler.cxxCommand);
1325 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1326 sprintf(eccCommand, "%s ", compiler.eccCommand);
1327 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1328 sprintf(earCommand, "%s ", compiler.earCommand);
1330 while(!f.Eof() && !ide.ShouldStopBuild())
1333 double lastTime = GetTime();
1337 //printf("Peeking and GetLine...\n");
1338 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1340 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1341 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1343 char * module = strstr(line, "No rule to make target `");
1347 module = strchr(module, '`') + 1;
1348 end = strchr(module, '\'');
1352 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1353 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1359 //ide.outputView.buildBox.Logf("error: %s\n", line);
1363 else if(strstr(line, "ear ") == line);
1364 else if(strstr(line, "strip ") == line);
1365 else if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1367 char moduleName[MAX_FILENAME];
1370 bool isPrecomp = false;
1372 if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line)
1374 module = strstr(line, " -c ");
1375 if(module) module += 4;
1377 else if(strstr(line, eccCommand) == line)
1379 module = strstr(line, " -c ");
1380 if(module) module += 4;
1381 //module = line + 3;
1382 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1383 compilingEC = 3;//2;
1385 else if(strstr(line, ecpCommand) == line)
1387 // module = line + 8;
1388 module = strstr(line, " -c ");
1389 if(module) module += 4;
1398 if(!compiling && !isPrecomp)
1400 ide.outputView.buildBox.Logf($"Compiling...\n");
1403 else if(!precompiling && isPrecomp)
1405 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1406 precompiling = true;
1408 // Changed escapeBackSlashes here to handle paths with spaces
1409 Tokenize(module, 1, tokens, true); // false);
1410 GetLastDirectory(module, moduleName);
1411 ide.outputView.buildBox.Logf("%s\n", moduleName);
1413 else if((module = strstr(line, " -o ")))
1416 precompiling = false;
1418 ide.outputView.buildBox.Logf($"Linking...\n");
1422 ide.outputView.buildBox.Logf("%s\n", line);
1426 if(compilingEC) compilingEC--;
1428 else if(strstr(line, "ar rcs") == line)
1429 ide.outputView.buildBox.Logf($"Building library...\n");
1430 else if(strstr(line, ecsCommand) == line)
1431 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1434 if(linking || compiling || precompiling)
1436 char * colon = strstr(line, ":"); //, * bracket;
1437 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1438 colon = strstr(colon + 1, ":");
1441 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1444 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1445 int len = (int)(colon - start);
1446 len = Min(len, MAX_LOCATION-1);
1447 // Don't be mistaken by the drive letter colon
1449 // TODO: need to fix colon - line gives char *
1450 // warning: incompatible expression colon - line (char *); expected int
1452 strncpy(moduleName, line, (int)(colon - line));
1453 moduleName[colon - line] = '\0';
1455 strncpy(moduleName, start, len);
1456 moduleName[len] = '\0';
1457 // Remove stuff in brackets
1458 //bracket = strstr(moduleName, "(");
1459 //if(bracket) *bracket = '\0';
1461 GetLastDirectory(moduleName, temp);
1462 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1465 strcpy(moduleName, $"Linker Error");
1469 strcpy(temp, topNode.path);
1470 PathCatSlash(temp, moduleName);
1471 MakePathRelative(temp, topNode.path, moduleName);
1473 if(strstr(line, "error:"))
1477 // Silence warnings for compiled EC
1478 char * objDir = strstr(moduleName, objDirExp.dir);
1482 if((pointer = strstr(line, "undefined")) ||
1483 (pointer = strstr(line, "No such file")) ||
1484 (pointer = strstr(line, "token")))
1486 strncat(moduleName, colon, pointer - colon);
1487 strcat(moduleName, "error: ");
1492 else if((pointer = strstr(line, "No such file")))
1494 strncat(moduleName, colon, pointer - colon);
1495 strcat(moduleName, "error: ");
1499 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1501 else if(strstr(line, "warning:"))
1506 if(this == ide.workspace.projects.firstIterator.data)
1507 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1510 char fullModuleName[MAX_LOCATION];
1511 strcpy(fullModuleName, topNode.path);
1512 PathCat(fullModuleName, moduleName);
1513 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1514 MakeSystemPath(fullModuleName);
1515 ide.outputView.buildBox.Logf(" %s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : "", fullModuleName, colon);
1520 ide.outputView.buildBox.Logf("%s\n", line);
1521 linking = compiling = precompiling = false;
1525 ide.outputView.buildBox.Logf("%s\n", line);
1529 //printf("Done getting line\n");
1530 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1532 //printf("Processing Input...\n");
1533 if(app.ProcessInput(true))
1535 app.UpdateDisplay();
1538 //printf("Waiting...\n");
1541 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1543 if(ide.ShouldStopBuild())
1545 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1548 else if(loggedALine || !isARun)
1550 if(f.GetExitCode() && !numErrors)
1552 bool result = f.GetLine(line, sizeof(line)-1);
1553 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1558 ide.outputView.buildBox.Logf("\n%s (%s) - ", GetTargetFileName(config), configName);
1560 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1562 ide.outputView.buildBox.Logf($"no error, ");
1565 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1567 ide.outputView.buildBox.Logf($"no warning\n");
1570 return numErrors == 0;
1573 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1576 int lenMakeCommand = strlen(compiler.makeCommand);
1581 double lastTime = GetTime();
1584 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1586 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1587 else if(strstr(line, "del") == line);
1588 else if(strstr(line, "rm") == line);
1589 else if(strstr(line, "Could Not Find") == line);
1592 ide.outputView.buildBox.Logf(line);
1593 ide.outputView.buildBox.Logf("\n");
1597 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1599 if(app.ProcessInput(true))
1601 app.UpdateDisplay();
1604 //Sleep(1.0 / PEEK_RESOLUTION);
1608 bool Build(bool isARun, ProjectNode onlyNode, CompilerConfig compiler, ProjectConfig config)
1610 bool result = false;
1612 char targetFileName[MAX_LOCATION] = "";
1613 char makeTarget[MAX_LOCATION] = "";
1614 char makeFile[MAX_LOCATION];
1615 char makeFilePath[MAX_LOCATION];
1616 char configName[MAX_LOCATION];
1617 DirExpression objDirExp = GetObjDir(compiler, config);
1618 PathBackup pathBackup { };
1620 int numJobs = compiler.numJobs;
1621 char command[MAX_LOCATION];
1622 char * compilerName;
1624 compilerName = CopyString(compiler.name);
1625 CamelCase(compilerName);
1627 strcpy(configName, config ? config.name : "Common");
1629 SetPath(false, compiler, config); //true
1630 CatTargetFileName(targetFileName, compiler, config);
1632 strcpy(makeFilePath, topNode.path);
1633 CatMakeFileName(makeFile, config);
1634 PathCatSlash(makeFilePath, makeFile);
1636 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1639 if(compiler.type.isVC)
1641 PrintLn("compiling a single file is not yet supported");
1646 char pushD[MAX_LOCATION];
1647 char cfDir[MAX_LOCATION];
1648 GetIDECompilerConfigsDir(cfDir);
1649 GetWorkingDir(pushD, sizeof(pushD));
1650 ChangeWorkingDir(topNode.path);
1651 // Create object dir if it does not exist already
1652 if(!FileExists(objDirExp.dir).isDirectory)
1653 Execute("%s CF_DIR=%s COMPILER=%s objdir -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, topNode.path, makeFilePath);
1654 ChangeWorkingDir(pushD);
1656 PathCatSlash(makeTarget+1, objDirExp.dir);
1657 PathCatSlash(makeTarget+1, onlyNode.name);
1658 StripExtension(makeTarget+1);
1659 strcat(makeTarget+1, ".o");
1660 makeTarget[0] = '\"';
1661 len = strlen(makeTarget);
1662 makeTarget[len++] = '\"';
1663 makeTarget[len++] = '\0';
1667 if(compiler.type.isVC)
1669 bool result = false;
1670 char oldwd[MAX_LOCATION];
1671 GetWorkingDir(oldwd, sizeof(oldwd));
1672 ChangeWorkingDir(topNode.path);
1674 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1675 ide.outputView.buildBox.Logf("command: %s\n", command);
1676 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1678 ProcessPipeOutputRaw(f);
1682 ChangeWorkingDir(oldwd);
1686 char cfDir[MAX_LOCATION];
1687 GetIDECompilerConfigsDir(cfDir);
1688 sprintf(command, "%s CF_DIR=%s COMPILER=%s -j%d %s%s%s -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, numJobs,
1689 compiler.ccacheEnabled ? "CCACHE=y " : "",
1690 compiler.distccEnabled ? "DISTCC=y " : "",
1691 makeTarget, topNode.path, makeFilePath);
1692 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1694 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode, compiler, config);
1698 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
1703 delete compilerName;
1707 void Clean(CompilerConfig compiler, ProjectConfig config, bool realclean)
1709 char makeFile[MAX_LOCATION];
1710 char makeFilePath[MAX_LOCATION];
1711 char command[MAX_LOCATION];
1712 char * compilerName;
1714 PathBackup pathBackup { };
1716 compilerName = CopyString(compiler.name);
1717 CamelCase(compilerName);
1719 SetPath(false, compiler, config);
1721 strcpy(makeFilePath, topNode.path);
1722 CatMakeFileName(makeFile, config);
1723 PathCatSlash(makeFilePath, makeFile);
1725 if(compiler.type.isVC)
1727 bool result = false;
1728 char oldwd[MAX_LOCATION];
1729 GetWorkingDir(oldwd, sizeof(oldwd));
1730 ChangeWorkingDir(topNode.path);
1732 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1733 ide.outputView.buildBox.Logf("command: %s\n", command);
1734 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1736 ProcessPipeOutputRaw(f);
1740 ChangeWorkingDir(oldwd);
1745 char cfDir[MAX_LOCATION];
1746 GetIDECompilerConfigsDir(cfDir);
1747 sprintf(command, "%s CF_DIR=%s COMPILER=%s %sclean -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, realclean ? "real" : "", topNode.path, makeFilePath);
1748 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1750 ide.outputView.buildBox.Tell($"Deleting target and object files...");
1751 ProcessCleanPipeOutput(f, compiler, config);
1754 ide.outputView.buildBox.Logf($"Target and object files deleted\n");
1759 delete compilerName;
1762 void Run(char * args, CompilerConfig compiler, ProjectConfig config)
1764 String target = new char[maxPathLen];
1765 char oldDirectory[MAX_LOCATION];
1766 DirExpression targetDirExp = GetTargetDir(compiler, config);
1767 PathBackup pathBackup { };
1769 // Build(project, ideMain, true, null);
1771 #if defined(__WIN32__)
1772 strcpy(target, topNode.path);
1776 PathCatSlash(target, targetDirExp.dir);
1777 CatTargetFileName(target, compiler, config);
1778 sprintf(target, "%s %s", target, args);
1779 GetWorkingDir(oldDirectory, MAX_LOCATION);
1781 if(strlen(ide.workspace.debugDir))
1783 char temp[MAX_LOCATION];
1784 strcpy(temp, topNode.path);
1785 PathCatSlash(temp, ide.workspace.debugDir);
1786 ChangeWorkingDir(temp);
1789 ChangeWorkingDir(topNode.path);
1790 // ChangeWorkingDir(topNode.path);
1791 SetPath(true, compiler, config);
1792 if(compiler.execPrefixCommand)
1794 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1795 prefixedTarget[0] = '\0';
1796 strcat(prefixedTarget, compiler.execPrefixCommand);
1797 strcat(prefixedTarget, " ");
1798 strcat(prefixedTarget, target);
1799 Execute(prefixedTarget);
1800 delete prefixedTarget;
1805 ChangeWorkingDir(oldDirectory);
1808 delete targetDirExp;
1812 void Compile(ProjectNode node, CompilerConfig compiler, ProjectConfig config)
1814 Build(false, node, compiler, config);
1818 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
1821 if(targetType == staticLibrary || targetType == sharedLibrary)
1822 strcat(fileName, "$(LP)");
1823 // !!! ReplaceSpaces must be done after all PathCat calls !!!
1824 // ReplaceSpaces(s, GetTargetFileName(config));
1825 strcat(fileName, GetTargetFileName(config));
1829 strcat(fileName, "$(E)");
1832 strcat(fileName, "$(SO)");
1835 strcat(fileName, "$(A)");
1840 bool GenerateCrossPlatformCf()
1842 bool result = false;
1843 char path[MAX_LOCATION];
1845 if(!GetProjectCompilerConfigsDir(path))
1846 GetIDECompilerConfigsDir(path);
1848 if(!FileExists(path).isDirectory)
1850 PathCatSlash(path, "crossplatform.mk");
1852 if(FileExists(path))
1855 File include = FileOpen(":crossplatform.mk", read);
1858 File f = FileOpen(path, write);
1861 for(; !include.Eof(); )
1864 int count = include.Read(buffer, 1, 4096);
1865 f.Write(buffer, 1, count);
1877 bool GenerateCompilerMk(CompilerConfig compiler)
1879 bool result = false;
1880 char path[MAX_LOCATION];
1882 char * compilerName;
1883 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
1884 Platform platform = GetRuntimePlatform();
1886 compilerName = CopyString(compiler.name);
1887 CamelCase(compilerName);
1888 name = PrintString(platform, "-", compilerName, ".cf");
1890 if(!GetProjectCompilerConfigsDir(path))
1891 GetIDECompilerConfigsDir(path);
1893 if(!FileExists(path).isDirectory)
1895 PathCatSlash(path, name);
1897 if(FileExists(path))
1900 File f = FileOpen(path, write);
1903 bool crossCompiling = compiler.targetPlatform != platform;
1905 f.Printf("# TOOLCHAIN\n\n");
1907 //f.Printf("SHELL := %s\n", "ar"/*compiler.arCommand*/); // is this really needed?
1908 f.Printf("CPP := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.cppCommand);
1909 f.Printf("CC := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.ccCommand);
1910 f.Printf("CXX := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.cxxCommand);
1911 f.Printf("ECP := %s\n", compiler.ecpCommand);
1912 f.Printf("ECC := %s\n", compiler.eccCommand);
1913 f.Printf("ECS := %s%s%s\n", compiler.ecsCommand,
1914 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1915 f.Printf("EAR := %s\n", compiler.earCommand);
1917 f.Printf("AS := as\n");
1918 f.Printf("LD := ld\n");
1919 f.Printf("AR := ar\n");
1920 f.Printf("STRIP := strip\n");
1921 f.Printf("UPX := upx\n");
1925 f.Printf("UPXFLAGS = -9\n\n"); // TOFEAT: Compression Level Option? Other UPX Options?
1927 f.Printf("# HARD CODED PLATFORM-SPECIFIC OPTIONS\n");
1928 f.Printf("ifdef %s\n", PlatformToMakefileVariable(tux));
1929 f.Printf("OFLAGS += -Wl,--no-undefined\n");
1930 f.Printf("endif\n\n");
1933 f.Printf("ifdef %s\n", PlatformToMakefileVariable(apple));
1934 f.Printf("OFLAGS += -framework cocoa -framework OpenGL\n");
1935 f.Printf("endif\n\n");
1938 f.Printf("PLATFORM = %s\n", (char *)compiler.targetPlatform);
1940 if((compiler.includeDirs && compiler.includeDirs.count) ||
1941 (compiler.libraryDirs && compiler.libraryDirs.count))
1943 if(compiler.includeDirs && compiler.includeDirs.count)
1945 f.Printf("CFLAGS +=");
1946 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
1949 if(compiler.libraryDirs && compiler.libraryDirs.count)
1951 f.Printf("OFLAGS +=");
1952 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
1962 delete compilerName;
1966 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath,
1967 CompilerConfig compiler, ProjectConfig config)
1969 bool result = false;
1970 char filePath[MAX_LOCATION];
1971 char makeFile[MAX_LOCATION];
1972 // PathBackup pathBackup { };
1973 // char oldDirectory[MAX_LOCATION];
1976 if(!altMakefilePath)
1978 strcpy(filePath, topNode.path);
1979 CatMakeFileName(makeFile, config);
1980 PathCatSlash(filePath, makeFile);
1983 #if defined(__WIN32__) && !defined(MAKEFILE_GENERATOR)
1984 if(compiler.type.isVC)
1986 GenerateVSSolutionFile(this, compiler);
1987 GenerateVCProjectFile(this, compiler);
1991 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
1993 /*SetPath(false, compiler, config);
1994 GetWorkingDir(oldDirectory, MAX_LOCATION);
1995 ChangeWorkingDir(topNode.path);*/
2002 Platform runtimePlatform = GetRuntimePlatform();
2003 char targetDir[MAX_LOCATION];
2004 char objDirExpNoSpaces[MAX_LOCATION];
2005 char objDirNoSpaces[MAX_LOCATION];
2006 char resDirNoSpaces[MAX_LOCATION];
2007 char targetDirExpNoSpaces[MAX_LOCATION];
2008 char fixedModuleName[MAX_FILENAME];
2009 char fixedConfigName[MAX_FILENAME];
2010 char fixedCompilerName[MAX_FILENAME];
2012 // Non-zero if we're building eC code
2013 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2014 int numCObjects = 0;
2015 bool containsCXX = false; // True if the project contains a C++ file
2016 bool sameObjTargetDirs;
2017 DirExpression objDirExp = GetObjDir(compiler, config);
2018 TargetTypes targetType = GetTargetType(config);
2020 bool crossCompiling = compiler.targetPlatform != runtimePlatform;
2021 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2022 bool tccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "tcc") != null;
2023 bool defaultPreprocessor = compiler.cppCommand && (strstr(compiler.cppCommand, "gcc") != null || compiler.cppCommand && strstr(compiler.cppCommand, "cpp") != null);
2024 char cfDir[MAX_LOCATION];
2025 int objectsParts, eCsourcesParts;
2026 Array<String> listItems { };
2027 Map<String, int> varStringLenDiffs { };
2028 Map<String, NameCollisionInfo> namesInfo { };
2029 bool forceBitDepth = false;
2031 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
2032 strcpy(targetDir, GetTargetDirExpression(compiler, config));
2033 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2035 strcpy(objDirExpNoSpaces, GetObjDirExpression(compiler, config));
2036 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2037 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
2038 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2039 //ReplaceSpaces(fixedPrjName, name);
2040 ReplaceSpaces(fixedModuleName, moduleName);
2041 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2042 ReplaceSpaces(fixedCompilerName, compiler.name);
2043 //CamelCase(fixedModuleName); // case is important for static linking
2044 CamelCase(fixedConfigName);
2045 CamelCase(fixedCompilerName);
2047 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2049 f.Printf(".PHONY: all objdir%s clean realclean\n\n", sameObjTargetDirs ? "" : " targetdir");
2051 f.Printf("# CONTENT\n\n");
2053 f.Printf("MODULE := %s\n", fixedModuleName);
2054 //f.Printf("VERSION = %s\n", version);
2055 f.Printf("CONFIG := %s\n", fixedConfigName);
2056 f.Printf("ifndef COMPILER\n");
2057 f.Printf("COMPILER := default\n");
2058 f.Printf("endif\n");
2061 if(compilerConfigsDir && compilerConfigsDir[0])
2063 strcpy(cfDir, compilerConfigsDir);
2064 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2068 strcpy(cfDir, "$(CF_DIR)");
2070 f.Printf("_CF_DIR = %s\n", cfDir);
2073 f.Printf("ifndef DEBUG\n");
2074 f.Printf("OPTIMIZE :=");
2075 switch(GetOptimization(config))
2079 f.Printf(" -ffast-math");
2085 if(GetDebug(config))
2089 f.Printf("OPTIMIZE := -g\n");
2090 f.Printf("NOSTRIP := y\n");
2091 f.Printf("endif\n");
2093 test = GetTargetTypeIsSetByPlatform(config);
2097 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2099 TargetTypes targetType;
2100 PlatformOptions projectPOs, configPOs;
2101 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2102 targetType = platformTargetType;
2108 f.Printf("ifdef %s\n", PlatformToMakefileVariable(platform));
2110 f.Printf("TARGET_TYPE = ");
2111 f.Printf(TargetTypeToMakefileVariable(targetType));
2115 f.Printf("else\n"); // ifCount should always be > 0
2117 f.Printf("TARGET_TYPE = ");
2118 f.Printf(TargetTypeToMakefileVariable(targetType));
2124 for(c = 0; c < ifCount; c++)
2125 f.Printf("endif\n");
2130 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2131 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2132 f.Printf("endif\n\n");
2134 f.Printf("# FLAGS\n\n");
2136 f.Printf("CFLAGS =\n");
2137 f.Printf("CECFLAGS =\n");
2138 f.Printf("ECFLAGS =\n");
2139 f.Printf("OFLAGS =\n");
2140 f.Printf("LIBS =\n");
2143 f.Printf("# INCLUDES\n\n");
2145 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2146 f.Printf("include $(_CF_DIR)$(PLATFORM)-$(COMPILER).cf\n", (char*)runtimePlatform, fixedCompilerName);
2149 f.Printf("# VARIABLES\n\n");
2151 f.Printf("OBJ = %s%s\n\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2153 f.Printf("ifdef DEBUG\n");
2154 f.Printf("CFLAGS += -D_DEBUG\n");
2155 f.Printf("endif\n\n");
2157 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2159 // test = GetTargetTypeIsSetByPlatform(config);
2161 char target[MAX_LOCATION];
2162 char targetNoSpaces[MAX_LOCATION];
2167 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2169 if(type != targetType)
2174 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2176 GetMakefileTargetFileName(type, target, config);
2177 strcpy(targetNoSpaces, targetDir);
2178 PathCatSlash(targetNoSpaces, target);
2179 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2180 f.Printf("TARGET = %s\n", targetNoSpaces);
2183 f.Printf("else\n"); // ifCount should always be > 0
2185 GetMakefileTargetFileName(targetType, target, config);
2186 strcpy(targetNoSpaces, targetDir);
2187 PathCatSlash(targetNoSpaces, target);
2188 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2189 f.Printf("TARGET = %s\n", targetNoSpaces);
2195 for(c = 0; c < ifCount; c++)
2196 f.Printf("endif\n");
2202 varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2204 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2206 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2208 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
2209 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs, null);
2213 char * map[4][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "BOWLS", "B" } };
2215 topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2216 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2218 f.Printf("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2219 if(eCsourcesParts > 1)
2221 for(c = 1; c <= eCsourcesParts; c++)
2222 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2226 for(c = 0; c < 3; c++)
2228 if(eCsourcesParts > 1)
2231 f.Printf("%s =", map[c][0]);
2232 for(n = 1; n <= eCsourcesParts; n++)
2233 f.Printf(" $(%s%d)", map[c][0], n);
2235 for(n = 1; n <= eCsourcesParts; n++)
2236 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2238 else if(eCsourcesParts == 1)
2239 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2244 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2245 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, "$(ECSOURCES)");
2248 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2249 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2251 f.Printf("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
2252 if((config && config.options && config.options.libraries) ||
2253 (options && options.libraries))
2255 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2256 f.Printf("LIBS +=");
2257 if(config && config.options && config.options.libraries)
2258 OutputLibraries(f, config.options.libraries);
2259 else if(options && options.libraries)
2260 OutputLibraries(f, options.libraries);
2262 f.Printf("endif\n");
2266 if(platforms || (config && config.platforms))
2269 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2270 //for(platform = win32; platform <= apple; platform++)
2272 f.Printf("# PLATFORM-SPECIFIC OPTIONS\n\n");
2273 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2275 PlatformOptions projectPlatformOptions, configPlatformOptions;
2276 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2278 if(projectPlatformOptions || configPlatformOptions)
2284 f.Printf(PlatformToMakefileVariable(platform));
2287 if((projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions && projectPlatformOptions.options.preprocessorDefinitions.count) ||
2288 (configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions && configPlatformOptions.options.preprocessorDefinitions.count) ||
2289 (projectPlatformOptions && projectPlatformOptions.options.includeDirs && projectPlatformOptions.options.includeDirs.count) ||
2290 (configPlatformOptions && configPlatformOptions.options.includeDirs && configPlatformOptions.options.includeDirs.count))
2292 f.Printf("CFLAGS +=");
2293 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2295 f.Printf(" \\\n\t -Wl");
2296 for(s : projectPlatformOptions.options.linkerOptions)
2299 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2301 f.Printf(" \\\n\t -Wl");
2302 for(s : configPlatformOptions.options.linkerOptions)
2305 if(projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions)
2306 OutputListOption(f, "D", projectPlatformOptions.options.preprocessorDefinitions, newLine, false);
2307 if(configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions)
2308 OutputListOption(f, "D", configPlatformOptions.options.preprocessorDefinitions, newLine, false );
2309 if(configPlatformOptions && configPlatformOptions.options.includeDirs)
2310 OutputListOption(f, "I", configPlatformOptions.options.includeDirs, lineEach, true);
2311 if(projectPlatformOptions && projectPlatformOptions.options.includeDirs)
2312 OutputListOption(f, "I", projectPlatformOptions.options.includeDirs, lineEach, true);
2316 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2317 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2318 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2319 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2321 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2322 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2323 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2325 f.Printf("OFLAGS +=");
2326 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2327 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2328 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2329 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2333 if((configPlatformOptions && configPlatformOptions.options.libraries))
2335 if(configPlatformOptions.options.libraries.count)
2337 f.Printf("LIBS +=");
2338 OutputLibraries(f, configPlatformOptions.options.libraries);
2342 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
2344 if(projectPlatformOptions.options.libraries.count)
2346 f.Printf("LIBS +=");
2347 OutputLibraries(f, projectPlatformOptions.options.libraries);
2351 f.Printf("endif\n\n");
2357 for(c = 0; c < ifCount; c++)
2358 f.Printf("endif\n");
2363 f.Printf("CFLAGS +=");
2366 f.Printf(" -fmessage-length=0 $(OPTIMIZE)");
2367 //if(compiler.targetPlatform.is32Bits)
2368 forceBitDepth = (options && options.buildBitDepth) || numCObjects;
2370 f.Printf((!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? " -m32" : " -m64");
2371 //else if(compiler.targetPlatform.is64Bits)
2372 // f.Printf(" -m64");
2373 f.Printf(" $(FPIC)");
2374 //f.Printf(" -fpack-struct");
2376 switch(GetWarnings(config))
2378 case all: f.Printf(" -Wall"); break;
2379 case none: f.Printf(" -w"); break;
2381 if(GetProfile(config))
2383 if(options && options.linkerOptions && options.linkerOptions.count)
2385 f.Printf(" \\\n\t -Wl");
2386 for(s : options.linkerOptions)
2390 if(options && options.preprocessorDefinitions)
2391 OutputListOption(f, "D", options.preprocessorDefinitions, newLine, false);
2392 if(config && config.options && config.options.preprocessorDefinitions)
2393 OutputListOption(f, "D", config.options.preprocessorDefinitions, newLine, false);
2394 if(config && config.options && config.options.includeDirs)
2395 OutputListOption(f, "I", config.options.includeDirs, lineEach, true);
2396 if(options && options.includeDirs)
2397 OutputListOption(f, "I", options.includeDirs, lineEach, true);
2400 f.Printf("CECFLAGS +=%s%s%s%s", defaultPreprocessor ? "" : " -cpp ", defaultPreprocessor ? "" : compiler.cppCommand,
2401 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
2404 f.Printf("ECFLAGS +=");
2405 if(GetMemoryGuard(config))
2406 f.Printf(" -memguard");
2407 if(GetStrictNameSpaces(config))
2408 f.Printf(" -strictns");
2409 if(GetNoLineNumbers(config))
2410 f.Printf(" -nolinenumbers");
2413 if((s = GetDefaultNameSpace(config)) && s[0])
2414 f.Printf(" -defaultns %s", s);
2418 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2419 f.Printf("OFLAGS +=");
2421 f.Printf((!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? " -m32" : " -m64 \\\n");
2423 if(GetProfile(config))
2425 if(config && config.options && config.options.libraryDirs)
2426 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
2427 if(options && options.libraryDirs)
2428 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
2430 f.Printf("endif\n\n");
2432 f.Printf("# TARGETS\n\n");
2434 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
2436 f.Printf("objdir:\n");
2437 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2438 //f.Printf("# PRE-BUILD COMMANDS\n");
2439 if(options && options.prebuildCommands)
2441 for(s : options.prebuildCommands)
2442 if(s && s[0]) f.Printf("\t%s\n", s);
2444 if(config && config.options && config.options.prebuildCommands)
2446 for(s : config.options.prebuildCommands)
2447 if(s && s[0]) f.Printf("\t%s\n", s);
2449 if(platforms || (config && config.platforms))
2452 //f.Printf("# PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2453 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2455 PlatformOptions projectPOs, configPOs;
2456 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2458 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2459 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2465 f.Printf(PlatformToMakefileVariable(platform));
2468 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2470 for(s : projectPOs.options.prebuildCommands)
2471 if(s && s[0]) f.Printf("\t%s\n", s);
2473 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2475 for(s : configPOs.options.prebuildCommands)
2476 if(s && s[0]) f.Printf("\t%s\n", s);
2483 for(c = 0; c < ifCount; c++)
2484 f.Printf("endif\n");
2489 if(!sameObjTargetDirs)
2491 f.Printf("targetdir:\n");
2492 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2497 // Main Module (Linking) for ECERE C modules
2498 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2499 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2500 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2501 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
2502 // Main Module (Linking) for ECERE C modules
2503 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2504 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2505 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2506 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2507 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2512 // This would not rebuild the target on updated objects
2513 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2515 // This should fix it for good!
2516 f.Printf("$(SYMBOLS): | objdir\n");
2517 f.Printf("$(OBJECTS): | objdir\n");
2519 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2520 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2522 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2523 f.Printf("\t$(%s) $(OFLAGS) $(OBJECTS) $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
2524 if(!GetDebug(config))
2526 f.Printf("ifndef NOSTRIP\n");
2527 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2528 f.Printf("endif\n");
2530 if(GetCompress(config))
2532 f.Printf("ifndef WINDOWS\n");
2533 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2534 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2535 f.Printf("endif\n");
2537 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2538 f.Printf("endif\n");
2541 if(resNode.files && resNode.files.count && !noResources)
2542 resNode.GenMakefileAddResources(f, resNode.path, config);
2544 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2545 f.Printf("endif\n");
2547 //f.Printf("# POST-BUILD COMMANDS\n");
2548 if(options && options.postbuildCommands)
2550 for(s : options.postbuildCommands)
2551 if(s && s[0]) f.Printf("\t%s\n", s);
2553 if(config && config.options && config.options.postbuildCommands)
2555 for(s : config.options.postbuildCommands)
2556 if(s && s[0]) f.Printf("\t%s\n", s);
2558 if(platforms || (config && config.platforms))
2561 //f.Printf("# PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2562 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2564 PlatformOptions projectPOs, configPOs;
2565 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2567 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2568 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2574 f.Printf(PlatformToMakefileVariable(platform));
2577 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2579 for(s : projectPOs.options.postbuildCommands)
2580 if(s && s[0]) f.Printf("\t%s\n", s);
2582 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2584 for(s : configPOs.options.postbuildCommands)
2585 if(s && s[0]) f.Printf("\t%s\n", s);
2592 for(c = 0; c < ifCount; c++)
2593 f.Printf("endif\n");
2598 f.Printf("# SYMBOL RULES\n\n");
2600 Map<Platform, bool> excludedPlatforms { };
2601 topNode.GenMakefilePrintSymbolRules(f, this, compiler, config, excludedPlatforms);
2602 delete excludedPlatforms;
2605 f.Printf("# C OBJECT RULES\n\n");
2607 Map<Platform, bool> excludedPlatforms { };
2608 topNode.GenMakefilePrintCObjectRules(f, this, compiler, config, excludedPlatforms);
2609 delete excludedPlatforms;
2612 f.Printf("# OBJECT RULES\n\n");
2613 // todo call this still but only generate rules whith specific options
2614 // see we-have-file-specific-options in ProjectNode.ec
2616 Map<Platform, bool> excludedPlatforms { };
2617 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, compiler, config, excludedPlatforms);
2618 delete excludedPlatforms;
2622 GenMakefilePrintMainObjectRule(f, compiler, config);
2624 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2625 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) " : "");
2626 OutputCleanActions(f, "OBJECTS", objectsParts);
2629 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
2630 OutputCleanActions(f, "BOWLS", eCsourcesParts);
2631 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
2632 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
2636 f.Printf("realclean: clean\n");
2637 f.Printf("\t$(call rmrq,$(OBJ))\n");
2638 if(!sameObjTargetDirs)
2639 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2646 varStringLenDiffs.Free();
2647 delete varStringLenDiffs;
2654 // ChangeWorkingDir(oldDirectory);
2655 // delete pathBackup;
2658 config.makingModified = false;
2662 void GenMakefilePrintMainObjectRule(File f, CompilerConfig compiler, ProjectConfig config)
2664 char extension[MAX_EXTENSION] = "c";
2665 char modulePath[MAX_LOCATION];
2666 char fixedModuleName[MAX_FILENAME];
2669 char objDirNoSpaces[MAX_LOCATION];
2670 DirExpression objDirExp = GetObjDir(compiler, config);
2672 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
2673 ReplaceSpaces(fixedModuleName, moduleName);
2675 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2676 //strcat(fixedModuleName, ".main");
2678 #if 0 // TODO: Fix nospaces stuff
2679 // *** Dependency command ***
2680 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2682 // System Includes (from global settings)
2683 for(item : compiler.dirs[Includes])
2685 strcat(command, " -isystem ");
2686 if(strchr(item.name, ' '))
2688 strcat(command, "\"");
2689 strcat(command, item);
2690 strcat(command, "\"");
2693 strcat(command, item);
2696 for(item = includeDirs.first; item; item = item.next)
2698 strcat(command, " -I");
2699 if(strchr(item.name, ' '))
2701 strcat(command, "\"");
2702 strcat(command, item.name);
2703 strcat(command, "\"");
2706 strcat(command, item.name);
2708 for(item = preprocessorDefs.first; item; item = item.next)
2710 strcat(command, " -D");
2711 strcat(command, item.name);
2715 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2719 bool firstLine = true;
2721 // To do some time: auto save external dependencies?
2724 if(dep.GetLine(line, sizeof(line)-1))
2728 char * colon = strstr(line, ":");
2729 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2743 // If we failed to generate dependencies...
2747 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2753 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2758 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
2759 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
2761 *projectPlatformOptions = null;
2762 *configPlatformOptions = null;
2767 if(!strcmpi(p.name, platform))
2769 *projectPlatformOptions = p;
2774 if(config && config.platforms)
2776 for(p : config.platforms)
2778 if(!strcmpi(p.name, platform))
2780 *configPlatformOptions = p;
2788 Project LegacyBinaryLoadProject(File f, char * filePath)
2790 Project project = null;
2791 char signature[sizeof(epjSignature)];
2793 f.Read(signature, sizeof(signature), 1);
2794 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2796 char topNodePath[MAX_LOCATION];
2797 /*ProjectConfig newConfig
2799 name = CopyString("Default");
2800 makingModified = true;
2801 compilingModified = true;
2802 linkingModified = true;
2806 project = Project { options = { } };
2807 LegacyBinaryLoadNode(project.topNode, f);
2808 delete project.topNode.path;
2809 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2810 MakeSlashPath(topNodePath);
2812 PathCatSlash(topNodePath, filePath);
2813 project.filePath = topNodePath;
2815 /* THIS IS ALREADY DONE BY filePath property
2816 StripLastDirectory(topNodePath, topNodePath);
2817 project.topNode.path = CopyString(topNodePath);
2819 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2821 // newConfig.options.defaultNameSpace = "";
2822 /*newConfig.objDir.dir = "obj";
2823 newConfig.targetDir.dir = "";*/
2825 //project.configurations = { [ newConfig ] };
2826 //project.config = newConfig;
2833 String targetFileName, targetDirectory, objectsDirectory;
2835 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2836 f.Read(&temp, sizeof(int),1);
2839 case 0: project.options.targetType = executable; break;
2840 case 1: project.options.targetType = sharedLibrary; break;
2841 case 2: project.options.targetType = staticLibrary; break;
2844 f.Read(&len, sizeof(int),1);
2845 targetFileName = new char[len+1];
2846 f.Read(targetFileName, sizeof(char), len+1);
2847 project.options.targetFileName = targetFileName;
2848 delete targetFileName;
2850 f.Read(&len, sizeof(int),1);
2851 targetDirectory = new char[len+1];
2852 f.Read(targetDirectory, sizeof(char), len+1);
2853 project.options.targetDirectory = targetDirectory;
2854 delete targetDirectory;
2856 f.Read(&len, sizeof(int),1);
2857 objectsDirectory = new byte[len+1];
2858 f.Read(objectsDirectory, sizeof(char), len+1);
2859 project.options.objectsDirectory = objectsDirectory;
2860 delete objectsDirectory;
2862 f.Read(&temp, sizeof(int),1);
2863 project./*config.*/options.debug = temp ? true : false;
2864 f.Read(&temp, sizeof(int),1);
2865 project./*config.*/options.optimization = temp ? speed : none;
2866 f.Read(&temp, sizeof(int),1);
2867 project./*config.*/options.profile = temp ? true : false;
2868 f.Read(&temp, sizeof(int),1);
2869 project.options.warnings = temp ? all : unset;
2871 f.Read(&count, sizeof(int),1);
2874 project.options.includeDirs = { };
2875 for(c = 0; c < count; c++)
2878 f.Read(&len, sizeof(int),1);
2879 name = new char[len+1];
2880 f.Read(name, sizeof(char), len+1);
2881 project.options.includeDirs.Add(name);
2885 f.Read(&count, sizeof(int),1);
2888 project.options.libraryDirs = { };
2889 for(c = 0; c < count; c++)
2892 f.Read(&len, sizeof(int),1);
2893 name = new char[len+1];
2894 f.Read(name, sizeof(char), len+1);
2895 project.options.libraryDirs.Add(name);
2899 f.Read(&count, sizeof(int),1);
2902 project.options.libraries = { };
2903 for(c = 0; c < count; c++)
2906 f.Read(&len, sizeof(int),1);
2907 name = new char[len+1];
2908 f.Read(name, sizeof(char), len+1);
2909 project.options.libraries.Add(name);
2913 f.Read(&count, sizeof(int),1);
2916 project.options.preprocessorDefinitions = { };
2917 for(c = 0; c < count; c++)
2920 f.Read(&len, sizeof(int),1);
2921 name = new char[len+1];
2922 f.Read(name, sizeof(char), len+1);
2923 project.options.preprocessorDefinitions.Add(name);
2927 f.Read(&temp, sizeof(int),1);
2928 project.options.console = temp ? true : false;
2931 for(node : project.topNode.files)
2933 if(node.type == resources)
2935 project.resNode = node;
2945 void ProjectConfig::LegacyProjectConfigLoad(File f)
2953 char subSection[128];
2959 f.GetLine(buffer, 65536 - 1);
2960 TrimLSpaces(buffer, buffer);
2961 TrimRSpaces(buffer, buffer);
2964 if(buffer[0] == '-')
2968 TrimLSpaces(equal, equal);
2969 if(!strcmpi(subSection, "LibraryDirs"))
2971 if(!options.libraryDirs)
2972 options.libraryDirs = { [ CopyString(equal) ] };
2974 options.libraryDirs.Add(CopyString(equal));
2976 else if(!strcmpi(subSection, "IncludeDirs"))
2978 if(!options.includeDirs)
2979 options.includeDirs = { [ CopyString(equal) ] };
2981 options.includeDirs.Add(CopyString(equal));
2984 else if(buffer[0] == '+')
2995 TrimLSpaces(equal, equal);
2996 delete name; name = CopyString(equal); // property::name = equal;
2999 else if(!strcmpi(buffer, "Compiler Options"))
3000 strcpy(section, buffer);
3001 else if(!strcmpi(buffer, "IncludeDirs"))
3002 strcpy(subSection, buffer);
3003 else if(!strcmpi(buffer, "Linker Options"))
3004 strcpy(section, buffer);
3005 else if(!strcmpi(buffer, "LibraryDirs"))
3006 strcpy(subSection, buffer);
3007 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3014 equal = strstr(buffer, "=");
3018 TrimRSpaces(buffer, buffer);
3020 TrimLSpaces(equal, equal);
3021 if(!strcmpi(buffer, "Target Name"))
3022 options.targetFileName = /*CopyString(*/equal/*)*/;
3023 else if(!strcmpi(buffer, "Target Type"))
3025 if(!strcmpi(equal, "Executable"))
3026 options.targetType = executable;
3027 else if(!strcmpi(equal, "Shared"))
3028 options.targetType = sharedLibrary;
3029 else if(!strcmpi(equal, "Static"))
3030 options.targetType = staticLibrary;
3032 options.targetType = executable;
3034 else if(!strcmpi(buffer, "Target Directory"))
3035 options.targetDirectory = /*CopyString(*/equal/*)*/;
3036 else if(!strcmpi(buffer, "Console"))
3037 options.console = ParseTrueFalseValue(equal);
3038 else if(!strcmpi(buffer, "Libraries"))
3040 if(!options.libraries) options.libraries = { };
3041 ParseArrayValue(options.libraries, equal);
3043 else if(!strcmpi(buffer, "Intermediate Directory"))
3044 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3045 else if(!strcmpi(buffer, "Debug"))
3046 options.debug = ParseTrueFalseValue(equal);
3047 else if(!strcmpi(buffer, "Optimize"))
3049 if(!strcmpi(equal, "None"))
3050 options.optimization = none;
3051 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3052 options.optimization = speed;
3053 else if(!strcmpi(equal, "Size"))
3054 options.optimization = size;
3056 options.optimization = none;
3058 else if(!strcmpi(buffer, "Compress"))
3059 options.compress = ParseTrueFalseValue(equal);
3060 else if(!strcmpi(buffer, "Profile"))
3061 options.profile = ParseTrueFalseValue(equal);
3062 else if(!strcmpi(buffer, "AllWarnings"))
3063 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3064 else if(!strcmpi(buffer, "MemoryGuard"))
3065 options.memoryGuard = ParseTrueFalseValue(equal);
3066 else if(!strcmpi(buffer, "Default Name Space"))
3067 options.defaultNameSpace = CopyString(equal);
3068 else if(!strcmpi(buffer, "Strict Name Spaces"))
3069 options.strictNameSpaces = ParseTrueFalseValue(equal);
3070 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3072 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3073 ParseArrayValue(options.preprocessorDefinitions, equal);
3079 if(!options.targetDirectory && options.objectsDirectory)
3080 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3081 //if(!objDir.dir) objDir.dir = "obj";
3082 //if(!targetDir.dir) targetDir.dir = "";
3083 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3084 // if(!defaultNameSpace) property::defaultNameSpace = "";
3085 makingModified = true;
3088 Project LegacyAsciiLoadProject(File f, char * filePath)
3090 Project project = null;
3091 ProjectNode node = null;
3093 char parentPath[MAX_LOCATION];
3094 char section[128] = "";
3095 char subSection[128] = "";
3097 bool configurationsPresent = false;
3107 f.GetLine(buffer, 65536 - 1);
3108 TrimLSpaces(buffer, buffer);
3109 TrimRSpaces(buffer, buffer);
3112 if(buffer[0] == '-' || buffer[0] == '=')
3114 bool simple = buffer[0] == '-';
3117 TrimLSpaces(equal, equal);
3118 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3120 if(!project.config.options.libraryDirs) project.config.options.libraryDirs = { };
3121 project.config.options.libraryDirs.Add(CopyString(equal));
3123 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3125 if(!project.config.options.includeDirs) project.config.options.includeDirs = { };
3126 project.config.options.includeDirs.Add(CopyString(equal));
3128 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3130 len = strlen(equal);
3133 char temp[MAX_LOCATION];
3134 ProjectNode child { };
3135 // We don't need to do this anymore, fileName is just a property that sets name & path
3136 // child.fileName = CopyString(equal);
3139 child.name = CopyString(equal);
3140 child.path = CopyString(parentPath);
3144 GetLastDirectory(equal, temp);
3145 child.name = CopyString(temp);
3146 StripLastDirectory(equal, temp);
3147 child.path = CopyString(temp);
3149 child.nodeType = file;
3150 child.parent = parent;
3151 child.indent = parent.indent + 1;
3153 child.icon = NodeIcons::SelectFileIcon(child.name);
3154 parent.files.Add(child);
3160 StripLastDirectory(parentPath, parentPath);
3161 parent = parent.parent;
3165 else if(buffer[0] == '+')
3169 TrimLSpaces(equal, equal);
3170 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3172 char temp[MAX_LOCATION];
3173 ProjectNode child { };
3174 // NEW: Folders now have a path set like files
3175 child.name = CopyString(equal);
3176 strcpy(temp, parentPath);
3177 PathCatSlash(temp, child.name);
3178 child.path = CopyString(temp);
3180 child.parent = parent;
3181 child.indent = parent.indent + 1;
3182 child.type = folder;
3183 child.nodeType = folder;
3185 child.icon = folder;
3186 PathCatSlash(parentPath, child.name);
3187 parent.files.Add(child);
3192 else if(!strcmpi(section, "Configurations"))
3194 ProjectConfig newConfig
3196 makingModified = true;
3200 LegacyProjectConfigLoad(newConfig, f);
3201 project.configurations.Add(newConfig);
3204 else if(!strcmpi(buffer, "ECERE Project File"));
3205 else if(!strcmpi(buffer, "Version 0a"))
3206 ; //strcpy(version, "0a");
3207 else if(!strcmpi(buffer, "Version 0.1a"))
3208 ; //strcpy(version, "0.1a");
3209 else if(!strcmpi(buffer, "Configurations"))
3211 project.configurations.Free();
3212 project.config = null;
3213 strcpy(section, buffer);
3214 configurationsPresent = true;
3216 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3218 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3219 char topNodePath[MAX_LOCATION];
3220 // newConfig.defaultNameSpace = "";
3221 //newConfig.objDir.dir = "obj";
3222 //newConfig.targetDir.dir = "";
3223 project = Project { /*options = { }*/ };
3224 project.configurations = { [ newConfig ] };
3225 project.config = newConfig;
3226 // if(project.topNode.path) delete project.topNode.path;
3227 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3228 MakeSlashPath(topNodePath);
3229 PathCatSlash(topNodePath, filePath);
3230 project.filePath = topNodePath;
3231 parentPath[0] = '\0';
3232 parent = project.topNode;
3234 strcpy(section, "Target");
3239 if(equal[0] == '\"')
3241 StripQuotes(equal, equal);
3242 delete project.moduleName; project.moduleName = CopyString(equal);
3246 else if(!strcmpi(buffer, "Compiler Options"));
3247 else if(!strcmpi(buffer, "IncludeDirs"))
3248 strcpy(subSection, buffer);
3249 else if(!strcmpi(buffer, "Linker Options"));
3250 else if(!strcmpi(buffer, "LibraryDirs"))
3251 strcpy(subSection, buffer);
3252 else if(!strcmpi(buffer, "Files"))
3254 strcpy(section, "Target");
3255 strcpy(subSection, buffer);
3257 else if(!strcmpi(buffer, "Resources"))
3259 ProjectNode child { };
3260 parent.files.Add(child);
3261 child.parent = parent;
3262 child.indent = parent.indent + 1;
3263 child.name = CopyString(buffer);
3264 child.path = CopyString("");
3265 child.type = resources;
3267 child.icon = archiveFile;
3268 project.resNode = child;
3271 strcpy(subSection, buffer);
3275 equal = strstr(buffer, "=");
3279 TrimRSpaces(buffer, buffer);
3281 TrimLSpaces(equal, equal);
3283 if(!strcmpi(section, "Target"))
3285 if(!strcmpi(buffer, "Build Exclusions"))
3287 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3289 /*if(node && node.type != NodeTypes::project)
3290 ParseListValue(node.buildExclusions, equal);*/
3293 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
3295 delete project.resNode.path;
3296 project.resNode.path = CopyString(equal);
3297 PathCatSlash(parentPath, equal);
3301 else if(!strcmpi(buffer, "Intermediate Directory"))
3302 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3303 else if(!strcmpi(buffer, "Debug"))
3304 project.config.options.debug = ParseTrueFalseValue(equal);
3305 else if(!strcmpi(buffer, "Optimize"))
3307 if(!strcmpi(equal, "None"))
3308 project.config.options.optimization = none;
3309 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3310 project.config.options.optimization = speed;
3311 else if(!strcmpi(equal, "Size"))
3312 project.config.options.optimization = size;
3314 project.config.options.optimization = none;
3316 else if(!strcmpi(buffer, "Profile"))
3317 project.config.options.profile = ParseTrueFalseValue(equal);
3318 else if(!strcmpi(buffer, "MemoryGuard"))
3319 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
3322 if(!project.options) project.options = { };
3324 // Project Wide Settings (All configs)
3325 if(!strcmpi(buffer, "Target Name"))
3326 project.options.targetFileName = /*CopyString(*/equal/*)*/;
3327 else if(!strcmpi(buffer, "Target Type"))
3329 if(!strcmpi(equal, "Executable"))
3330 project.options.targetType = executable;
3331 else if(!strcmpi(equal, "Shared"))
3332 project.options.targetType = sharedLibrary;
3333 else if(!strcmpi(equal, "Static"))
3334 project.options.targetType = staticLibrary;
3336 project.options.targetType = executable;
3338 else if(!strcmpi(buffer, "Target Directory"))
3339 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
3340 else if(!strcmpi(buffer, "Console"))
3341 project.options.console = ParseTrueFalseValue(equal);
3342 else if(!strcmpi(buffer, "Libraries"))
3344 if(!project.options.libraries) project.options.libraries = { };
3345 ParseArrayValue(project.options.libraries, equal);
3347 else if(!strcmpi(buffer, "AllWarnings"))
3348 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3349 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3351 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3353 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
3354 ParseListValue(node.preprocessorDefs, equal);*/
3358 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
3359 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3370 SplitPlatformLibraries(project);
3372 if(configurationsPresent)
3373 CombineIdenticalConfigOptions(project);
3377 void SplitPlatformLibraries(Project project)
3379 if(project && project.configurations)
3381 for(cfg : project.configurations)
3383 if(cfg.options.libraries && cfg.options.libraries.count)
3385 Iterator<String> it { cfg.options.libraries };
3389 char * platformName = strstr(l, ":");
3392 PlatformOptions platform = null;
3394 if(!cfg.platforms) cfg.platforms = { };
3395 for(p : cfg.platforms)
3397 if(!strcmpi(platformName, p.name))
3405 platform = { name = CopyString(platformName), options = { libraries = { } } };
3406 cfg.platforms.Add(platform);
3408 *(platformName-1) = 0;
3409 platform.options.libraries.Add(CopyString(l));
3411 cfg.options.libraries.Delete(it.pointer);
3420 void CombineIdenticalConfigOptions(Project project)
3422 if(project && project.configurations && project.configurations.count)
3425 ProjectOptions nullOptions { };
3426 ProjectConfig firstConfig = null;
3427 for(cfg : project.configurations)
3429 if(cfg.options.targetType != staticLibrary)
3436 firstConfig = project.configurations.firstIterator.data;
3438 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3440 if(!member.isProperty)
3442 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3447 for(cfg : project.configurations)
3449 if(cfg != firstConfig)
3451 if(cfg.options.targetType != staticLibrary)
3455 if(type.type == noHeadClass || type.type == normalClass)
3457 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3458 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3459 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3463 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3464 (byte *)firstConfig.options + member.offset + member._class.offset,
3465 (byte *)cfg.options + member.offset + member._class.offset);
3477 if(type.type == noHeadClass || type.type == normalClass)
3479 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3480 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3481 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3486 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3487 (byte *)firstConfig.options + member.offset + member._class.offset,
3488 (byte *)nullOptions + member.offset + member._class.offset))
3492 if(!project.options) project.options = { };
3494 /*if(type.type == noHeadClass || type.type == normalClass)
3496 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3497 (byte *)project.options + member.offset + member._class.offset,
3498 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3502 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3503 // TOFIX: ListBox::SetData / OnCopy mess
3504 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3505 (byte *)project.options + member.offset + member._class.offset,
3506 (type.typeSize > 4) ? address :
3507 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3508 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3509 (void *)*(byte *)address )));
3512 (byte *)project.options + member.offset + member._class.offset,
3513 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3515 for(cfg : project.configurations)
3517 if(cfg.options.targetType == staticLibrary)
3521 if(type.type == noHeadClass || type.type == normalClass)
3523 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3524 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3525 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3529 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3530 (byte *)firstConfig.options + member.offset + member._class.offset,
3531 (byte *)cfg.options + member.offset + member._class.offset);
3536 if(cfg != firstConfig)
3538 if(type.type == noHeadClass || type.type == normalClass)
3540 type._vTbl[__ecereVMethodID_class_OnFree](type,
3541 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3545 type._vTbl[__ecereVMethodID_class_OnFree](type,
3546 (byte *)cfg.options + member.offset + member._class.offset);
3548 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3551 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3558 // Compare Platform Specific Settings
3561 for(cfg : project.configurations)
3563 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3564 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3570 if(same && firstConfig.platforms)
3572 for(cfg : project.configurations)
3574 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3576 if(cfg != firstConfig)
3578 cfg.platforms.Free();
3579 delete cfg.platforms;
3582 project.platforms = firstConfig.platforms;
3583 firstConfig.platforms = null;
3587 // Static libraries can't contain libraries
3588 for(cfg : project.configurations)
3590 if(cfg.options.targetType == staticLibrary)
3592 if(!cfg.options.libraries) cfg.options.libraries = { };
3593 cfg.options.libraries.Free();
3599 Project LoadProject(char * filePath)
3601 Project project = null;
3602 File f = FileOpen(filePath, read);
3605 project = LegacyBinaryLoadProject(f, filePath);
3608 JSONParser parser { f = f };
3609 JSONResult result = parser.GetObject(class(Project), &project);
3612 char insidePath[MAX_LOCATION];
3614 delete project.topNode.files;
3615 if(!project.files) project.files = { };
3616 project.topNode.files = project.files;
3617 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3618 delete project.resNode.path;
3619 project.resNode.path = project.resourcesPath;
3620 project.resourcesPath = null;
3621 project.resNode.nodeType = (ProjectNodeType)-1;
3622 delete project.resNode.files;
3623 project.resNode.files = project.resources;
3624 project.files = null;
3625 project.resources = null;
3626 if(!project.configurations) project.configurations = { };
3629 char topNodePath[MAX_LOCATION];
3630 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3631 MakeSlashPath(topNodePath);
3632 PathCatSlash(topNodePath, filePath);
3633 project.filePath = topNodePath;//filePath;
3636 project.topNode.FixupNode(insidePath);
3641 project = LegacyAsciiLoadProject(f, filePath);
3647 if(!project.options) project.options = { };
3648 if(!project.config && project.configurations)
3649 project.config = project.configurations.firstIterator.data;
3651 if(!project.resNode)
3653 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3656 if(!project.moduleName)
3657 project.moduleName = CopyString(project.name);
3658 if(project.config &&
3659 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3660 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3662 //delete project.config.options.targetFileName;
3664 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
3665 project.config.options.optimization = none;
3666 project.config.options.debug = true;
3667 //project.config.options.warnings = unset;
3668 project.config.options.memoryGuard = false;
3669 project.config.compilingModified = true;
3670 project.config.linkingModified = true;
3672 else if(!project.topNode.name && project.config)
3674 project.topNode.name = CopyString(project.config.options.targetFileName);
3677 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3678 project.topNode.configurations = project.configurations;
3679 project.topNode.platforms = project.platforms;
3680 project.topNode.options = project.options;*/