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();
51 #ifdef MAKEFILE_GENERATOR
52 CompilerConfig defaultCompiler;
55 // LEGACY BINARY EPJ LOADING
57 SetBool ParseTrueFalseValue(char * string)
59 if(!strcmpi(string, "True")) return true;
63 void ParseArrayValue(Array<String> array, char * equal)
65 char * start, * comma;
67 string = CopyString(equal);
71 comma = strstr(start, ",");
74 array.Add(CopyString(start));
84 void ProjectNode::LegacyBinaryLoadNode(File f)
89 f.Read(&len, sizeof(len), 1);
90 name = new char[len+1];
92 f.Read(name, sizeof(char), len+1);
93 f.Read(&len, sizeof(len), 1);
95 path = new char[len+1];
96 f.Read(path, sizeof(char), len+1);
99 fileName = new char[fileNameLen+2];
100 strcpy(fileName, path);
101 if(fileName[0]) strcat(fileName, "/");
102 strcat(fileName, name);
105 f.Read(&type, sizeof(type), 1);
106 f.Read(&count, sizeof(count), 1);
111 icon = NodeIcons::SelectFileIcon(name);
116 icon = NodeIcons::SelectNodeIcon(type);
119 if(count && !files) files = { };
120 for(c = 0; c < count; c++)
122 ProjectNode child { };
125 child.indent = indent + 1;
126 LegacyBinaryLoadNode(child, f);
130 /*void LegacyBinarySaveNode(File f)
135 f.Write(&len, sizeof(len), 1);
136 f.Write(name, sizeof(char), len+1);
140 // Projects Absolute Path Are Not Saved
142 f.Write(&len, sizeof(len), 1);
143 f.Write(&len, sizeof(char), 1);
148 f.Write(&len, sizeof(len), 1);
149 f.Write(path, sizeof(char), len+1);
151 f.Write(&type, sizeof(type), 1);
152 f.Write(&children.count, sizeof(children.count), 1);
153 for(child = children.first; child; child.next)
157 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
160 char printPath[MAX_LOCATION];
162 if(type == project && (files.count /*|| preprocessorDefs.first*/))
164 f.Printf("\n Files\n");
166 else if(type == file)
168 if(!strcmp(path, insidePath))
169 f.Printf("%s - %s\n", indentation, name);
172 strcpy(printPath, path);
173 len = strlen(printPath);
175 if(printPath[len-1] != '/')
176 strcat(printPath, "/");
177 strcat(printPath, name);
178 f.Printf("%s = %s\n", indentation, printPath);
181 f.Printf("\nError\n\n");
183 else if(type == folder)
185 f.Printf("%s + %s\n", indentation, name);
187 else if(type == resources && files.count)
189 PathCatSlash(insidePath, path);
190 f.Printf("\n%sResources\n", indentation);
192 f.Printf("%s Path = %s\n", indentation, path);
195 /*if(buildExclusions.first && type != project)
197 for(item = buildExclusions.first; item; item = item.next)
199 if(item == buildExclusions.first)
200 f.Printf("%s Build Exclusions = %s", indentation, item.name);
202 f.Printf(", %s", item.name);
207 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
209 for(item = preprocessorDefs.first; item; item = item.next)
211 if(item == preprocessorDefs.first)
212 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
214 f.Printf(", %s", item.name);
220 if(type == project && (files.count /*|| preprocessorDefs.first*/))
224 LegacyAsciiSaveNode(child, f, indentation, insidePath);
226 else if(type == folder)
228 strcat(indentation, " ");
229 // WHAT WAS THIS: strcpy(printPath, path);
230 // TOCHECK: why is Unix/PathCat not used here
231 len = strlen(insidePath);
233 if(insidePath[len-1] != '/')
234 strcat(insidePath, "/");
235 strcat(insidePath, name);
238 LegacyAsciiSaveNode(child, f, indentation, insidePath);
239 f.Printf("%s -\n", indentation);
240 indentation[strlen(indentation) - 3] = '\0';
241 StripLastDirectory(insidePath, insidePath);
243 else if(type == resources && files.count)
247 LegacyAsciiSaveNode(child, f, indentation, insidePath);
248 StripLastDirectory(insidePath, insidePath);
253 void ProjectConfig::LegacyProjectConfigSave(File f)
255 char * indentation = " ";
257 //f.Printf("\n * Common\n");
259 f.Printf("\n + %s\n", name);
260 f.Printf("\n Compiler\n\n");
261 if(objDir.expression[0])
262 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
263 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
264 switch(options.optimization)
266 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
267 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
268 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
270 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
272 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
273 if(options.memoryGuard == true)
274 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
275 if(options.strictNameSpaces == true)
276 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
277 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
278 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
279 TOFIX: Compiler Bug {
280 if(options.preprocessorDefinitions.count)
283 for(item : options.preprocessorDefinitions)
287 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
291 f.Printf(", %s", item);
296 if(options.includeDirs.count)
298 f.Printf("\n%sInclude Directories\n", indentation);
299 for(item : options.includeDirs)
300 f.Printf("%s - %s\n", indentation, name);
304 f.Printf("\n%sLinker\n\n", indentation);
305 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
306 switch(options.targetType)
308 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
309 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
310 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
312 if(targetDir.expression[0])
313 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
315 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
317 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
318 if(options.libraries.count)
321 for(item : options.libraries)
325 f.Printf("\n%sLibraries = %s", indentation, name);
329 f.Printf(", %s", item);
333 if(options.libraryDirs.count)
335 f.Printf("\n%sLibrary Directories\n\n", indentation);
336 for(item : options.libraryDirs)
337 f.Printf(" - %s\n", indentation, item);
341 void LegacyAsciiSaveProject(File f, Project project)
343 char indentation[128*3];
344 char path[MAX_LOCATION];
346 f.Printf("\nECERE Project File : Format Version 0.1b\n");
347 f.Printf("\nDescription\n%s\n.\n", project.description);
348 f.Printf("\nLicense\n%s\n.\n", project.license);
349 f.Printf("\nModule Name = %s\n", project.moduleName);
350 f.Printf("\n Configurations\n");
351 //////////////////////////////////////commonConfig.Save(f, true);
352 for(cfg : project.configurations)
353 LegacyProjectConfigSave(cfg, f);
355 strcpy(indentation, " ");
357 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
363 // *** NEW JSON PROJECT FORMAT ***
364 public enum ProjectNodeType { file, folder };
366 // *******************************
368 define PEEK_RESOLUTION = (18.2 * 10);
374 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
376 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources };
378 define WorkspaceExtension = "ews";
379 define ProjectExtension = "epj";
381 define stringInFileIncludedFrom = "In file included from ";
383 void ReplaceSpaces(char * output, char * source)
388 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
390 if(ch == ' ') output[dc++] = '\\';
393 if(ch == '(' || ch == ')') output[dc++] = '\\';
403 void ReplaceUnwantedMakeChars(char * output, char * source)
408 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
412 if(ch == '(' || ch == ')') output[dc++] = '\\';
425 static void OutputNoSpace(File f, char * source)
427 char * output = new char[strlen(source)+1024];
428 ReplaceSpaces(output, source);
433 enum ListOutputMethod { inPlace, newLine, lineEach };
435 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
438 const int breakListLength = 1536;
439 const int breakLineLength = 78; // TODO: turn this into an option.
441 int c, len, itemCount = 0;
442 Array<int> breaks { };
446 MapNode<String, int> mn;
447 for(c=0; c<list.count; c++)
449 len = strlen(list[c]) + 3;
450 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
452 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
454 if(strstr(list[c], mn.key))
458 if(charCount + len > breakListLength)
460 breaks.Add(itemCount);
468 breaks.Add(itemCount);
469 numOfBreaks = breaks.count;
474 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
475 for(c=0; c<numOfBreaks; c++)
476 f.Printf(" $(%s%d)", name, c+1);
480 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
486 for(c=0; c<numOfBreaks; c++)
489 f.Printf("%s%d =", name, c+1);
492 itemCount = breaks[c];
493 for(n=offset; n<offset+itemCount; n++)
495 if(false) // TODO: turn this into an option.
497 int itemLen = strlen(list[n]);
498 if(len > 3 && len + itemLen > breakLineLength)
500 f.Printf(" \\\n\t%s", list[n]);
506 f.Printf(" %s", list[n]);
510 f.Printf(" \\\n\t%s", list[n]);
525 void OutputCleanActions(File f, char * name, int parts)
530 for(c=0; c<parts; c++)
531 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
534 f.Printf("\t$(call rmq,$(%s))\n", name);
537 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
541 if(method == newLine)
545 if(method == lineEach)
547 f.Printf(" -%s", option);
549 OutputNoSpace(f, item);
551 f.Printf("%s", item);
556 static void OutputLibraries(File f, Array<String> libraries)
558 for(item : libraries)
560 char ext[MAX_EXTENSION];
561 char temp[MAX_LOCATION];
563 bool usedFunction = false;
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);
578 f.Printf(" \\\n\t$(call _L,");
587 void CamelCase(char * string)
589 int c, len = strlen(string);
590 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
591 string[c] = (char)tolower(string[c]);
594 CompilerConfig GetCompilerConfig()
596 #ifndef MAKEFILE_GENERATOR
597 CompilerConfig compiler = null;
598 if(ide && ide.workspace)
599 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
602 incref defaultCompiler;
603 return defaultCompiler;
607 define localTargetType = config && config.options && config.options.targetType ?
608 config.options.targetType : options && options.targetType ?
609 options.targetType : TargetTypes::executable;
610 define localWarnings = config && config.options && config.options.warnings ?
611 config.options.warnings : options && options.warnings ?
612 options.warnings : WarningsOption::unset;
613 define localDebug = config && config.options && config.options.debug ?
614 config.options.debug : options && options.debug ?
615 options.debug : SetBool::unset;
616 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
617 config.options.memoryGuard : options && options.memoryGuard ?
618 options.memoryGuard : SetBool::unset;
619 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
620 config.options.noLineNumbers : options && options.noLineNumbers ?
621 options.noLineNumbers : SetBool::unset;
622 define localProfile = config && config.options && config.options.profile ?
623 config.options.profile : options && options.profile ?
624 options.profile : SetBool::unset;
625 define localOptimization = config && config.options && config.options.optimization ?
626 config.options.optimization : options && options.optimization ?
627 options.optimization : OptimizationStrategy::none;
628 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
629 config.options.defaultNameSpace : options && options.defaultNameSpace ?
630 options.defaultNameSpace : null;
631 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
632 config.options.strictNameSpaces : options && options.strictNameSpaces ?
633 options.strictNameSpaces : SetBool::unset;
634 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
635 define localTargetFileName = config && config.options && config.options.targetFileName ?
636 config.options.targetFileName : options && options.targetFileName ?
637 options.targetFileName : "";
638 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
639 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
640 options.targetDirectory : null;
641 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
642 ideSettings.projectDefaultIntermediateObjDir[0] ?
643 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
644 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
645 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
646 options.objectsDirectory : null;
647 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
648 ideSettings.projectDefaultIntermediateObjDir[0] ?
649 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
650 define localConsole = config && config.options && config.options.console ?
651 config.options.console : options && options.console ?
652 options.console : SetBool::unset;
653 define localCompress = config && config.options && config.options.compress ?
654 config.options.compress : options && options.compress ?
655 options.compress : SetBool::unset;
657 define platformTargetType =
658 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
659 configPOs.options.targetType :
660 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
661 projectPOs.options.targetType : TargetTypes::unset;
664 // we should have some kind of direct mapping between a platform and it's makefile variable
665 char * PlatformToMakefileVariable(Platform platform)
667 return platform == win32 ? "WINDOWS" :
668 platform == tux ? "LINUX" :
669 platform == apple ? "OSX" :
673 char * TargetTypeToMakefileVariable(TargetTypes targetType)
675 return targetType == executable ? "executable" :
676 targetType == sharedLibrary ? "sharedlib" :
677 targetType == staticLibrary ? "staticlib" :
681 // Move this to ProjectConfig? null vs Common to consider...
682 char * GetConfigName(ProjectConfig config)
684 return config ? config.name : "Common";
687 char * PlatformToMakefileTargetVariable(Platform platform)
689 return platform == win32 ? "WINDOWS_TARGET" :
690 platform == tux ? "LINUX_TARGET" :
691 platform == apple ? "OSX_TARGET" :
695 class Project : struct
697 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
698 // We might want to tweak this default behavior of regular classes ?
699 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
704 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
705 property Array<PlatformOptions> platforms
707 get { return platforms; }
710 if(platforms) { platforms.Free(); delete platforms; }
713 List<PlatformOptions> empty { };
714 Iterator<PlatformOptions> it { value };
716 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
717 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
727 if(p.options && !p.options.isEmpty)
734 List<ProjectConfig> configurations;
735 LinkList<ProjectNode> files;
736 String resourcesPath;
737 LinkList<ProjectNode> resources;
739 property char * description
741 set { delete description; if(value && value[0]) description = CopyString(value); }
742 get { return description ? description : ""; }
743 isset { return description != null && description[0]; }
746 property char * license
748 set { delete license; if(value && value[0]) license = CopyString(value); }
749 get { return license ? license : ""; }
750 isset { return license != null && license[0]; }
753 property char * compilerConfigsDir
755 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
756 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
757 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
761 // topNode.name holds the file name (.epj)
762 ProjectOptions options;
763 Array<PlatformOptions> platforms;
764 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
767 ProjectConfig config;
769 // This is the file name stripped of the epj extension
770 // It should NOT be edited, saved or loaded anywhere
775 String compilerConfigsDir;
776 #ifndef MAKEFILE_GENERATOR
777 FileMonitor fileMonitor
779 this, FileChange { modified = true };
780 bool OnFileNotify(FileChange action, char * param)
782 fileMonitor.StopMonitoring();
783 if(OnProjectModified(action, param))
784 fileMonitor.StartMonitoring();
789 bool StartMonitoring()
791 fileMonitor.fileName = filePath;
792 fileMonitor.StartMonitoring();
796 bool StopMonitoring()
798 fileMonitor.StopMonitoring();
802 bool OnProjectModified(FileChange fileChange, char * param)
805 sprintf(temp, $"The project %s was modified by another application.\n"
806 "Would you like to reload it and lose your changes?", name);
807 if(MessageBox { type = yesNo, master = ide,
808 text = $"Project has been modified", contents = temp }.Modal() == yes)
810 Project project = LoadProject(filePath);
813 ProjectView projectView = ide.projectView;
814 DataRow prev = topNode.row ? topNode.row.previous : null;
815 FileMonitor fm = fileMonitor;
817 if(projectView) projectView.DeleteNode(topNode);
822 topNode.project = this;
826 projectView.AddNode(topNode, null);
827 topNode.row.Move(prev);
829 eSystem_Delete(project);
838 // This frees contents without freeing the instance
839 // For use from destructor and for file monitor reloading
840 // (To work around JSON loader (LoadProject) always returning a new instance)
843 if(platforms) { platforms.Free(); delete platforms; }
844 if(configurations) { configurations.Free(); delete configurations; }
845 if(files) { files.Free(); delete files; }
846 if(resources) { resources.Free(); delete resources; }
848 delete resourcesPath;
852 delete compilerConfigsDir;
861 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
862 topNode.configurations = null;
863 topNode.platforms = null;
864 topNode.options = null;
869 property ProjectConfig config
875 topNode.info = CopyString(GetConfigName(config));
878 property char * filePath
884 char string[MAX_LOCATION];
885 GetLastDirectory(value, string);
887 topNode.name = CopyString(string);
888 StripExtension(string);
890 name = CopyString(string);
891 StripLastDirectory(value, string);
893 topNode.path = CopyString(string);
895 filePath = CopyString(value);
900 TargetTypes GetTargetType(ProjectConfig config)
902 TargetTypes targetType = localTargetType;
906 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
909 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
911 PlatformOptions projectPOs, configPOs;
912 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
913 if(platformTargetType)
920 char * GetObjDirExpression(ProjectConfig config)
922 // TODO: Support platform options
923 char * expression = localObjectsDirectory;
925 expression = settingsObjectsDirectory;
929 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config)
931 char * expression = GetObjDirExpression(config);
932 DirExpression objDir { type = intermediateObjectsDir };
933 objDir.Evaluate(expression, this, compiler, config);
937 char * GetTargetDirExpression(ProjectConfig config)
939 // TODO: Support platform options
940 char * expression = localTargetDirectory;
942 expression = settingsTargetDirectory;
946 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config)
948 char * expression = GetTargetDirExpression(config);
949 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
950 targetDir.Evaluate(expression, this, compiler, config);
954 WarningsOption GetWarnings(ProjectConfig config)
956 WarningsOption warnings = localWarnings;
960 bool GetDebug(ProjectConfig config)
962 SetBool debug = localDebug;
963 return debug == true;
966 bool GetMemoryGuard(ProjectConfig config)
968 SetBool memoryGuard = localMemoryGuard;
969 return memoryGuard == true;
972 bool GetNoLineNumbers(ProjectConfig config)
974 SetBool noLineNumbers = localNoLineNumbers;
975 return noLineNumbers == true;
978 bool GetProfile(ProjectConfig config)
980 SetBool profile = localProfile;
981 return profile == true;
984 OptimizationStrategy GetOptimization(ProjectConfig config)
986 OptimizationStrategy optimization = localOptimization;
990 String GetDefaultNameSpace(ProjectConfig config)
992 String defaultNameSpace = localDefaultNameSpace;
993 return defaultNameSpace;
996 bool GetStrictNameSpaces(ProjectConfig config)
998 SetBool strictNameSpaces = localStrictNameSpaces;
999 return strictNameSpaces == true;
1002 String GetTargetFileName(ProjectConfig config)
1004 String targetFileName = localTargetFileName;
1005 return targetFileName;
1008 //String targetDirectory;
1009 //String objectsDirectory;
1010 bool GetConsole(ProjectConfig config)
1012 SetBool console = localConsole;
1013 return console == true;
1016 bool GetCompress(ProjectConfig config)
1018 SetBool compress = localCompress;
1019 return compress == true;
1021 //SetBool excludeFromBuild;
1023 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1025 #ifndef MAKEFILE_GENERATOR
1026 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1030 bool GetConfigIsInDebugSession(ProjectConfig config)
1032 #ifndef MAKEFILE_GENERATOR
1033 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1037 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config)
1039 #ifndef MAKEFILE_GENERATOR
1040 ide.SetPath(projectsDirs, compiler, config);
1044 #ifndef MAKEFILE_GENERATOR
1045 bool Save(char * fileName)
1048 /*char output[MAX_LOCATION];
1049 ChangeExtension(fileName, "json", output);
1050 f = FileOpen(output, write);*/
1051 f = FileOpen(fileName, write);
1054 files = topNode.files;
1055 resources = resNode.files;
1056 resourcesPath = resNode.path;
1058 files.Remove(resNode);
1061 WriteJSONObject(f, class(Project), this, 0);
1067 resourcesPath = null;
1074 // This method is only called from Debugger, should be moved to Debugger class?
1075 #ifndef MAKEFILE_GENERATOR
1076 bool GetRelativePath(char * filePath, char * relativePath)
1079 char moduleName[MAX_FILENAME];
1080 GetLastDirectory(filePath, moduleName);
1081 // try with workspace dir first?
1082 if((node = topNode.Find(moduleName, false)))
1084 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1085 PathCatSlash(relativePath, node.name);
1090 // Tweak for automatically resolving symbol loader modules
1091 char * sl = strstr(moduleName, ".main.ec");
1092 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1094 char objDir[MAX_LOCATION];
1095 DirExpression objDirExp;
1096 CompilerConfig compiler = ide.debugger.currentCompiler;
1097 ProjectConfig config = ide.debugger.prjConfig;
1098 // This is not perfect, as multiple source files exist for the symbol loader module...
1099 // We try to set it in the debug config object directory.
1100 if(!compiler || !config)
1102 // If we're not currently debugging, set a breakpoint in the active compiler/config
1103 compiler = GetCompilerConfig();
1104 config = this.config;
1105 // If the current config is not debuggable, set it in the first debuggable config found
1106 if(config && !config.options.debug)
1108 for(c : configurations; c.options.debug)
1115 objDirExp = GetObjDir(compiler, config);
1116 strcpy(objDir, objDirExp.dir);
1118 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1119 ReplaceSpaces(objDir, objDir);
1120 strcpy(relativePath, objDir);
1122 PathCatSlash(relativePath, moduleName);
1126 // WARNING: On failure, relative path is uninitialized
1131 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1133 TargetTypes targetType = GetTargetType(config);
1134 String targetFileName = GetTargetFileName(config);
1135 if(targetType == staticLibrary)
1137 PathCatSlash(string, "lib");
1138 strcat(string, targetFileName);
1140 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1142 PathCatSlash(string, "lib");
1143 strcat(string, targetFileName);
1146 PathCatSlash(string, targetFileName);
1151 if(compiler.targetPlatform == win32)
1152 strcat(string, ".exe");
1155 if(compiler.targetPlatform == win32)
1156 strcat(string, ".dll");
1157 else if(compiler.targetPlatform == apple)
1158 strcat(string, ".dylib");
1160 strcat(string, ".so");
1163 strcat(string, ".a");
1168 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1170 bool result = false;
1171 char temp[MAX_LOCATION];
1172 strcpy(cfDir, topNode.path);
1173 if(compilerConfigsDir && compilerConfigsDir[0])
1175 PathCatSlash(cfDir, compilerConfigsDir);
1180 strcpy(temp, cfDir);
1181 // Using a relative path makes it less likely to run into spaces issues
1182 // Even with escaped spaces, there still seems to be issues including a config file
1183 // in a path containing spaces
1185 MakePathRelative(temp, topNode.path, cfDir);
1188 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1192 strcpy(temp, cfDir);
1193 ReplaceSpaces(cfDir, temp);
1198 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1200 char temp[MAX_LOCATION];
1201 bool result = false;
1202 strcpy(cfDir, topNode.path);
1203 if(ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1205 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1210 // Default to <ProjectDir>/.configs if unset
1211 PathCatSlash(cfDir, ".configs");
1216 strcpy(temp, cfDir);
1217 // Using a relative path makes it less likely to run into spaces issues
1218 // Even with escaped spaces, there still seems to be issues including a config file
1219 // in a path containing spaces
1220 if(IsPathInsideOf(cfDir, topNode.path))
1221 MakePathRelative(temp, topNode.path, cfDir);
1223 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1227 strcpy(temp, cfDir);
1228 ReplaceSpaces(cfDir, temp);
1233 void CatMakeFileName(char * string, ProjectConfig config)
1235 char projectName[MAX_LOCATION];
1236 strcpy(projectName, name);
1237 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1240 #ifndef MAKEFILE_GENERATOR
1241 void MarkChanges(ProjectNode node)
1243 for(cfg : topNode.configurations)
1245 ProjectConfig c = null;
1246 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1248 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1249 (!c.options || !cfg.options)))
1250 cfg.symbolGenModified = true;
1252 cfg.makingModified = true;
1256 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1258 for(cfg : configurations)
1261 cfg.makingModified = true;
1263 cfg.compilingModified = true;
1265 cfg.linkingModified = true;
1267 cfg.symbolGenModified = true;
1269 if(compiling || linking)
1271 ide.projectView.modifiedDocument = true;
1272 ide.workspace.modified = true;
1276 void RotateActiveConfig(bool forward)
1278 if(configurations.first && configurations.last != configurations.first)
1280 Iterator<ProjectConfig> cfg { configurations };
1281 while(forward ? cfg.Next() : cfg.Prev())
1282 if(cfg.data == config)
1296 property::config = cfg.data;
1297 ide.workspace.modified = true;
1298 ide.projectView.Update(null);
1302 void ProcessPipeOutputRaw(DualPipe f)
1305 while(!f.Eof() && !ide.ShouldStopBuild())
1308 double lastTime = GetTime();
1312 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1314 ide.outputView.buildBox.Logf("%s\n", line);
1316 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1318 //printf("Processing Input...\n");
1319 if(app.ProcessInput(true))
1321 app.UpdateDisplay();
1324 //printf("Waiting...\n");
1327 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1329 if(ide.ShouldStopBuild())
1331 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1336 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode,
1337 CompilerConfig compiler, ProjectConfig config)
1340 bool compiling = false, linking = false, precompiling = false;
1341 int compilingEC = 0;
1342 int numErrors = 0, numWarnings = 0;
1343 bool loggedALine = false;
1344 char * configName = config.name;
1345 int lenMakeCommand = strlen(compiler.makeCommand);
1347 char cppCommand[MAX_LOCATION];
1348 char ccCommand[MAX_LOCATION];
1349 char cxxCommand[MAX_LOCATION];
1350 char ecpCommand[MAX_LOCATION];
1351 char eccCommand[MAX_LOCATION];
1352 char ecsCommand[MAX_LOCATION];
1353 char earCommand[MAX_LOCATION];
1355 char * cc = compiler.ccCommand;
1356 char * cxx = compiler.cxxCommand;
1357 char * cpp = compiler.cppCommand;
1358 sprintf(cppCommand, "%s%s%s%s ",
1359 compiler.ccacheEnabled ? "ccache " : "",
1360 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1361 compiler.distccEnabled ? "distcc " : "",
1362 compiler.cppCommand);
1363 sprintf(ccCommand, "%s%s%s%s ",
1364 compiler.ccacheEnabled ? "ccache " : "",
1365 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1366 compiler.distccEnabled ? "distcc " : "",
1367 compiler.ccCommand);
1368 sprintf(cxxCommand, "%s%s%s%s ",
1369 compiler.ccacheEnabled ? "ccache " : "",
1370 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1371 compiler.distccEnabled ? "distcc " : "",
1372 compiler.cxxCommand);
1373 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1374 sprintf(eccCommand, "%s ", compiler.eccCommand);
1375 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1376 sprintf(earCommand, "%s ", compiler.earCommand);
1378 while(!f.Eof() && !ide.ShouldStopBuild())
1381 double lastTime = GetTime();
1385 //printf("Peeking and GetLine...\n");
1386 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1388 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1389 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1391 char * module = strstr(line, "No rule to make target `");
1395 module = strchr(module, '`') + 1;
1396 end = strchr(module, '\'');
1400 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1401 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1407 //ide.outputView.buildBox.Logf("error: %s\n", line);
1411 else if(strstr(line, "ear ") == line);
1412 else if(strstr(line, "strip ") == line);
1413 else if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1415 char moduleName[MAX_FILENAME];
1418 bool isPrecomp = false;
1420 if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line)
1422 module = strstr(line, " -c ");
1423 if(module) module += 4;
1425 else if(strstr(line, eccCommand) == line)
1427 module = strstr(line, " -c ");
1428 if(module) module += 4;
1429 //module = line + 3;
1430 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1431 compilingEC = 3;//2;
1433 else if(strstr(line, ecpCommand) == line)
1435 // module = line + 8;
1436 module = strstr(line, " -c ");
1437 if(module) module += 4;
1446 if(!compiling && !isPrecomp)
1448 ide.outputView.buildBox.Logf($"Compiling...\n");
1451 else if(!precompiling && isPrecomp)
1453 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1454 precompiling = true;
1456 // Changed escapeBackSlashes here to handle paths with spaces
1457 Tokenize(module, 1, tokens, true); // false);
1458 GetLastDirectory(module, moduleName);
1459 ide.outputView.buildBox.Logf("%s\n", moduleName);
1461 else if((module = strstr(line, " -o ")))
1464 precompiling = false;
1466 ide.outputView.buildBox.Logf($"Linking...\n");
1470 ide.outputView.buildBox.Logf("%s\n", line);
1474 if(compilingEC) compilingEC--;
1476 else if(strstr(line, "ar rcs") == line)
1477 ide.outputView.buildBox.Logf($"Building library...\n");
1478 else if(strstr(line, ecsCommand) == line)
1479 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1482 if(linking || compiling || precompiling)
1484 char * colon = strstr(line, ":"); //, * bracket;
1485 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1486 colon = strstr(colon + 1, ":");
1489 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1492 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1493 int len = (int)(colon - start);
1494 len = Min(len, MAX_LOCATION-1);
1495 // Don't be mistaken by the drive letter colon
1497 // TODO: need to fix colon - line gives char *
1498 // warning: incompatible expression colon - line (char *); expected int
1500 strncpy(moduleName, line, (int)(colon - line));
1501 moduleName[colon - line] = '\0';
1503 strncpy(moduleName, start, len);
1504 moduleName[len] = '\0';
1505 // Remove stuff in brackets
1506 //bracket = strstr(moduleName, "(");
1507 //if(bracket) *bracket = '\0';
1509 GetLastDirectory(moduleName, temp);
1510 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1513 strcpy(moduleName, $"Linker Error");
1517 strcpy(temp, topNode.path);
1518 PathCatSlash(temp, moduleName);
1519 MakePathRelative(temp, topNode.path, moduleName);
1521 if(strstr(line, "error:"))
1525 // Silence warnings for compiled EC
1526 char * objDir = strstr(moduleName, objDirExp.dir);
1530 if((pointer = strstr(line, "undefined")) ||
1531 (pointer = strstr(line, "No such file")) ||
1532 (pointer = strstr(line, "token")))
1534 strncat(moduleName, colon, pointer - colon);
1535 strcat(moduleName, "error: ");
1540 else if((pointer = strstr(line, "No such file")))
1542 strncat(moduleName, colon, pointer - colon);
1543 strcat(moduleName, "error: ");
1547 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1549 else if(strstr(line, "warning:"))
1554 if(this == ide.workspace.projects.firstIterator.data)
1555 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1558 char fullModuleName[MAX_LOCATION];
1559 strcpy(fullModuleName, topNode.path);
1560 PathCat(fullModuleName, moduleName);
1561 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1562 MakeSystemPath(fullModuleName);
1563 ide.outputView.buildBox.Logf(" %s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : "", fullModuleName, colon);
1568 ide.outputView.buildBox.Logf("%s\n", line);
1569 linking = compiling = precompiling = false;
1573 ide.outputView.buildBox.Logf("%s\n", line);
1577 //printf("Done getting line\n");
1578 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1580 //printf("Processing Input...\n");
1581 if(app.ProcessInput(true))
1583 app.UpdateDisplay();
1586 //printf("Waiting...\n");
1589 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1591 if(ide.ShouldStopBuild())
1593 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1596 else if(loggedALine || !isARun)
1598 if(f.GetExitCode() && !numErrors)
1600 bool result = f.GetLine(line, sizeof(line)-1);
1601 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1606 ide.outputView.buildBox.Logf("\n%s (%s) - ", GetTargetFileName(config), configName);
1608 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1610 ide.outputView.buildBox.Logf($"no error, ");
1613 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1615 ide.outputView.buildBox.Logf($"no warning\n");
1618 return numErrors == 0;
1621 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1624 int lenMakeCommand = strlen(compiler.makeCommand);
1629 double lastTime = GetTime();
1632 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1634 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1635 else if(strstr(line, "del") == line);
1636 else if(strstr(line, "rm") == line);
1637 else if(strstr(line, "Could Not Find") == line);
1640 ide.outputView.buildBox.Logf(line);
1641 ide.outputView.buildBox.Logf("\n");
1645 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1647 if(app.ProcessInput(true))
1649 app.UpdateDisplay();
1652 //Sleep(1.0 / PEEK_RESOLUTION);
1656 bool Build(bool isARun, ProjectNode onlyNode, CompilerConfig compiler, ProjectConfig config)
1658 bool result = false;
1660 char targetFileName[MAX_LOCATION] = "";
1661 char makeTarget[MAX_LOCATION] = "";
1662 char makeFile[MAX_LOCATION];
1663 char makeFilePath[MAX_LOCATION];
1664 char configName[MAX_LOCATION];
1665 DirExpression objDirExp = GetObjDir(compiler, config);
1666 PathBackup pathBackup { };
1667 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1668 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1670 int numJobs = compiler.numJobs;
1671 char command[MAX_LOCATION];
1672 char * compilerName;
1674 compilerName = CopyString(compiler.name);
1675 CamelCase(compilerName);
1677 strcpy(configName, config ? config.name : "Common");
1679 SetPath(false, compiler, config); //true
1680 CatTargetFileName(targetFileName, compiler, config);
1682 strcpy(makeFilePath, topNode.path);
1683 CatMakeFileName(makeFile, config);
1684 PathCatSlash(makeFilePath, makeFile);
1686 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1689 if(compiler.type.isVC)
1691 PrintLn("compiling a single file is not yet supported");
1696 char pushD[MAX_LOCATION];
1697 char cfDir[MAX_LOCATION];
1698 GetIDECompilerConfigsDir(cfDir, true, true);
1699 GetWorkingDir(pushD, sizeof(pushD));
1700 ChangeWorkingDir(topNode.path);
1701 // Create object dir if it does not exist already
1702 if(!FileExists(objDirExp.dir).isDirectory)
1704 sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s objdir -C \"%s\" -f \"%s\"",
1705 compiler.makeCommand, cfDir,
1706 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
1707 compilerName, topNode.path, makeFilePath);
1710 ide.outputView.buildBox.Logf("command: %s\n", command);
1715 ChangeWorkingDir(pushD);
1717 PathCatSlash(makeTarget+1, objDirExp.dir);
1718 PathCatSlash(makeTarget+1, onlyNode.name);
1719 StripExtension(makeTarget+1);
1720 strcat(makeTarget+1, ".o");
1721 makeTarget[0] = '\"';
1722 len = strlen(makeTarget);
1723 makeTarget[len++] = '\"';
1724 makeTarget[len++] = '\0';
1728 if(compiler.type.isVC)
1730 bool result = false;
1731 char oldwd[MAX_LOCATION];
1732 GetWorkingDir(oldwd, sizeof(oldwd));
1733 ChangeWorkingDir(topNode.path);
1735 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1736 ide.outputView.buildBox.Logf("command: %s\n", command);
1739 ide.outputView.buildBox.Logf("command: %s\n", command);
1741 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1743 ProcessPipeOutputRaw(f);
1747 ChangeWorkingDir(oldwd);
1751 char cfDir[MAX_LOCATION];
1752 GetIDECompilerConfigsDir(cfDir, true, true);
1753 sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s -j%d %s%s%s -C \"%s\" -f \"%s\"",
1754 compiler.makeCommand, cfDir,
1755 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
1756 compilerName, numJobs,
1757 compiler.ccacheEnabled ? "CCACHE=y " : "",
1758 compiler.distccEnabled ? "DISTCC=y " : "",
1759 makeTarget, topNode.path, makeFilePath);
1762 ide.outputView.buildBox.Logf("command: %s\n", command);
1764 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1766 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode, compiler, config);
1771 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
1773 ide.outputView.buildBox.Logf("command: %s\n", command);
1780 delete compilerName;
1784 void Clean(CompilerConfig compiler, ProjectConfig config, bool realclean)
1786 char makeFile[MAX_LOCATION];
1787 char makeFilePath[MAX_LOCATION];
1788 char command[MAX_LOCATION];
1789 char * compilerName;
1791 PathBackup pathBackup { };
1792 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1793 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1795 compilerName = CopyString(compiler.name);
1796 CamelCase(compilerName);
1798 SetPath(false, compiler, config);
1800 strcpy(makeFilePath, topNode.path);
1801 CatMakeFileName(makeFile, config);
1802 PathCatSlash(makeFilePath, makeFile);
1804 if(compiler.type.isVC)
1806 bool result = false;
1807 char oldwd[MAX_LOCATION];
1808 GetWorkingDir(oldwd, sizeof(oldwd));
1809 ChangeWorkingDir(topNode.path);
1811 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1812 ide.outputView.buildBox.Logf("command: %s\n", command);
1815 ide.outputView.buildBox.Logf("command: %s\n", command);
1817 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1819 ProcessPipeOutputRaw(f);
1823 ChangeWorkingDir(oldwd);
1828 char cfDir[MAX_LOCATION];
1829 GetIDECompilerConfigsDir(cfDir, true, true);
1830 sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s %sclean -C \"%s\" -f \"%s\"",
1831 compiler.makeCommand, cfDir,
1832 crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
1833 compilerName, realclean ? "real" : "", topNode.path, makeFilePath);
1836 ide.outputView.buildBox.Logf("command: %s\n", command);
1838 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1840 ide.outputView.buildBox.Tell($"Deleting target and object files...");
1841 ProcessCleanPipeOutput(f, compiler, config);
1844 ide.outputView.buildBox.Logf($"Target and object files deleted\n");
1849 delete compilerName;
1852 void Run(char * args, CompilerConfig compiler, ProjectConfig config)
1854 String target = new char[maxPathLen];
1855 char oldDirectory[MAX_LOCATION];
1856 DirExpression targetDirExp = GetTargetDir(compiler, config);
1857 PathBackup pathBackup { };
1859 // Build(project, ideMain, true, null);
1861 #if defined(__WIN32__)
1862 strcpy(target, topNode.path);
1866 PathCatSlash(target, targetDirExp.dir);
1867 CatTargetFileName(target, compiler, config);
1868 sprintf(target, "%s %s", target, args);
1869 GetWorkingDir(oldDirectory, MAX_LOCATION);
1871 if(strlen(ide.workspace.debugDir))
1873 char temp[MAX_LOCATION];
1874 strcpy(temp, topNode.path);
1875 PathCatSlash(temp, ide.workspace.debugDir);
1876 ChangeWorkingDir(temp);
1879 ChangeWorkingDir(topNode.path);
1880 // ChangeWorkingDir(topNode.path);
1881 SetPath(true, compiler, config);
1882 if(compiler.execPrefixCommand)
1884 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1885 prefixedTarget[0] = '\0';
1886 strcat(prefixedTarget, compiler.execPrefixCommand);
1887 strcat(prefixedTarget, " ");
1888 strcat(prefixedTarget, target);
1889 Execute(prefixedTarget);
1890 delete prefixedTarget;
1895 ChangeWorkingDir(oldDirectory);
1898 delete targetDirExp;
1902 void Compile(ProjectNode node, CompilerConfig compiler, ProjectConfig config)
1904 Build(false, node, compiler, config);
1908 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
1911 if(targetType == staticLibrary || targetType == sharedLibrary)
1912 strcat(fileName, "$(LP)");
1913 // !!! ReplaceSpaces must be done after all PathCat calls !!!
1914 // ReplaceSpaces(s, GetTargetFileName(config));
1915 strcat(fileName, GetTargetFileName(config));
1919 strcat(fileName, "$(E)");
1922 strcat(fileName, "$(SO)");
1925 strcat(fileName, "$(A)");
1930 bool GenerateCrossPlatformMk()
1932 bool result = false;
1933 char path[MAX_LOCATION];
1935 if(!GetProjectCompilerConfigsDir(path, false, false))
1936 GetIDECompilerConfigsDir(path, false, false);
1938 if(!FileExists(path).isDirectory)
1942 char dirName[MAX_FILENAME];
1943 GetLastDirectory(path, dirName);
1944 if(!strcmp(dirName, ".configs"))
1945 FileSetAttribs(path, FileAttribs { isHidden = true });
1948 PathCatSlash(path, "crossplatform.mk");
1950 if(FileExists(path))
1953 File include = FileOpen(":crossplatform.mk", read);
1956 File f = FileOpen(path, write);
1959 for(; !include.Eof(); )
1962 int count = include.Read(buffer, 1, 4096);
1963 f.Write(buffer, 1, count);
1975 bool GenerateCompilerCf(CompilerConfig compiler)
1977 bool result = false;
1978 char path[MAX_LOCATION];
1980 char * compilerName;
1981 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
1982 Platform platform = compiler.targetPlatform;
1984 compilerName = CopyString(compiler.name);
1985 CamelCase(compilerName);
1986 name = PrintString(platform, "-", compilerName, ".cf");
1988 if(!GetProjectCompilerConfigsDir(path, false, false))
1989 GetIDECompilerConfigsDir(path, false, false);
1991 if(!FileExists(path).isDirectory)
1995 char dirName[MAX_FILENAME];
1996 GetLastDirectory(path, dirName);
1997 if(!strcmp(dirName, ".configs"))
1998 FileSetAttribs(path, FileAttribs { isHidden = true });
2001 PathCatSlash(path, name);
2003 if(FileExists(path))
2006 File f = FileOpen(path, write);
2009 f.Printf("# TOOLCHAIN\n\n");
2011 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2012 f.Printf("CPP := %s\n", compiler.cppCommand);
2013 f.Printf("CC := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.ccCommand);
2014 f.Printf("CXX := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.cxxCommand);
2015 f.Printf("ECP := %s\n", compiler.ecpCommand);
2016 f.Printf("ECC := %s\n", compiler.eccCommand);
2017 f.Printf("ECS := %s -t $(TARGET_PLATFORM)\n", compiler.ecsCommand);
2018 f.Printf("EAR := %s\n", compiler.earCommand);
2020 f.Printf("AS := as\n");
2021 f.Printf("LD := ld\n");
2022 f.Printf("AR := ar\n");
2023 f.Printf("STRIP := strip\n");
2024 f.Printf("UPX := upx\n");
2027 if(compiler.environmentVars && compiler.environmentVars.count)
2029 f.Printf("# ENVIRONMENT VARIABLES\n");
2030 for(e : compiler.environmentVars)
2032 f.Printf("export %s := %s\n", e.name, e.string);
2036 f.Printf("UPXFLAGS = -9\n\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2038 f.Printf("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2039 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(tux));
2040 f.Printf("LDFLAGS += -Wl,--no-undefined\n");
2041 f.Printf("endif\n\n");
2044 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(apple));
2045 f.Printf("LDFLAGS += -framework cocoa -framework OpenGL\n");
2046 f.Printf("endif\n");
2050 f.Printf("\nCFLAGS += -fmessage-length=0\n");
2053 if(compiler.includeDirs && compiler.includeDirs.count)
2055 f.Printf("\nCFLAGS +=");
2056 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
2059 if(compiler.prepDirectives && compiler.prepDirectives.count)
2061 f.Printf("\nCFLAGS +=");
2062 OutputListOption(f, "D", compiler.prepDirectives, inPlace, true);
2065 if(compiler.libraryDirs && compiler.libraryDirs.count)
2067 f.Printf("\nLDFLAGS +=");
2068 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
2069 // We would need a bool option to know whether we want to add to rpath as well...
2070 // OutputListOption(f, "Wl,-rpath ", compiler.libraryDirs, lineEach, true);
2073 if(compiler.excludeLibs && compiler.excludeLibs.count)
2075 f.Puts("\nEXCLUDED_LIBS =");
2076 for(l : compiler.excludeLibs)
2082 if(compiler.linkerFlags && compiler.linkerFlags.count)
2084 f.Printf("\nLDFLAGS +=");
2085 OutputListOption(f, "Wl,", compiler.linkerFlags, inPlace, true);
2088 f.Printf("\nFORCE_64_BIT = %s", compiler.supportsBitDepth ? "-m64" : "");
2089 f.Printf("\nFORCE_32_BIT = %s", compiler.supportsBitDepth ? "-m32" : "");
2096 delete compilerName;
2100 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2102 bool result = false;
2103 char filePath[MAX_LOCATION];
2104 char makeFile[MAX_LOCATION];
2105 // PathBackup pathBackup { };
2106 // char oldDirectory[MAX_LOCATION];
2109 if(!altMakefilePath)
2111 strcpy(filePath, topNode.path);
2112 CatMakeFileName(makeFile, config);
2113 PathCatSlash(filePath, makeFile);
2116 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2118 /*SetPath(false, compiler, config);
2119 GetWorkingDir(oldDirectory, MAX_LOCATION);
2120 ChangeWorkingDir(topNode.path);*/
2127 char targetDir[MAX_LOCATION];
2128 char objDirExpNoSpaces[MAX_LOCATION];
2129 char objDirNoSpaces[MAX_LOCATION];
2130 char resDirNoSpaces[MAX_LOCATION];
2131 char targetDirExpNoSpaces[MAX_LOCATION];
2132 char fixedModuleName[MAX_FILENAME];
2133 char fixedConfigName[MAX_FILENAME];
2135 // Non-zero if we're building eC code
2136 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2137 int numCObjects = 0;
2138 bool containsCXX = false; // True if the project contains a C++ file
2139 bool sameObjTargetDirs;
2140 String objDirExp = GetObjDirExpression(config);
2141 TargetTypes targetType = GetTargetType(config);
2143 char cfDir[MAX_LOCATION];
2144 int objectsParts, eCsourcesParts;
2145 Array<String> listItems { };
2146 Map<String, int> varStringLenDiffs { };
2147 Map<String, NameCollisionInfo> namesInfo { };
2148 bool forceBitDepth = false;
2150 ReplaceSpaces(objDirNoSpaces, objDirExp);
2151 strcpy(targetDir, GetTargetDirExpression(config));
2152 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2154 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2155 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2156 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
2157 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2158 ReplaceSpaces(fixedModuleName, moduleName);
2159 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2160 CamelCase(fixedConfigName);
2162 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2164 f.Printf(".PHONY: all objdir%s clean realclean\n\n", sameObjTargetDirs ? "" : " targetdir");
2166 f.Printf("# CONTENT\n\n");
2168 f.Printf("MODULE := %s\n", fixedModuleName);
2169 //f.Printf("VERSION = %s\n", version);
2170 f.Printf("CONFIG := %s\n", fixedConfigName);
2171 f.Printf("ifndef COMPILER\n");
2172 f.Printf("COMPILER := default\n");
2173 f.Printf("endif\n");
2176 if(compilerConfigsDir && compilerConfigsDir[0])
2178 strcpy(cfDir, compilerConfigsDir);
2179 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2184 GetIDECompilerConfigsDir(cfDir, true, true);
2185 // Use CF_DIR environment variable for absolute paths only
2186 if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2187 strcpy(cfDir, "$(CF_DIR)");
2190 f.Printf("_CF_DIR = %s\n", cfDir);
2193 f.Printf("ifndef DEBUG\n");
2194 f.Printf("OPTIMIZE :=");
2195 switch(GetOptimization(config))
2199 f.Printf(" -ffast-math");
2205 if(GetDebug(config))
2209 f.Printf("OPTIMIZE := -g\n");
2210 f.Printf("NOSTRIP := y\n");
2211 f.Printf("endif\n");
2213 test = GetTargetTypeIsSetByPlatform(config);
2217 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2219 TargetTypes targetType;
2220 PlatformOptions projectPOs, configPOs;
2221 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2222 targetType = platformTargetType;
2228 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2230 f.Printf("TARGET_TYPE = ");
2231 f.Printf(TargetTypeToMakefileVariable(targetType));
2235 f.Printf("else\n"); // ifCount should always be > 0
2237 f.Printf("TARGET_TYPE = ");
2238 f.Printf(TargetTypeToMakefileVariable(targetType));
2244 for(c = 0; c < ifCount; c++)
2245 f.Printf("endif\n");
2250 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2251 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2252 f.Printf("endif\n\n");
2254 f.Printf("# FLAGS\n\n");
2256 f.Printf("CFLAGS =\n");
2257 f.Printf("CECFLAGS =\n");
2258 f.Printf("ECFLAGS =\n");
2259 f.Printf("OFLAGS =\n");
2260 f.Printf("LDFLAGS =\n");
2261 f.Printf("LIBS =\n");
2264 f.Printf("# INCLUDES\n\n");
2266 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2267 f.Printf("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2270 f.Printf("# VARIABLES\n\n");
2272 f.Printf("OBJ = %s%s\n\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2274 f.Printf("ifdef DEBUG\n");
2275 f.Printf("CFLAGS += -D_DEBUG\n");
2276 f.Printf("endif\n\n");
2278 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2280 // test = GetTargetTypeIsSetByPlatform(config);
2282 char target[MAX_LOCATION];
2283 char targetNoSpaces[MAX_LOCATION];
2288 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2290 if(type != targetType)
2295 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2297 GetMakefileTargetFileName(type, target, config);
2298 strcpy(targetNoSpaces, targetDir);
2299 PathCatSlash(targetNoSpaces, target);
2300 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2301 f.Printf("TARGET = %s\n", targetNoSpaces);
2304 f.Printf("else\n"); // ifCount should always be > 0
2306 GetMakefileTargetFileName(targetType, target, config);
2307 strcpy(targetNoSpaces, targetDir);
2308 PathCatSlash(targetNoSpaces, target);
2309 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2310 f.Printf("TARGET = %s\n", targetNoSpaces);
2316 for(c = 0; c < ifCount; c++)
2317 f.Printf("endif\n");
2323 // Use something fixed here, to not cause Makefile differences across compilers...
2324 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2325 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2327 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2329 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2331 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
2332 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs, null);
2336 char * map[4][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "BOWLS", "B" } };
2338 topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2339 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2341 f.Printf("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2342 if(eCsourcesParts > 1)
2344 for(c = 1; c <= eCsourcesParts; c++)
2345 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2349 for(c = 0; c < 3; c++)
2351 if(eCsourcesParts > 1)
2354 f.Printf("%s =", map[c][0]);
2355 for(n = 1; n <= eCsourcesParts; n++)
2356 f.Printf(" $(%s%d)", map[c][0], n);
2358 for(n = 1; n <= eCsourcesParts; n++)
2359 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2361 else if(eCsourcesParts == 1)
2362 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2367 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2368 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, "$(ECSOURCES)");
2371 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2372 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2374 f.Printf("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
2375 if((config && config.options && config.options.libraries) ||
2376 (options && options.libraries))
2378 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2379 f.Printf("LIBS +=");
2380 if(config && config.options && config.options.libraries)
2381 OutputLibraries(f, config.options.libraries);
2382 else if(options && options.libraries)
2383 OutputLibraries(f, options.libraries);
2385 f.Printf("endif\n");
2389 if(platforms || (config && config.platforms))
2392 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2393 //for(platform = win32; platform <= apple; platform++)
2395 f.Printf("# TARGET_PLATFORM-SPECIFIC OPTIONS\n\n");
2396 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2398 PlatformOptions projectPlatformOptions, configPlatformOptions;
2399 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2401 if(projectPlatformOptions || configPlatformOptions)
2406 f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2409 if((projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions && projectPlatformOptions.options.preprocessorDefinitions.count) ||
2410 (configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions && configPlatformOptions.options.preprocessorDefinitions.count) ||
2411 (projectPlatformOptions && projectPlatformOptions.options.includeDirs && projectPlatformOptions.options.includeDirs.count) ||
2412 (configPlatformOptions && configPlatformOptions.options.includeDirs && configPlatformOptions.options.includeDirs.count))
2414 f.Printf("CFLAGS +=");
2415 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2417 f.Printf(" \\\n\t -Wl");
2418 for(s : projectPlatformOptions.options.linkerOptions)
2421 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2423 f.Printf(" \\\n\t -Wl");
2424 for(s : configPlatformOptions.options.linkerOptions)
2427 if(projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions)
2428 OutputListOption(f, "D", projectPlatformOptions.options.preprocessorDefinitions, newLine, false);
2429 if(configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions)
2430 OutputListOption(f, "D", configPlatformOptions.options.preprocessorDefinitions, newLine, false );
2431 if(configPlatformOptions && configPlatformOptions.options.includeDirs)
2432 OutputListOption(f, "I", configPlatformOptions.options.includeDirs, lineEach, true);
2433 if(projectPlatformOptions && projectPlatformOptions.options.includeDirs)
2434 OutputListOption(f, "I", projectPlatformOptions.options.includeDirs, lineEach, true);
2438 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2439 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2440 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2441 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2443 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2444 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2445 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2447 f.Printf("OFLAGS +=");
2448 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2449 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2450 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2451 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2455 if((configPlatformOptions && configPlatformOptions.options.libraries))
2457 if(configPlatformOptions.options.libraries.count)
2459 f.Printf("LIBS +=");
2460 OutputLibraries(f, configPlatformOptions.options.libraries);
2464 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
2466 if(projectPlatformOptions.options.libraries.count)
2468 f.Printf("LIBS +=");
2469 OutputLibraries(f, projectPlatformOptions.options.libraries);
2473 f.Printf("endif\n\n");
2479 for(c = 0; c < ifCount; c++)
2480 f.Printf("endif\n");
2485 f.Printf("CFLAGS +=");
2488 f.Printf(" $(OPTIMIZE)");
2489 forceBitDepth = (options && options.buildBitDepth) || numCObjects;
2491 f.Printf(" %s",(!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? "$(FORCE_32_BIT)" : "$(FORCE_64_BIT)");
2492 f.Printf(" $(FPIC)");
2494 switch(GetWarnings(config))
2496 case all: f.Printf(" -Wall"); break;
2497 case none: f.Printf(" -w"); break;
2499 if(GetProfile(config))
2501 if(options && options.linkerOptions && options.linkerOptions.count)
2503 f.Printf(" \\\n\t -Wl");
2504 for(s : options.linkerOptions)
2508 if(options && options.preprocessorDefinitions)
2509 OutputListOption(f, "D", options.preprocessorDefinitions, newLine, false);
2510 if(config && config.options && config.options.preprocessorDefinitions)
2511 OutputListOption(f, "D", config.options.preprocessorDefinitions, newLine, false);
2512 if(config && config.options && config.options.includeDirs)
2513 OutputListOption(f, "I", config.options.includeDirs, lineEach, true);
2514 if(options && options.includeDirs)
2515 OutputListOption(f, "I", options.includeDirs, lineEach, true);
2518 f.Printf("CECFLAGS += -cpp $(call escspace,$(CPP)) -t $(TARGET_PLATFORM)");
2521 f.Printf("ECFLAGS +=");
2522 if(GetMemoryGuard(config))
2523 f.Printf(" -memguard");
2524 if(GetStrictNameSpaces(config))
2525 f.Printf(" -strictns");
2526 if(GetNoLineNumbers(config))
2527 f.Printf(" -nolinenumbers");
2530 if((s = GetDefaultNameSpace(config)) && s[0])
2531 f.Printf(" -defaultns %s", s);
2535 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2536 f.Printf("OFLAGS +=");
2538 f.Printf((!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? " -m32" : " -m64 \\\n");
2540 if(GetProfile(config))
2542 if(config && config.options && config.options.libraryDirs)
2543 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
2544 if(options && options.libraryDirs)
2545 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
2547 f.Printf("OFLAGS += $(LDFLAGS)\n");
2548 f.Printf("endif\n\n");
2550 f.Printf("# TARGETS\n\n");
2552 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
2554 f.Printf("objdir:\n");
2555 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2556 //f.Printf("# PRE-BUILD COMMANDS\n");
2557 if(options && options.prebuildCommands)
2559 for(s : options.prebuildCommands)
2560 if(s && s[0]) f.Printf("\t%s\n", s);
2562 if(config && config.options && config.options.prebuildCommands)
2564 for(s : config.options.prebuildCommands)
2565 if(s && s[0]) f.Printf("\t%s\n", s);
2567 if(platforms || (config && config.platforms))
2570 //f.Printf("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2571 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2573 PlatformOptions projectPOs, configPOs;
2574 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2576 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2577 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2583 f.Printf(PlatformToMakefileVariable(platform));
2586 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2588 for(s : projectPOs.options.prebuildCommands)
2589 if(s && s[0]) f.Printf("\t%s\n", s);
2591 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2593 for(s : configPOs.options.prebuildCommands)
2594 if(s && s[0]) f.Printf("\t%s\n", s);
2601 for(c = 0; c < ifCount; c++)
2602 f.Printf("endif\n");
2607 if(!sameObjTargetDirs)
2609 f.Printf("targetdir:\n");
2610 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2615 // Main Module (Linking) for ECERE C modules
2616 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2617 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2618 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2619 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
2620 // Main Module (Linking) for ECERE C modules
2621 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2622 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2623 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2624 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2625 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2630 // This would not rebuild the target on updated objects
2631 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2633 // This should fix it for good!
2634 f.Printf("$(SYMBOLS): | objdir\n");
2635 f.Printf("$(OBJECTS): | objdir\n");
2637 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2638 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2640 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2641 f.Printf("\t$(%s) $(OFLAGS) $(OBJECTS) $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
2642 if(!GetDebug(config))
2644 f.Printf("ifndef NOSTRIP\n");
2645 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2646 f.Printf("endif\n");
2648 if(GetCompress(config))
2650 f.Printf("ifndef WINDOWS\n");
2651 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2652 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2653 f.Printf("endif\n");
2655 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2656 f.Printf("endif\n");
2659 if(resNode.files && resNode.files.count && !noResources)
2660 resNode.GenMakefileAddResources(f, resNode.path, config);
2662 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2663 f.Printf("endif\n");
2665 //f.Printf("# POST-BUILD COMMANDS\n");
2666 if(options && options.postbuildCommands)
2668 for(s : options.postbuildCommands)
2669 if(s && s[0]) f.Printf("\t%s\n", s);
2671 if(config && config.options && config.options.postbuildCommands)
2673 for(s : config.options.postbuildCommands)
2674 if(s && s[0]) f.Printf("\t%s\n", s);
2676 if(platforms || (config && config.platforms))
2679 //f.Printf("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2680 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2682 PlatformOptions projectPOs, configPOs;
2683 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2685 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2686 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2692 f.Printf(PlatformToMakefileVariable(platform));
2695 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2697 for(s : projectPOs.options.postbuildCommands)
2698 if(s && s[0]) f.Printf("\t%s\n", s);
2700 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2702 for(s : configPOs.options.postbuildCommands)
2703 if(s && s[0]) f.Printf("\t%s\n", s);
2710 for(c = 0; c < ifCount; c++)
2711 f.Printf("endif\n");
2716 f.Printf("# SYMBOL RULES\n\n");
2718 Map<Platform, bool> excludedPlatforms { };
2719 topNode.GenMakefilePrintSymbolRules(f, this, config, excludedPlatforms);
2720 delete excludedPlatforms;
2723 f.Printf("# C OBJECT RULES\n\n");
2725 Map<Platform, bool> excludedPlatforms { };
2726 topNode.GenMakefilePrintCObjectRules(f, this, config, excludedPlatforms);
2727 delete excludedPlatforms;
2730 f.Printf("# OBJECT RULES\n\n");
2731 // todo call this still but only generate rules whith specific options
2732 // see we-have-file-specific-options in ProjectNode.ec
2734 Map<Platform, bool> excludedPlatforms { };
2735 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, excludedPlatforms);
2736 delete excludedPlatforms;
2740 GenMakefilePrintMainObjectRule(f, config);
2742 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2743 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) " : "");
2744 OutputCleanActions(f, "OBJECTS", objectsParts);
2747 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
2748 OutputCleanActions(f, "BOWLS", eCsourcesParts);
2749 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
2750 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
2754 f.Printf("realclean: clean\n");
2755 f.Printf("\t$(call rmrq,$(OBJ))\n");
2756 if(!sameObjTargetDirs)
2757 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2764 varStringLenDiffs.Free();
2765 delete varStringLenDiffs;
2772 // ChangeWorkingDir(oldDirectory);
2773 // delete pathBackup;
2776 config.makingModified = false;
2780 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
2782 char extension[MAX_EXTENSION] = "c";
2783 char modulePath[MAX_LOCATION];
2784 char fixedModuleName[MAX_FILENAME];
2787 char objDirNoSpaces[MAX_LOCATION];
2788 String objDirExp = GetObjDirExpression(config);
2790 ReplaceSpaces(objDirNoSpaces, objDirExp);
2791 ReplaceSpaces(fixedModuleName, moduleName);
2793 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2794 //strcat(fixedModuleName, ".main");
2796 #if 0 // TODO: Fix nospaces stuff
2797 // *** Dependency command ***
2798 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2800 // System Includes (from global settings)
2801 for(item : compiler.dirs[Includes])
2803 strcat(command, " -isystem ");
2804 if(strchr(item.name, ' '))
2806 strcat(command, "\"");
2807 strcat(command, item);
2808 strcat(command, "\"");
2811 strcat(command, item);
2814 for(item = includeDirs.first; item; item = item.next)
2816 strcat(command, " -I");
2817 if(strchr(item.name, ' '))
2819 strcat(command, "\"");
2820 strcat(command, item.name);
2821 strcat(command, "\"");
2824 strcat(command, item.name);
2826 for(item = preprocessorDefs.first; item; item = item.next)
2828 strcat(command, " -D");
2829 strcat(command, item.name);
2833 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2837 bool firstLine = true;
2839 // To do some time: auto save external dependencies?
2842 if(dep.GetLine(line, sizeof(line)-1))
2846 char * colon = strstr(line, ":");
2847 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2861 // If we failed to generate dependencies...
2865 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2871 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2874 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
2875 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
2877 *projectPlatformOptions = null;
2878 *configPlatformOptions = null;
2883 if(!strcmpi(p.name, platform))
2885 *projectPlatformOptions = p;
2890 if(config && config.platforms)
2892 for(p : config.platforms)
2894 if(!strcmpi(p.name, platform))
2896 *configPlatformOptions = p;
2904 Project LegacyBinaryLoadProject(File f, char * filePath)
2906 Project project = null;
2907 char signature[sizeof(epjSignature)];
2909 f.Read(signature, sizeof(signature), 1);
2910 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2912 char topNodePath[MAX_LOCATION];
2913 /*ProjectConfig newConfig
2915 name = CopyString("Default");
2916 makingModified = true;
2917 compilingModified = true;
2918 linkingModified = true;
2922 project = Project { options = { } };
2923 LegacyBinaryLoadNode(project.topNode, f);
2924 delete project.topNode.path;
2925 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2926 MakeSlashPath(topNodePath);
2928 PathCatSlash(topNodePath, filePath);
2929 project.filePath = topNodePath;
2931 /* THIS IS ALREADY DONE BY filePath property
2932 StripLastDirectory(topNodePath, topNodePath);
2933 project.topNode.path = CopyString(topNodePath);
2935 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2937 // newConfig.options.defaultNameSpace = "";
2938 /*newConfig.objDir.dir = "obj";
2939 newConfig.targetDir.dir = "";*/
2941 //project.configurations = { [ newConfig ] };
2942 //project.config = newConfig;
2949 String targetFileName, targetDirectory, objectsDirectory;
2951 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2952 f.Read(&temp, sizeof(int),1);
2955 case 0: project.options.targetType = executable; break;
2956 case 1: project.options.targetType = sharedLibrary; break;
2957 case 2: project.options.targetType = staticLibrary; break;
2960 f.Read(&len, sizeof(int),1);
2961 targetFileName = new char[len+1];
2962 f.Read(targetFileName, sizeof(char), len+1);
2963 project.options.targetFileName = targetFileName;
2964 delete targetFileName;
2966 f.Read(&len, sizeof(int),1);
2967 targetDirectory = new char[len+1];
2968 f.Read(targetDirectory, sizeof(char), len+1);
2969 project.options.targetDirectory = targetDirectory;
2970 delete targetDirectory;
2972 f.Read(&len, sizeof(int),1);
2973 objectsDirectory = new byte[len+1];
2974 f.Read(objectsDirectory, sizeof(char), len+1);
2975 project.options.objectsDirectory = objectsDirectory;
2976 delete objectsDirectory;
2978 f.Read(&temp, sizeof(int),1);
2979 project./*config.*/options.debug = temp ? true : false;
2980 f.Read(&temp, sizeof(int),1);
2981 project./*config.*/options.optimization = temp ? speed : none;
2982 f.Read(&temp, sizeof(int),1);
2983 project./*config.*/options.profile = temp ? true : false;
2984 f.Read(&temp, sizeof(int),1);
2985 project.options.warnings = temp ? all : unset;
2987 f.Read(&count, sizeof(int),1);
2990 project.options.includeDirs = { };
2991 for(c = 0; c < count; c++)
2994 f.Read(&len, sizeof(int),1);
2995 name = new char[len+1];
2996 f.Read(name, sizeof(char), len+1);
2997 project.options.includeDirs.Add(name);
3001 f.Read(&count, sizeof(int),1);
3004 project.options.libraryDirs = { };
3005 for(c = 0; c < count; c++)
3008 f.Read(&len, sizeof(int),1);
3009 name = new char[len+1];
3010 f.Read(name, sizeof(char), len+1);
3011 project.options.libraryDirs.Add(name);
3015 f.Read(&count, sizeof(int),1);
3018 project.options.libraries = { };
3019 for(c = 0; c < count; c++)
3022 f.Read(&len, sizeof(int),1);
3023 name = new char[len+1];
3024 f.Read(name, sizeof(char), len+1);
3025 project.options.libraries.Add(name);
3029 f.Read(&count, sizeof(int),1);
3032 project.options.preprocessorDefinitions = { };
3033 for(c = 0; c < count; c++)
3036 f.Read(&len, sizeof(int),1);
3037 name = new char[len+1];
3038 f.Read(name, sizeof(char), len+1);
3039 project.options.preprocessorDefinitions.Add(name);
3043 f.Read(&temp, sizeof(int),1);
3044 project.options.console = temp ? true : false;
3047 for(node : project.topNode.files)
3049 if(node.type == resources)
3051 project.resNode = node;
3061 void ProjectConfig::LegacyProjectConfigLoad(File f)
3069 char subSection[128];
3075 f.GetLine(buffer, 65536 - 1);
3076 TrimLSpaces(buffer, buffer);
3077 TrimRSpaces(buffer, buffer);
3080 if(buffer[0] == '-')
3084 TrimLSpaces(equal, equal);
3085 if(!strcmpi(subSection, "LibraryDirs"))
3087 if(!options.libraryDirs)
3088 options.libraryDirs = { [ CopyString(equal) ] };
3090 options.libraryDirs.Add(CopyString(equal));
3092 else if(!strcmpi(subSection, "IncludeDirs"))
3094 if(!options.includeDirs)
3095 options.includeDirs = { [ CopyString(equal) ] };
3097 options.includeDirs.Add(CopyString(equal));
3100 else if(buffer[0] == '+')
3111 TrimLSpaces(equal, equal);
3112 delete name; name = CopyString(equal); // property::name = equal;
3115 else if(!strcmpi(buffer, "Compiler Options"))
3116 strcpy(section, buffer);
3117 else if(!strcmpi(buffer, "IncludeDirs"))
3118 strcpy(subSection, buffer);
3119 else if(!strcmpi(buffer, "Linker Options"))
3120 strcpy(section, buffer);
3121 else if(!strcmpi(buffer, "LibraryDirs"))
3122 strcpy(subSection, buffer);
3123 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3130 equal = strstr(buffer, "=");
3134 TrimRSpaces(buffer, buffer);
3136 TrimLSpaces(equal, equal);
3137 if(!strcmpi(buffer, "Target Name"))
3138 options.targetFileName = /*CopyString(*/equal/*)*/;
3139 else if(!strcmpi(buffer, "Target Type"))
3141 if(!strcmpi(equal, "Executable"))
3142 options.targetType = executable;
3143 else if(!strcmpi(equal, "Shared"))
3144 options.targetType = sharedLibrary;
3145 else if(!strcmpi(equal, "Static"))
3146 options.targetType = staticLibrary;
3148 options.targetType = executable;
3150 else if(!strcmpi(buffer, "Target Directory"))
3151 options.targetDirectory = /*CopyString(*/equal/*)*/;
3152 else if(!strcmpi(buffer, "Console"))
3153 options.console = ParseTrueFalseValue(equal);
3154 else if(!strcmpi(buffer, "Libraries"))
3156 if(!options.libraries) options.libraries = { };
3157 ParseArrayValue(options.libraries, equal);
3159 else if(!strcmpi(buffer, "Intermediate Directory"))
3160 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3161 else if(!strcmpi(buffer, "Debug"))
3162 options.debug = ParseTrueFalseValue(equal);
3163 else if(!strcmpi(buffer, "Optimize"))
3165 if(!strcmpi(equal, "None"))
3166 options.optimization = none;
3167 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3168 options.optimization = speed;
3169 else if(!strcmpi(equal, "Size"))
3170 options.optimization = size;
3172 options.optimization = none;
3174 else if(!strcmpi(buffer, "Compress"))
3175 options.compress = ParseTrueFalseValue(equal);
3176 else if(!strcmpi(buffer, "Profile"))
3177 options.profile = ParseTrueFalseValue(equal);
3178 else if(!strcmpi(buffer, "AllWarnings"))
3179 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3180 else if(!strcmpi(buffer, "MemoryGuard"))
3181 options.memoryGuard = ParseTrueFalseValue(equal);
3182 else if(!strcmpi(buffer, "Default Name Space"))
3183 options.defaultNameSpace = CopyString(equal);
3184 else if(!strcmpi(buffer, "Strict Name Spaces"))
3185 options.strictNameSpaces = ParseTrueFalseValue(equal);
3186 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3188 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3189 ParseArrayValue(options.preprocessorDefinitions, equal);
3195 if(!options.targetDirectory && options.objectsDirectory)
3196 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3197 //if(!objDir.dir) objDir.dir = "obj";
3198 //if(!targetDir.dir) targetDir.dir = "";
3199 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3200 // if(!defaultNameSpace) property::defaultNameSpace = "";
3201 makingModified = true;
3204 Project LegacyAsciiLoadProject(File f, char * filePath)
3206 Project project = null;
3207 ProjectNode node = null;
3209 char parentPath[MAX_LOCATION];
3210 char section[128] = "";
3211 char subSection[128] = "";
3213 bool configurationsPresent = false;
3223 f.GetLine(buffer, 65536 - 1);
3224 TrimLSpaces(buffer, buffer);
3225 TrimRSpaces(buffer, buffer);
3228 if(buffer[0] == '-' || buffer[0] == '=')
3230 bool simple = buffer[0] == '-';
3233 TrimLSpaces(equal, equal);
3234 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3236 if(!project.config.options.libraryDirs)
3237 project.config.options.libraryDirs = { [ CopyString(equal) ] };
3239 project.config.options.libraryDirs.Add(CopyString(equal));
3241 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3243 if(!project.config.options.includeDirs)
3244 project.config.options.includeDirs = { [ CopyString(equal) ] };
3246 project.config.options.includeDirs.Add(CopyString(equal));
3248 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3250 len = strlen(equal);
3253 char temp[MAX_LOCATION];
3254 ProjectNode child { };
3255 // We don't need to do this anymore, fileName is just a property that sets name & path
3256 // child.fileName = CopyString(equal);
3259 child.name = CopyString(equal);
3260 child.path = CopyString(parentPath);
3264 GetLastDirectory(equal, temp);
3265 child.name = CopyString(temp);
3266 StripLastDirectory(equal, temp);
3267 child.path = CopyString(temp);
3269 child.nodeType = file;
3270 child.parent = parent;
3271 child.indent = parent.indent + 1;
3273 child.icon = NodeIcons::SelectFileIcon(child.name);
3274 parent.files.Add(child);
3280 StripLastDirectory(parentPath, parentPath);
3281 parent = parent.parent;
3285 else if(buffer[0] == '+')
3289 TrimLSpaces(equal, equal);
3290 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3292 char temp[MAX_LOCATION];
3293 ProjectNode child { };
3294 // NEW: Folders now have a path set like files
3295 child.name = CopyString(equal);
3296 strcpy(temp, parentPath);
3297 PathCatSlash(temp, child.name);
3298 child.path = CopyString(temp);
3300 child.parent = parent;
3301 child.indent = parent.indent + 1;
3302 child.type = folder;
3303 child.nodeType = folder;
3305 child.icon = folder;
3306 PathCatSlash(parentPath, child.name);
3307 parent.files.Add(child);
3312 else if(!strcmpi(section, "Configurations"))
3314 ProjectConfig newConfig
3316 makingModified = true;
3320 LegacyProjectConfigLoad(newConfig, f);
3321 project.configurations.Add(newConfig);
3324 else if(!strcmpi(buffer, "ECERE Project File"));
3325 else if(!strcmpi(buffer, "Version 0a"))
3326 ; //strcpy(version, "0a");
3327 else if(!strcmpi(buffer, "Version 0.1a"))
3328 ; //strcpy(version, "0.1a");
3329 else if(!strcmpi(buffer, "Configurations"))
3331 project.configurations.Free();
3332 project.config = null;
3333 strcpy(section, buffer);
3334 configurationsPresent = true;
3336 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3338 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3339 char topNodePath[MAX_LOCATION];
3340 // newConfig.defaultNameSpace = "";
3341 //newConfig.objDir.dir = "obj";
3342 //newConfig.targetDir.dir = "";
3343 project = Project { /*options = { }*/ };
3344 project.configurations = { [ newConfig ] };
3345 project.config = newConfig;
3346 // if(project.topNode.path) delete project.topNode.path;
3347 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3348 MakeSlashPath(topNodePath);
3349 PathCatSlash(topNodePath, filePath);
3350 project.filePath = topNodePath;
3351 parentPath[0] = '\0';
3352 parent = project.topNode;
3354 strcpy(section, "Target");
3359 if(equal[0] == '\"')
3361 StripQuotes(equal, equal);
3362 delete project.moduleName; project.moduleName = CopyString(equal);
3366 else if(!strcmpi(buffer, "Compiler Options"));
3367 else if(!strcmpi(buffer, "IncludeDirs"))
3368 strcpy(subSection, buffer);
3369 else if(!strcmpi(buffer, "Linker Options"));
3370 else if(!strcmpi(buffer, "LibraryDirs"))
3371 strcpy(subSection, buffer);
3372 else if(!strcmpi(buffer, "Files"))
3374 strcpy(section, "Target");
3375 strcpy(subSection, buffer);
3377 else if(!strcmpi(buffer, "Resources"))
3379 ProjectNode child { };
3380 parent.files.Add(child);
3381 child.parent = parent;
3382 child.indent = parent.indent + 1;
3383 child.name = CopyString(buffer);
3384 child.path = CopyString("");
3385 child.type = resources;
3387 child.icon = archiveFile;
3388 project.resNode = child;
3391 strcpy(subSection, buffer);
3395 equal = strstr(buffer, "=");
3399 TrimRSpaces(buffer, buffer);
3401 TrimLSpaces(equal, equal);
3403 if(!strcmpi(section, "Target"))
3405 if(!strcmpi(buffer, "Build Exclusions"))
3407 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3409 /*if(node && node.type != NodeTypes::project)
3410 ParseListValue(node.buildExclusions, equal);*/
3413 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
3415 delete project.resNode.path;
3416 project.resNode.path = CopyString(equal);
3417 PathCatSlash(parentPath, equal);
3421 else if(!strcmpi(buffer, "Intermediate Directory"))
3422 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3423 else if(!strcmpi(buffer, "Debug"))
3424 project.config.options.debug = ParseTrueFalseValue(equal);
3425 else if(!strcmpi(buffer, "Optimize"))
3427 if(!strcmpi(equal, "None"))
3428 project.config.options.optimization = none;
3429 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3430 project.config.options.optimization = speed;
3431 else if(!strcmpi(equal, "Size"))
3432 project.config.options.optimization = size;
3434 project.config.options.optimization = none;
3436 else if(!strcmpi(buffer, "Profile"))
3437 project.config.options.profile = ParseTrueFalseValue(equal);
3438 else if(!strcmpi(buffer, "MemoryGuard"))
3439 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
3442 if(!project.options) project.options = { };
3444 // Project Wide Settings (All configs)
3445 if(!strcmpi(buffer, "Target Name"))
3446 project.options.targetFileName = /*CopyString(*/equal/*)*/;
3447 else if(!strcmpi(buffer, "Target Type"))
3449 if(!strcmpi(equal, "Executable"))
3450 project.options.targetType = executable;
3451 else if(!strcmpi(equal, "Shared"))
3452 project.options.targetType = sharedLibrary;
3453 else if(!strcmpi(equal, "Static"))
3454 project.options.targetType = staticLibrary;
3456 project.options.targetType = executable;
3458 else if(!strcmpi(buffer, "Target Directory"))
3459 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
3460 else if(!strcmpi(buffer, "Console"))
3461 project.options.console = ParseTrueFalseValue(equal);
3462 else if(!strcmpi(buffer, "Libraries"))
3464 if(!project.options.libraries) project.options.libraries = { };
3465 ParseArrayValue(project.options.libraries, equal);
3467 else if(!strcmpi(buffer, "AllWarnings"))
3468 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3469 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3471 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3473 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
3474 ParseListValue(node.preprocessorDefs, equal);*/
3478 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
3479 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3490 SplitPlatformLibraries(project);
3492 if(configurationsPresent)
3493 CombineIdenticalConfigOptions(project);
3497 void SplitPlatformLibraries(Project project)
3499 if(project && project.configurations)
3501 for(cfg : project.configurations)
3503 if(cfg.options.libraries && cfg.options.libraries.count)
3505 Iterator<String> it { cfg.options.libraries };
3509 char * platformName = strstr(l, ":");
3512 PlatformOptions platform = null;
3514 if(!cfg.platforms) cfg.platforms = { };
3515 for(p : cfg.platforms)
3517 if(!strcmpi(platformName, p.name))
3525 platform = { name = CopyString(platformName), options = { libraries = { } } };
3526 cfg.platforms.Add(platform);
3528 *(platformName-1) = 0;
3529 platform.options.libraries.Add(CopyString(l));
3531 cfg.options.libraries.Delete(it.pointer);
3540 void CombineIdenticalConfigOptions(Project project)
3542 if(project && project.configurations && project.configurations.count)
3545 ProjectOptions nullOptions { };
3546 ProjectConfig firstConfig = null;
3547 for(cfg : project.configurations)
3549 if(cfg.options.targetType != staticLibrary)
3556 firstConfig = project.configurations.firstIterator.data;
3558 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3560 if(!member.isProperty)
3562 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3567 for(cfg : project.configurations)
3569 if(cfg != firstConfig)
3571 if(cfg.options.targetType != staticLibrary)
3575 if(type.type == noHeadClass || type.type == normalClass)
3577 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3578 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3579 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3583 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3584 (byte *)firstConfig.options + member.offset + member._class.offset,
3585 (byte *)cfg.options + member.offset + member._class.offset);
3597 if(type.type == noHeadClass || type.type == normalClass)
3599 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3600 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3601 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3606 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3607 (byte *)firstConfig.options + member.offset + member._class.offset,
3608 (byte *)nullOptions + member.offset + member._class.offset))
3612 if(!project.options) project.options = { };
3614 /*if(type.type == noHeadClass || type.type == normalClass)
3616 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3617 (byte *)project.options + member.offset + member._class.offset,
3618 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3622 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3623 // TOFIX: ListBox::SetData / OnCopy mess
3624 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3625 (byte *)project.options + member.offset + member._class.offset,
3626 (type.typeSize > 4) ? address :
3627 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3628 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3629 (void *)*(byte *)address )));
3632 (byte *)project.options + member.offset + member._class.offset,
3633 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3635 for(cfg : project.configurations)
3637 if(cfg.options.targetType == staticLibrary)
3641 if(type.type == noHeadClass || type.type == normalClass)
3643 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3644 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3645 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3649 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3650 (byte *)firstConfig.options + member.offset + member._class.offset,
3651 (byte *)cfg.options + member.offset + member._class.offset);
3656 if(cfg != firstConfig)
3658 if(type.type == noHeadClass || type.type == normalClass)
3660 type._vTbl[__ecereVMethodID_class_OnFree](type,
3661 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3665 type._vTbl[__ecereVMethodID_class_OnFree](type,
3666 (byte *)cfg.options + member.offset + member._class.offset);
3668 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3671 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3678 // Compare Platform Specific Settings
3681 for(cfg : project.configurations)
3683 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3684 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3690 if(same && firstConfig.platforms)
3692 for(cfg : project.configurations)
3694 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3696 if(cfg != firstConfig)
3698 cfg.platforms.Free();
3699 delete cfg.platforms;
3702 project.platforms = firstConfig.platforms;
3703 firstConfig.platforms = null;
3707 // Static libraries can't contain libraries
3708 for(cfg : project.configurations)
3710 if(cfg.options.targetType == staticLibrary)
3712 if(!cfg.options.libraries) cfg.options.libraries = { };
3713 cfg.options.libraries.Free();
3719 Project LoadProject(char * filePath)
3721 Project project = null;
3722 File f = FileOpen(filePath, read);
3725 project = LegacyBinaryLoadProject(f, filePath);
3728 JSONParser parser { f = f };
3729 JSONResult result = parser.GetObject(class(Project), &project);
3732 char insidePath[MAX_LOCATION];
3734 delete project.topNode.files;
3735 if(!project.files) project.files = { };
3736 project.topNode.files = project.files;
3737 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3738 delete project.resNode.path;
3739 project.resNode.path = project.resourcesPath;
3740 project.resourcesPath = null;
3741 project.resNode.nodeType = (ProjectNodeType)-1;
3742 delete project.resNode.files;
3743 project.resNode.files = project.resources;
3744 project.files = null;
3745 project.resources = null;
3746 if(!project.configurations) project.configurations = { };
3749 char topNodePath[MAX_LOCATION];
3750 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3751 MakeSlashPath(topNodePath);
3752 PathCatSlash(topNodePath, filePath);
3753 project.filePath = topNodePath;//filePath;
3756 project.topNode.FixupNode(insidePath);
3761 project = LegacyAsciiLoadProject(f, filePath);
3767 if(!project.options) project.options = { };
3768 if(!project.config && project.configurations)
3769 project.config = project.configurations.firstIterator.data;
3771 if(!project.resNode)
3773 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3776 if(!project.moduleName)
3777 project.moduleName = CopyString(project.name);
3778 if(project.config &&
3779 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3780 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3782 //delete project.config.options.targetFileName;
3784 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
3785 project.config.options.optimization = none;
3786 project.config.options.debug = true;
3787 //project.config.options.warnings = unset;
3788 project.config.options.memoryGuard = false;
3789 project.config.compilingModified = true;
3790 project.config.linkingModified = true;
3792 else if(!project.topNode.name && project.config)
3794 project.topNode.name = CopyString(project.config.options.targetFileName);
3797 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3798 project.topNode.configurations = project.configurations;
3799 project.topNode.platforms = project.platforms;
3800 project.topNode.options = project.options;*/