2 public import static "ecere"
7 #ifndef MAKEFILE_GENERATOR
9 // We should have the .sln/.vcproj generation even on other platforms
10 // e.g. detect from an environment variable pointing to a Windows drive
16 import "ProjectConfig"
22 static void DummyFunction()
30 extern int __ecereVMethodID_class_OnCompare;
31 extern int __ecereVMethodID_class_OnFree;
33 IDESettings ideSettings;
35 IDESettingsContainer settingsContainer
38 dataOwner = &ideSettings;
39 dataClass = class(IDESettings);
41 void OnLoad(GlobalSettingsData data)
43 IDESettings settings = (IDESettings)data;
44 #ifndef MAKEFILE_GENERATOR
45 globalSettingsDialog.ideSettings = settings;
46 ide.UpdateRecentMenus();
47 // ide.UpdateMakefiles(); -- can't really regenerate on Load since all recent menus changes will happen
52 #ifdef MAKEFILE_GENERATOR
53 CompilerConfig defaultCompiler;
56 // LEGACY BINARY EPJ LOADING
58 SetBool ParseTrueFalseValue(char * string)
60 if(!strcmpi(string, "True")) return true;
64 void ParseArrayValue(Array<String> array, char * equal)
66 char * start, * comma;
68 string = CopyString(equal);
72 comma = strstr(start, ",");
75 array.Add(CopyString(start));
85 void ProjectNode::LegacyBinaryLoadNode(File f)
90 f.Read(&len, sizeof(len), 1);
91 name = new char[len+1];
93 f.Read(name, sizeof(char), len+1);
94 f.Read(&len, sizeof(len), 1);
96 path = new char[len+1];
97 f.Read(path, sizeof(char), len+1);
100 fileName = new char[fileNameLen+2];
101 strcpy(fileName, path);
102 if(fileName[0]) strcat(fileName, "/");
103 strcat(fileName, name);
106 f.Read(&type, sizeof(type), 1);
107 f.Read(&count, sizeof(count), 1);
112 icon = NodeIcons::SelectFileIcon(name);
117 icon = NodeIcons::SelectNodeIcon(type);
120 if(count && !files) files = { };
121 for(c = 0; c < count; c++)
123 ProjectNode child { };
126 child.indent = indent + 1;
127 LegacyBinaryLoadNode(child, f);
131 /*void LegacyBinarySaveNode(File f)
136 f.Write(&len, sizeof(len), 1);
137 f.Write(name, sizeof(char), len+1);
141 // Projects Absolute Path Are Not Saved
143 f.Write(&len, sizeof(len), 1);
144 f.Write(&len, sizeof(char), 1);
149 f.Write(&len, sizeof(len), 1);
150 f.Write(path, sizeof(char), len+1);
152 f.Write(&type, sizeof(type), 1);
153 f.Write(&children.count, sizeof(children.count), 1);
154 for(child = children.first; child; child.next)
158 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
161 char printPath[MAX_LOCATION];
163 if(type == project && (files.count /*|| preprocessorDefs.first*/))
165 f.Printf("\n Files\n");
167 else if(type == file)
169 if(!strcmp(path, insidePath))
170 f.Printf("%s - %s\n", indentation, name);
173 strcpy(printPath, path);
174 len = strlen(printPath);
176 if(printPath[len-1] != '/')
177 strcat(printPath, "/");
178 strcat(printPath, name);
179 f.Printf("%s = %s\n", indentation, printPath);
182 f.Printf("\nError\n\n");
184 else if(type == folder)
186 f.Printf("%s + %s\n", indentation, name);
188 else if(type == resources && files.count)
190 PathCatSlash(insidePath, path);
191 f.Printf("\n%sResources\n", indentation);
193 f.Printf("%s Path = %s\n", indentation, path);
196 /*if(buildExclusions.first && type != project)
198 for(item = buildExclusions.first; item; item = item.next)
200 if(item == buildExclusions.first)
201 f.Printf("%s Build Exclusions = %s", indentation, item.name);
203 f.Printf(", %s", item.name);
208 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
210 for(item = preprocessorDefs.first; item; item = item.next)
212 if(item == preprocessorDefs.first)
213 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
215 f.Printf(", %s", item.name);
221 if(type == project && (files.count /*|| preprocessorDefs.first*/))
225 LegacyAsciiSaveNode(child, f, indentation, insidePath);
227 else if(type == folder)
229 strcat(indentation, " ");
230 // WHAT WAS THIS: strcpy(printPath, path);
231 // TOCHECK: why is Unix/PathCat not used here
232 len = strlen(insidePath);
234 if(insidePath[len-1] != '/')
235 strcat(insidePath, "/");
236 strcat(insidePath, name);
239 LegacyAsciiSaveNode(child, f, indentation, insidePath);
240 f.Printf("%s -\n", indentation);
241 indentation[strlen(indentation) - 3] = '\0';
242 StripLastDirectory(insidePath, insidePath);
244 else if(type == resources && files.count)
248 LegacyAsciiSaveNode(child, f, indentation, insidePath);
249 StripLastDirectory(insidePath, insidePath);
254 void ProjectConfig::LegacyProjectConfigSave(File f)
256 char * indentation = " ";
258 //f.Printf("\n * Common\n");
260 f.Printf("\n + %s\n", name);
261 f.Printf("\n Compiler\n\n");
262 if(objDir.expression[0])
263 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
264 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
265 switch(options.optimization)
267 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
268 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
269 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
271 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
273 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
274 if(options.memoryGuard == true)
275 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
276 if(options.strictNameSpaces == true)
277 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
278 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
279 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
280 TOFIX: Compiler Bug {
281 if(options.preprocessorDefinitions.count)
284 for(item : options.preprocessorDefinitions)
288 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
292 f.Printf(", %s", item);
297 if(options.includeDirs.count)
299 f.Printf("\n%sInclude Directories\n", indentation);
300 for(item : options.includeDirs)
301 f.Printf("%s - %s\n", indentation, name);
305 f.Printf("\n%sLinker\n\n", indentation);
306 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
307 switch(options.targetType)
309 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
310 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
311 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
313 if(targetDir.expression[0])
314 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
316 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
318 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
319 if(options.libraries.count)
322 for(item : options.libraries)
326 f.Printf("\n%sLibraries = %s", indentation, name);
330 f.Printf(", %s", item);
334 if(options.libraryDirs.count)
336 f.Printf("\n%sLibrary Directories\n\n", indentation);
337 for(item : options.libraryDirs)
338 f.Printf(" - %s\n", indentation, item);
342 void LegacyAsciiSaveProject(File f, Project project)
344 char indentation[128*3];
345 char path[MAX_LOCATION];
347 f.Printf("\nECERE Project File : Format Version 0.1b\n");
348 f.Printf("\nDescription\n%s\n.\n", project.description);
349 f.Printf("\nLicense\n%s\n.\n", project.license);
350 f.Printf("\nModule Name = %s\n", project.moduleName);
351 f.Printf("\n Configurations\n");
352 //////////////////////////////////////commonConfig.Save(f, true);
353 for(cfg : project.configurations)
354 LegacyProjectConfigSave(cfg, f);
356 strcpy(indentation, " ");
358 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
364 // *** NEW JSON PROJECT FORMAT ***
365 public enum ProjectNodeType { file, folder };
367 // *******************************
369 define PEEK_RESOLUTION = (18.2 * 10);
375 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
377 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources };
379 define WorkspaceExtension = "ews";
380 define ProjectExtension = "epj";
382 define stringInFileIncludedFrom = "In file included from ";
384 void ReplaceSpaces(char * output, char * source)
389 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
391 if(ch == ' ') output[dc++] = '\\';
394 if(ch == '(' || ch == ')') output[dc++] = '\\';
404 void ReplaceUnwantedMakeChars(char * output, char * source)
409 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
413 if(ch == '(' || ch == ')') output[dc++] = '\\';
426 static void OutputNoSpace(File f, char * source)
428 char * output = new char[strlen(source)+1024];
429 ReplaceSpaces(output, source);
434 enum ListOutputMethod { inPlace, newLine, lineEach };
436 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
439 const int breakListLength = 1536;
440 const int breakLineLength = 78; // TODO: turn this into an option.
442 int c, len, itemCount = 0;
443 Array<int> breaks { };
447 MapNode<String, int> mn;
448 for(c=0; c<list.count; c++)
450 len = strlen(list[c]) + 3;
451 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
453 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
455 if(strstr(list[c], mn.key))
459 if(charCount + len > breakListLength)
461 breaks.Add(itemCount);
469 breaks.Add(itemCount);
470 numOfBreaks = breaks.count;
475 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
476 for(c=0; c<numOfBreaks; c++)
477 f.Printf(" $(%s%d)", name, c+1);
481 f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
487 for(c=0; c<numOfBreaks; c++)
490 f.Printf("%s%d =", name, c+1);
493 itemCount = breaks[c];
494 for(n=offset; n<offset+itemCount; n++)
496 if(false) // TODO: turn this into an option.
498 int itemLen = strlen(list[n]);
499 if(len > 3 && len + itemLen > breakLineLength)
501 f.Printf(" \\\n\t%s", list[n]);
507 f.Printf(" %s", list[n]);
511 f.Printf(" \\\n\t%s", list[n]);
526 void OutputCleanActions(File f, char * name, int parts)
531 for(c=0; c<parts; c++)
532 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
535 f.Printf("\t$(call rmq,$(%s))\n", name);
538 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
542 if(method == newLine)
546 if(method == lineEach)
548 f.Printf(" -%s", option);
550 OutputNoSpace(f, item);
552 f.Printf("%s", item);
557 static void OutputLibraries(File f, Array<String> libraries)
559 for(item : libraries)
561 char ext[MAX_EXTENSION];
562 char temp[MAX_LOCATION];
564 GetExtension(item, ext);
565 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
569 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
571 if(!strncmp(item, "lib", 3))
572 strcpy(temp, item + 3);
575 StripExtension(temp);
584 void CamelCase(char * string)
586 int c, len = strlen(string);
587 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
588 string[c] = (char)tolower(string[c]);
591 CompilerConfig GetCompilerConfig()
593 #ifndef MAKEFILE_GENERATOR
594 CompilerConfig compiler = null;
595 if(ide && ide.workspace)
596 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
599 incref defaultCompiler;
600 return defaultCompiler;
604 define localTargetType = config && config.options && config.options.targetType ?
605 config.options.targetType : options && options.targetType ?
606 options.targetType : TargetTypes::executable;
607 define localWarnings = config && config.options && config.options.warnings ?
608 config.options.warnings : options && options.warnings ?
609 options.warnings : WarningsOption::unset;
610 define localDebug = config && config.options && config.options.debug ?
611 config.options.debug : options && options.debug ?
612 options.debug : SetBool::unset;
613 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
614 config.options.memoryGuard : options && options.memoryGuard ?
615 options.memoryGuard : SetBool::unset;
616 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
617 config.options.noLineNumbers : options && options.noLineNumbers ?
618 options.noLineNumbers : SetBool::unset;
619 define localProfile = config && config.options && config.options.profile ?
620 config.options.profile : options && options.profile ?
621 options.profile : SetBool::unset;
622 define localOptimization = config && config.options && config.options.optimization ?
623 config.options.optimization : options && options.optimization ?
624 options.optimization : OptimizationStrategy::none;
625 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
626 config.options.defaultNameSpace : options && options.defaultNameSpace ?
627 options.defaultNameSpace : null;
628 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
629 config.options.strictNameSpaces : options && options.strictNameSpaces ?
630 options.strictNameSpaces : SetBool::unset;
631 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
632 define localTargetFileName = config && config.options && config.options.targetFileName ?
633 config.options.targetFileName : options && options.targetFileName ?
634 options.targetFileName : "";
635 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
636 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
637 options.targetDirectory : null;
638 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
639 ideSettings.projectDefaultIntermediateObjDir[0] ?
640 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
641 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
642 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
643 options.objectsDirectory : null;
644 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
645 ideSettings.projectDefaultIntermediateObjDir[0] ?
646 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
647 define localConsole = config && config.options && config.options.console ?
648 config.options.console : options && options.console ?
649 options.console : SetBool::unset;
650 define localCompress = config && config.options && config.options.compress ?
651 config.options.compress : options && options.compress ?
652 options.compress : SetBool::unset;
654 define platformTargetType =
655 configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
656 configPOs.options.targetType :
657 projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
658 projectPOs.options.targetType : TargetTypes::unset;
661 // we should have some kind of direct mapping between a platform and it's makefile variable
662 char * PlatformToMakefileVariable(Platform platform)
664 return platform == win32 ? "WINDOWS" :
665 platform == tux ? "LINUX" :
666 platform == apple ? "OSX"/*"APPLE"*/ :
670 char * TargetTypeToMakefileVariable(TargetTypes targetType)
672 return targetType == executable ? "executable" :
673 targetType == sharedLibrary ? "sharedlib" :
674 targetType == staticLibrary ? "staticlib" :
678 // Move this to ProjectConfig? null vs Common to consider...
679 char * GetConfigName(ProjectConfig config)
681 return config ? config.name : "Common";
684 class Project : struct
686 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
687 // We might want to tweak this default behavior of regular classes ?
688 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
693 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
694 property Array<PlatformOptions> platforms
696 get { return platforms; }
699 if(platforms) { platforms.Free(); delete platforms; }
702 List<PlatformOptions> empty { };
703 Iterator<PlatformOptions> it { value };
705 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
706 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
716 if(p.options && !p.options.isEmpty)
723 List<ProjectConfig> configurations;
724 LinkList<ProjectNode> files;
725 String resourcesPath;
726 LinkList<ProjectNode> resources;
728 property char * description
730 set { delete description; if(value && value[0]) description = CopyString(value); }
731 get { return description ? description : ""; }
732 isset { return description != null && description[0]; }
735 property char * license
737 set { delete license; if(value && value[0]) license = CopyString(value); }
738 get { return license ? license : ""; }
739 isset { return license != null && license[0]; }
742 property char * compilerConfigsDir
744 set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
745 get { return compilerConfigsDir ? compilerConfigsDir : ""; }
746 isset { return compilerConfigsDir && compilerConfigsDir[0]; }
750 // topNode.name holds the file name (.epj)
751 ProjectOptions options;
752 Array<PlatformOptions> platforms;
753 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
756 ProjectConfig config;
758 // This is the file name stripped of the epj extension
759 // It should NOT be edited, saved or loaded anywhere
764 String compilerConfigsDir;
768 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
769 topNode.configurations = null;
770 topNode.platforms = null;
771 topNode.options = null;
774 if(platforms) { platforms.Free(); delete platforms; }
775 if(configurations) { configurations.Free(); delete configurations; }
776 if(files) { files.Free(); delete files; }
777 if(resources) { resources.Free(); delete resources; }
779 delete resourcesPath;
783 delete compilerConfigsDir;
790 property ProjectConfig config
796 topNode.info = CopyString(GetConfigName(config));
799 property char * filePath
805 char string[MAX_LOCATION];
806 GetLastDirectory(value, string);
808 topNode.name = CopyString(string);
809 StripExtension(string);
811 name = CopyString(string);
812 StripLastDirectory(value, string);
814 topNode.path = CopyString(string);
816 filePath = CopyString(value);
821 TargetTypes GetTargetType(ProjectConfig config)
823 TargetTypes targetType = localTargetType;
827 bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
830 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
832 PlatformOptions projectPOs, configPOs;
833 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
834 if(platformTargetType)
841 char * GetObjDirExpression(CompilerConfig compiler, ProjectConfig config)
843 // TODO: Support platform options
844 char * expression = localObjectsDirectory;
846 expression = settingsObjectsDirectory;
850 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config)
852 char * expression = GetObjDirExpression(compiler, config);
853 DirExpression objDir { type = intermediateObjectsDir };
854 objDir.Evaluate(expression, this, compiler, config);
858 char * GetTargetDirExpression(CompilerConfig compiler, ProjectConfig config)
860 // TODO: Support platform options
861 char * expression = localTargetDirectory;
863 expression = settingsTargetDirectory;
867 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config)
869 char * expression = GetTargetDirExpression(compiler, config);
870 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
871 targetDir.Evaluate(expression, this, compiler, config);
875 WarningsOption GetWarnings(ProjectConfig config)
877 WarningsOption warnings = localWarnings;
881 bool GetDebug(ProjectConfig config)
883 SetBool debug = localDebug;
884 return debug == true;
887 bool GetMemoryGuard(ProjectConfig config)
889 SetBool memoryGuard = localMemoryGuard;
890 return memoryGuard == true;
893 bool GetNoLineNumbers(ProjectConfig config)
895 SetBool noLineNumbers = localNoLineNumbers;
896 return noLineNumbers == true;
899 bool GetProfile(ProjectConfig config)
901 SetBool profile = localProfile;
902 return profile == true;
905 OptimizationStrategy GetOptimization(ProjectConfig config)
907 OptimizationStrategy optimization = localOptimization;
911 String GetDefaultNameSpace(ProjectConfig config)
913 String defaultNameSpace = localDefaultNameSpace;
914 return defaultNameSpace;
917 bool GetStrictNameSpaces(ProjectConfig config)
919 SetBool strictNameSpaces = localStrictNameSpaces;
920 return strictNameSpaces == true;
923 String GetTargetFileName(ProjectConfig config)
925 String targetFileName = localTargetFileName;
926 return targetFileName;
929 //String targetDirectory;
930 //String objectsDirectory;
931 bool GetConsole(ProjectConfig config)
933 SetBool console = localConsole;
934 return console == true;
937 bool GetCompress(ProjectConfig config)
939 SetBool compress = localCompress;
940 return compress == true;
942 //SetBool excludeFromBuild;
944 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
946 #ifndef MAKEFILE_GENERATOR
947 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
951 bool GetConfigIsInDebugSession(ProjectConfig config)
953 #ifndef MAKEFILE_GENERATOR
954 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
958 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config)
960 #ifndef MAKEFILE_GENERATOR
961 ide.SetPath(projectsDirs, compiler, config);
965 #ifndef MAKEFILE_GENERATOR
966 bool Save(char * fileName)
969 /*char output[MAX_LOCATION];
970 ChangeExtension(fileName, "json", output);
971 f = FileOpen(output, write);*/
972 f = FileOpen(fileName, write);
975 files = topNode.files;
976 resources = resNode.files;
977 resourcesPath = resNode.path;
979 files.Remove(resNode);
982 WriteJSONObject(f, class(Project), this, 0);
988 resourcesPath = null;
995 #ifndef MAKEFILE_GENERATOR
996 bool GetRelativePath(char * filePath, char * relativePath)
999 char moduleName[MAX_FILENAME];
1000 GetLastDirectory(filePath, moduleName);
1001 // try with workspace dir first?
1002 if((node = topNode.Find(moduleName, false)))
1004 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1005 PathCatSlash(relativePath, node.name);
1008 // WARNING: On failure, relative path is uninitialized
1013 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1015 TargetTypes targetType = GetTargetType(config);
1016 String targetFileName = GetTargetFileName(config);
1017 if(targetType == staticLibrary)
1019 PathCatSlash(string, "lib");
1020 strcat(string, targetFileName);
1022 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1024 PathCatSlash(string, "lib");
1025 strcat(string, targetFileName);
1028 PathCatSlash(string, targetFileName);
1033 if(compiler.targetPlatform == win32)
1034 strcat(string, ".exe");
1037 if(compiler.targetPlatform == win32)
1038 strcat(string, ".dll");
1039 else if(compiler.targetPlatform == apple)
1040 strcat(string, ".dylib");
1042 strcat(string, ".so");
1045 strcat(string, ".a");
1050 void GetCompilerConfigsDir(char * cfDir)
1052 strcpy(cfDir, topNode.path);
1053 if(compilerConfigsDir && compilerConfigsDir[0])
1054 PathCatSlash(cfDir, compilerConfigsDir);
1055 else if(ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1056 PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1057 if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1061 void CatMakeFileName(char * string, ProjectConfig config)
1063 char projectName[MAX_LOCATION];
1064 strcpy(projectName, name);
1065 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1068 #ifndef MAKEFILE_GENERATOR
1069 void MarkChanges(ProjectNode node)
1071 for(cfg : topNode.configurations)
1073 ProjectConfig c = null;
1074 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1076 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1077 (!c.options || !cfg.options)))
1078 cfg.symbolGenModified = true;
1080 cfg.makingModified = true;
1084 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1086 for(cfg : configurations)
1089 cfg.makingModified = true;
1091 cfg.compilingModified = true;
1093 cfg.linkingModified = true;
1095 cfg.symbolGenModified = true;
1097 if(compiling || linking)
1099 ide.projectView.modifiedDocument = true;
1100 ide.workspace.modified = true;
1104 void RotateActiveConfig(bool forward)
1106 if(configurations.first && configurations.last != configurations.first)
1108 Iterator<ProjectConfig> cfg { configurations };
1109 while(forward ? cfg.Next() : cfg.Prev())
1110 if(cfg.data == config)
1124 property::config = cfg.data;
1125 ide.workspace.modified = true;
1126 ide.projectView.Update(null);
1130 void ProcessPipeOutputRaw(DualPipe f)
1133 while(!f.Eof() && !ide.ShouldStopBuild())
1136 double lastTime = GetTime();
1140 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1142 ide.outputView.buildBox.Logf("%s\n", line);
1144 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1146 //printf("Processing Input...\n");
1147 if(app.ProcessInput(true))
1149 app.UpdateDisplay();
1152 //printf("Waiting...\n");
1155 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1157 if(ide.ShouldStopBuild())
1159 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1164 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode,
1165 CompilerConfig compiler, ProjectConfig config)
1168 bool compiling = false, linking = false, precompiling = false;
1169 int compilingEC = 0;
1170 int numErrors = 0, numWarnings = 0;
1171 bool loggedALine = false;
1172 char * configName = config.name;
1173 int lenMakeCommand = strlen(compiler.makeCommand);
1175 char cppCommand[MAX_LOCATION];
1176 char ccCommand[MAX_LOCATION];
1177 char ecpCommand[MAX_LOCATION];
1178 char eccCommand[MAX_LOCATION];
1179 char ecsCommand[MAX_LOCATION];
1180 char earCommand[MAX_LOCATION];
1182 char * cc = compiler.ccCommand;
1183 char * cpp = compiler.cppCommand;
1184 sprintf(cppCommand, "%s%s%s%s ",
1185 compiler.ccacheEnabled ? "ccache " : "",
1186 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1187 compiler.distccEnabled ? "distcc " : "",
1188 compiler.cppCommand);
1189 sprintf(ccCommand, "%s%s%s%s ",
1190 compiler.ccacheEnabled ? "ccache " : "",
1191 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1192 compiler.distccEnabled ? "distcc " : "",
1193 compiler.ccCommand);
1194 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1195 sprintf(eccCommand, "%s ", compiler.eccCommand);
1196 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1197 sprintf(earCommand, "%s ", compiler.earCommand);
1199 while(!f.Eof() && !ide.ShouldStopBuild())
1202 double lastTime = GetTime();
1206 //printf("Peeking and GetLine...\n");
1207 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1209 char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1210 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1212 char * module = strstr(line, "No rule to make target `");
1216 module = strchr(module, '`') + 1;
1217 end = strchr(module, '\'');
1221 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1222 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1228 //ide.outputView.buildBox.Logf("error: %s\n", line);
1232 else if(strstr(line, "ear ") == line);
1233 else if(strstr(line, "strip ") == line);
1234 else if(strstr(line, ccCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1236 char moduleName[MAX_FILENAME];
1239 bool isPrecomp = false;
1241 if(strstr(line, ccCommand) == line)
1243 module = strstr(line, " -c ");
1244 if(module) module += 4;
1246 else if(strstr(line, eccCommand) == line)
1248 module = strstr(line, " -c ");
1249 if(module) module += 4;
1250 //module = line + 3;
1251 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1252 compilingEC = 3;//2;
1254 else if(strstr(line, ecpCommand) == line)
1256 // module = line + 8;
1257 module = strstr(line, " -c ");
1258 if(module) module += 4;
1267 if(!compiling && !isPrecomp)
1269 ide.outputView.buildBox.Logf($"Compiling...\n");
1272 else if(!precompiling && isPrecomp)
1274 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1275 precompiling = true;
1277 // Changed escapeBackSlashes here to handle paths with spaces
1278 Tokenize(module, 1, tokens, true); // false);
1279 GetLastDirectory(module, moduleName);
1280 ide.outputView.buildBox.Logf("%s\n", moduleName);
1282 else if((module = strstr(line, " -o ")))
1285 precompiling = false;
1287 ide.outputView.buildBox.Logf($"Linking...\n");
1291 ide.outputView.buildBox.Logf("%s\n", line);
1295 if(compilingEC) compilingEC--;
1297 else if(strstr(line, "ar rcs") == line)
1298 ide.outputView.buildBox.Logf($"Building library...\n");
1299 else if(strstr(line, ecsCommand) == line)
1300 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1303 if(linking || compiling || precompiling)
1305 char * colon = strstr(line, ":"); //, * bracket;
1306 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1307 colon = strstr(colon + 1, ":");
1310 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1313 char * start = inFileIncludedFrom ? line + strlen(stringInFileIncludedFrom) : line;
1314 int len = (int)(colon - start);
1315 len = Min(len, MAX_LOCATION-1);
1316 // Don't be mistaken by the drive letter colon
1318 // TODO: need to fix colon - line gives char *
1319 // warning: incompatible expression colon - line (char *); expected int
1321 strncpy(moduleName, line, (int)(colon - line));
1322 moduleName[colon - line] = '\0';
1324 strncpy(moduleName, start, len);
1325 moduleName[len] = '\0';
1326 // Remove stuff in brackets
1327 //bracket = strstr(moduleName, "(");
1328 //if(bracket) *bracket = '\0';
1330 GetLastDirectory(moduleName, temp);
1331 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1334 strcpy(moduleName, $"Linker Error");
1338 strcpy(temp, topNode.path);
1339 PathCatSlash(temp, moduleName);
1340 MakePathRelative(temp, topNode.path, moduleName);
1342 if(strstr(line, "error:"))
1346 // Silence warnings for compiled EC
1347 char * objDir = strstr(moduleName, objDirExp.dir);
1351 if((pointer = strstr(line, "undefined")) ||
1352 (pointer = strstr(line, "No such file")) ||
1353 (pointer = strstr(line, "token")))
1355 strncat(moduleName, colon, pointer - colon);
1356 strcat(moduleName, "error: ");
1361 else if((pointer = strstr(line, "No such file")))
1363 strncat(moduleName, colon, pointer - colon);
1364 strcat(moduleName, "error: ");
1368 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1370 else if(strstr(line, "warning:"))
1375 if(this == ide.workspace.projects.firstIterator.data)
1376 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1379 char fullModuleName[MAX_LOCATION];
1380 strcpy(fullModuleName, topNode.path);
1381 PathCat(fullModuleName, moduleName);
1382 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1383 MakeSystemPath(fullModuleName);
1384 ide.outputView.buildBox.Logf(" %s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : "", fullModuleName, colon);
1389 ide.outputView.buildBox.Logf("%s\n", line);
1390 linking = compiling = precompiling = false;
1394 ide.outputView.buildBox.Logf("%s\n", line);
1398 //printf("Done getting line\n");
1399 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1401 //printf("Processing Input...\n");
1402 if(app.ProcessInput(true))
1404 app.UpdateDisplay();
1407 //printf("Waiting...\n");
1410 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1412 if(ide.ShouldStopBuild())
1414 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1417 else if(loggedALine || !isARun)
1419 if(f.GetExitCode() && !numErrors)
1421 bool result = f.GetLine(line, sizeof(line)-1);
1422 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1427 ide.outputView.buildBox.Logf("\n%s (%s) - ", GetTargetFileName(config), configName);
1429 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1431 ide.outputView.buildBox.Logf($"no error, ");
1434 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1436 ide.outputView.buildBox.Logf($"no warning\n");
1439 return numErrors == 0;
1442 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1445 int lenMakeCommand = strlen(compiler.makeCommand);
1450 double lastTime = GetTime();
1453 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1455 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1456 else if(strstr(line, "del") == line);
1457 else if(strstr(line, "rm") == line);
1458 else if(strstr(line, "Could Not Find") == line);
1461 ide.outputView.buildBox.Logf(line);
1462 ide.outputView.buildBox.Logf("\n");
1466 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1468 if(app.ProcessInput(true))
1470 app.UpdateDisplay();
1473 //Sleep(1.0 / PEEK_RESOLUTION);
1477 bool Build(bool isARun, ProjectNode onlyNode, CompilerConfig compiler, ProjectConfig config)
1479 bool result = false;
1481 char targetFileName[MAX_LOCATION] = "";
1482 char makeTarget[MAX_LOCATION] = "";
1483 char makeFile[MAX_LOCATION];
1484 char makeFilePath[MAX_LOCATION];
1485 char configName[MAX_LOCATION];
1486 DirExpression objDirExp = GetObjDir(compiler, config);
1487 PathBackup pathBackup { };
1489 int numJobs = compiler.numJobs;
1490 char command[MAX_LOCATION];
1491 char * compilerName;
1493 compilerName = CopyString(compiler.name);
1494 CamelCase(compilerName);
1496 strcpy(configName, config ? config.name : "Common");
1498 SetPath(false, compiler, config); //true
1499 CatTargetFileName(targetFileName, compiler, config);
1501 strcpy(makeFilePath, topNode.path);
1502 CatMakeFileName(makeFile, config);
1503 PathCatSlash(makeFilePath, makeFile);
1505 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1508 if(compiler.type.isVC)
1510 PrintLn("compiling a single file is not yet supported");
1515 char pushD[MAX_LOCATION];
1516 char cfDir[MAX_LOCATION];
1517 GetCompilerConfigsDir(cfDir);
1518 GetWorkingDir(pushD, sizeof(pushD));
1519 ChangeWorkingDir(topNode.path);
1520 // Create object dir if it does not exist already
1521 if(!FileExists(objDirExp.dir).isDirectory)
1522 Execute("%s E_IDE_CF_DIR=%s COMPILER=%s objdir -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, topNode.path, makeFilePath);
1523 ChangeWorkingDir(pushD);
1525 PathCatSlash(makeTarget+1, objDirExp.dir);
1526 PathCatSlash(makeTarget+1, onlyNode.name);
1527 StripExtension(makeTarget+1);
1528 strcat(makeTarget+1, ".o");
1529 makeTarget[0] = '\"';
1530 len = strlen(makeTarget);
1531 makeTarget[len++] = '\"';
1532 makeTarget[len++] = '\0';
1536 if(compiler.type.isVC)
1538 bool result = false;
1539 char oldwd[MAX_LOCATION];
1540 GetWorkingDir(oldwd, sizeof(oldwd));
1541 ChangeWorkingDir(topNode.path);
1543 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1544 ide.outputView.buildBox.Logf("command: %s\n", command);
1545 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1547 ProcessPipeOutputRaw(f);
1551 ChangeWorkingDir(oldwd);
1555 char cfDir[MAX_LOCATION];
1556 GetCompilerConfigsDir(cfDir);
1557 sprintf(command, "%s E_IDE_CF_DIR=%s COMPILER=%s -j%d %s%s%s -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, numJobs,
1558 compiler.ccacheEnabled ? "CCACHE=y " : "",
1559 compiler.distccEnabled ? "DISTCC=y " : "",
1560 makeTarget, topNode.path, makeFilePath);
1561 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1563 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode, compiler, config);
1567 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
1572 delete compilerName;
1576 void Clean(CompilerConfig compiler, ProjectConfig config, bool realclean)
1578 char makeFile[MAX_LOCATION];
1579 char makeFilePath[MAX_LOCATION];
1580 char command[MAX_LOCATION];
1581 char * compilerName;
1583 PathBackup pathBackup { };
1585 compilerName = CopyString(compiler.name);
1586 CamelCase(compilerName);
1588 SetPath(false, compiler, config);
1590 strcpy(makeFilePath, topNode.path);
1591 CatMakeFileName(makeFile, config);
1592 PathCatSlash(makeFilePath, makeFile);
1594 if(compiler.type.isVC)
1596 bool result = false;
1597 char oldwd[MAX_LOCATION];
1598 GetWorkingDir(oldwd, sizeof(oldwd));
1599 ChangeWorkingDir(topNode.path);
1601 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1602 ide.outputView.buildBox.Logf("command: %s\n", command);
1603 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1605 ProcessPipeOutputRaw(f);
1609 ChangeWorkingDir(oldwd);
1614 char cfDir[MAX_LOCATION];
1615 GetCompilerConfigsDir(cfDir);
1616 sprintf(command, "%s E_IDE_CF_DIR=%s COMPILER=%s %sclean -C \"%s\" -f \"%s\"", compiler.makeCommand, cfDir, compilerName, realclean ? "real" : "", topNode.path, makeFilePath);
1617 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1619 ide.outputView.buildBox.Tell($"Deleting target and object files...");
1620 ProcessCleanPipeOutput(f, compiler, config);
1623 ide.outputView.buildBox.Logf($"Target and object files deleted\n");
1628 delete compilerName;
1631 void Run(char * args, CompilerConfig compiler, ProjectConfig config)
1633 String target = new char[maxPathLen];
1634 char oldDirectory[MAX_LOCATION];
1635 DirExpression targetDirExp = GetTargetDir(compiler, config);
1636 PathBackup pathBackup { };
1638 // Build(project, ideMain, true, null);
1640 #if defined(__WIN32__)
1641 strcpy(target, topNode.path);
1645 PathCatSlash(target, targetDirExp.dir);
1646 CatTargetFileName(target, compiler, config);
1647 sprintf(target, "%s %s", target, args);
1648 GetWorkingDir(oldDirectory, MAX_LOCATION);
1650 if(strlen(ide.workspace.debugDir))
1652 char temp[MAX_LOCATION];
1653 strcpy(temp, topNode.path);
1654 PathCatSlash(temp, ide.workspace.debugDir);
1655 ChangeWorkingDir(temp);
1658 ChangeWorkingDir(topNode.path);
1659 // ChangeWorkingDir(topNode.path);
1660 SetPath(true, compiler, config);
1661 if(compiler.execPrefixCommand)
1663 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1664 prefixedTarget[0] = '\0';
1665 strcat(prefixedTarget, compiler.execPrefixCommand);
1666 strcat(prefixedTarget, " ");
1667 strcat(prefixedTarget, target);
1668 Execute(prefixedTarget);
1669 delete prefixedTarget;
1674 ChangeWorkingDir(oldDirectory);
1677 delete targetDirExp;
1681 void Compile(ProjectNode node, CompilerConfig compiler, ProjectConfig config)
1683 Build(false, node, compiler, config);
1687 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
1690 if(targetType == staticLibrary || targetType == sharedLibrary)
1691 strcat(fileName, "$(LP)");
1692 // !!! ReplaceSpaces must be done after all PathCat calls !!!
1693 // ReplaceSpaces(s, GetTargetFileName(config));
1694 strcat(fileName, GetTargetFileName(config));
1698 strcat(fileName, "$(E)");
1701 strcat(fileName, "$(SO)");
1704 strcat(fileName, "$(A)");
1709 bool GenerateDebugCf(CompilerConfig compiler)
1711 bool result = false;
1712 char path[MAX_LOCATION];
1714 GetCompilerConfigsDir(path);
1715 if(!FileExists(path).isDirectory)
1717 PathCatSlash(path, "debug.cf");
1719 if(FileExists(path))
1722 File f = FileOpen(path, write);
1725 f.Printf(".PHONY: debug_lists\n");
1728 f.Printf("ifdef WINDOWS\n");
1729 f.Printf(".PHONY: debug_openssl\n");
1730 f.Printf("debug_openssl:\n");
1731 f.Printf(" @$(call echo,OPENSSL_CONF = $(OPENSSL_CONF))\n");
1732 f.Printf(" @$(call echo,_OPENSSL_CONF = $(_OPENSSL_CONF))\n");
1733 f.Printf(" @$(call echo,OPENSSL_INCLUDE_DIR = $(OPENSSL_INCLUDE_DIR))\n");
1734 f.Printf(" @$(call echo,OPENSSL_LIB_DIR = $(OPENSSL_LIB_DIR))\n");
1735 f.Printf(" @$(call echo,OPENSSL_BIN_DIR = $(OPENSSL_BIN_DIR))\n");
1736 f.Printf("endif\n");
1739 f.Printf("debug_lists:\n");
1740 f.Printf(" @$(call echo,ECSOURCES = $(ECSOURCES))\n");
1741 f.Printf(" @$(call echo,SYMBOLS = $(SYMBOLS))\n");
1742 f.Printf(" @$(call echo,IMPORTS = $(IMPORTS))\n");
1743 f.Printf(" @$(call echo,COBJECTS = $(COBJECTS))\n");
1751 bool GenerateCrossPlatformCf()
1753 bool result = false;
1754 char path[MAX_LOCATION];
1756 GetCompilerConfigsDir(path);
1757 if(!FileExists(path).isDirectory)
1759 PathCatSlash(path, "crossplatform.cf");
1761 if(FileExists(path))
1764 File include = FileOpen(":crossplatform.cf", read);
1767 File f = FileOpen(path, write);
1770 for(; !include.Eof(); )
1773 int count = include.Read(buffer, 1, 4096);
1774 f.Write(buffer, 1, count);
1786 bool GenerateCompilerMk(CompilerConfig compiler)
1788 bool result = false;
1789 char path[MAX_LOCATION];
1791 char * compilerName;
1792 bool gccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "gcc") != null;
1793 Platform platform = GetRuntimePlatform();
1795 compilerName = CopyString(compiler.name);
1796 CamelCase(compilerName);
1797 name = PrintString(platform, "-", compilerName, ".cf");
1799 GetCompilerConfigsDir(path);
1800 if(!FileExists(path).isDirectory)
1802 PathCatSlash(path, name);
1804 if(FileExists(path))
1807 File f = FileOpen(path, write);
1810 bool crossCompiling = compiler.targetPlatform != platform;
1812 f.Printf("# TOOLCHAIN\n\n");
1814 //f.Printf("SHELL := %s\n", "ar"/*compiler.arCommand*/); // is this really needed?
1815 f.Printf("CPP := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.cppCommand);
1816 f.Printf("CC := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.ccCommand);
1817 f.Printf("ECP := %s\n", compiler.ecpCommand);
1818 f.Printf("ECC := %s\n", compiler.eccCommand);
1819 f.Printf("ECS := %s%s%s\n", compiler.ecsCommand,
1820 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1821 f.Printf("EAR := %s\n", compiler.earCommand);
1823 f.Printf("AS := as\n");
1824 f.Printf("LD := ld\n");
1825 f.Printf("AR := ar\n");
1826 f.Printf("STRIP := strip\n");
1827 f.Printf("UPX := upx\n");
1831 f.Printf("UPXFLAGS = -9\n\n"); // TOFEAT: Compression Level Option? Other UPX Options?
1833 f.Printf("# HARD CODED PLATFORM-SPECIFIC OPTIONS\n");
1834 f.Printf("ifdef %s\n", PlatformToMakefileVariable(tux));
1835 f.Printf("OFLAGS += -Wl,--no-undefined\n");
1836 f.Printf("endif\n\n");
1839 f.Printf("ifdef %s\n", PlatformToMakefileVariable(apple));
1840 f.Printf("OFLAGS += -framework cocoa -framework OpenGL\n");
1841 f.Printf("endif\n\n");
1844 f.Printf("PLATFORM = %s\n", (char *)compiler.targetPlatform);
1846 if((compiler.includeDirs && compiler.includeDirs.count) ||
1847 (compiler.libraryDirs && compiler.libraryDirs.count))
1849 if(compiler.includeDirs && compiler.includeDirs.count)
1851 f.Printf("CFLAGS +=");
1852 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
1855 if(compiler.libraryDirs && compiler.libraryDirs.count)
1857 f.Printf("OFLAGS +=");
1858 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
1868 delete compilerName;
1872 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath,
1873 CompilerConfig compiler, ProjectConfig config)
1875 bool result = false;
1876 char filePath[MAX_LOCATION];
1877 char makeFile[MAX_LOCATION];
1878 // PathBackup pathBackup { };
1879 // char oldDirectory[MAX_LOCATION];
1882 if(!altMakefilePath)
1884 strcpy(filePath, topNode.path);
1885 CatMakeFileName(makeFile, config);
1886 PathCatSlash(filePath, makeFile);
1889 #if defined(__WIN32__) && !defined(MAKEFILE_GENERATOR)
1890 if(compiler.type.isVC)
1892 GenerateVSSolutionFile(this, compiler);
1893 GenerateVCProjectFile(this, compiler);
1897 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
1899 /*SetPath(false, compiler, config);
1900 GetWorkingDir(oldDirectory, MAX_LOCATION);
1901 ChangeWorkingDir(topNode.path);*/
1908 Platform runtimePlatform = GetRuntimePlatform();
1909 char targetDir[MAX_LOCATION];
1910 char objDirExpNoSpaces[MAX_LOCATION];
1911 char objDirNoSpaces[MAX_LOCATION];
1912 char resDirNoSpaces[MAX_LOCATION];
1913 char targetDirExpNoSpaces[MAX_LOCATION];
1914 char fixedModuleName[MAX_FILENAME];
1915 char fixedConfigName[MAX_FILENAME];
1916 char fixedCompilerName[MAX_FILENAME];
1918 int numCObjects = 0;
1919 bool sameObjTargetDirs;
1920 DirExpression objDirExp = GetObjDir(compiler, config);
1921 TargetTypes targetType = GetTargetType(config);
1923 bool crossCompiling = compiler.targetPlatform != runtimePlatform;
1924 bool gccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "gcc") != null;
1925 bool tccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "tcc") != null;
1926 bool defaultPreprocessor = compiler.cppCommand && (strstr(compiler.cppCommand, "gcc") != null || compiler.cppCommand && strstr(compiler.cppCommand, "cpp") != null);
1928 int objectsParts, eCsourcesParts;
1929 Array<String> listItems { };
1930 Map<String, int> varStringLenDiffs { };
1931 Map<String, NameCollisionInfo> namesInfo { };
1933 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
1934 strcpy(targetDir, GetTargetDirExpression(compiler, config));
1935 ReplaceSpaces(targetDirExpNoSpaces, targetDir);
1937 strcpy(objDirExpNoSpaces, GetObjDirExpression(compiler, config));
1938 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1939 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
1940 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
1941 //ReplaceSpaces(fixedPrjName, name);
1942 ReplaceSpaces(fixedModuleName, moduleName);
1943 ReplaceSpaces(fixedConfigName, GetConfigName(config));
1944 ReplaceSpaces(fixedCompilerName, compiler.name);
1945 //CamelCase(fixedModuleName); // case is important for static linking
1946 CamelCase(fixedConfigName);
1947 CamelCase(fixedCompilerName);
1949 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
1951 f.Printf(".PHONY: all objdir%s clean realclean\n\n", sameObjTargetDirs ? "" : " targetdir");
1953 f.Printf("# CONTENT\n\n");
1955 f.Printf("MODULE := %s\n", fixedModuleName);
1956 //f.Printf("VERSION = %s\n", version);
1957 f.Printf("CONFIG := %s\n", fixedConfigName);
1958 f.Printf("ifndef COMPILER\n");
1959 f.Printf("COMPILER := default\n");
1960 f.Printf("endif\n");
1962 f.Printf("ifndef DEBUG\n");
1963 f.Printf("OPTIMIZE :=");
1964 switch(GetOptimization(config))
1968 f.Printf(" -ffast-math");
1974 if(GetDebug(config))
1978 f.Printf("OPTIMIZE := -g\n");
1979 f.Printf("NOSTRIP := y\n");
1980 f.Printf("endif\n");
1982 test = GetTargetTypeIsSetByPlatform(config);
1986 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1988 TargetTypes targetType;
1989 PlatformOptions projectPOs, configPOs;
1990 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1991 targetType = platformTargetType;
1997 f.Printf("ifdef %s\n", PlatformToMakefileVariable(platform));
1999 f.Printf("TARGET_TYPE = ");
2000 f.Printf(TargetTypeToMakefileVariable(targetType));
2004 f.Printf("else\n"); // ifCount should always be > 0
2006 f.Printf("TARGET_TYPE = ");
2007 f.Printf(TargetTypeToMakefileVariable(targetType));
2013 for(c = 0; c < ifCount; c++)
2014 f.Printf("endif\n");
2019 f.Printf("# FLAGS\n\n");
2021 f.Printf("CFLAGS =\n");
2022 f.Printf("CECFLAGS =\n");
2023 f.Printf("ECFLAGS =\n");
2024 f.Printf("OFLAGS =\n");
2025 f.Printf("LIBS =\n");
2028 f.Printf("# INCLUDES\n\n");
2030 f.Printf("include %s\n", includemkPath ? includemkPath : "$(E_IDE_CF_DIR)crossplatform.cf");
2031 f.Printf("include $(E_IDE_CF_DIR)%s-%s.cf\n", (char*)runtimePlatform, fixedCompilerName);
2034 f.Printf("# VARIABLES\n\n");
2036 f.Printf("ifndef DEBUG\n");
2037 f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2039 f.Printf("OBJ = %s.debug%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2040 f.Printf("endif\n\n");
2042 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2044 // test = GetTargetTypeIsSetByPlatform(config);
2046 char target[MAX_LOCATION];
2047 char targetNoSpaces[MAX_LOCATION];
2052 for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2054 if(type != targetType)
2059 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2061 GetMakefileTargetFileName(type, target, config);
2062 f.Printf("ifndef DEBUG\n");
2063 strcpy(targetNoSpaces, targetDir);
2064 PathCatSlash(targetNoSpaces, target);
2065 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2066 f.Printf("TARGET = %s\n", targetNoSpaces);
2068 strcpy(targetNoSpaces, targetDir);
2069 strcat(targetNoSpaces, ".debug");
2070 PathCatSlash(targetNoSpaces, target);
2071 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2072 f.Printf("TARGET = %s\n", targetNoSpaces);
2073 f.Printf("endif\n");
2076 f.Printf("else\n"); // ifCount should always be > 0
2078 GetMakefileTargetFileName(targetType, target, config);
2079 f.Printf("ifndef DEBUG\n");
2080 strcpy(targetNoSpaces, targetDir);
2081 PathCatSlash(targetNoSpaces, target);
2082 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2083 f.Printf("TARGET = %s\n", targetNoSpaces);
2085 strcpy(targetNoSpaces, targetDir);
2086 strcat(targetNoSpaces, ".debug");
2087 PathCatSlash(targetNoSpaces, target);
2088 ReplaceSpaces(targetNoSpaces, targetNoSpaces);
2089 f.Printf("TARGET = %s\n", targetNoSpaces);
2090 f.Printf("endif\n");
2096 for(c = 0; c < ifCount; c++)
2097 f.Printf("endif\n");
2103 varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2105 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2107 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config);
2109 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
2110 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs, null);
2114 char * map[3][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" } };
2116 topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config);
2117 eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2119 f.Printf("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2120 if(eCsourcesParts > 1)
2122 for(c = 1; c <= eCsourcesParts; c++)
2123 f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2127 for(c = 0; c < 3; c++)
2129 if(eCsourcesParts > 1)
2132 f.Printf("%s =", map[c][0]);
2133 for(n = 1; n <= eCsourcesParts; n++)
2134 f.Printf(" $(%s%d)", map[c][0], n);
2136 for(n = 1; n <= eCsourcesParts; n++)
2137 f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2139 else if(eCsourcesParts == 1)
2140 f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2145 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config);
2146 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, "$(ECSOURCES)");
2149 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config);
2150 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2152 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2153 f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2154 f.Printf("endif\n\n");
2156 if((config && config.options && config.options.libraries) ||
2157 (options && options.libraries))
2159 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2160 f.Printf("LIBS +=");
2161 if(config && config.options && config.options.libraries)
2162 OutputLibraries(f, config.options.libraries);
2163 else if(options && options.libraries)
2164 OutputLibraries(f, options.libraries);
2166 f.Printf("endif\n");
2169 f.Printf("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
2171 if(platforms || (config && config.platforms))
2174 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2175 //for(platform = win32; platform <= apple; platform++)
2177 f.Printf("# PLATFORM-SPECIFIC OPTIONS\n\n");
2178 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2180 PlatformOptions projectPlatformOptions, configPlatformOptions;
2181 MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2183 if(projectPlatformOptions || configPlatformOptions)
2189 f.Printf(PlatformToMakefileVariable(platform));
2192 if((projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions && projectPlatformOptions.options.preprocessorDefinitions.count) ||
2193 (configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions && configPlatformOptions.options.preprocessorDefinitions.count) ||
2194 (projectPlatformOptions && projectPlatformOptions.options.includeDirs && projectPlatformOptions.options.includeDirs.count) ||
2195 (configPlatformOptions && configPlatformOptions.options.includeDirs && configPlatformOptions.options.includeDirs.count))
2197 f.Printf("CFLAGS +=");
2198 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2200 f.Printf(" \\\n\t -Wl");
2201 for(s : projectPlatformOptions.options.linkerOptions)
2204 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2206 f.Printf(" \\\n\t -Wl");
2207 for(s : configPlatformOptions.options.linkerOptions)
2210 if(projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions)
2211 OutputListOption(f, "D", projectPlatformOptions.options.preprocessorDefinitions, newLine, false);
2212 if(configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions)
2213 OutputListOption(f, "D", configPlatformOptions.options.preprocessorDefinitions, newLine, false );
2214 if(configPlatformOptions && configPlatformOptions.options.includeDirs)
2215 OutputListOption(f, "I", configPlatformOptions.options.includeDirs, lineEach, true);
2216 if(projectPlatformOptions && projectPlatformOptions.options.includeDirs)
2217 OutputListOption(f, "I", projectPlatformOptions.options.includeDirs, lineEach, true);
2221 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2222 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2223 (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2224 (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2226 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2227 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2228 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2230 f.Printf("OFLAGS +=");
2231 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2232 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2233 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2234 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2238 if(projectPlatformOptions && projectPlatformOptions.options.libraries &&
2239 projectPlatformOptions.options.libraries.count)
2241 f.Printf("LIBS +=");
2242 OutputLibraries(f, projectPlatformOptions.options.libraries);
2245 if((configPlatformOptions && configPlatformOptions.options.libraries &&
2246 configPlatformOptions.options.libraries.count))
2248 f.Printf("LIBS +=");
2249 OutputLibraries(f, configPlatformOptions.options.libraries);
2252 f.Printf("endif\n\n");
2258 for(c = 0; c < ifCount; c++)
2259 f.Printf("endif\n");
2264 f.Printf("CFLAGS +=");
2267 f.Printf(" -fmessage-length=0 $(OPTIMIZE)");
2268 //if(compiler.targetPlatform.is32Bits)
2270 //else if(compiler.targetPlatform.is64Bits)
2271 // f.Printf(" -m64");
2272 f.Printf(" $(FPIC)");
2273 //f.Printf(" -fpack-struct");
2275 switch(GetWarnings(config))
2277 case all: f.Printf(" -Wall"); break;
2278 case none: f.Printf(" -w"); break;
2280 if(GetProfile(config))
2282 if(options && options.linkerOptions && options.linkerOptions.count)
2284 f.Printf(" \\\n\t -Wl");
2285 for(s : options.linkerOptions)
2289 if(options && options.preprocessorDefinitions)
2290 OutputListOption(f, "D", options.preprocessorDefinitions, newLine, false);
2291 if(config && config.options && config.options.preprocessorDefinitions)
2292 OutputListOption(f, "D", config.options.preprocessorDefinitions, newLine, false);
2293 if(config && config.options && config.options.includeDirs)
2294 OutputListOption(f, "I", config.options.includeDirs, lineEach, true);
2295 if(options && options.includeDirs)
2296 OutputListOption(f, "I", options.includeDirs, lineEach, true);
2299 f.Printf("CECFLAGS +=%s%s%s%s", defaultPreprocessor ? "" : " -cpp ", defaultPreprocessor ? "" : compiler.cppCommand,
2300 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
2303 f.Printf("ECFLAGS +=");
2304 if(GetMemoryGuard(config))
2305 f.Printf(" -memguard");
2306 if(GetStrictNameSpaces(config))
2307 f.Printf(" -strictns");
2308 if(GetNoLineNumbers(config))
2309 f.Printf(" -nolinenumbers");
2312 if((s = GetDefaultNameSpace(config)) && s[0])
2313 f.Printf(" -defaultns %s", s);
2317 f.Printf("OFLAGS +=\n");
2318 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2319 f.Printf("OFLAGS += -m32");
2320 if(GetProfile(config))
2322 if(config && config.options && config.options.libraryDirs)
2323 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
2324 if(options && options.libraryDirs)
2325 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
2327 f.Printf("endif\n\n");
2329 f.Printf("# TARGETS\n\n");
2331 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
2333 f.Printf("objdir:\n");
2334 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2335 //f.Printf("# PRE-BUILD COMMANDS\n");
2336 if(options && options.prebuildCommands)
2338 for(s : options.prebuildCommands)
2339 if(s && s[0]) f.Printf("\t%s\n", s);
2341 if(config && config.options && config.options.prebuildCommands)
2343 for(s : config.options.prebuildCommands)
2344 if(s && s[0]) f.Printf("\t%s\n", s);
2346 if(platforms || (config && config.platforms))
2349 //f.Printf("# PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2350 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2352 PlatformOptions projectPOs, configPOs;
2353 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2355 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2356 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2362 f.Printf(PlatformToMakefileVariable(platform));
2365 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2367 for(s : projectPOs.options.prebuildCommands)
2368 if(s && s[0]) f.Printf("\t%s\n", s);
2370 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2372 for(s : configPOs.options.prebuildCommands)
2373 if(s && s[0]) f.Printf("\t%s\n", s);
2380 for(c = 0; c < ifCount; c++)
2381 f.Printf("endif\n");
2386 if(!sameObjTargetDirs)
2388 f.Printf("targetdir:\n");
2389 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2394 // Main Module (Linking) for ECERE C modules
2395 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2396 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2397 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2398 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
2399 // Main Module (Linking) for ECERE C modules
2400 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2401 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2402 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2403 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2404 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2409 // This would not rebuild the target on updated objects
2410 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2412 // This should fix it for good!
2413 f.Printf("$(SYMBOLS): | objdir\n");
2414 f.Printf("$(OBJECTS): | objdir\n");
2416 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2417 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2419 f.Printf("ifneq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(staticLibrary));
2420 f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET) $(INSTALLNAME)\n");
2421 if(!GetDebug(config))
2423 f.Printf("ifndef NOSTRIP\n");
2424 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2425 f.Printf("endif\n");
2427 if(GetCompress(config))
2429 f.Printf("ifndef WINDOWS\n");
2430 f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(executable));
2431 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2432 f.Printf("endif\n");
2434 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2435 f.Printf("endif\n");
2438 if(resNode.files && resNode.files.count && !noResources)
2439 resNode.GenMakefileAddResources(f, resNode.path, config);
2441 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2442 f.Printf("endif\n");
2444 //f.Printf("# POST-BUILD COMMANDS\n");
2445 if(options && options.postbuildCommands)
2447 for(s : options.postbuildCommands)
2448 if(s && s[0]) f.Printf("\t%s\n", s);
2450 if(config && config.options && config.options.postbuildCommands)
2452 for(s : config.options.postbuildCommands)
2453 if(s && s[0]) f.Printf("\t%s\n", s);
2455 if(platforms || (config && config.platforms))
2458 //f.Printf("# PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2459 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2461 PlatformOptions projectPOs, configPOs;
2462 MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2464 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2465 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2471 f.Printf(PlatformToMakefileVariable(platform));
2474 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2476 for(s : projectPOs.options.postbuildCommands)
2477 if(s && s[0]) f.Printf("\t%s\n", s);
2479 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2481 for(s : configPOs.options.postbuildCommands)
2482 if(s && s[0]) f.Printf("\t%s\n", s);
2489 for(c = 0; c < ifCount; c++)
2490 f.Printf("endif\n");
2495 f.Printf("# SYMBOL RULES\n\n");
2497 Map<Platform, bool> excludedPlatforms { };
2498 topNode.GenMakefilePrintSymbolRules(f, this, compiler, config, excludedPlatforms);
2499 delete excludedPlatforms;
2502 f.Printf("# C OBJECT RULES\n\n");
2504 Map<Platform, bool> excludedPlatforms { };
2505 topNode.GenMakefilePrintCObjectRules(f, this, compiler, config, excludedPlatforms);
2506 delete excludedPlatforms;
2509 f.Printf("# OBJECT RULES\n\n");
2510 // todo call this still but only generate rules whith specific options
2511 // see we-have-file-specific-options in ProjectNode.ec
2513 Map<Platform, bool> excludedPlatforms { };
2514 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, compiler, config, excludedPlatforms);
2515 delete excludedPlatforms;
2519 GenMakefilePrintMainObjectRule(f, compiler, config);
2521 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2522 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) " : "");
2523 OutputCleanActions(f, "OBJECTS", objectsParts);
2524 OutputCleanActions(f, "COBJECTS", eCsourcesParts);
2527 OutputCleanActions(f, "IMPORTS", eCsourcesParts);
2528 OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
2532 f.Printf("realclean: clean\n");
2533 f.Printf("\t$(call rmrq,$(OBJ))\n");
2534 if(!sameObjTargetDirs)
2535 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2538 f.Printf("include $(E_IDE_CF_DIR)debug.cf\n");
2544 varStringLenDiffs.Free();
2545 delete varStringLenDiffs;
2552 // ChangeWorkingDir(oldDirectory);
2553 // delete pathBackup;
2556 config.makingModified = false;
2560 void GenMakefilePrintMainObjectRule(File f, CompilerConfig compiler, ProjectConfig config)
2562 char extension[MAX_EXTENSION] = "c";
2563 char modulePath[MAX_LOCATION];
2564 char fixedModuleName[MAX_FILENAME];
2567 char objDirNoSpaces[MAX_LOCATION];
2568 DirExpression objDirExp = GetObjDir(compiler, config);
2570 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
2571 ReplaceSpaces(fixedModuleName, moduleName);
2573 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2574 //strcat(fixedModuleName, ".main");
2576 #if 0 // TODO: Fix nospaces stuff
2577 // *** Dependency command ***
2578 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2580 // System Includes (from global settings)
2581 for(item : compiler.dirs[Includes])
2583 strcat(command, " -isystem ");
2584 if(strchr(item.name, ' '))
2586 strcat(command, "\"");
2587 strcat(command, item);
2588 strcat(command, "\"");
2591 strcat(command, item);
2594 for(item = includeDirs.first; item; item = item.next)
2596 strcat(command, " -I");
2597 if(strchr(item.name, ' '))
2599 strcat(command, "\"");
2600 strcat(command, item.name);
2601 strcat(command, "\"");
2604 strcat(command, item.name);
2606 for(item = preprocessorDefs.first; item; item = item.next)
2608 strcat(command, " -D");
2609 strcat(command, item.name);
2613 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2617 bool firstLine = true;
2619 // To do some time: auto save external dependencies?
2622 if(dep.GetLine(line, sizeof(line)-1))
2626 char * colon = strstr(line, ":");
2627 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2641 // If we failed to generate dependencies...
2645 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2651 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2656 void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
2657 PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
2659 *projectPlatformOptions = null;
2660 *configPlatformOptions = null;
2665 if(!strcmpi(p.name, platform))
2667 *projectPlatformOptions = p;
2672 if(config && config.platforms)
2674 for(p : config.platforms)
2676 if(!strcmpi(p.name, platform))
2678 *configPlatformOptions = p;
2686 Project LegacyBinaryLoadProject(File f, char * filePath)
2688 Project project = null;
2689 char signature[sizeof(epjSignature)];
2691 f.Read(signature, sizeof(signature), 1);
2692 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2694 char topNodePath[MAX_LOCATION];
2695 /*ProjectConfig newConfig
2697 name = CopyString("Default");
2698 makingModified = true;
2699 compilingModified = true;
2700 linkingModified = true;
2704 project = Project { options = { } };
2705 LegacyBinaryLoadNode(project.topNode, f);
2706 delete project.topNode.path;
2707 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2708 MakeSlashPath(topNodePath);
2710 PathCatSlash(topNodePath, filePath);
2711 project.filePath = topNodePath;
2713 /* THIS IS ALREADY DONE BY filePath property
2714 StripLastDirectory(topNodePath, topNodePath);
2715 project.topNode.path = CopyString(topNodePath);
2717 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2719 // newConfig.options.defaultNameSpace = "";
2720 /*newConfig.objDir.dir = "obj";
2721 newConfig.targetDir.dir = "";*/
2723 //project.configurations = { [ newConfig ] };
2724 //project.config = newConfig;
2731 String targetFileName, targetDirectory, objectsDirectory;
2733 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2734 f.Read(&temp, sizeof(int),1);
2737 case 0: project.options.targetType = executable; break;
2738 case 1: project.options.targetType = sharedLibrary; break;
2739 case 2: project.options.targetType = staticLibrary; break;
2742 f.Read(&len, sizeof(int),1);
2743 targetFileName = new char[len+1];
2744 f.Read(targetFileName, sizeof(char), len+1);
2745 project.options.targetFileName = targetFileName;
2746 delete targetFileName;
2748 f.Read(&len, sizeof(int),1);
2749 targetDirectory = new char[len+1];
2750 f.Read(targetDirectory, sizeof(char), len+1);
2751 project.options.targetDirectory = targetDirectory;
2752 delete targetDirectory;
2754 f.Read(&len, sizeof(int),1);
2755 objectsDirectory = new byte[len+1];
2756 f.Read(objectsDirectory, sizeof(char), len+1);
2757 project.options.objectsDirectory = objectsDirectory;
2758 delete objectsDirectory;
2760 f.Read(&temp, sizeof(int),1);
2761 project./*config.*/options.debug = temp ? true : false;
2762 f.Read(&temp, sizeof(int),1);
2763 project./*config.*/options.optimization = temp ? speed : none;
2764 f.Read(&temp, sizeof(int),1);
2765 project./*config.*/options.profile = temp ? true : false;
2766 f.Read(&temp, sizeof(int),1);
2767 project.options.warnings = temp ? all : unset;
2769 f.Read(&count, sizeof(int),1);
2772 project.options.includeDirs = { };
2773 for(c = 0; c < count; c++)
2776 f.Read(&len, sizeof(int),1);
2777 name = new char[len+1];
2778 f.Read(name, sizeof(char), len+1);
2779 project.options.includeDirs.Add(name);
2783 f.Read(&count, sizeof(int),1);
2786 project.options.libraryDirs = { };
2787 for(c = 0; c < count; c++)
2790 f.Read(&len, sizeof(int),1);
2791 name = new char[len+1];
2792 f.Read(name, sizeof(char), len+1);
2793 project.options.libraryDirs.Add(name);
2797 f.Read(&count, sizeof(int),1);
2800 project.options.libraries = { };
2801 for(c = 0; c < count; c++)
2804 f.Read(&len, sizeof(int),1);
2805 name = new char[len+1];
2806 f.Read(name, sizeof(char), len+1);
2807 project.options.libraries.Add(name);
2811 f.Read(&count, sizeof(int),1);
2814 project.options.preprocessorDefinitions = { };
2815 for(c = 0; c < count; c++)
2818 f.Read(&len, sizeof(int),1);
2819 name = new char[len+1];
2820 f.Read(name, sizeof(char), len+1);
2821 project.options.preprocessorDefinitions.Add(name);
2825 f.Read(&temp, sizeof(int),1);
2826 project.options.console = temp ? true : false;
2829 for(node : project.topNode.files)
2831 if(node.type == resources)
2833 project.resNode = node;
2843 void ProjectConfig::LegacyProjectConfigLoad(File f)
2851 char subSection[128];
2857 f.GetLine(buffer, 65536 - 1);
2858 TrimLSpaces(buffer, buffer);
2859 TrimRSpaces(buffer, buffer);
2862 if(buffer[0] == '-')
2866 TrimLSpaces(equal, equal);
2867 if(!strcmpi(subSection, "LibraryDirs"))
2869 if(!options.libraryDirs)
2870 options.libraryDirs = { [ CopyString(equal) ] };
2872 options.libraryDirs.Add(CopyString(equal));
2874 else if(!strcmpi(subSection, "IncludeDirs"))
2876 if(!options.includeDirs)
2877 options.includeDirs = { [ CopyString(equal) ] };
2879 options.includeDirs.Add(CopyString(equal));
2882 else if(buffer[0] == '+')
2893 TrimLSpaces(equal, equal);
2894 delete name; name = CopyString(equal); // property::name = equal;
2897 else if(!strcmpi(buffer, "Compiler Options"))
2898 strcpy(section, buffer);
2899 else if(!strcmpi(buffer, "IncludeDirs"))
2900 strcpy(subSection, buffer);
2901 else if(!strcmpi(buffer, "Linker Options"))
2902 strcpy(section, buffer);
2903 else if(!strcmpi(buffer, "LibraryDirs"))
2904 strcpy(subSection, buffer);
2905 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
2912 equal = strstr(buffer, "=");
2916 TrimRSpaces(buffer, buffer);
2918 TrimLSpaces(equal, equal);
2919 if(!strcmpi(buffer, "Target Name"))
2920 options.targetFileName = /*CopyString(*/equal/*)*/;
2921 else if(!strcmpi(buffer, "Target Type"))
2923 if(!strcmpi(equal, "Executable"))
2924 options.targetType = executable;
2925 else if(!strcmpi(equal, "Shared"))
2926 options.targetType = sharedLibrary;
2927 else if(!strcmpi(equal, "Static"))
2928 options.targetType = staticLibrary;
2930 options.targetType = executable;
2932 else if(!strcmpi(buffer, "Target Directory"))
2933 options.targetDirectory = /*CopyString(*/equal/*)*/;
2934 else if(!strcmpi(buffer, "Console"))
2935 options.console = ParseTrueFalseValue(equal);
2936 else if(!strcmpi(buffer, "Libraries"))
2938 if(!options.libraries) options.libraries = { };
2939 ParseArrayValue(options.libraries, equal);
2941 else if(!strcmpi(buffer, "Intermediate Directory"))
2942 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
2943 else if(!strcmpi(buffer, "Debug"))
2944 options.debug = ParseTrueFalseValue(equal);
2945 else if(!strcmpi(buffer, "Optimize"))
2947 if(!strcmpi(equal, "None"))
2948 options.optimization = none;
2949 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
2950 options.optimization = speed;
2951 else if(!strcmpi(equal, "Size"))
2952 options.optimization = size;
2954 options.optimization = none;
2956 else if(!strcmpi(buffer, "Compress"))
2957 options.compress = ParseTrueFalseValue(equal);
2958 else if(!strcmpi(buffer, "Profile"))
2959 options.profile = ParseTrueFalseValue(equal);
2960 else if(!strcmpi(buffer, "AllWarnings"))
2961 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
2962 else if(!strcmpi(buffer, "MemoryGuard"))
2963 options.memoryGuard = ParseTrueFalseValue(equal);
2964 else if(!strcmpi(buffer, "Default Name Space"))
2965 options.defaultNameSpace = CopyString(equal);
2966 else if(!strcmpi(buffer, "Strict Name Spaces"))
2967 options.strictNameSpaces = ParseTrueFalseValue(equal);
2968 else if(!strcmpi(buffer, "Preprocessor Definitions"))
2970 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
2971 ParseArrayValue(options.preprocessorDefinitions, equal);
2977 if(!options.targetDirectory && options.objectsDirectory)
2978 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
2979 //if(!objDir.dir) objDir.dir = "obj";
2980 //if(!targetDir.dir) targetDir.dir = "";
2981 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
2982 // if(!defaultNameSpace) property::defaultNameSpace = "";
2983 makingModified = true;
2986 Project LegacyAsciiLoadProject(File f, char * filePath)
2988 Project project = null;
2989 ProjectNode node = null;
2991 char parentPath[MAX_LOCATION];
2992 char section[128] = "";
2993 char subSection[128] = "";
2995 bool configurationsPresent = false;
3005 f.GetLine(buffer, 65536 - 1);
3006 TrimLSpaces(buffer, buffer);
3007 TrimRSpaces(buffer, buffer);
3010 if(buffer[0] == '-' || buffer[0] == '=')
3012 bool simple = buffer[0] == '-';
3015 TrimLSpaces(equal, equal);
3016 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3018 if(!project.config.options.libraryDirs) project.config.options.libraryDirs = { };
3019 project.config.options.libraryDirs.Add(CopyString(equal));
3021 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3023 if(!project.config.options.includeDirs) project.config.options.includeDirs = { };
3024 project.config.options.includeDirs.Add(CopyString(equal));
3026 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3028 len = strlen(equal);
3031 char temp[MAX_LOCATION];
3032 ProjectNode child { };
3033 // We don't need to do this anymore, fileName is just a property that sets name & path
3034 // child.fileName = CopyString(equal);
3037 child.name = CopyString(equal);
3038 child.path = CopyString(parentPath);
3042 GetLastDirectory(equal, temp);
3043 child.name = CopyString(temp);
3044 StripLastDirectory(equal, temp);
3045 child.path = CopyString(temp);
3047 child.nodeType = file;
3048 child.parent = parent;
3049 child.indent = parent.indent + 1;
3051 child.icon = NodeIcons::SelectFileIcon(child.name);
3052 parent.files.Add(child);
3058 StripLastDirectory(parentPath, parentPath);
3059 parent = parent.parent;
3063 else if(buffer[0] == '+')
3067 TrimLSpaces(equal, equal);
3068 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3070 char temp[MAX_LOCATION];
3071 ProjectNode child { };
3072 // NEW: Folders now have a path set like files
3073 child.name = CopyString(equal);
3074 strcpy(temp, parentPath);
3075 PathCatSlash(temp, child.name);
3076 child.path = CopyString(temp);
3078 child.parent = parent;
3079 child.indent = parent.indent + 1;
3080 child.type = folder;
3081 child.nodeType = folder;
3083 child.icon = folder;
3084 PathCatSlash(parentPath, child.name);
3085 parent.files.Add(child);
3090 else if(!strcmpi(section, "Configurations"))
3092 ProjectConfig newConfig
3094 makingModified = true;
3098 LegacyProjectConfigLoad(newConfig, f);
3099 project.configurations.Add(newConfig);
3102 else if(!strcmpi(buffer, "ECERE Project File"));
3103 else if(!strcmpi(buffer, "Version 0a"))
3104 ; //strcpy(version, "0a");
3105 else if(!strcmpi(buffer, "Version 0.1a"))
3106 ; //strcpy(version, "0.1a");
3107 else if(!strcmpi(buffer, "Configurations"))
3109 project.configurations.Free();
3110 project.config = null;
3111 strcpy(section, buffer);
3112 configurationsPresent = true;
3114 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3116 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3117 char topNodePath[MAX_LOCATION];
3118 // newConfig.defaultNameSpace = "";
3119 //newConfig.objDir.dir = "obj";
3120 //newConfig.targetDir.dir = "";
3121 project = Project { /*options = { }*/ };
3122 project.configurations = { [ newConfig ] };
3123 project.config = newConfig;
3124 // if(project.topNode.path) delete project.topNode.path;
3125 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3126 MakeSlashPath(topNodePath);
3127 PathCatSlash(topNodePath, filePath);
3128 project.filePath = topNodePath;
3129 parentPath[0] = '\0';
3130 parent = project.topNode;
3132 strcpy(section, "Target");
3137 if(equal[0] == '\"')
3139 StripQuotes(equal, equal);
3140 delete project.moduleName; project.moduleName = CopyString(equal);
3144 else if(!strcmpi(buffer, "Compiler Options"));
3145 else if(!strcmpi(buffer, "IncludeDirs"))
3146 strcpy(subSection, buffer);
3147 else if(!strcmpi(buffer, "Linker Options"));
3148 else if(!strcmpi(buffer, "LibraryDirs"))
3149 strcpy(subSection, buffer);
3150 else if(!strcmpi(buffer, "Files"))
3152 strcpy(section, "Target");
3153 strcpy(subSection, buffer);
3155 else if(!strcmpi(buffer, "Resources"))
3157 ProjectNode child { };
3158 parent.files.Add(child);
3159 child.parent = parent;
3160 child.indent = parent.indent + 1;
3161 child.name = CopyString(buffer);
3162 child.path = CopyString("");
3163 child.type = resources;
3165 child.icon = archiveFile;
3166 project.resNode = child;
3169 strcpy(subSection, buffer);
3173 equal = strstr(buffer, "=");
3177 TrimRSpaces(buffer, buffer);
3179 TrimLSpaces(equal, equal);
3181 if(!strcmpi(section, "Target"))
3183 if(!strcmpi(buffer, "Build Exclusions"))
3185 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3187 /*if(node && node.type != NodeTypes::project)
3188 ParseListValue(node.buildExclusions, equal);*/
3191 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
3193 delete project.resNode.path;
3194 project.resNode.path = CopyString(equal);
3195 PathCatSlash(parentPath, equal);
3199 else if(!strcmpi(buffer, "Intermediate Directory"))
3200 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3201 else if(!strcmpi(buffer, "Debug"))
3202 project.config.options.debug = ParseTrueFalseValue(equal);
3203 else if(!strcmpi(buffer, "Optimize"))
3205 if(!strcmpi(equal, "None"))
3206 project.config.options.optimization = none;
3207 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3208 project.config.options.optimization = speed;
3209 else if(!strcmpi(equal, "Size"))
3210 project.config.options.optimization = size;
3212 project.config.options.optimization = none;
3214 else if(!strcmpi(buffer, "Profile"))
3215 project.config.options.profile = ParseTrueFalseValue(equal);
3216 else if(!strcmpi(buffer, "MemoryGuard"))
3217 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
3220 if(!project.options) project.options = { };
3222 // Project Wide Settings (All configs)
3223 if(!strcmpi(buffer, "Target Name"))
3224 project.options.targetFileName = /*CopyString(*/equal/*)*/;
3225 else if(!strcmpi(buffer, "Target Type"))
3227 if(!strcmpi(equal, "Executable"))
3228 project.options.targetType = executable;
3229 else if(!strcmpi(equal, "Shared"))
3230 project.options.targetType = sharedLibrary;
3231 else if(!strcmpi(equal, "Static"))
3232 project.options.targetType = staticLibrary;
3234 project.options.targetType = executable;
3236 else if(!strcmpi(buffer, "Target Directory"))
3237 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
3238 else if(!strcmpi(buffer, "Console"))
3239 project.options.console = ParseTrueFalseValue(equal);
3240 else if(!strcmpi(buffer, "Libraries"))
3242 if(!project.options.libraries) project.options.libraries = { };
3243 ParseArrayValue(project.options.libraries, equal);
3245 else if(!strcmpi(buffer, "AllWarnings"))
3246 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3247 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3249 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3251 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
3252 ParseListValue(node.preprocessorDefs, equal);*/
3256 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
3257 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3268 SplitPlatformLibraries(project);
3270 if(configurationsPresent)
3271 CombineIdenticalConfigOptions(project);
3275 void SplitPlatformLibraries(Project project)
3277 if(project && project.configurations)
3279 for(cfg : project.configurations)
3281 if(cfg.options.libraries && cfg.options.libraries.count)
3283 Iterator<String> it { cfg.options.libraries };
3287 char * platformName = strstr(l, ":");
3290 PlatformOptions platform = null;
3292 if(!cfg.platforms) cfg.platforms = { };
3293 for(p : cfg.platforms)
3295 if(!strcmpi(platformName, p.name))
3303 platform = { name = CopyString(platformName), options = { libraries = { } } };
3304 cfg.platforms.Add(platform);
3306 *(platformName-1) = 0;
3307 platform.options.libraries.Add(CopyString(l));
3309 cfg.options.libraries.Delete(it.pointer);
3318 void CombineIdenticalConfigOptions(Project project)
3320 if(project && project.configurations && project.configurations.count)
3323 ProjectOptions nullOptions { };
3324 ProjectConfig firstConfig = null;
3325 for(cfg : project.configurations)
3327 if(cfg.options.targetType != staticLibrary)
3334 firstConfig = project.configurations.firstIterator.data;
3336 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3338 if(!member.isProperty)
3340 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3345 for(cfg : project.configurations)
3347 if(cfg != firstConfig)
3349 if(cfg.options.targetType != staticLibrary)
3353 if(type.type == noHeadClass || type.type == normalClass)
3355 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3356 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3357 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3361 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3362 (byte *)firstConfig.options + member.offset + member._class.offset,
3363 (byte *)cfg.options + member.offset + member._class.offset);
3375 if(type.type == noHeadClass || type.type == normalClass)
3377 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3378 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3379 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3384 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3385 (byte *)firstConfig.options + member.offset + member._class.offset,
3386 (byte *)nullOptions + member.offset + member._class.offset))
3390 if(!project.options) project.options = { };
3392 /*if(type.type == noHeadClass || type.type == normalClass)
3394 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3395 (byte *)project.options + member.offset + member._class.offset,
3396 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3400 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3401 // TOFIX: ListBox::SetData / OnCopy mess
3402 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3403 (byte *)project.options + member.offset + member._class.offset,
3404 (type.typeSize > 4) ? address :
3405 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3406 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3407 (void *)*(byte *)address )));
3410 (byte *)project.options + member.offset + member._class.offset,
3411 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3413 for(cfg : project.configurations)
3415 if(cfg.options.targetType == staticLibrary)
3419 if(type.type == noHeadClass || type.type == normalClass)
3421 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3422 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3423 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3427 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3428 (byte *)firstConfig.options + member.offset + member._class.offset,
3429 (byte *)cfg.options + member.offset + member._class.offset);
3434 if(cfg != firstConfig)
3436 if(type.type == noHeadClass || type.type == normalClass)
3438 type._vTbl[__ecereVMethodID_class_OnFree](type,
3439 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3443 type._vTbl[__ecereVMethodID_class_OnFree](type,
3444 (byte *)cfg.options + member.offset + member._class.offset);
3446 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3449 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3456 // Compare Platform Specific Settings
3459 for(cfg : project.configurations)
3461 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3462 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3468 if(same && firstConfig.platforms)
3470 for(cfg : project.configurations)
3472 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3474 if(cfg != firstConfig)
3476 cfg.platforms.Free();
3477 delete cfg.platforms;
3480 project.platforms = firstConfig.platforms;
3481 firstConfig.platforms = null;
3485 // Static libraries can't contain libraries
3486 for(cfg : project.configurations)
3488 if(cfg.options.targetType == staticLibrary)
3490 if(!cfg.options.libraries) cfg.options.libraries = { };
3491 cfg.options.libraries.Free();
3497 Project LoadProject(char * filePath)
3499 Project project = null;
3500 File f = FileOpen(filePath, read);
3503 project = LegacyBinaryLoadProject(f, filePath);
3506 JSONParser parser { f = f };
3507 JSONResult result = parser.GetObject(class(Project), &project);
3510 char insidePath[MAX_LOCATION];
3512 delete project.topNode.files;
3513 if(!project.files) project.files = { };
3514 project.topNode.files = project.files;
3515 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3516 delete project.resNode.path;
3517 project.resNode.path = project.resourcesPath;
3518 project.resourcesPath = null;
3519 project.resNode.nodeType = (ProjectNodeType)-1;
3520 delete project.resNode.files;
3521 project.resNode.files = project.resources;
3522 project.files = null;
3523 project.resources = null;
3524 if(!project.configurations) project.configurations = { };
3527 char topNodePath[MAX_LOCATION];
3528 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3529 MakeSlashPath(topNodePath);
3530 PathCatSlash(topNodePath, filePath);
3531 project.filePath = topNodePath;//filePath;
3534 project.topNode.FixupNode(insidePath);
3539 project = LegacyAsciiLoadProject(f, filePath);
3545 if(!project.options) project.options = { };
3546 if(!project.config && project.configurations)
3547 project.config = project.configurations.firstIterator.data;
3549 if(!project.resNode)
3551 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3554 if(!project.moduleName)
3555 project.moduleName = CopyString(project.name);
3556 if(project.config &&
3557 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3558 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3560 //delete project.config.options.targetFileName;
3562 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
3563 project.config.options.optimization = none;
3564 project.config.options.debug = true;
3565 //project.config.options.warnings = unset;
3566 project.config.options.memoryGuard = false;
3567 project.config.compilingModified = true;
3568 project.config.linkingModified = true;
3570 else if(!project.topNode.name && project.config)
3572 project.topNode.name = CopyString(project.config.options.targetFileName);
3575 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3576 project.topNode.configurations = project.configurations;
3577 project.topNode.platforms = project.platforms;
3578 project.topNode.options = project.options;*/