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"/*"APPLE"*/ :
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 class Project : struct
689 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
690 // We might want to tweak this default behavior of regular classes ?
691 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
696 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
697 property Array<PlatformOptions> platforms
699 get { return platforms; }
702 if(platforms) { platforms.Free(); delete platforms; }
705 List<PlatformOptions> empty { };
706 Iterator<PlatformOptions> it { value };
708 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
709 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
719 if(p.options && !p.options.isEmpty)
726 List<ProjectConfig> configurations;
727 LinkList<ProjectNode> files;
728 String resourcesPath;
729 LinkList<ProjectNode> resources;
731 property char * description
733 set { delete description; if(value && value[0]) description = CopyString(value); }
734 get { return description ? description : ""; }
735 isset { return description != null && description[0]; }
738 property char * license
740 set { delete license; if(value && value[0]) license = CopyString(value); }
741 get { return license ? license : ""; }
742 isset { return license != null && license[0]; }
745 property char * compilerConfigsDir
747 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
748 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
749 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
753 // topNode.name holds the file name (.epj)
754 ProjectOptions options;
755 Array<PlatformOptions> platforms;
756 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
759 ProjectConfig config;
761 // This is the file name stripped of the epj extension
762 // It should NOT be edited, saved or loaded anywhere
767 String compilerConfigsDir;
768 #ifndef MAKEFILE_GENERATOR
769 FileMonitor fileMonitor
771 this, FileChange { modified = true };
772 bool OnFileNotify(FileChange action, char * param)
774 fileMonitor.StopMonitoring();
775 if(OnProjectModified(action, param))
776 fileMonitor.StartMonitoring();
781 bool StartMonitoring()
783 fileMonitor.fileName = filePath;
784 fileMonitor.StartMonitoring();
788 bool StopMonitoring()
790 fileMonitor.StopMonitoring();
794 bool OnProjectModified(FileChange fileChange, char * param)
797 sprintf(temp, $"The project %s was modified by another application.\n"
798 "Would you like to reload it and lose your changes?", name);
799 if(MessageBox { type = yesNo, master = ide,
800 text = $"Project has been modified", contents = temp }.Modal() == yes)
802 Project project = LoadProject(filePath);
805 ProjectView projectView = ide.projectView;
806 DataRow prev = topNode.row ? topNode.row.previous : null;
807 FileMonitor fm = fileMonitor;
809 if(projectView) projectView.DeleteNode(topNode);
814 topNode.project = this;
818 projectView.AddNode(topNode, null);
819 topNode.row.Move(prev);
821 eSystem_Delete(project);
830 // This frees contents without freeing the instance
831 // For use from destructor and for file monitor reloading
832 // (To work around JSON loader (LoadProject) always returning a new instance)
835 if(platforms) { platforms.Free(); delete platforms; }
836 if(configurations) { configurations.Free(); delete configurations; }
837 if(files) { files.Free(); delete files; }
838 if(resources) { resources.Free(); delete resources; }
840 delete resourcesPath;
844 delete compilerConfigsDir;
853 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
854 topNode.configurations = null;
855 topNode.platforms = null;
856 topNode.options = null;
861 property ProjectConfig config
867 topNode.info = CopyString(GetConfigName(config));
870 property char * filePath
876 char string[MAX_LOCATION];
877 GetLastDirectory(value, string);
879 topNode.name = CopyString(string);
880 StripExtension(string);
882 name = CopyString(string);
883 StripLastDirectory(value, string);
885 topNode.path = CopyString(string);
887 filePath = CopyString(value);
892 TargetTypes GetTargetType(ProjectConfig config)
894 TargetTypes targetType = localTargetType;
898 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
901 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
903 PlatformOptions projectPOs, configPOs;
904 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
905 if(platformTargetType)
912 char * GetObjDirExpression(ProjectConfig config)
914 // TODO: Support platform options
915 char * expression = localObjectsDirectory;
917 expression = settingsObjectsDirectory;
921 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config)
923 char * expression = GetObjDirExpression(config);
924 DirExpression objDir { type = intermediateObjectsDir };
925 objDir.Evaluate(expression, this, compiler, config);
929 char * GetTargetDirExpression(ProjectConfig config)
931 // TODO: Support platform options
932 char * expression = localTargetDirectory;
934 expression = settingsTargetDirectory;
938 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config)
940 char * expression = GetTargetDirExpression(config);
941 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
942 targetDir.Evaluate(expression, this, compiler, config);
946 WarningsOption GetWarnings(ProjectConfig config)
948 WarningsOption warnings = localWarnings;
952 bool GetDebug(ProjectConfig config)
954 SetBool debug = localDebug;
955 return debug == true;
958 bool GetMemoryGuard(ProjectConfig config)
960 SetBool memoryGuard = localMemoryGuard;
961 return memoryGuard == true;
964 bool GetNoLineNumbers(ProjectConfig config)
966 SetBool noLineNumbers = localNoLineNumbers;
967 return noLineNumbers == true;
970 bool GetProfile(ProjectConfig config)
972 SetBool profile = localProfile;
973 return profile == true;
976 OptimizationStrategy GetOptimization(ProjectConfig config)
978 OptimizationStrategy optimization = localOptimization;
982 String GetDefaultNameSpace(ProjectConfig config)
984 String defaultNameSpace = localDefaultNameSpace;
985 return defaultNameSpace;
988 bool GetStrictNameSpaces(ProjectConfig config)
990 SetBool strictNameSpaces = localStrictNameSpaces;
991 return strictNameSpaces == true;
994 String GetTargetFileName(ProjectConfig config)
996 String targetFileName = localTargetFileName;
997 return targetFileName;
1000 //String targetDirectory;
1001 //String objectsDirectory;
1002 bool GetConsole(ProjectConfig config)
1004 SetBool console = localConsole;
1005 return console == true;
1008 bool GetCompress(ProjectConfig config)
1010 SetBool compress = localCompress;
1011 return compress == true;
1013 //SetBool excludeFromBuild;
1015 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1017 #ifndef MAKEFILE_GENERATOR
1018 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1022 bool GetConfigIsInDebugSession(ProjectConfig config)
1024 #ifndef MAKEFILE_GENERATOR
1025 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1029 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config)
1031 #ifndef MAKEFILE_GENERATOR
1032 ide.SetPath(projectsDirs, compiler, config);
1036 #ifndef MAKEFILE_GENERATOR
1037 bool Save(char * fileName)
1040 /*char output[MAX_LOCATION];
1041 ChangeExtension(fileName, "json", output);
1042 f = FileOpen(output, write);*/
1043 f = FileOpen(fileName, write);
1046 files = topNode.files;
1047 resources = resNode.files;
1048 resourcesPath = resNode.path;
1050 files.Remove(resNode);
1053 WriteJSONObject(f, class(Project), this, 0);
1059 resourcesPath = null;
1066 // This method is only called from Debugger, should be moved to Debugger class?
1067 #ifndef MAKEFILE_GENERATOR
1068 bool GetRelativePath(char * filePath, char * relativePath)
1071 char moduleName[MAX_FILENAME];
1072 GetLastDirectory(filePath, moduleName);
1073 // try with workspace dir first?
1074 if((node = topNode.Find(moduleName, false)))
1076 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1077 PathCatSlash(relativePath, node.name);
1082 // Tweak for automatically resolving symbol loader modules
1083 char * sl = strstr(moduleName, ".main.ec");
1084 if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1086 char objDir[MAX_LOCATION];
1087 DirExpression objDirExp;
1088 CompilerConfig compiler = ide.debugger.currentCompiler;
1089 ProjectConfig config = ide.debugger.prjConfig;
1090 // This is not perfect, as multiple source files exist for the symbol loader module...
1091 // We try to set it in the debug config object directory.
1092 if(!compiler || !config)
1094 // If we're not currently debugging, set a breakpoint in the active compiler/config
1095 compiler = GetCompilerConfig();
1096 config = this.config;
1097 // If the current config is not debuggable, set it in the first debuggable config found
1098 if(config && !config.options.debug)
1100 for(c : configurations; c.options.debug)
1107 objDirExp = GetObjDir(compiler, config);
1108 strcpy(objDir, objDirExp.dir);
1110 ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1111 ReplaceSpaces(objDir, objDir);
1112 strcpy(relativePath, objDir);
1114 PathCatSlash(relativePath, moduleName);
1118 // WARNING: On failure, relative path is uninitialized
1123 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1125 TargetTypes targetType = GetTargetType(config);
1126 String targetFileName = GetTargetFileName(config);
1127 if(targetType == staticLibrary)
1129 PathCatSlash(string, "lib");
1130 strcat(string, targetFileName);
1132 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1134 PathCatSlash(string, "lib");
1135 strcat(string, targetFileName);
1138 PathCatSlash(string, targetFileName);
1143 if(compiler.targetPlatform == win32)
1144 strcat(string, ".exe");
1147 if(compiler.targetPlatform == win32)
1148 strcat(string, ".dll");
1149 else if(compiler.targetPlatform == apple)
1150 strcat(string, ".dylib");
1152 strcat(string, ".so");
1155 strcat(string, ".a");
1160 bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1162 bool result = false;
1163 char temp[MAX_LOCATION];
1164 strcpy(cfDir, topNode.path);
1165 if(compilerConfigsDir && compilerConfigsDir[0])
1167 PathCatSlash(cfDir, compilerConfigsDir);
1172 strcpy(temp, cfDir);
1173 // Using a relative path makes it less likely to run into spaces issues
1174 // Even with escaped spaces, there still seems to be issues including a config file
1175 // in a path containing spaces
1177 MakePathRelative(temp, topNode.path, cfDir);
1180 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1184 strcpy(temp, cfDir);
1185 ReplaceSpaces(cfDir, temp);
1190 bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1192 char temp[MAX_LOCATION];
1193 bool result = false;
1194 strcpy(cfDir, topNode.path);
1195 if(ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1197 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1202 // Default to <ProjectDir>/.configs if unset
1203 PathCatSlash(cfDir, ".configs");
1208 strcpy(temp, cfDir);
1209 // Using a relative path makes it less likely to run into spaces issues
1210 // Even with escaped spaces, there still seems to be issues including a config file
1211 // in a path containing spaces
1213 MakePathRelative(temp, topNode.path, cfDir);
1215 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1219 strcpy(temp, cfDir);
1220 ReplaceSpaces(cfDir, temp);
1225 void CatMakeFileName(char * string, ProjectConfig config)
1227 char projectName[MAX_LOCATION];
1228 strcpy(projectName, name);
1229 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1232 #ifndef MAKEFILE_GENERATOR
1233 void MarkChanges(ProjectNode node)
1235 for(cfg : topNode.configurations)
1237 ProjectConfig c = null;
1238 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1240 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1241 (!c.options || !cfg.options)))
1242 cfg.symbolGenModified = true;
1244 cfg.makingModified = true;
1248 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1250 for(cfg : configurations)
1253 cfg.makingModified = true;
1255 cfg.compilingModified = true;
1257 cfg.linkingModified = true;
1259 cfg.symbolGenModified = true;
1261 if(compiling || linking)
1263 ide.projectView.modifiedDocument = true;
1264 ide.workspace.modified = true;
1268 void RotateActiveConfig(bool forward)
1270 if(configurations.first && configurations.last != configurations.first)
1272 Iterator<ProjectConfig> cfg { configurations };
1273 while(forward ? cfg.Next() : cfg.Prev())
1274 if(cfg.data == config)
1288 property::config = cfg.data;
1289 ide.workspace.modified = true;
1290 ide.projectView.Update(null);
1294 void ProcessPipeOutputRaw(DualPipe f)
1297 while(!f.Eof() && !ide.ShouldStopBuild())
1300 double lastTime = GetTime();
1304 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1306 ide.outputView.buildBox.Logf("%s\n", line);
1308 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1310 //printf("Processing Input...\n");
1311 if(app.ProcessInput(true))
1313 app.UpdateDisplay();
1316 //printf("Waiting...\n");
1319 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1321 if(ide.ShouldStopBuild())
1323 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1328 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode,
1329 CompilerConfig compiler, ProjectConfig config)
1332 bool compiling = false, linking = false, precompiling = false;
1333 int compilingEC = 0;
1334 int numErrors = 0, numWarnings = 0;
1335 bool loggedALine = false;
1336 char * configName = config.name;
1337 int lenMakeCommand = strlen(compiler.makeCommand);
1339 char cppCommand[MAX_LOCATION];
1340 char ccCommand[MAX_LOCATION];
1341 char cxxCommand[MAX_LOCATION];
1342 char ecpCommand[MAX_LOCATION];
1343 char eccCommand[MAX_LOCATION];
1344 char ecsCommand[MAX_LOCATION];
1345 char earCommand[MAX_LOCATION];
1347 char * cc = compiler.ccCommand;
1348 char * cxx = compiler.cxxCommand;
1349 char * cpp = compiler.cppCommand;
1350 sprintf(cppCommand, "%s%s%s%s ",
1351 compiler.ccacheEnabled ? "ccache " : "",
1352 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1353 compiler.distccEnabled ? "distcc " : "",
1354 compiler.cppCommand);
1355 sprintf(ccCommand, "%s%s%s%s ",
1356 compiler.ccacheEnabled ? "ccache " : "",
1357 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1358 compiler.distccEnabled ? "distcc " : "",
1359 compiler.ccCommand);
1360 sprintf(cxxCommand, "%s%s%s%s ",
1361 compiler.ccacheEnabled ? "ccache " : "",
1362 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1363 compiler.distccEnabled ? "distcc " : "",
1364 compiler.cxxCommand);
1365 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1366 sprintf(eccCommand, "%s ", compiler.eccCommand);
1367 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1368 sprintf(earCommand, "%s ", compiler.earCommand);
1370 while(!f.Eof() && !ide.ShouldStopBuild())
1373 double lastTime = GetTime();
1377 //printf("Peeking and GetLine...\n");
1378 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1380 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1381 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1383 char * module = strstr(line, "No rule to make target `");
1387 module = strchr(module, '`') + 1;
1388 end = strchr(module, '\'');
1392 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1393 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1399 //ide.outputView.buildBox.Logf("error: %s\n", line);
1403 else if(strstr(line, "ear ") == line);
1404 else if(strstr(line, "strip ") == line);
1405 else if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1407 char moduleName[MAX_FILENAME];
1410 bool isPrecomp = false;
1412 if(strstr(line, ccCommand) == line || strstr(line, cxxCommand) == line)
1414 module = strstr(line, " -c ");
1415 if(module) module += 4;
1417 else if(strstr(line, eccCommand) == line)
1419 module = strstr(line, " -c ");
1420 if(module) module += 4;
1421 //module = line + 3;
1422 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1423 compilingEC = 3;//2;
1425 else if(strstr(line, ecpCommand) == line)
1427 // module = line + 8;
1428 module = strstr(line, " -c ");
1429 if(module) module += 4;
1438 if(!compiling && !isPrecomp)
1440 ide.outputView.buildBox.Logf($"Compiling...\n");
1443 else if(!precompiling && isPrecomp)
1445 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1446 precompiling = true;
1448 // Changed escapeBackSlashes here to handle paths with spaces
1449 Tokenize(module, 1, tokens, true); // false);
1450 GetLastDirectory(module, moduleName);
1451 ide.outputView.buildBox.Logf("%s\n", moduleName);
1453 else if((module = strstr(line, " -o ")))
1456 precompiling = false;
1458 ide.outputView.buildBox.Logf($"Linking...\n");
1462 ide.outputView.buildBox.Logf("%s\n", line);
1466 if(compilingEC) compilingEC--;
1468 else if(strstr(line, "ar rcs") == line)
1469 ide.outputView.buildBox.Logf($"Building library...\n");
1470 else if(strstr(line, ecsCommand) == line)
1471 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1474 if(linking || compiling || precompiling)
1476 char * colon = strstr(line, ":"); //, * bracket;
1477 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1478 colon = strstr(colon + 1, ":");
1481 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1484 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1485 int len = (int)(colon - start);
1486 len = Min(len, MAX_LOCATION-1);
1487 // Don't be mistaken by the drive letter colon
1489 // TODO: need to fix colon - line gives char *
1490 // warning: incompatible expression colon - line (char *); expected int
1492 strncpy(moduleName, line, (int)(colon - line));
1493 moduleName[colon - line] = '\0';
1495 strncpy(moduleName, start, len);
1496 moduleName[len] = '\0';
1497 // Remove stuff in brackets
1498 //bracket = strstr(moduleName, "(");
1499 //if(bracket) *bracket = '\0';
1501 GetLastDirectory(moduleName, temp);
1502 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1505 strcpy(moduleName, $"Linker Error");
1509 strcpy(temp, topNode.path);
1510 PathCatSlash(temp, moduleName);
1511 MakePathRelative(temp, topNode.path, moduleName);
1513 if(strstr(line, "error:"))
1517 // Silence warnings for compiled EC
1518 char * objDir = strstr(moduleName, objDirExp.dir);
1522 if((pointer = strstr(line, "undefined")) ||
1523 (pointer = strstr(line, "No such file")) ||
1524 (pointer = strstr(line, "token")))
1526 strncat(moduleName, colon, pointer - colon);
1527 strcat(moduleName, "error: ");
1532 else if((pointer = strstr(line, "No such file")))
1534 strncat(moduleName, colon, pointer - colon);
1535 strcat(moduleName, "error: ");
1539 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1541 else if(strstr(line, "warning:"))
1546 if(this == ide.workspace.projects.firstIterator.data)
1547 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1550 char fullModuleName[MAX_LOCATION];
1551 strcpy(fullModuleName, topNode.path);
1552 PathCat(fullModuleName, moduleName);
1553 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1554 MakeSystemPath(fullModuleName);
1555 ide.outputView.buildBox.Logf(" %s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : "", fullModuleName, colon);
1560 ide.outputView.buildBox.Logf("%s\n", line);
1561 linking = compiling = precompiling = false;
1565 ide.outputView.buildBox.Logf("%s\n", line);
1569 //printf("Done getting line\n");
1570 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1572 //printf("Processing Input...\n");
1573 if(app.ProcessInput(true))
1575 app.UpdateDisplay();
1578 //printf("Waiting...\n");
1581 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1583 if(ide.ShouldStopBuild())
1585 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1588 else if(loggedALine || !isARun)
1590 if(f.GetExitCode() && !numErrors)
1592 bool result = f.GetLine(line, sizeof(line)-1);
1593 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1598 ide.outputView.buildBox.Logf("\n%s (%s) - ", GetTargetFileName(config), configName);
1600 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1602 ide.outputView.buildBox.Logf($"no error, ");
1605 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1607 ide.outputView.buildBox.Logf($"no warning\n");
1610 return numErrors == 0;
1613 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1616 int lenMakeCommand = strlen(compiler.makeCommand);
1621 double lastTime = GetTime();
1624 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1626 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1627 else if(strstr(line, "del") == line);
1628 else if(strstr(line, "rm") == line);
1629 else if(strstr(line, "Could Not Find") == line);
1632 ide.outputView.buildBox.Logf(line);
1633 ide.outputView.buildBox.Logf("\n");
1637 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1639 if(app.ProcessInput(true))
1641 app.UpdateDisplay();
1644 //Sleep(1.0 / PEEK_RESOLUTION);
1648 bool Build(bool isARun, ProjectNode onlyNode, CompilerConfig compiler, ProjectConfig config)
1650 bool result = false;
1652 char targetFileName[MAX_LOCATION] = "";
1653 char makeTarget[MAX_LOCATION] = "";
1654 char makeFile[MAX_LOCATION];
1655 char makeFilePath[MAX_LOCATION];
1656 char configName[MAX_LOCATION];
1657 DirExpression objDirExp = GetObjDir(compiler, config);
1658 PathBackup pathBackup { };
1659 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1660 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1662 int numJobs = compiler.numJobs;
1663 char command[MAX_LOCATION];
1664 char * compilerName;
1666 compilerName = CopyString(compiler.name);
1667 CamelCase(compilerName);
1669 strcpy(configName, config ? config.name : "Common");
1671 SetPath(false, compiler, config); //true
1672 CatTargetFileName(targetFileName, compiler, config);
1674 strcpy(makeFilePath, topNode.path);
1675 CatMakeFileName(makeFile, config);
1676 PathCatSlash(makeFilePath, makeFile);
1678 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1681 if(compiler.type.isVC)
1683 PrintLn("compiling a single file is not yet supported");
1688 char pushD[MAX_LOCATION];
1689 char cfDir[MAX_LOCATION];
1690 GetIDECompilerConfigsDir(cfDir, true, true);
1691 GetWorkingDir(pushD, sizeof(pushD));
1692 ChangeWorkingDir(topNode.path);
1693 // Create object dir if it does not exist already
1694 if(!FileExists(objDirExp.dir).isDirectory)
1695 Execute("%s CF_DIR=%s%s%s COMPILER=%s objdir -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir,
1696 crossCompiling ? " PLATFORM=" : "", targetPlatform, compilerName, topNode.path, makeFilePath);
1697 ChangeWorkingDir(pushD);
1699 PathCatSlash(makeTarget+1, objDirExp.dir);
1700 PathCatSlash(makeTarget+1, onlyNode.name);
1701 StripExtension(makeTarget+1);
1702 strcat(makeTarget+1, ".o");
1703 makeTarget[0] = '\"';
1704 len = strlen(makeTarget);
1705 makeTarget[len++] = '\"';
1706 makeTarget[len++] = '\0';
1710 if(compiler.type.isVC)
1712 bool result = false;
1713 char oldwd[MAX_LOCATION];
1714 GetWorkingDir(oldwd, sizeof(oldwd));
1715 ChangeWorkingDir(topNode.path);
1717 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1718 ide.outputView.buildBox.Logf("command: %s\n", command);
1719 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1721 ProcessPipeOutputRaw(f);
1725 ChangeWorkingDir(oldwd);
1729 char cfDir[MAX_LOCATION];
1730 GetIDECompilerConfigsDir(cfDir, true, true);
1731 sprintf(command, "%s CF_DIR=\"%s\"%s%s COMPILER=%s -j%d %s%s%s -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir,
1732 crossCompiling ? " PLATFORM=" : "", targetPlatform,
1733 compilerName, numJobs,
1734 compiler.ccacheEnabled ? "CCACHE=y " : "",
1735 compiler.distccEnabled ? "DISTCC=y " : "",
1736 makeTarget, topNode.path, makeFilePath);
1737 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1739 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode, compiler, config);
1743 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
1748 delete compilerName;
1752 void Clean(CompilerConfig compiler, ProjectConfig config, bool realclean)
1754 char makeFile[MAX_LOCATION];
1755 char makeFilePath[MAX_LOCATION];
1756 char command[MAX_LOCATION];
1757 char * compilerName;
1759 PathBackup pathBackup { };
1760 bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1761 char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1763 compilerName = CopyString(compiler.name);
1764 CamelCase(compilerName);
1766 SetPath(false, compiler, config);
1768 strcpy(makeFilePath, topNode.path);
1769 CatMakeFileName(makeFile, config);
1770 PathCatSlash(makeFilePath, makeFile);
1772 if(compiler.type.isVC)
1774 bool result = false;
1775 char oldwd[MAX_LOCATION];
1776 GetWorkingDir(oldwd, sizeof(oldwd));
1777 ChangeWorkingDir(topNode.path);
1779 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1780 ide.outputView.buildBox.Logf("command: %s\n", command);
1781 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1783 ProcessPipeOutputRaw(f);
1787 ChangeWorkingDir(oldwd);
1792 char cfDir[MAX_LOCATION];
1793 GetIDECompilerConfigsDir(cfDir, true, true);
1794 sprintf(command, "%s CF_DIR=%s%s%s COMPILER=%s %sclean -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir,
1795 crossCompiling ? " PLATFORM=" : "", targetPlatform, compilerName, realclean ? "real" : "", topNode.path, makeFilePath);
1796 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1798 ide.outputView.buildBox.Tell($"Deleting target and object files...");
1799 ProcessCleanPipeOutput(f, compiler, config);
1802 ide.outputView.buildBox.Logf($"Target and object files deleted\n");
1807 delete compilerName;
1810 void Run(char * args, CompilerConfig compiler, ProjectConfig config)
1812 String target = new char[maxPathLen];
1813 char oldDirectory[MAX_LOCATION];
1814 DirExpression targetDirExp = GetTargetDir(compiler, config);
1815 PathBackup pathBackup { };
1817 // Build(project, ideMain, true, null);
1819 #if defined(__WIN32__)
1820 strcpy(target, topNode.path);
1824 PathCatSlash(target, targetDirExp.dir);
1825 CatTargetFileName(target, compiler, config);
1826 sprintf(target, "%s %s", target, args);
1827 GetWorkingDir(oldDirectory, MAX_LOCATION);
1829 if(strlen(ide.workspace.debugDir))
1831 char temp[MAX_LOCATION];
1832 strcpy(temp, topNode.path);
1833 PathCatSlash(temp, ide.workspace.debugDir);
1834 ChangeWorkingDir(temp);
1837 ChangeWorkingDir(topNode.path);
1838 // ChangeWorkingDir(topNode.path);
1839 SetPath(true, compiler, config);
1840 if(compiler.execPrefixCommand)
1842 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1843 prefixedTarget[0] = '\0';
1844 strcat(prefixedTarget, compiler.execPrefixCommand);
1845 strcat(prefixedTarget, " ");
1846 strcat(prefixedTarget, target);
1847 Execute(prefixedTarget);
1848 delete prefixedTarget;
1853 ChangeWorkingDir(oldDirectory);
1856 delete targetDirExp;
1860 void Compile(ProjectNode node, CompilerConfig compiler, ProjectConfig config)
1862 Build(false, node, compiler, config);
1866 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
1869 if(targetType == staticLibrary || targetType == sharedLibrary)
1870 strcat(fileName, "$(LP)");
1871 // !!! ReplaceSpaces must be done after all PathCat calls !!!
1872 // ReplaceSpaces(s, GetTargetFileName(config));
1873 strcat(fileName, GetTargetFileName(config));
1877 strcat(fileName, "$(E)");
1880 strcat(fileName, "$(SO)");
1883 strcat(fileName, "$(A)");
1888 bool GenerateCrossPlatformCf()
1890 bool result = false;
1891 char path[MAX_LOCATION];
1893 if(!GetProjectCompilerConfigsDir(path, false, false))
1894 GetIDECompilerConfigsDir(path, false, false);
1896 if(!FileExists(path).isDirectory)
1900 char dirName[MAX_FILENAME];
1901 GetLastDirectory(path, dirName);
1902 if(!strcmp(dirName, ".configs"))
1903 FileSetAttribs(path, FileAttribs { isHidden = true });
1906 PathCatSlash(path, "crossplatform.mk");
1908 if(FileExists(path))
1911 File include = FileOpen(":crossplatform.mk", read);
1914 File f = FileOpen(path, write);
1917 for(; !include.Eof(); )
1920 int count = include.Read(buffer, 1, 4096);
1921 f.Write(buffer, 1, count);
1933 bool GenerateCompilerMk(CompilerConfig compiler)
1935 bool result = false;
1936 char path[MAX_LOCATION];
1938 char * compilerName;
1939 bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
1940 Platform platform = compiler.targetPlatform;
1942 compilerName = CopyString(compiler.name);
1943 CamelCase(compilerName);
1944 name = PrintString(platform, "-", compilerName, ".cf");
1946 if(!GetProjectCompilerConfigsDir(path, false, false))
1947 GetIDECompilerConfigsDir(path, false, false);
1949 if(!FileExists(path).isDirectory)
1953 char dirName[MAX_FILENAME];
1954 GetLastDirectory(path, dirName);
1955 if(!strcmp(dirName, ".configs"))
1956 FileSetAttribs(path, FileAttribs { isHidden = true });
1959 PathCatSlash(path, name);
1961 if(FileExists(path))
1964 File f = FileOpen(path, write);
1968 if(compiler.targetPlatform != GetRuntimePlatform())
1969 f.Printf("\nPLATFORM = %s\n", (char *)compiler.targetPlatform);
1972 f.Printf("# TOOLCHAIN\n\n");
1974 //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
1975 f.Printf("CPP := %s\n", compiler.cppCommand);
1976 f.Printf("CC := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.ccCommand);
1977 f.Printf("CXX := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.cxxCommand);
1978 f.Printf("ECP := %s\n", compiler.ecpCommand);
1979 f.Printf("ECC := %s\n", compiler.eccCommand);
1980 f.Printf("ECS := %s -t $(PLATFORM)\n", compiler.ecsCommand);
1981 f.Printf("EAR := %s\n", compiler.earCommand);
1983 f.Printf("AS := as\n");
1984 f.Printf("LD := ld\n");
1985 f.Printf("AR := ar\n");
1986 f.Printf("STRIP := strip\n");
1987 f.Printf("UPX := upx\n");
1991 f.Printf("UPXFLAGS = -9\n\n"); // TOFEAT: Compression Level Option? Other UPX Options?
1993 f.Printf("# HARD CODED PLATFORM-SPECIFIC OPTIONS\n");
1994 f.Printf("ifeq \"$(PLATFORM)\" \"linux\"\n"); //, PlatformToMakefileVariable(tux));
1995 f.Printf("OFLAGS += -Wl,--no-undefined\n");
1996 f.Printf("endif\n\n");
1999 f.Printf("ifeq \"$(PLATFORM)\" \"apple\"\n"); //%s\n", PlatformToMakefileVariable(apple));
2000 f.Printf("OFLAGS += -framework cocoa -framework OpenGL\n");
2001 f.Printf("endif\n");
2005 f.Printf("\nCFLAGS += -fmessage-length=0\n");
2008 if(compiler.includeDirs && compiler.includeDirs.count)
2010 f.Printf("\nCFLAGS +=");
2011 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
2014 if(compiler.prepDirectives && compiler.prepDirectives.count)
2016 f.Printf("\nCFLAGS +=");
2017 OutputListOption(f, "D", compiler.prepDirectives, inPlace, true);
2020 if(compiler.libraryDirs && compiler.libraryDirs.count)
2022 f.Printf("\nOFLAGS +=");
2023 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
2026 if(compiler.excludeLibs && compiler.excludeLibs.count)
2028 f.Puts("\nEXCLUDED_LIBS =");
2029 for(l : compiler.excludeLibs)
2035 f.Printf("\nFORCE_64_BIT = %s", compiler.supportsBitDepth ? "-m64" : "");
2036 f.Printf("\nFORCE_32_BIT = %s", compiler.supportsBitDepth ? "-m32" : "");
2042 delete compilerName;
2046 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2048 bool result = false;
2049 char filePath[MAX_LOCATION];
2050 char makeFile[MAX_LOCATION];
2051 // PathBackup pathBackup { };
2052 // char oldDirectory[MAX_LOCATION];
2055 if(!altMakefilePath)
2057 strcpy(filePath, topNode.path);
2058 CatMakeFileName(makeFile, config);
2059 PathCatSlash(filePath, makeFile);
2062 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2064 /*SetPath(false, compiler, config);
2065 GetWorkingDir(oldDirectory, MAX_LOCATION);
2066 ChangeWorkingDir(topNode.path);*/
2073 char targetDir[MAX_LOCATION];
2074 char objDirExpNoSpaces[MAX_LOCATION];
2075 char objDirNoSpaces[MAX_LOCATION];
2076 char resDirNoSpaces[MAX_LOCATION];
2077 char targetDirExpNoSpaces[MAX_LOCATION];
2078 char fixedModuleName[MAX_FILENAME];
2079 char fixedConfigName[MAX_FILENAME];
2081 // Non-zero if we're building eC code
2082 // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2083 int numCObjects = 0;
2084 bool containsCXX = false; // True if the project contains a C++ file
2085 bool sameObjTargetDirs;
2086 String objDirExp = GetObjDirExpression(config);
2087 TargetTypes targetType = GetTargetType(config);
2089 char cfDir[MAX_LOCATION];
2090 int objectsParts, eCsourcesParts;
2091 Array<String> listItems { };
2092 Map<String, int> varStringLenDiffs { };
2093 Map<String, NameCollisionInfo> namesInfo { };
2094 bool forceBitDepth = false;
2096 ReplaceSpaces(objDirNoSpaces, objDirExp);
2097 strcpy(targetDir, GetTargetDirExpression(config));
2098 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2100 strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2101 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2102 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
2103 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2104 ReplaceSpaces(fixedModuleName, moduleName);
2105 ReplaceSpaces(fixedConfigName, GetConfigName(config));
2106 CamelCase(fixedConfigName);
2108 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2110 f.Printf(".PHONY: all objdir%s clean realclean\n\n", sameObjTargetDirs ? "" : " targetdir");
2112 f.Printf("# CONTENT\n\n");
2114 f.Printf("MODULE := %s\n", fixedModuleName);
2115 //f.Printf("VERSION = %s\n", version);
2116 f.Printf("CONFIG := %s\n", fixedConfigName);
2117 f.Printf("ifndef COMPILER\n");
2118 f.Printf("COMPILER := default\n");
2119 f.Printf("endif\n");
2122 if(compilerConfigsDir && compilerConfigsDir[0])
2124 strcpy(cfDir, compilerConfigsDir);
2125 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2129 strcpy(cfDir, "$(CF_DIR)");
2131 f.Printf("_CF_DIR = %s\n", cfDir);
2134 f.Printf("ifndef DEBUG\n");
2135 f.Printf("OPTIMIZE :=");
2136 switch(GetOptimization(config))
2140 f.Printf(" -ffast-math");
2146 if(GetDebug(config))
2150 f.Printf("OPTIMIZE := -g\n");
2151 f.Printf("NOSTRIP := y\n");
2152 f.Printf("endif\n");
2154 test = GetTargetTypeIsSetByPlatform(config);
2158 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2160 TargetTypes targetType;
2161 PlatformOptions projectPOs, configPOs;
2162 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2163 targetType = platformTargetType;
2169 f.Printf("ifeq \"$(PLATFORM)\" \"%s\"\n", (char *)platform); //%s\n", PlatformToMakefileVariable(platform));
2171 f.Printf("TARGET_TYPE = ");
2172 f.Printf(TargetTypeToMakefileVariable(targetType));
2176 f.Printf("else\n"); // ifCount should always be > 0
2178 f.Printf("TARGET_TYPE = ");
2179 f.Printf(TargetTypeToMakefileVariable(targetType));
2185 for(c = 0; c < ifCount; c++)
2186 f.Printf("endif\n");
2191 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2192 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2193 f.Printf("endif\n\n");
2195 f.Printf("# FLAGS\n\n");
2197 f.Printf("CFLAGS =\n");
2198 f.Printf("CECFLAGS =\n");
2199 f.Printf("ECFLAGS =\n");
2200 f.Printf("OFLAGS =\n");
2201 f.Printf("LIBS =\n");
2204 f.Printf("# INCLUDES\n\n");
2206 f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2207 f.Printf("include $(_CF_DIR)$(PLATFORM)-$(COMPILER).cf\n");
2210 f.Printf("# VARIABLES\n\n");
2212 f.Printf("OBJ = %s%s\n\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2214 f.Printf("ifdef DEBUG\n");
2215 f.Printf("CFLAGS += -D_DEBUG\n");
2216 f.Printf("endif\n\n");
2218 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2220 // test = GetTargetTypeIsSetByPlatform(config);
2222 char target[MAX_LOCATION];
2223 char targetNoSpaces[MAX_LOCATION];
2228 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2230 if(type != targetType)
2235 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2237 GetMakefileTargetFileName(type, target, config);
2238 strcpy(targetNoSpaces, targetDir);
2239 PathCatSlash(targetNoSpaces, target);
2240 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2241 f.Printf("TARGET = %s\n", targetNoSpaces);
2244 f.Printf("else\n"); // ifCount should always be > 0
2246 GetMakefileTargetFileName(targetType, target, config);
2247 strcpy(targetNoSpaces, targetDir);
2248 PathCatSlash(targetNoSpaces, target);
2249 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2250 f.Printf("TARGET = %s\n", targetNoSpaces);
2256 for(c = 0; c < ifCount; c++)
2257 f.Printf("endif\n");
2263 // Use something fixed here, to not cause Makefile differences across compilers...
2264 varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2265 // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2267 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2269 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2271 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
2272 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs, null);
2276 char * map[4][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "BOWLS", "B" } };
2278 topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2279 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2281 f.Printf("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2282 if(eCsourcesParts > 1)
2284 for(c = 1; c <= eCsourcesParts; c++)
2285 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2289 for(c = 0; c < 3; c++)
2291 if(eCsourcesParts > 1)
2294 f.Printf("%s =", map[c][0]);
2295 for(n = 1; n <= eCsourcesParts; n++)
2296 f.Printf(" $(%s%d)", map[c][0], n);
2298 for(n = 1; n <= eCsourcesParts; n++)
2299 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2301 else if(eCsourcesParts == 1)
2302 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2307 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2308 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, "$(ECSOURCES)");
2311 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2312 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2314 f.Printf("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
2315 if((config && config.options && config.options.libraries) ||
2316 (options && options.libraries))
2318 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2319 f.Printf("LIBS +=");
2320 if(config && config.options && config.options.libraries)
2321 OutputLibraries(f, config.options.libraries);
2322 else if(options && options.libraries)
2323 OutputLibraries(f, options.libraries);
2325 f.Printf("endif\n");
2329 if(platforms || (config && config.platforms))
2332 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2333 //for(platform = win32; platform <= apple; platform++)
2335 f.Printf("# PLATFORM-SPECIFIC OPTIONS\n\n");
2336 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2338 PlatformOptions projectPlatformOptions, configPlatformOptions;
2339 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2341 if(projectPlatformOptions || configPlatformOptions)
2346 f.Printf("ifeq \"$(PLATFORM)\" \"");
2347 // f.Printf(PlatformToMakefileVariable(platform));
2348 f.Printf((char *)platform);
2351 if((projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions && projectPlatformOptions.options.preprocessorDefinitions.count) ||
2352 (configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions && configPlatformOptions.options.preprocessorDefinitions.count) ||
2353 (projectPlatformOptions && projectPlatformOptions.options.includeDirs && projectPlatformOptions.options.includeDirs.count) ||
2354 (configPlatformOptions && configPlatformOptions.options.includeDirs && configPlatformOptions.options.includeDirs.count))
2356 f.Printf("CFLAGS +=");
2357 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2359 f.Printf(" \\\n\t -Wl");
2360 for(s : projectPlatformOptions.options.linkerOptions)
2363 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2365 f.Printf(" \\\n\t -Wl");
2366 for(s : configPlatformOptions.options.linkerOptions)
2369 if(projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions)
2370 OutputListOption(f, "D", projectPlatformOptions.options.preprocessorDefinitions, newLine, false);
2371 if(configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions)
2372 OutputListOption(f, "D", configPlatformOptions.options.preprocessorDefinitions, newLine, false );
2373 if(configPlatformOptions && configPlatformOptions.options.includeDirs)
2374 OutputListOption(f, "I", configPlatformOptions.options.includeDirs, lineEach, true);
2375 if(projectPlatformOptions && projectPlatformOptions.options.includeDirs)
2376 OutputListOption(f, "I", projectPlatformOptions.options.includeDirs, lineEach, true);
2380 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2381 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2382 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2383 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2385 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2386 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2387 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2389 f.Printf("OFLAGS +=");
2390 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2391 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2392 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2393 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2397 if((configPlatformOptions && configPlatformOptions.options.libraries))
2399 if(configPlatformOptions.options.libraries.count)
2401 f.Printf("LIBS +=");
2402 OutputLibraries(f, configPlatformOptions.options.libraries);
2406 else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
2408 if(projectPlatformOptions.options.libraries.count)
2410 f.Printf("LIBS +=");
2411 OutputLibraries(f, projectPlatformOptions.options.libraries);
2415 f.Printf("endif\n\n");
2421 for(c = 0; c < ifCount; c++)
2422 f.Printf("endif\n");
2427 f.Printf("CFLAGS +=");
2430 f.Printf(" $(OPTIMIZE)");
2431 forceBitDepth = (options && options.buildBitDepth) || numCObjects;
2433 f.Printf(" %s",(!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? "$(FORCE_32_BIT)" : "$(FORCE_64_BIT)");
2434 f.Printf(" $(FPIC)");
2436 switch(GetWarnings(config))
2438 case all: f.Printf(" -Wall"); break;
2439 case none: f.Printf(" -w"); break;
2441 if(GetProfile(config))
2443 if(options && options.linkerOptions && options.linkerOptions.count)
2445 f.Printf(" \\\n\t -Wl");
2446 for(s : options.linkerOptions)
2450 if(options && options.preprocessorDefinitions)
2451 OutputListOption(f, "D", options.preprocessorDefinitions, newLine, false);
2452 if(config && config.options && config.options.preprocessorDefinitions)
2453 OutputListOption(f, "D", config.options.preprocessorDefinitions, newLine, false);
2454 if(config && config.options && config.options.includeDirs)
2455 OutputListOption(f, "I", config.options.includeDirs, lineEach, true);
2456 if(options && options.includeDirs)
2457 OutputListOption(f, "I", options.includeDirs, lineEach, true);
2460 f.Printf("CECFLAGS += -cpp $(call escspace,$(CPP)) -t $(PLATFORM)");
2463 f.Printf("ECFLAGS +=");
2464 if(GetMemoryGuard(config))
2465 f.Printf(" -memguard");
2466 if(GetStrictNameSpaces(config))
2467 f.Printf(" -strictns");
2468 if(GetNoLineNumbers(config))
2469 f.Printf(" -nolinenumbers");
2472 if((s = GetDefaultNameSpace(config)) && s[0])
2473 f.Printf(" -defaultns %s", s);
2477 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2478 f.Printf("OFLAGS +=");
2480 f.Printf((!options || !options.buildBitDepth || options.buildBitDepth == bits32) ? " -m32" : " -m64 \\\n");
2482 if(GetProfile(config))
2484 if(config && config.options && config.options.libraryDirs)
2485 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
2486 if(options && options.libraryDirs)
2487 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
2489 f.Printf("endif\n\n");
2491 f.Printf("# TARGETS\n\n");
2493 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
2495 f.Printf("objdir:\n");
2496 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2497 //f.Printf("# PRE-BUILD COMMANDS\n");
2498 if(options && options.prebuildCommands)
2500 for(s : options.prebuildCommands)
2501 if(s && s[0]) f.Printf("\t%s\n", s);
2503 if(config && config.options && config.options.prebuildCommands)
2505 for(s : config.options.prebuildCommands)
2506 if(s && s[0]) f.Printf("\t%s\n", s);
2508 if(platforms || (config && config.platforms))
2511 //f.Printf("# PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2512 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2514 PlatformOptions projectPOs, configPOs;
2515 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2517 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2518 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2524 f.Printf(PlatformToMakefileVariable(platform));
2527 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2529 for(s : projectPOs.options.prebuildCommands)
2530 if(s && s[0]) f.Printf("\t%s\n", s);
2532 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2534 for(s : configPOs.options.prebuildCommands)
2535 if(s && s[0]) f.Printf("\t%s\n", s);
2542 for(c = 0; c < ifCount; c++)
2543 f.Printf("endif\n");
2548 if(!sameObjTargetDirs)
2550 f.Printf("targetdir:\n");
2551 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2556 // Main Module (Linking) for ECERE C modules
2557 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2558 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2559 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2560 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
2561 // Main Module (Linking) for ECERE C modules
2562 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2563 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2564 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2565 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2566 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2571 // This would not rebuild the target on updated objects
2572 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2574 // This should fix it for good!
2575 f.Printf("$(SYMBOLS): | objdir\n");
2576 f.Printf("$(OBJECTS): | objdir\n");
2578 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2579 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2581 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2582 f.Printf("\t$(%s) $(OFLAGS) $(OBJECTS) $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
2583 if(!GetDebug(config))
2585 f.Printf("ifndef NOSTRIP\n");
2586 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2587 f.Printf("endif\n");
2589 if(GetCompress(config))
2591 f.Printf("ifndef WINDOWS\n");
2592 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2593 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2594 f.Printf("endif\n");
2596 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2597 f.Printf("endif\n");
2600 if(resNode.files && resNode.files.count && !noResources)
2601 resNode.GenMakefileAddResources(f, resNode.path, config);
2603 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2604 f.Printf("endif\n");
2606 //f.Printf("# POST-BUILD COMMANDS\n");
2607 if(options && options.postbuildCommands)
2609 for(s : options.postbuildCommands)
2610 if(s && s[0]) f.Printf("\t%s\n", s);
2612 if(config && config.options && config.options.postbuildCommands)
2614 for(s : config.options.postbuildCommands)
2615 if(s && s[0]) f.Printf("\t%s\n", s);
2617 if(platforms || (config && config.platforms))
2620 //f.Printf("# PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2621 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2623 PlatformOptions projectPOs, configPOs;
2624 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2626 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2627 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2633 f.Printf(PlatformToMakefileVariable(platform));
2636 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2638 for(s : projectPOs.options.postbuildCommands)
2639 if(s && s[0]) f.Printf("\t%s\n", s);
2641 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2643 for(s : configPOs.options.postbuildCommands)
2644 if(s && s[0]) f.Printf("\t%s\n", s);
2651 for(c = 0; c < ifCount; c++)
2652 f.Printf("endif\n");
2657 f.Printf("# SYMBOL RULES\n\n");
2659 Map<Platform, bool> excludedPlatforms { };
2660 topNode.GenMakefilePrintSymbolRules(f, this, config, excludedPlatforms);
2661 delete excludedPlatforms;
2664 f.Printf("# C OBJECT RULES\n\n");
2666 Map<Platform, bool> excludedPlatforms { };
2667 topNode.GenMakefilePrintCObjectRules(f, this, config, excludedPlatforms);
2668 delete excludedPlatforms;
2671 f.Printf("# OBJECT RULES\n\n");
2672 // todo call this still but only generate rules whith specific options
2673 // see we-have-file-specific-options in ProjectNode.ec
2675 Map<Platform, bool> excludedPlatforms { };
2676 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, excludedPlatforms);
2677 delete excludedPlatforms;
2681 GenMakefilePrintMainObjectRule(f, config);
2683 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2684 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) " : "");
2685 OutputCleanActions(f, "OBJECTS", objectsParts);
2688 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
2689 OutputCleanActions(f, "BOWLS", eCsourcesParts);
2690 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
2691 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
2695 f.Printf("realclean: clean\n");
2696 f.Printf("\t$(call rmrq,$(OBJ))\n");
2697 if(!sameObjTargetDirs)
2698 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2705 varStringLenDiffs.Free();
2706 delete varStringLenDiffs;
2713 // ChangeWorkingDir(oldDirectory);
2714 // delete pathBackup;
2717 config.makingModified = false;
2721 void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
2723 char extension[MAX_EXTENSION] = "c";
2724 char modulePath[MAX_LOCATION];
2725 char fixedModuleName[MAX_FILENAME];
2728 char objDirNoSpaces[MAX_LOCATION];
2729 String objDirExp = GetObjDirExpression(config);
2731 ReplaceSpaces(objDirNoSpaces, objDirExp);
2732 ReplaceSpaces(fixedModuleName, moduleName);
2734 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2735 //strcat(fixedModuleName, ".main");
2737 #if 0 // TODO: Fix nospaces stuff
2738 // *** Dependency command ***
2739 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2741 // System Includes (from global settings)
2742 for(item : compiler.dirs[Includes])
2744 strcat(command, " -isystem ");
2745 if(strchr(item.name, ' '))
2747 strcat(command, "\"");
2748 strcat(command, item);
2749 strcat(command, "\"");
2752 strcat(command, item);
2755 for(item = includeDirs.first; item; item = item.next)
2757 strcat(command, " -I");
2758 if(strchr(item.name, ' '))
2760 strcat(command, "\"");
2761 strcat(command, item.name);
2762 strcat(command, "\"");
2765 strcat(command, item.name);
2767 for(item = preprocessorDefs.first; item; item = item.next)
2769 strcat(command, " -D");
2770 strcat(command, item.name);
2774 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2778 bool firstLine = true;
2780 // To do some time: auto save external dependencies?
2783 if(dep.GetLine(line, sizeof(line)-1))
2787 char * colon = strstr(line, ":");
2788 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2802 // If we failed to generate dependencies...
2806 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2812 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2815 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
2816 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
2818 *projectPlatformOptions = null;
2819 *configPlatformOptions = null;
2824 if(!strcmpi(p.name, platform))
2826 *projectPlatformOptions = p;
2831 if(config && config.platforms)
2833 for(p : config.platforms)
2835 if(!strcmpi(p.name, platform))
2837 *configPlatformOptions = p;
2845 Project LegacyBinaryLoadProject(File f, char * filePath)
2847 Project project = null;
2848 char signature[sizeof(epjSignature)];
2850 f.Read(signature, sizeof(signature), 1);
2851 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2853 char topNodePath[MAX_LOCATION];
2854 /*ProjectConfig newConfig
2856 name = CopyString("Default");
2857 makingModified = true;
2858 compilingModified = true;
2859 linkingModified = true;
2863 project = Project { options = { } };
2864 LegacyBinaryLoadNode(project.topNode, f);
2865 delete project.topNode.path;
2866 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2867 MakeSlashPath(topNodePath);
2869 PathCatSlash(topNodePath, filePath);
2870 project.filePath = topNodePath;
2872 /* THIS IS ALREADY DONE BY filePath property
2873 StripLastDirectory(topNodePath, topNodePath);
2874 project.topNode.path = CopyString(topNodePath);
2876 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2878 // newConfig.options.defaultNameSpace = "";
2879 /*newConfig.objDir.dir = "obj";
2880 newConfig.targetDir.dir = "";*/
2882 //project.configurations = { [ newConfig ] };
2883 //project.config = newConfig;
2890 String targetFileName, targetDirectory, objectsDirectory;
2892 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2893 f.Read(&temp, sizeof(int),1);
2896 case 0: project.options.targetType = executable; break;
2897 case 1: project.options.targetType = sharedLibrary; break;
2898 case 2: project.options.targetType = staticLibrary; break;
2901 f.Read(&len, sizeof(int),1);
2902 targetFileName = new char[len+1];
2903 f.Read(targetFileName, sizeof(char), len+1);
2904 project.options.targetFileName = targetFileName;
2905 delete targetFileName;
2907 f.Read(&len, sizeof(int),1);
2908 targetDirectory = new char[len+1];
2909 f.Read(targetDirectory, sizeof(char), len+1);
2910 project.options.targetDirectory = targetDirectory;
2911 delete targetDirectory;
2913 f.Read(&len, sizeof(int),1);
2914 objectsDirectory = new byte[len+1];
2915 f.Read(objectsDirectory, sizeof(char), len+1);
2916 project.options.objectsDirectory = objectsDirectory;
2917 delete objectsDirectory;
2919 f.Read(&temp, sizeof(int),1);
2920 project./*config.*/options.debug = temp ? true : false;
2921 f.Read(&temp, sizeof(int),1);
2922 project./*config.*/options.optimization = temp ? speed : none;
2923 f.Read(&temp, sizeof(int),1);
2924 project./*config.*/options.profile = temp ? true : false;
2925 f.Read(&temp, sizeof(int),1);
2926 project.options.warnings = temp ? all : unset;
2928 f.Read(&count, sizeof(int),1);
2931 project.options.includeDirs = { };
2932 for(c = 0; c < count; c++)
2935 f.Read(&len, sizeof(int),1);
2936 name = new char[len+1];
2937 f.Read(name, sizeof(char), len+1);
2938 project.options.includeDirs.Add(name);
2942 f.Read(&count, sizeof(int),1);
2945 project.options.libraryDirs = { };
2946 for(c = 0; c < count; c++)
2949 f.Read(&len, sizeof(int),1);
2950 name = new char[len+1];
2951 f.Read(name, sizeof(char), len+1);
2952 project.options.libraryDirs.Add(name);
2956 f.Read(&count, sizeof(int),1);
2959 project.options.libraries = { };
2960 for(c = 0; c < count; c++)
2963 f.Read(&len, sizeof(int),1);
2964 name = new char[len+1];
2965 f.Read(name, sizeof(char), len+1);
2966 project.options.libraries.Add(name);
2970 f.Read(&count, sizeof(int),1);
2973 project.options.preprocessorDefinitions = { };
2974 for(c = 0; c < count; c++)
2977 f.Read(&len, sizeof(int),1);
2978 name = new char[len+1];
2979 f.Read(name, sizeof(char), len+1);
2980 project.options.preprocessorDefinitions.Add(name);
2984 f.Read(&temp, sizeof(int),1);
2985 project.options.console = temp ? true : false;
2988 for(node : project.topNode.files)
2990 if(node.type == resources)
2992 project.resNode = node;
3002 void ProjectConfig::LegacyProjectConfigLoad(File f)
3010 char subSection[128];
3016 f.GetLine(buffer, 65536 - 1);
3017 TrimLSpaces(buffer, buffer);
3018 TrimRSpaces(buffer, buffer);
3021 if(buffer[0] == '-')
3025 TrimLSpaces(equal, equal);
3026 if(!strcmpi(subSection, "LibraryDirs"))
3028 if(!options.libraryDirs)
3029 options.libraryDirs = { [ CopyString(equal) ] };
3031 options.libraryDirs.Add(CopyString(equal));
3033 else if(!strcmpi(subSection, "IncludeDirs"))
3035 if(!options.includeDirs)
3036 options.includeDirs = { [ CopyString(equal) ] };
3038 options.includeDirs.Add(CopyString(equal));
3041 else if(buffer[0] == '+')
3052 TrimLSpaces(equal, equal);
3053 delete name; name = CopyString(equal); // property::name = equal;
3056 else if(!strcmpi(buffer, "Compiler Options"))
3057 strcpy(section, buffer);
3058 else if(!strcmpi(buffer, "IncludeDirs"))
3059 strcpy(subSection, buffer);
3060 else if(!strcmpi(buffer, "Linker Options"))
3061 strcpy(section, buffer);
3062 else if(!strcmpi(buffer, "LibraryDirs"))
3063 strcpy(subSection, buffer);
3064 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3071 equal = strstr(buffer, "=");
3075 TrimRSpaces(buffer, buffer);
3077 TrimLSpaces(equal, equal);
3078 if(!strcmpi(buffer, "Target Name"))
3079 options.targetFileName = /*CopyString(*/equal/*)*/;
3080 else if(!strcmpi(buffer, "Target Type"))
3082 if(!strcmpi(equal, "Executable"))
3083 options.targetType = executable;
3084 else if(!strcmpi(equal, "Shared"))
3085 options.targetType = sharedLibrary;
3086 else if(!strcmpi(equal, "Static"))
3087 options.targetType = staticLibrary;
3089 options.targetType = executable;
3091 else if(!strcmpi(buffer, "Target Directory"))
3092 options.targetDirectory = /*CopyString(*/equal/*)*/;
3093 else if(!strcmpi(buffer, "Console"))
3094 options.console = ParseTrueFalseValue(equal);
3095 else if(!strcmpi(buffer, "Libraries"))
3097 if(!options.libraries) options.libraries = { };
3098 ParseArrayValue(options.libraries, equal);
3100 else if(!strcmpi(buffer, "Intermediate Directory"))
3101 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3102 else if(!strcmpi(buffer, "Debug"))
3103 options.debug = ParseTrueFalseValue(equal);
3104 else if(!strcmpi(buffer, "Optimize"))
3106 if(!strcmpi(equal, "None"))
3107 options.optimization = none;
3108 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3109 options.optimization = speed;
3110 else if(!strcmpi(equal, "Size"))
3111 options.optimization = size;
3113 options.optimization = none;
3115 else if(!strcmpi(buffer, "Compress"))
3116 options.compress = ParseTrueFalseValue(equal);
3117 else if(!strcmpi(buffer, "Profile"))
3118 options.profile = ParseTrueFalseValue(equal);
3119 else if(!strcmpi(buffer, "AllWarnings"))
3120 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3121 else if(!strcmpi(buffer, "MemoryGuard"))
3122 options.memoryGuard = ParseTrueFalseValue(equal);
3123 else if(!strcmpi(buffer, "Default Name Space"))
3124 options.defaultNameSpace = CopyString(equal);
3125 else if(!strcmpi(buffer, "Strict Name Spaces"))
3126 options.strictNameSpaces = ParseTrueFalseValue(equal);
3127 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3129 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3130 ParseArrayValue(options.preprocessorDefinitions, equal);
3136 if(!options.targetDirectory && options.objectsDirectory)
3137 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3138 //if(!objDir.dir) objDir.dir = "obj";
3139 //if(!targetDir.dir) targetDir.dir = "";
3140 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
3141 // if(!defaultNameSpace) property::defaultNameSpace = "";
3142 makingModified = true;
3145 Project LegacyAsciiLoadProject(File f, char * filePath)
3147 Project project = null;
3148 ProjectNode node = null;
3150 char parentPath[MAX_LOCATION];
3151 char section[128] = "";
3152 char subSection[128] = "";
3154 bool configurationsPresent = false;
3164 f.GetLine(buffer, 65536 - 1);
3165 TrimLSpaces(buffer, buffer);
3166 TrimRSpaces(buffer, buffer);
3169 if(buffer[0] == '-' || buffer[0] == '=')
3171 bool simple = buffer[0] == '-';
3174 TrimLSpaces(equal, equal);
3175 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3177 if(!project.config.options.libraryDirs)
3178 project.config.options.libraryDirs = { [ CopyString(equal) ] };
3180 project.config.options.libraryDirs.Add(CopyString(equal));
3182 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3184 if(!project.config.options.includeDirs)
3185 project.config.options.includeDirs = { [ CopyString(equal) ] };
3187 project.config.options.includeDirs.Add(CopyString(equal));
3189 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3191 len = strlen(equal);
3194 char temp[MAX_LOCATION];
3195 ProjectNode child { };
3196 // We don't need to do this anymore, fileName is just a property that sets name & path
3197 // child.fileName = CopyString(equal);
3200 child.name = CopyString(equal);
3201 child.path = CopyString(parentPath);
3205 GetLastDirectory(equal, temp);
3206 child.name = CopyString(temp);
3207 StripLastDirectory(equal, temp);
3208 child.path = CopyString(temp);
3210 child.nodeType = file;
3211 child.parent = parent;
3212 child.indent = parent.indent + 1;
3214 child.icon = NodeIcons::SelectFileIcon(child.name);
3215 parent.files.Add(child);
3221 StripLastDirectory(parentPath, parentPath);
3222 parent = parent.parent;
3226 else if(buffer[0] == '+')
3230 TrimLSpaces(equal, equal);
3231 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3233 char temp[MAX_LOCATION];
3234 ProjectNode child { };
3235 // NEW: Folders now have a path set like files
3236 child.name = CopyString(equal);
3237 strcpy(temp, parentPath);
3238 PathCatSlash(temp, child.name);
3239 child.path = CopyString(temp);
3241 child.parent = parent;
3242 child.indent = parent.indent + 1;
3243 child.type = folder;
3244 child.nodeType = folder;
3246 child.icon = folder;
3247 PathCatSlash(parentPath, child.name);
3248 parent.files.Add(child);
3253 else if(!strcmpi(section, "Configurations"))
3255 ProjectConfig newConfig
3257 makingModified = true;
3261 LegacyProjectConfigLoad(newConfig, f);
3262 project.configurations.Add(newConfig);
3265 else if(!strcmpi(buffer, "ECERE Project File"));
3266 else if(!strcmpi(buffer, "Version 0a"))
3267 ; //strcpy(version, "0a");
3268 else if(!strcmpi(buffer, "Version 0.1a"))
3269 ; //strcpy(version, "0.1a");
3270 else if(!strcmpi(buffer, "Configurations"))
3272 project.configurations.Free();
3273 project.config = null;
3274 strcpy(section, buffer);
3275 configurationsPresent = true;
3277 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3279 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3280 char topNodePath[MAX_LOCATION];
3281 // newConfig.defaultNameSpace = "";
3282 //newConfig.objDir.dir = "obj";
3283 //newConfig.targetDir.dir = "";
3284 project = Project { /*options = { }*/ };
3285 project.configurations = { [ newConfig ] };
3286 project.config = newConfig;
3287 // if(project.topNode.path) delete project.topNode.path;
3288 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3289 MakeSlashPath(topNodePath);
3290 PathCatSlash(topNodePath, filePath);
3291 project.filePath = topNodePath;
3292 parentPath[0] = '\0';
3293 parent = project.topNode;
3295 strcpy(section, "Target");
3300 if(equal[0] == '\"')
3302 StripQuotes(equal, equal);
3303 delete project.moduleName; project.moduleName = CopyString(equal);
3307 else if(!strcmpi(buffer, "Compiler Options"));
3308 else if(!strcmpi(buffer, "IncludeDirs"))
3309 strcpy(subSection, buffer);
3310 else if(!strcmpi(buffer, "Linker Options"));
3311 else if(!strcmpi(buffer, "LibraryDirs"))
3312 strcpy(subSection, buffer);
3313 else if(!strcmpi(buffer, "Files"))
3315 strcpy(section, "Target");
3316 strcpy(subSection, buffer);
3318 else if(!strcmpi(buffer, "Resources"))
3320 ProjectNode child { };
3321 parent.files.Add(child);
3322 child.parent = parent;
3323 child.indent = parent.indent + 1;
3324 child.name = CopyString(buffer);
3325 child.path = CopyString("");
3326 child.type = resources;
3328 child.icon = archiveFile;
3329 project.resNode = child;
3332 strcpy(subSection, buffer);
3336 equal = strstr(buffer, "=");
3340 TrimRSpaces(buffer, buffer);
3342 TrimLSpaces(equal, equal);
3344 if(!strcmpi(section, "Target"))
3346 if(!strcmpi(buffer, "Build Exclusions"))
3348 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3350 /*if(node && node.type != NodeTypes::project)
3351 ParseListValue(node.buildExclusions, equal);*/
3354 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
3356 delete project.resNode.path;
3357 project.resNode.path = CopyString(equal);
3358 PathCatSlash(parentPath, equal);
3362 else if(!strcmpi(buffer, "Intermediate Directory"))
3363 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3364 else if(!strcmpi(buffer, "Debug"))
3365 project.config.options.debug = ParseTrueFalseValue(equal);
3366 else if(!strcmpi(buffer, "Optimize"))
3368 if(!strcmpi(equal, "None"))
3369 project.config.options.optimization = none;
3370 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3371 project.config.options.optimization = speed;
3372 else if(!strcmpi(equal, "Size"))
3373 project.config.options.optimization = size;
3375 project.config.options.optimization = none;
3377 else if(!strcmpi(buffer, "Profile"))
3378 project.config.options.profile = ParseTrueFalseValue(equal);
3379 else if(!strcmpi(buffer, "MemoryGuard"))
3380 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
3383 if(!project.options) project.options = { };
3385 // Project Wide Settings (All configs)
3386 if(!strcmpi(buffer, "Target Name"))
3387 project.options.targetFileName = /*CopyString(*/equal/*)*/;
3388 else if(!strcmpi(buffer, "Target Type"))
3390 if(!strcmpi(equal, "Executable"))
3391 project.options.targetType = executable;
3392 else if(!strcmpi(equal, "Shared"))
3393 project.options.targetType = sharedLibrary;
3394 else if(!strcmpi(equal, "Static"))
3395 project.options.targetType = staticLibrary;
3397 project.options.targetType = executable;
3399 else if(!strcmpi(buffer, "Target Directory"))
3400 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
3401 else if(!strcmpi(buffer, "Console"))
3402 project.options.console = ParseTrueFalseValue(equal);
3403 else if(!strcmpi(buffer, "Libraries"))
3405 if(!project.options.libraries) project.options.libraries = { };
3406 ParseArrayValue(project.options.libraries, equal);
3408 else if(!strcmpi(buffer, "AllWarnings"))
3409 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3410 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3412 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3414 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
3415 ParseListValue(node.preprocessorDefs, equal);*/
3419 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
3420 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3431 SplitPlatformLibraries(project);
3433 if(configurationsPresent)
3434 CombineIdenticalConfigOptions(project);
3438 void SplitPlatformLibraries(Project project)
3440 if(project && project.configurations)
3442 for(cfg : project.configurations)
3444 if(cfg.options.libraries && cfg.options.libraries.count)
3446 Iterator<String> it { cfg.options.libraries };
3450 char * platformName = strstr(l, ":");
3453 PlatformOptions platform = null;
3455 if(!cfg.platforms) cfg.platforms = { };
3456 for(p : cfg.platforms)
3458 if(!strcmpi(platformName, p.name))
3466 platform = { name = CopyString(platformName), options = { libraries = { } } };
3467 cfg.platforms.Add(platform);
3469 *(platformName-1) = 0;
3470 platform.options.libraries.Add(CopyString(l));
3472 cfg.options.libraries.Delete(it.pointer);
3481 void CombineIdenticalConfigOptions(Project project)
3483 if(project && project.configurations && project.configurations.count)
3486 ProjectOptions nullOptions { };
3487 ProjectConfig firstConfig = null;
3488 for(cfg : project.configurations)
3490 if(cfg.options.targetType != staticLibrary)
3497 firstConfig = project.configurations.firstIterator.data;
3499 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3501 if(!member.isProperty)
3503 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3508 for(cfg : project.configurations)
3510 if(cfg != firstConfig)
3512 if(cfg.options.targetType != staticLibrary)
3516 if(type.type == noHeadClass || type.type == normalClass)
3518 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3519 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3520 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3524 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3525 (byte *)firstConfig.options + member.offset + member._class.offset,
3526 (byte *)cfg.options + member.offset + member._class.offset);
3538 if(type.type == noHeadClass || type.type == normalClass)
3540 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3541 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3542 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3547 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3548 (byte *)firstConfig.options + member.offset + member._class.offset,
3549 (byte *)nullOptions + member.offset + member._class.offset))
3553 if(!project.options) project.options = { };
3555 /*if(type.type == noHeadClass || type.type == normalClass)
3557 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3558 (byte *)project.options + member.offset + member._class.offset,
3559 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3563 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3564 // TOFIX: ListBox::SetData / OnCopy mess
3565 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3566 (byte *)project.options + member.offset + member._class.offset,
3567 (type.typeSize > 4) ? address :
3568 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3569 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3570 (void *)*(byte *)address )));
3573 (byte *)project.options + member.offset + member._class.offset,
3574 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3576 for(cfg : project.configurations)
3578 if(cfg.options.targetType == staticLibrary)
3582 if(type.type == noHeadClass || type.type == normalClass)
3584 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3585 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3586 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3590 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3591 (byte *)firstConfig.options + member.offset + member._class.offset,
3592 (byte *)cfg.options + member.offset + member._class.offset);
3597 if(cfg != firstConfig)
3599 if(type.type == noHeadClass || type.type == normalClass)
3601 type._vTbl[__ecereVMethodID_class_OnFree](type,
3602 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3606 type._vTbl[__ecereVMethodID_class_OnFree](type,
3607 (byte *)cfg.options + member.offset + member._class.offset);
3609 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3612 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3619 // Compare Platform Specific Settings
3622 for(cfg : project.configurations)
3624 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3625 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3631 if(same && firstConfig.platforms)
3633 for(cfg : project.configurations)
3635 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3637 if(cfg != firstConfig)
3639 cfg.platforms.Free();
3640 delete cfg.platforms;
3643 project.platforms = firstConfig.platforms;
3644 firstConfig.platforms = null;
3648 // Static libraries can't contain libraries
3649 for(cfg : project.configurations)
3651 if(cfg.options.targetType == staticLibrary)
3653 if(!cfg.options.libraries) cfg.options.libraries = { };
3654 cfg.options.libraries.Free();
3660 Project LoadProject(char * filePath)
3662 Project project = null;
3663 File f = FileOpen(filePath, read);
3666 project = LegacyBinaryLoadProject(f, filePath);
3669 JSONParser parser { f = f };
3670 JSONResult result = parser.GetObject(class(Project), &project);
3673 char insidePath[MAX_LOCATION];
3675 delete project.topNode.files;
3676 if(!project.files) project.files = { };
3677 project.topNode.files = project.files;
3678 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3679 delete project.resNode.path;
3680 project.resNode.path = project.resourcesPath;
3681 project.resourcesPath = null;
3682 project.resNode.nodeType = (ProjectNodeType)-1;
3683 delete project.resNode.files;
3684 project.resNode.files = project.resources;
3685 project.files = null;
3686 project.resources = null;
3687 if(!project.configurations) project.configurations = { };
3690 char topNodePath[MAX_LOCATION];
3691 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3692 MakeSlashPath(topNodePath);
3693 PathCatSlash(topNodePath, filePath);
3694 project.filePath = topNodePath;//filePath;
3697 project.topNode.FixupNode(insidePath);
3702 project = LegacyAsciiLoadProject(f, filePath);
3708 if(!project.options) project.options = { };
3709 if(!project.config && project.configurations)
3710 project.config = project.configurations.firstIterator.data;
3712 if(!project.resNode)
3714 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3717 if(!project.moduleName)
3718 project.moduleName = CopyString(project.name);
3719 if(project.config &&
3720 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3721 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3723 //delete project.config.options.targetFileName;
3725 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
3726 project.config.options.optimization = none;
3727 project.config.options.debug = true;
3728 //project.config.options.warnings = unset;
3729 project.config.options.memoryGuard = false;
3730 project.config.compilingModified = true;
3731 project.config.linkingModified = true;
3733 else if(!project.topNode.name && project.config)
3735 project.topNode.name = CopyString(project.config.options.targetFileName);
3738 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3739 project.topNode.configurations = project.configurations;
3740 project.topNode.platforms = project.platforms;
3741 project.topNode.options = project.options;*/