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 };
379 define WorkspaceExtension = "ews";
380 define ProjectExtension = "epj";
382 void ReplaceSpaces(char * output, char * source)
387 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
389 if(ch == ' ') output[dc++] = '\\';
392 if(ch == '(' || ch == ')') output[dc++] = '\\';
402 static void OutputNoSpace(File f, char * source)
404 char * output = new char[strlen(source)+1024];
405 ReplaceSpaces(output, source);
410 enum ListOutputMethod { inPlace, newLine, lineEach };
412 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs)
415 const int breakListLength = 1536;
416 const int breakLineLength = 78; // TODO: turn this into an option.
418 int c, len, itemCount = 0;
419 Array<int> breaks { };
423 MapNode<String, int> mn;
424 for(c=0; c<list.count; c++)
426 len = strlen(list[c]) + 3;
427 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
429 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
431 if(strstr(list[c], mn.key))
435 if(charCount + len > breakListLength)
437 breaks.Add(itemCount);
445 breaks.Add(itemCount);
446 numOfBreaks = breaks.count;
451 f.Printf("%s =", name);
452 for(c=0; c<numOfBreaks; c++)
453 f.Printf(" $(%s%d)", name, c+1);
457 f.Printf("%s =", name);
463 for(c=0; c<numOfBreaks; c++)
466 f.Printf("%s%d =", name, c+1);
469 itemCount = breaks[c];
470 for(n=offset; n<offset+itemCount; n++)
472 if(false) // TODO: turn this into an option.
474 int itemLen = strlen(list[n]);
475 if(len > 3 && len + itemLen > breakLineLength)
477 f.Printf(" \\\n\t%s", list[n]);
483 f.Printf(" %s", list[n]);
487 f.Printf(" \\\n\t%s", list[n]);
502 void OutputCleanActions(File f, char * name, int parts)
507 for(c=0; c<parts; c++)
508 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
511 f.Printf("\t$(call rmq,$(%s))\n", name);
514 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
518 if(method == newLine)
522 if(method == lineEach)
524 f.Printf(" -%s", option);
526 OutputNoSpace(f, item);
528 f.Printf("%s", item);
533 static void OutputLibraries(File f, Array<String> libraries)
535 for(item : libraries)
537 char ext[MAX_EXTENSION];
538 char temp[MAX_LOCATION];
540 GetExtension(item, ext);
541 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
545 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
547 if(!strncmp(item, "lib", 3))
548 strcpy(temp, item + 3);
551 StripExtension(temp);
560 void CamelCase(char * string)
562 int c, len = strlen(string);
563 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
564 string[c] = (char)tolower(string[c]);
567 CompilerConfig GetCompilerConfig()
569 #ifndef MAKEFILE_GENERATOR
570 CompilerConfig compiler = null;
571 if(ide && ide.workspace)
572 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
575 incref defaultCompiler;
576 return defaultCompiler;
580 define localTargetType = config && config.options && config.options.targetType ?
581 config.options.targetType : options && options.targetType ?
582 options.targetType : TargetTypes::executable;
583 define localWarnings = config && config.options && config.options.warnings ?
584 config.options.warnings : options && options.warnings ?
585 options.warnings : WarningsOption::unset;
586 define localDebug = config && config.options && config.options.debug ?
587 config.options.debug : options && options.debug ?
588 options.debug : SetBool::unset;
589 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
590 config.options.memoryGuard : options && options.memoryGuard ?
591 options.memoryGuard : SetBool::unset;
592 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
593 config.options.noLineNumbers : options && options.noLineNumbers ?
594 options.noLineNumbers : SetBool::unset;
595 define localProfile = config && config.options && config.options.profile ?
596 config.options.profile : options && options.profile ?
597 options.profile : SetBool::unset;
598 define localOptimization = config && config.options && config.options.optimization ?
599 config.options.optimization : options && options.optimization ?
600 options.optimization : OptimizationStrategy::none;
601 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
602 config.options.defaultNameSpace : options && options.defaultNameSpace ?
603 options.defaultNameSpace : null;
604 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
605 config.options.strictNameSpaces : options && options.strictNameSpaces ?
606 options.strictNameSpaces : SetBool::unset;
607 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
608 define localTargetFileName = config && config.options && config.options.targetFileName ?
609 config.options.targetFileName : options && options.targetFileName ?
610 options.targetFileName : "";
611 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
612 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
613 options.targetDirectory : null;
614 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
615 ideSettings.projectDefaultIntermediateObjDir[0] ?
616 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
617 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
618 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
619 options.objectsDirectory : null;
620 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
621 ideSettings.projectDefaultIntermediateObjDir[0] ?
622 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
623 define localConsole = config && config.options && config.options.console ?
624 config.options.console : options && options.console ?
625 options.console : SetBool::unset;
626 define localCompress = config && config.options && config.options.compress ?
627 config.options.compress : options && options.compress ?
628 options.compress : SetBool::unset;
630 char * PlatformToMakefileVariable(Platform platform)
632 return platform == win32 ? "WINDOWS" : platform == tux ? "LINUX" : platform == apple ? "OSX"/*"APPLE"*/ : platform;
635 // Move this to ProjectConfig? null vs Common to consider...
636 char * GetConfigName(ProjectConfig config)
638 return config ? config.name : "Common";
641 class Project : struct
643 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
644 // We might want to tweak this default behavior of regular classes ?
645 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
650 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
651 property Array<PlatformOptions> platforms
653 get { return platforms; }
656 if(platforms) { platforms.Free(); delete platforms; }
659 List<PlatformOptions> empty { };
660 Iterator<PlatformOptions> it { value };
662 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
663 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
673 if(p.options && !p.options.isEmpty)
680 List<ProjectConfig> configurations;
681 LinkList<ProjectNode> files;
682 String resourcesPath;
683 LinkList<ProjectNode> resources;
685 property char * description
687 set { delete description; if(value && value[0]) description = CopyString(value); }
688 get { return description ? description : ""; }
689 isset { return description != null && description[0]; }
692 property char * license
694 set { delete license; if(value && value[0]) license = CopyString(value); }
695 get { return license ? license : ""; }
696 isset { return license != null && license[0]; }
700 // topNode.name holds the file name (.epj)
701 ProjectOptions options;
702 Array<PlatformOptions> platforms;
703 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
706 ProjectConfig config;
708 // This is the file name stripped of the epj extension
709 // It should NOT be edited, saved or loaded anywhere
717 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
718 topNode.configurations = null;
719 topNode.platforms = null;
720 topNode.options = null;
723 if(platforms) { platforms.Free(); delete platforms; }
724 if(configurations) { configurations.Free(); delete configurations; }
725 if(files) { files.Free(); delete files; }
726 if(resources) { resources.Free(); delete resources; }
728 delete resourcesPath;
738 property ProjectConfig config
744 topNode.info = CopyString(GetConfigName(config));
747 property char * filePath
753 char string[MAX_LOCATION];
754 GetLastDirectory(value, string);
756 topNode.name = CopyString(string);
757 StripExtension(string);
759 name = CopyString(string);
760 StripLastDirectory(value, string);
762 topNode.path = CopyString(string);
764 filePath = CopyString(value);
769 TargetTypes GetTargetType(ProjectConfig config)
771 // TODO: Implement platform specific options?
772 TargetTypes targetType = localTargetType;
776 char * GetObjDirExpression(CompilerConfig compiler, ProjectConfig config)
778 // TODO: Support platform options
779 char * expression = localObjectsDirectory;
781 expression = settingsObjectsDirectory;
785 DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config)
787 char * expression = GetObjDirExpression(compiler, config);
788 DirExpression objDir { type = intermediateObjectsDir };
789 objDir.Evaluate(expression, this, compiler, config);
793 char * GetTargetDirExpression(CompilerConfig compiler, ProjectConfig config)
795 // TODO: Support platform options
796 char * expression = localTargetDirectory;
798 expression = settingsTargetDirectory;
802 DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config)
804 char * expression = GetTargetDirExpression(compiler, config);
805 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
806 targetDir.Evaluate(expression, this, compiler, config);
810 WarningsOption GetWarnings(ProjectConfig config)
812 WarningsOption warnings = localWarnings;
816 bool GetDebug(ProjectConfig config)
818 SetBool debug = localDebug;
819 return debug == true;
822 bool GetMemoryGuard(ProjectConfig config)
824 SetBool memoryGuard = localMemoryGuard;
825 return memoryGuard == true;
828 bool GetNoLineNumbers(ProjectConfig config)
830 SetBool noLineNumbers = localNoLineNumbers;
831 return noLineNumbers == true;
834 bool GetProfile(ProjectConfig config)
836 SetBool profile = localProfile;
837 return profile == true;
840 OptimizationStrategy GetOptimization(ProjectConfig config)
842 OptimizationStrategy optimization = localOptimization;
846 String GetDefaultNameSpace(ProjectConfig config)
848 String defaultNameSpace = localDefaultNameSpace;
849 return defaultNameSpace;
852 bool GetStrictNameSpaces(ProjectConfig config)
854 SetBool strictNameSpaces = localStrictNameSpaces;
855 return strictNameSpaces == true;
858 String GetTargetFileName(ProjectConfig config)
860 String targetFileName = localTargetFileName;
861 return targetFileName;
864 //String targetDirectory;
865 //String objectsDirectory;
866 bool GetConsole(ProjectConfig config)
868 SetBool console = localConsole;
869 return console == true;
872 bool GetCompress(ProjectConfig config)
874 SetBool compress = localCompress;
875 return compress == true;
877 //SetBool excludeFromBuild;
879 bool GetConfigIsInActiveDebugSession(ProjectConfig config)
881 #ifndef MAKEFILE_GENERATOR
882 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
886 bool GetConfigIsInDebugSession(ProjectConfig config)
888 #ifndef MAKEFILE_GENERATOR
889 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
893 void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config)
895 #ifndef MAKEFILE_GENERATOR
896 ide.SetPath(projectsDirs, compiler, config);
900 #ifndef MAKEFILE_GENERATOR
901 bool Save(char * fileName)
904 /*char output[MAX_LOCATION];
905 ChangeExtension(fileName, "json", output);
906 f = FileOpen(output, write);*/
907 f = FileOpen(fileName, write);
910 files = topNode.files;
911 resources = resNode.files;
912 resourcesPath = resNode.path;
914 files.Remove(resNode);
917 WriteJSONObject(f, class(Project), this, 0);
923 resourcesPath = null;
930 #ifndef MAKEFILE_GENERATOR
931 bool GetRelativePath(char * filePath, char * relativePath)
934 char moduleName[MAX_FILENAME];
935 GetLastDirectory(filePath, moduleName);
936 // try with workspace dir first?
937 if((node = topNode.Find(moduleName, false)))
939 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
940 PathCatSlash(relativePath, node.name);
943 // WARNING: On failure, relative path is uninitialized
948 void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
950 TargetTypes targetType = GetTargetType(config);
951 String targetFileName = GetTargetFileName(config);
952 if(targetType == staticLibrary)
954 PathCatSlash(string, "lib");
955 strcat(string, targetFileName);
957 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
959 PathCatSlash(string, "lib");
960 strcat(string, targetFileName);
963 PathCatSlash(string, targetFileName);
968 if(compiler.targetPlatform == win32)
969 strcat(string, ".exe");
972 if(compiler.targetPlatform == win32)
973 strcat(string, ".dll");
974 else if(compiler.targetPlatform == apple)
975 strcat(string, ".dylib");
977 strcat(string, ".so");
980 strcat(string, ".a");
985 void CatMakeFileName(char * string, CompilerConfig compiler, ProjectConfig config)
987 char projectName[MAX_LOCATION];
988 strcpy(projectName, name);
989 if(strcmpi(compiler.name, defaultCompilerName))
990 sprintf(string, "%s-%s-%s.Makefile", projectName, compiler.name, config.name);
992 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
995 #ifndef MAKEFILE_GENERATOR
996 void MarkChanges(ProjectNode node)
998 for(cfg : topNode.configurations)
1000 ProjectConfig c = null;
1001 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1003 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1004 (!c.options || !cfg.options)))
1005 cfg.symbolGenModified = true;
1007 cfg.makingModified = true;
1011 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1013 for(cfg : configurations)
1016 cfg.makingModified = true;
1018 cfg.compilingModified = true;
1020 cfg.linkingModified = true;
1022 cfg.symbolGenModified = true;
1024 if(compiling || linking)
1026 ide.projectView.modifiedDocument = true;
1027 ide.workspace.modified = true;
1031 void RotateActiveConfig(bool forward)
1033 if(configurations.first && configurations.last != configurations.first)
1035 Iterator<ProjectConfig> cfg { configurations };
1036 while(forward ? cfg.Next() : cfg.Prev())
1037 if(cfg.data == config)
1051 property::config = cfg.data;
1052 ide.workspace.modified = true;
1053 ide.projectView.Update(null);
1057 void ProcessPipeOutputRaw(DualPipe f)
1060 while(!f.Eof() && !ide.ShouldStopBuild())
1063 double lastTime = GetTime();
1067 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1069 ide.outputView.buildBox.Logf("%s\n", line);
1071 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1073 //printf("Processing Input...\n");
1074 if(app.ProcessInput(true))
1076 app.UpdateDisplay();
1079 //printf("Waiting...\n");
1082 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1084 if(ide.ShouldStopBuild())
1086 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1091 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode,
1092 CompilerConfig compiler, ProjectConfig config)
1095 bool compiling = false, linking = false, precompiling = false;
1096 int compilingEC = 0;
1097 int numErrors = 0, numWarnings = 0;
1098 bool loggedALine = false;
1099 char * configName = config.name;
1100 int lenMakeCommand = strlen(compiler.makeCommand);
1102 char cppCommand[MAX_LOCATION];
1103 char ccCommand[MAX_LOCATION];
1104 char ecpCommand[MAX_LOCATION];
1105 char eccCommand[MAX_LOCATION];
1106 char ecsCommand[MAX_LOCATION];
1107 char earCommand[MAX_LOCATION];
1109 char * cc = compiler.ccCommand;
1110 char * cpp = compiler.cppCommand;
1111 sprintf(cppCommand, "%s%s%s%s ",
1112 compiler.ccacheEnabled ? "ccache " : "",
1113 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1114 compiler.distccEnabled ? "distcc " : "",
1115 compiler.cppCommand);
1116 sprintf(ccCommand, "%s%s%s%s ",
1117 compiler.ccacheEnabled ? "ccache " : "",
1118 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1119 compiler.distccEnabled ? "distcc " : "",
1120 compiler.ccCommand);
1121 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1122 sprintf(eccCommand, "%s ", compiler.eccCommand);
1123 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1124 sprintf(earCommand, "%s ", compiler.earCommand);
1126 while(!f.Eof() && !ide.ShouldStopBuild())
1129 double lastTime = GetTime();
1133 //printf("Peeking and GetLine...\n");
1134 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1136 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1138 char * module = strstr(line, "No rule to make target `");
1142 module = strchr(module, '`') + 1;
1143 end = strchr(module, '\'');
1147 ide.outputView.buildBox.Logf($" %s: No such file or directory\n", module);
1148 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1154 //ide.outputView.buildBox.Logf("error: %s\n", line);
1158 else if(strstr(line, "ear ") == line);
1159 else if(strstr(line, "strip ") == line);
1160 else if(strstr(line, ccCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1162 char moduleName[MAX_FILENAME];
1165 bool isPrecomp = false;
1167 if(strstr(line, ccCommand) == line)
1169 module = strstr(line, " -c ");
1170 if(module) module += 4;
1172 else if(strstr(line, eccCommand) == line)
1174 module = strstr(line, " -c ");
1175 if(module) module += 4;
1176 //module = line + 3;
1177 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1178 compilingEC = 3;//2;
1180 else if(strstr(line, ecpCommand) == line)
1182 // module = line + 8;
1183 module = strstr(line, " -c ");
1184 if(module) module += 4;
1193 if(!compiling && !isPrecomp)
1195 ide.outputView.buildBox.Logf($"Compiling...\n");
1198 else if(!precompiling && isPrecomp)
1200 ide.outputView.buildBox.Logf($"Generating symbols...\n");
1201 precompiling = true;
1203 Tokenize(module, 1, tokens, false);
1204 GetLastDirectory(module, moduleName);
1205 ide.outputView.buildBox.Logf("%s\n", moduleName);
1207 else if((module = strstr(line, " -o ")))
1210 precompiling = false;
1212 ide.outputView.buildBox.Logf($"Linking...\n");
1216 ide.outputView.buildBox.Logf("%s\n", line);
1220 if(compilingEC) compilingEC--;
1222 else if(strstr(line, "ar rcs") == line)
1223 ide.outputView.buildBox.Logf($"Building library...\n");
1224 else if(strstr(line, ecsCommand) == line)
1225 ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1228 if(linking || compiling || precompiling)
1230 char * colon = strstr(line, ":"); //, * bracket;
1231 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1232 colon = strstr(colon + 1, ":");
1235 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1237 int len = (int)(colon - line);
1238 len = Min(len, MAX_LOCATION-1);
1239 // Don't be mistaken by the drive letter colon
1241 // TODO: need to fix colon - line gives char *
1242 // warning: incompatible expression colon - line (char *); expected int
1244 strncpy(moduleName, line, (int)(colon - line));
1245 moduleName[colon - line] = '\0';
1247 strncpy(moduleName, line, len);
1248 moduleName[len] = '\0';
1249 // Remove stuff in brackets
1250 //bracket = strstr(moduleName, "(");
1251 //if(bracket) *bracket = '\0';
1253 GetLastDirectory(moduleName, temp);
1254 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1257 strcpy(moduleName, $"Linker Error");
1261 strcpy(temp, topNode.path);
1262 PathCatSlash(temp, moduleName);
1263 MakePathRelative(temp, topNode.path, moduleName);
1265 if(strstr(line, "error:"))
1269 // Silence warnings for compiled EC
1270 char * objDir = strstr(moduleName, objDirExp.dir);
1274 if((pointer = strstr(line, "undefined")) ||
1275 (pointer = strstr(line, "No such file")) ||
1276 (pointer = strstr(line, "token")))
1278 strncat(moduleName, colon, pointer - colon);
1279 strcat(moduleName, "error: ");
1284 else if((pointer = strstr(line, "No such file")))
1286 strncat(moduleName, colon, pointer - colon);
1287 strcat(moduleName, "error: ");
1291 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1293 else if(strstr(line, "warning:"))
1298 if(this == ide.workspace.projects.firstIterator.data)
1299 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1302 char fullModuleName[MAX_LOCATION];
1303 strcpy(fullModuleName, topNode.path);
1304 PathCat(fullModuleName, moduleName);
1305 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1306 MakeSystemPath(fullModuleName);
1307 ide.outputView.buildBox.Logf(" %s%s\n", fullModuleName, colon);
1312 ide.outputView.buildBox.Logf("%s\n", line);
1313 linking = compiling = precompiling = false;
1317 ide.outputView.buildBox.Logf("%s\n", line);
1321 //printf("Done getting line\n");
1322 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1324 //printf("Processing Input...\n");
1325 if(app.ProcessInput(true))
1327 app.UpdateDisplay();
1330 //printf("Waiting...\n");
1333 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1335 if(ide.ShouldStopBuild())
1337 ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1340 else if(loggedALine || !isARun)
1342 if(f.GetExitCode() && !numErrors)
1344 bool result = f.GetLine(line, sizeof(line)-1);
1345 ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1350 ide.outputView.buildBox.Logf("\n%s (%s) - ", GetTargetFileName(config), configName);
1352 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1354 ide.outputView.buildBox.Logf($"no error, ");
1357 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1359 ide.outputView.buildBox.Logf($"no warning\n");
1362 return numErrors == 0;
1365 void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1368 int lenMakeCommand = strlen(compiler.makeCommand);
1373 double lastTime = GetTime();
1376 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1378 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1379 else if(strstr(line, "del") == line);
1380 else if(strstr(line, "rm") == line);
1381 else if(strstr(line, "Could Not Find") == line);
1384 ide.outputView.buildBox.Logf(line);
1385 ide.outputView.buildBox.Logf("\n");
1389 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1391 if(app.ProcessInput(true))
1393 app.UpdateDisplay();
1396 //Sleep(1.0 / PEEK_RESOLUTION);
1400 bool Build(bool isARun, ProjectNode onlyNode, CompilerConfig compiler, ProjectConfig config)
1402 bool result = false;
1404 char targetFileName[MAX_LOCATION] = "";
1405 char makeTarget[MAX_LOCATION] = "";
1406 char makeFile[MAX_LOCATION];
1407 char makeFilePath[MAX_LOCATION];
1408 char configName[MAX_LOCATION];
1409 DirExpression objDirExp = GetObjDir(compiler, config);
1410 PathBackup pathBackup { };
1412 int numJobs = compiler.numJobs;
1413 char command[MAX_LOCATION];
1415 strcpy(configName, config ? config.name : "Common");
1417 SetPath(false, compiler, config); //true
1418 CatTargetFileName(targetFileName, compiler, config);
1420 strcpy(makeFilePath, topNode.path);
1421 CatMakeFileName(makeFile, compiler, config);
1422 PathCatSlash(makeFilePath, makeFile);
1424 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1427 if(compiler.type.isVC)
1429 PrintLn("compiling a single file is not yet supported");
1434 char pushD[MAX_LOCATION];
1435 GetWorkingDir(pushD, sizeof(pushD));
1436 ChangeWorkingDir(topNode.path);
1437 // Create object dir if it does not exist already
1438 if(!FileExists(objDirExp.dir).isDirectory)
1439 Execute("%s objdir -C \"%s\" -f \"%s\"", compiler.makeCommand, topNode.path, makeFilePath);
1440 ChangeWorkingDir(pushD);
1442 PathCatSlash(makeTarget+1, objDirExp.dir);
1443 PathCatSlash(makeTarget+1, onlyNode.name);
1444 StripExtension(makeTarget+1);
1445 strcat(makeTarget+1, ".o");
1446 makeTarget[0] = '\"';
1447 len = strlen(makeTarget);
1448 makeTarget[len++] = '\"';
1449 makeTarget[len++] = '\0';
1453 if(compiler.type.isVC)
1455 bool result = false;
1456 char oldwd[MAX_LOCATION];
1457 GetWorkingDir(oldwd, sizeof(oldwd));
1458 ChangeWorkingDir(topNode.path);
1460 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1461 ide.outputView.buildBox.Logf("command: %s\n", command);
1462 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1464 ProcessPipeOutputRaw(f);
1468 ChangeWorkingDir(oldwd);
1472 sprintf(command, "%s -j%d %s%s%s -C \"%s\" -f \"%s\"", compiler.makeCommand, numJobs,
1473 compiler.ccacheEnabled ? "CCACHE=y " : "",
1474 compiler.distccEnabled ? "DISTCC=y " : "",
1475 makeTarget, topNode.path, makeFilePath);
1476 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1478 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode, compiler, config);
1482 ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
1491 void Clean(CompilerConfig compiler, ProjectConfig config)
1493 char makeFile[MAX_LOCATION];
1494 char makeFilePath[MAX_LOCATION];
1495 char command[MAX_LOCATION];
1497 PathBackup pathBackup { };
1499 SetPath(false, compiler, config);
1501 strcpy(makeFilePath, topNode.path);
1502 CatMakeFileName(makeFile, compiler, config);
1503 PathCatSlash(makeFilePath, makeFile);
1505 if(compiler.type.isVC)
1507 bool result = false;
1508 char oldwd[MAX_LOCATION];
1509 GetWorkingDir(oldwd, sizeof(oldwd));
1510 ChangeWorkingDir(topNode.path);
1512 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1513 ide.outputView.buildBox.Logf("command: %s\n", command);
1514 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1516 ProcessPipeOutputRaw(f);
1520 ChangeWorkingDir(oldwd);
1525 sprintf(command, "%s clean -C \"%s\" -f \"%s\"", compiler.makeCommand, topNode.path, makeFilePath);
1526 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1528 ide.outputView.buildBox.Tell($"Deleting target and object files...");
1529 ProcessCleanPipeOutput(f, compiler, config);
1532 ide.outputView.buildBox.Logf($"Target and object files deleted\n");
1539 void Run(char * args, CompilerConfig compiler, ProjectConfig config)
1541 String target = new char[maxPathLen];
1542 char oldDirectory[MAX_LOCATION];
1543 DirExpression targetDirExp = GetTargetDir(compiler, config);
1544 PathBackup pathBackup { };
1546 // Build(project, ideMain, true, null);
1548 #if defined(__WIN32__)
1549 strcpy(target, topNode.path);
1553 PathCatSlash(target, targetDirExp.dir);
1554 CatTargetFileName(target, compiler, config);
1555 sprintf(target, "%s %s", target, args);
1556 GetWorkingDir(oldDirectory, MAX_LOCATION);
1558 if(strlen(ide.workspace.debugDir))
1560 char temp[MAX_LOCATION];
1561 strcpy(temp, topNode.path);
1562 PathCatSlash(temp, ide.workspace.debugDir);
1563 ChangeWorkingDir(temp);
1566 ChangeWorkingDir(topNode.path);
1567 // ChangeWorkingDir(topNode.path);
1568 SetPath(true, compiler, config);
1569 if(compiler.execPrefixCommand)
1571 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1572 prefixedTarget[0] = '\0';
1573 strcat(prefixedTarget, compiler.execPrefixCommand);
1574 strcat(prefixedTarget, " ");
1575 strcat(prefixedTarget, target);
1576 Execute(prefixedTarget);
1577 delete prefixedTarget;
1582 ChangeWorkingDir(oldDirectory);
1585 delete targetDirExp;
1589 void Compile(ProjectNode node, CompilerConfig compiler, ProjectConfig config)
1591 Build(false, node, compiler, config);
1595 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
1597 char s[MAX_LOCATION];
1599 if(targetType == staticLibrary || targetType == sharedLibrary)
1600 strcat(fileName, "$(LP)");
1601 ReplaceSpaces(s, GetTargetFileName(config));
1602 strcat(fileName, s);
1606 strcat(fileName, "$(E)");
1609 strcat(fileName, "$(SO)");
1612 strcat(fileName, "$(A)");
1617 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath,
1618 CompilerConfig compiler, ProjectConfig config)
1620 bool result = false;
1621 char filePath[MAX_LOCATION];
1622 char makeFile[MAX_LOCATION];
1623 // PathBackup pathBackup { };
1624 // char oldDirectory[MAX_LOCATION];
1627 if(!altMakefilePath)
1629 strcpy(filePath, topNode.path);
1630 CatMakeFileName(makeFile, compiler, config);
1631 PathCatSlash(filePath, makeFile);
1634 #if defined(__WIN32__) && !defined(MAKEFILE_GENERATOR)
1635 if(compiler.type.isVC)
1637 GenerateVSSolutionFile(this, compiler);
1638 GenerateVCProjectFile(this, compiler);
1642 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
1644 /*SetPath(false, compiler, config);
1645 GetWorkingDir(oldDirectory, MAX_LOCATION);
1646 ChangeWorkingDir(topNode.path);*/
1650 char temp[MAX_LOCATION];
1651 char target[MAX_LOCATION];
1652 char targetNoSpaces[MAX_LOCATION];
1653 char objDirExpNoSpaces[MAX_LOCATION];
1654 char objDirNoSpaces[MAX_LOCATION];
1655 char resDirNoSpaces[MAX_LOCATION];
1656 char targetDirExpNoSpaces[MAX_LOCATION];
1657 char fixedModuleName[MAX_FILENAME];
1658 char fixedConfigName[MAX_FILENAME];
1659 char fixedCompilerName[MAX_FILENAME];
1661 int numCObjects = 0;
1662 bool sameObjTargetDirs;
1663 DirExpression objDirExp = GetObjDir(compiler, config);
1664 TargetTypes targetType = GetTargetType(config);
1666 bool crossCompiling = compiler.targetPlatform != GetRuntimePlatform();
1667 bool gccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "gcc") != null;
1668 bool tccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "tcc") != null;
1669 bool defaultPreprocessor = compiler.cppCommand && (strstr(compiler.cppCommand, "gcc") != null || compiler.cppCommand && strstr(compiler.cppCommand, "cpp") != null);
1671 int objectsParts, cobjectsParts, symbolsParts, importsParts;
1672 Array<String> listItems { };
1673 Map<String, int> varStringLenDiffs { };
1674 Map<String, NameCollisionInfo> namesInfo { };
1676 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
1677 strcpy(temp, GetTargetDirExpression(compiler, config));
1678 ReplaceSpaces(targetDirExpNoSpaces, temp);
1679 GetMakefileTargetFileName(targetType, target, config);
1680 PathCatSlash(temp, target);
1681 ReplaceSpaces(targetNoSpaces, temp);
1683 strcpy(objDirExpNoSpaces, GetObjDirExpression(compiler, config));
1684 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1685 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
1686 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
1687 //ReplaceSpaces(fixedPrjName, name);
1688 ReplaceSpaces(fixedModuleName, moduleName);
1689 ReplaceSpaces(fixedConfigName, GetConfigName(config));
1690 ReplaceSpaces(fixedCompilerName, compiler.name);
1691 //CamelCase(fixedModuleName); // case is important for static linking
1692 CamelCase(fixedConfigName);
1693 CamelCase(fixedCompilerName);
1695 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
1697 f.Printf(".PHONY: all objdir%s clean distclean\n\n", sameObjTargetDirs ? "" : " targetdir");
1699 f.Printf("# CONTENT\n\n");
1701 f.Printf("MODULE := %s\n", fixedModuleName);
1702 //f.Printf("VERSION = %s\n", version);
1703 f.Printf("CONFIG := %s\n", fixedConfigName);
1704 f.Printf("COMPILER := %s\n", fixedCompilerName);
1706 f.Printf("PLATFORM = %s\n", (char *)compiler.targetPlatform);
1707 f.Printf("TARGET_TYPE = %s\n", targetType == executable ? "executable" :
1708 (targetType == sharedLibrary ? "sharedlib" : (targetType == staticLibrary ? "staticlib" : "unknown")));
1711 f.Printf("OBJ = %s%s\n\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
1713 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
1715 if(targetType == executable)
1716 f.Printf("CONSOLE = %s\n\n", GetConsole(config) ? "-mconsole" : "-mwindows");
1718 f.Printf("TARGET = %s\n\n", targetNoSpaces);
1720 varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
1722 topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
1724 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config);
1726 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
1727 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs);
1729 topNode.GenMakefilePrintNode(f, this, cObjects, namesInfo, listItems, config);
1730 cobjectsParts = OutputFileList(f, "COBJECTS", listItems, varStringLenDiffs);
1732 topNode.GenMakefilePrintNode(f, this, symbols, null, listItems, config);
1733 symbolsParts = OutputFileList(f, "SYMBOLS", listItems, varStringLenDiffs);
1735 topNode.GenMakefilePrintNode(f, this, imports, null, listItems, config);
1736 importsParts = OutputFileList(f, "IMPORTS", listItems, varStringLenDiffs);
1738 topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config);
1739 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs);
1742 resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config);
1743 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs);
1747 f.Printf("# CROSS-PLATFORM MAGIC\n\n");
1749 f.Printf("include %s\n\n", includemkPath);
1753 File include = FileOpen(":include.mk", read);
1756 for(; !include.Eof(); )
1759 int count = include.Read(buffer, 1, 4096);
1760 f.Write(buffer, 1, count);
1768 if(strcmpi(compiler.cppCommand, "cpp") ||
1769 strcmpi(compiler.ccCommand, "gcc") ||
1770 strcmpi(compiler.ecpCommand, "ecp") ||
1771 strcmpi(compiler.eccCommand, "ecc") ||
1772 strcmpi(compiler.ecsCommand, "ecs") || crossCompiling ||
1773 strcmpi(compiler.earCommand, "ear"))
1775 f.Printf("# TOOLCHAIN\n\n");
1777 //f.Printf("SHELL := %s\n", "ar"/*compiler.arCommand*/); // is this really needed?
1778 if(strcmpi(compiler.cppCommand, "cpp"))
1779 f.Printf("CPP := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.cppCommand);
1780 if(strcmpi(compiler.ccCommand, "gcc"))
1781 f.Printf("CC := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.ccCommand);
1782 if(strcmpi(compiler.ecpCommand, "ecp"))
1783 f.Printf("ECP := %s\n", compiler.ecpCommand);
1784 if(strcmpi(compiler.eccCommand, "ecc"))
1785 f.Printf("ECC := %s\n", compiler.eccCommand);
1786 if(strcmpi(compiler.ecsCommand, "ecs") || crossCompiling)
1788 f.Printf("ECS := %s%s%s\n", compiler.ecsCommand,
1789 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1791 if(strcmpi(compiler.earCommand, "ear"))
1792 f.Printf("EAR := %s\n", compiler.earCommand);
1796 f.Printf("# FLAGS\n\n");
1798 f.Printf("CFLAGS =");
1801 f.Printf(" -fmessage-length=0");
1802 switch(GetOptimization(config))
1806 f.Printf(" -ffast-math");
1812 //if(compiler.targetPlatform.is32Bits)
1814 //else if(compiler.targetPlatform.is64Bits)
1815 // f.Printf(" -m64");
1816 f.Printf(" $(FPIC)");
1817 //f.Printf(" -fpack-struct");
1819 switch(GetWarnings(config))
1821 case all: f.Printf(" -Wall"); break;
1822 case none: f.Printf(" -w"); break;
1824 if(GetDebug(config))
1826 if(GetProfile(config))
1828 if(options && options.linkerOptions && options.linkerOptions.count)
1830 f.Printf(" \\\n\t -Wl");
1831 for(s : options.linkerOptions)
1835 if(options && options.preprocessorDefinitions)
1836 OutputListOption(f, "D", options.preprocessorDefinitions, newLine, false);
1837 if(config && config.options && config.options.preprocessorDefinitions)
1838 OutputListOption(f, "D", config.options.preprocessorDefinitions, newLine, false);
1840 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
1841 if(options && options.includeDirs)
1842 OutputListOption(f, "I", options.includeDirs, lineEach, true);
1843 if(config && config.options && config.options.includeDirs)
1844 OutputListOption(f, "I", config.options.includeDirs, lineEach, true);
1847 f.Printf("CECFLAGS =%s%s%s%s", defaultPreprocessor ? "" : " -cpp ", defaultPreprocessor ? "" : compiler.cppCommand,
1848 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1851 f.Printf("ECFLAGS =");
1852 if(GetMemoryGuard(config))
1853 f.Printf(" -memguard");
1854 if(GetStrictNameSpaces(config))
1855 f.Printf(" -strictns");
1856 if(GetNoLineNumbers(config))
1857 f.Printf(" -nolinenumbers");
1860 if((s = GetDefaultNameSpace(config)) && s[0])
1861 f.Printf(" -defaultns %s", s);
1865 if(targetType != staticLibrary)
1867 f.Printf("OFLAGS = -m32"); // TARGET_TYPE is fixed in a Makefile, we don't want this. $(if TARGET_TYPE_STATIC_LIBRARY,,-m32)");
1868 if(GetProfile(config))
1871 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
1872 if(options && options.libraryDirs)
1873 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
1874 if(config && config.options && config.options.libraryDirs)
1875 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
1880 if(targetType != staticLibrary)
1882 if(config && config.options && config.options.libraries)
1883 OutputLibraries(f, config.options.libraries);
1884 else if(options && options.libraries)
1885 OutputLibraries(f, options.libraries);
1887 f.Printf(" $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
1889 f.Printf("UPXFLAGS = -9\n\n"); // TOFEAT: Compression Level Option? Other UPX Options?
1891 f.Printf("# HARD CODED PLATFORM-SPECIFIC OPTIONS\n");
1892 f.Printf("ifdef %s\n", PlatformToMakefileVariable(tux));
1893 f.Printf("OFLAGS += -Wl,--no-undefined\n");
1894 f.Printf("endif\n\n");
1897 f.Printf("ifdef %s\n", PlatformToMakefileVariable(apple));
1898 f.Printf("OFLAGS += -framework cocoa -framework OpenGL\n");
1899 f.Printf("endif\n\n");
1901 if(platforms || (config && config.platforms))
1905 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
1906 //for(platform = win32; platform <= apple; platform++)
1908 f.Printf("# PLATFORM-SPECIFIC OPTIONS\n\n");
1909 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1911 PlatformOptions projectPlatformOptions = null;
1912 PlatformOptions configPlatformOptions = null;
1918 if(!strcmpi(p.name, platform))
1920 projectPlatformOptions = p;
1925 if(config && config.platforms)
1927 for(p : config.platforms)
1929 if(!strcmpi(p.name, platform))
1931 configPlatformOptions = p;
1936 if(projectPlatformOptions || configPlatformOptions)
1942 // we should have some kind of direct mapping between a platform and it's makefile variable
1943 f.Printf(PlatformToMakefileVariable(platform));
1946 if((projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions && projectPlatformOptions.options.preprocessorDefinitions.count) ||
1947 (configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions && configPlatformOptions.options.preprocessorDefinitions.count) ||
1948 (projectPlatformOptions && projectPlatformOptions.options.includeDirs && projectPlatformOptions.options.includeDirs.count) ||
1949 (configPlatformOptions && configPlatformOptions.options.includeDirs && configPlatformOptions.options.includeDirs.count))
1951 f.Printf("CFLAGS +=");
1952 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
1954 f.Printf(" \\\n\t -Wl");
1955 for(s : projectPlatformOptions.options.linkerOptions)
1958 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
1960 f.Printf(" \\\n\t -Wl");
1961 for(s : configPlatformOptions.options.linkerOptions)
1964 if(projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions)
1965 OutputListOption(f, "D", projectPlatformOptions.options.preprocessorDefinitions, newLine, false);
1966 if(configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions)
1967 OutputListOption(f, "D", configPlatformOptions.options.preprocessorDefinitions, newLine, false );
1968 if(projectPlatformOptions && projectPlatformOptions.options.includeDirs)
1969 OutputListOption(f, "I", projectPlatformOptions.options.includeDirs, lineEach, true);
1970 if(configPlatformOptions && configPlatformOptions.options.includeDirs)
1971 OutputListOption(f, "I", configPlatformOptions.options.includeDirs, lineEach, true);
1975 if(targetType != staticLibrary)
1977 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
1978 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
1980 f.Printf("OFLAGS +=");
1981 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
1982 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
1983 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
1984 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
1988 if(projectPlatformOptions && projectPlatformOptions.options.libraries &&
1989 projectPlatformOptions.options.libraries.count/* &&
1990 (!config || !config.options || !config.options.libraries)*/)
1992 f.Printf("LIBS +=");
1993 OutputLibraries(f, projectPlatformOptions.options.libraries);
1996 {/*TOFIX: EXTRA CURLIES FOR NASTY WARNING*/if((configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
1998 f.Printf("LIBS +=");
1999 OutputLibraries(f, configPlatformOptions.options.libraries);
2007 for(c = 0; c < ifCount; c++)
2008 f.Printf("endif\n");
2014 f.Printf("# TARGETS\n\n");
2016 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
2018 f.Printf("objdir:\n");
2019 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2020 //f.Printf("# PRE-BUILD COMMANDS\n");
2021 if(options && options.prebuildCommands)
2023 for(s : options.prebuildCommands)
2024 if(s && s[0]) f.Printf("\t%s\n", s);
2026 if(config && config.options && config.options.prebuildCommands)
2028 for(s : config.options.prebuildCommands)
2029 if(s && s[0]) f.Printf("\t%s\n", s);
2031 if(platforms || (config && config.platforms))
2035 //f.Printf("# PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2036 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2038 PlatformOptions projectPOs = null;
2039 PlatformOptions configPOs = null;
2045 if(!strcmpi(p.name, platform))
2052 if(config && config.platforms)
2054 for(p : config.platforms)
2056 if(!strcmpi(p.name, platform))
2063 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2064 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2070 f.Printf(PlatformToMakefileVariable(platform));
2073 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2075 for(s : projectPOs.options.prebuildCommands)
2076 if(s && s[0]) f.Printf("\t%s\n", s);
2078 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2080 for(s : configPOs.options.prebuildCommands)
2081 if(s && s[0]) f.Printf("\t%s\n", s);
2088 for(c = 0; c < ifCount; c++)
2089 f.Printf("endif\n");
2095 if(!sameObjTargetDirs)
2097 f.Printf("targetdir:\n");
2098 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2103 // Main Module (Linking) for ECERE C modules
2104 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2105 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2106 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2107 GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
2108 // Main Module (Linking) for ECERE C modules
2109 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2110 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2111 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2112 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2113 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2118 // This would not rebuild the target on updated objects
2119 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2121 // This should fix it for good!
2122 f.Printf("$(SYMBOLS): | objdir\n");
2123 f.Printf("$(OBJECTS): | objdir\n");
2125 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2126 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2128 if(targetType == sharedLibrary || targetType == executable)
2130 // f.Printf("\tinstall_name_tool $(TARGET) $(LP)$(MODULE)%s\n", targetType == sharedLibrary ? "$(SO)" : "$(A)");
2131 //f.Printf("ifdef OSX\n");
2132 //f.Printf("ifeq \"$(TARGET_TYPE)\" \"sharedlib\"\n");
2133 //f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET) -install_name $(LP)$(MODULE)$(SO)\n");
2134 //f.Printf("endif\n");
2135 //f.Printf("else\n");
2136 //f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET)\n");
2137 //f.Printf("endif\n");
2138 f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET) $(INSTALLNAME)\n");
2140 if(!GetDebug(config))
2142 f.Printf("ifndef NOSTRIP\n");
2143 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2144 f.Printf("endif\n");
2146 if(GetCompress(config))
2148 f.Printf("ifndef WINDOWS\n");
2149 f.Printf("ifeq \"$(TARGET_TYPE)\" \"executable\"\n");
2150 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2151 f.Printf("endif\n");
2153 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2154 f.Printf("endif\n");
2157 if(resNode.files && resNode.files.count && !noResources)
2158 resNode.GenMakefileAddResources(f, resNode.path, config);
2161 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2163 //f.Printf("# POST-BUILD COMMANDS\n");
2164 if(options && options.postbuildCommands)
2166 for(s : options.postbuildCommands)
2167 if(s && s[0]) f.Printf("\t%s\n", s);
2169 if(config && config.options && config.options.postbuildCommands)
2171 for(s : config.options.postbuildCommands)
2172 if(s && s[0]) f.Printf("\t%s\n", s);
2174 if(platforms || (config && config.platforms))
2179 //f.Printf("# PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2180 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2182 PlatformOptions projectPOs = null;
2183 PlatformOptions configPOs = null;
2189 if(!strcmpi(p.name, platform))
2196 if(config && config.platforms)
2198 for(p : config.platforms)
2200 if(!strcmpi(p.name, platform))
2207 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2208 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2214 f.Printf(PlatformToMakefileVariable(platform));
2217 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2219 for(s : projectPOs.options.postbuildCommands)
2220 if(s && s[0]) f.Printf("\t%s\n", s);
2222 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2224 for(s : configPOs.options.postbuildCommands)
2225 if(s && s[0]) f.Printf("\t%s\n", s);
2232 for(c = 0; c < ifCount; c++)
2233 f.Printf("endif\n");
2239 f.Printf("# SYMBOL RULES\n\n");
2240 topNode.GenMakefilePrintSymbolRules(f, this, compiler, config);
2242 f.Printf("# C OBJECT RULES\n\n");
2243 topNode.GenMakefilePrintCObjectRules(f, this, compiler, config);
2247 f.Printf("# IMPLICIT OBJECT RULE\n\n");
2249 f.Printf("$(OBJ)%%$(O) : $(OBJ)%%.c\n");
2250 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $< -o $@\n\n");
2253 f.Printf("# OBJECT RULES\n\n");
2254 // todo call this still but only generate rules whith specific options
2255 // see we-have-file-specific-options in ProjectNode.ec
2256 topNode.GenMakefilePrintObjectRules(f, this, namesInfo, compiler, config);
2259 GenMakefilePrintMainObjectRule(f, compiler, config);
2261 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2262 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) " : "");
2263 OutputCleanActions(f, "OBJECTS", objectsParts);
2264 OutputCleanActions(f, "COBJECTS", cobjectsParts);
2267 OutputCleanActions(f, "IMPORTS", importsParts);
2268 OutputCleanActions(f, "SYMBOLS", symbolsParts);
2272 f.Printf("distclean: clean\n");
2273 f.Printf("\t$(call rmdirq,$(OBJ))\n");
2274 if(!sameObjTargetDirs)
2275 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2281 varStringLenDiffs.Free();
2282 delete varStringLenDiffs;
2289 // ChangeWorkingDir(oldDirectory);
2290 // delete pathBackup;
2293 config.makingModified = false;
2297 void GenMakefilePrintMainObjectRule(File f, CompilerConfig compiler, ProjectConfig config)
2299 char extension[MAX_EXTENSION] = "c";
2300 char modulePath[MAX_LOCATION];
2301 char fixedModuleName[MAX_FILENAME];
2304 char objDirNoSpaces[MAX_LOCATION];
2305 DirExpression objDirExp = GetObjDir(compiler, config);
2307 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
2308 ReplaceSpaces(fixedModuleName, moduleName);
2310 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2311 //strcat(fixedModuleName, ".main");
2313 #if 0 // TODO: Fix nospaces stuff
2314 // *** Dependency command ***
2315 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2317 // System Includes (from global settings)
2318 for(item : compiler.dirs[Includes])
2320 strcat(command, " -isystem ");
2321 if(strchr(item.name, ' '))
2323 strcat(command, "\"");
2324 strcat(command, item);
2325 strcat(command, "\"");
2328 strcat(command, item);
2331 for(item = includeDirs.first; item; item = item.next)
2333 strcat(command, " -I");
2334 if(strchr(item.name, ' '))
2336 strcat(command, "\"");
2337 strcat(command, item.name);
2338 strcat(command, "\"");
2341 strcat(command, item.name);
2343 for(item = preprocessorDefs.first; item; item = item.next)
2345 strcat(command, " -D");
2346 strcat(command, item.name);
2350 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2354 bool firstLine = true;
2356 // To do some time: auto save external dependencies?
2359 if(dep.GetLine(line, sizeof(line)-1))
2363 char * colon = strstr(line, ":");
2364 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2378 // If we failed to generate dependencies...
2382 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2388 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2394 Project LegacyBinaryLoadProject(File f, char * filePath)
2396 Project project = null;
2397 char signature[sizeof(epjSignature)];
2399 f.Read(signature, sizeof(signature), 1);
2400 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2402 char topNodePath[MAX_LOCATION];
2403 /*ProjectConfig newConfig
2405 name = CopyString("Default");
2406 makingModified = true;
2407 compilingModified = true;
2408 linkingModified = true;
2412 project = Project { options = { } };
2413 LegacyBinaryLoadNode(project.topNode, f);
2414 delete project.topNode.path;
2415 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2416 MakeSlashPath(topNodePath);
2418 PathCatSlash(topNodePath, filePath);
2419 project.filePath = topNodePath;
2421 /* THIS IS ALREADY DONE BY filePath property
2422 StripLastDirectory(topNodePath, topNodePath);
2423 project.topNode.path = CopyString(topNodePath);
2425 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2427 // newConfig.options.defaultNameSpace = "";
2428 /*newConfig.objDir.dir = "obj";
2429 newConfig.targetDir.dir = "";*/
2431 //project.configurations = { [ newConfig ] };
2432 //project.config = newConfig;
2439 String targetFileName, targetDirectory, objectsDirectory;
2441 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2442 f.Read(&temp, sizeof(int),1);
2445 case 0: project.options.targetType = executable; break;
2446 case 1: project.options.targetType = sharedLibrary; break;
2447 case 2: project.options.targetType = staticLibrary; break;
2450 f.Read(&len, sizeof(int),1);
2451 targetFileName = new char[len+1];
2452 f.Read(targetFileName, sizeof(char), len+1);
2453 project.options.targetFileName = targetFileName;
2454 delete targetFileName;
2456 f.Read(&len, sizeof(int),1);
2457 targetDirectory = new char[len+1];
2458 f.Read(targetDirectory, sizeof(char), len+1);
2459 project.options.targetDirectory = targetDirectory;
2460 delete targetDirectory;
2462 f.Read(&len, sizeof(int),1);
2463 objectsDirectory = new byte[len+1];
2464 f.Read(objectsDirectory, sizeof(char), len+1);
2465 project.options.objectsDirectory = objectsDirectory;
2466 delete objectsDirectory;
2468 f.Read(&temp, sizeof(int),1);
2469 project./*config.*/options.debug = temp ? true : false;
2470 f.Read(&temp, sizeof(int),1);
2471 project./*config.*/options.optimization = temp ? speed : none;
2472 f.Read(&temp, sizeof(int),1);
2473 project./*config.*/options.profile = temp ? true : false;
2474 f.Read(&temp, sizeof(int),1);
2475 project.options.warnings = temp ? all : unset;
2477 f.Read(&count, sizeof(int),1);
2480 project.options.includeDirs = { };
2481 for(c = 0; c < count; c++)
2484 f.Read(&len, sizeof(int),1);
2485 name = new char[len+1];
2486 f.Read(name, sizeof(char), len+1);
2487 project.options.includeDirs.Add(name);
2491 f.Read(&count, sizeof(int),1);
2494 project.options.libraryDirs = { };
2495 for(c = 0; c < count; c++)
2498 f.Read(&len, sizeof(int),1);
2499 name = new char[len+1];
2500 f.Read(name, sizeof(char), len+1);
2501 project.options.libraryDirs.Add(name);
2505 f.Read(&count, sizeof(int),1);
2508 project.options.libraries = { };
2509 for(c = 0; c < count; c++)
2512 f.Read(&len, sizeof(int),1);
2513 name = new char[len+1];
2514 f.Read(name, sizeof(char), len+1);
2515 project.options.libraries.Add(name);
2519 f.Read(&count, sizeof(int),1);
2522 project.options.preprocessorDefinitions = { };
2523 for(c = 0; c < count; c++)
2526 f.Read(&len, sizeof(int),1);
2527 name = new char[len+1];
2528 f.Read(name, sizeof(char), len+1);
2529 project.options.preprocessorDefinitions.Add(name);
2533 f.Read(&temp, sizeof(int),1);
2534 project.options.console = temp ? true : false;
2537 for(node : project.topNode.files)
2539 if(node.type == resources)
2541 project.resNode = node;
2551 void ProjectConfig::LegacyProjectConfigLoad(File f)
2559 char subSection[128];
2565 f.GetLine(buffer, 65536 - 1);
2566 TrimLSpaces(buffer, buffer);
2567 TrimRSpaces(buffer, buffer);
2570 if(buffer[0] == '-')
2574 TrimLSpaces(equal, equal);
2575 if(!strcmpi(subSection, "LibraryDirs"))
2577 if(!options.libraryDirs)
2578 options.libraryDirs = { [ CopyString(equal) ] };
2580 options.libraryDirs.Add(CopyString(equal));
2582 else if(!strcmpi(subSection, "IncludeDirs"))
2584 if(!options.includeDirs)
2585 options.includeDirs = { [ CopyString(equal) ] };
2587 options.includeDirs.Add(CopyString(equal));
2590 else if(buffer[0] == '+')
2601 TrimLSpaces(equal, equal);
2602 delete name; name = CopyString(equal); // property::name = equal;
2605 else if(!strcmpi(buffer, "Compiler Options"))
2606 strcpy(section, buffer);
2607 else if(!strcmpi(buffer, "IncludeDirs"))
2608 strcpy(subSection, buffer);
2609 else if(!strcmpi(buffer, "Linker Options"))
2610 strcpy(section, buffer);
2611 else if(!strcmpi(buffer, "LibraryDirs"))
2612 strcpy(subSection, buffer);
2613 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
2620 equal = strstr(buffer, "=");
2624 TrimRSpaces(buffer, buffer);
2626 TrimLSpaces(equal, equal);
2627 if(!strcmpi(buffer, "Target Name"))
2628 options.targetFileName = /*CopyString(*/equal/*)*/;
2629 else if(!strcmpi(buffer, "Target Type"))
2631 if(!strcmpi(equal, "Executable"))
2632 options.targetType = executable;
2633 else if(!strcmpi(equal, "Shared"))
2634 options.targetType = sharedLibrary;
2635 else if(!strcmpi(equal, "Static"))
2636 options.targetType = staticLibrary;
2638 options.targetType = executable;
2640 else if(!strcmpi(buffer, "Target Directory"))
2641 options.targetDirectory = /*CopyString(*/equal/*)*/;
2642 else if(!strcmpi(buffer, "Console"))
2643 options.console = ParseTrueFalseValue(equal);
2644 else if(!strcmpi(buffer, "Libraries"))
2646 if(!options.libraries) options.libraries = { };
2647 ParseArrayValue(options.libraries, equal);
2649 else if(!strcmpi(buffer, "Intermediate Directory"))
2650 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
2651 else if(!strcmpi(buffer, "Debug"))
2652 options.debug = ParseTrueFalseValue(equal);
2653 else if(!strcmpi(buffer, "Optimize"))
2655 if(!strcmpi(equal, "None"))
2656 options.optimization = none;
2657 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
2658 options.optimization = speed;
2659 else if(!strcmpi(equal, "Size"))
2660 options.optimization = size;
2662 options.optimization = none;
2664 else if(!strcmpi(buffer, "Compress"))
2665 options.compress = ParseTrueFalseValue(equal);
2666 else if(!strcmpi(buffer, "Profile"))
2667 options.profile = ParseTrueFalseValue(equal);
2668 else if(!strcmpi(buffer, "AllWarnings"))
2669 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
2670 else if(!strcmpi(buffer, "MemoryGuard"))
2671 options.memoryGuard = ParseTrueFalseValue(equal);
2672 else if(!strcmpi(buffer, "Default Name Space"))
2673 options.defaultNameSpace = CopyString(equal);
2674 else if(!strcmpi(buffer, "Strict Name Spaces"))
2675 options.strictNameSpaces = ParseTrueFalseValue(equal);
2676 else if(!strcmpi(buffer, "Preprocessor Definitions"))
2678 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
2679 ParseArrayValue(options.preprocessorDefinitions, equal);
2685 if(!options.targetDirectory && options.objectsDirectory)
2686 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
2687 //if(!objDir.dir) objDir.dir = "obj";
2688 //if(!targetDir.dir) targetDir.dir = "";
2689 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
2690 // if(!defaultNameSpace) property::defaultNameSpace = "";
2691 makingModified = true;
2694 Project LegacyAsciiLoadProject(File f, char * filePath)
2696 Project project = null;
2697 ProjectNode node = null;
2699 char parentPath[MAX_LOCATION];
2700 char section[128] = "";
2701 char subSection[128] = "";
2703 bool configurationsPresent = false;
2713 f.GetLine(buffer, 65536 - 1);
2714 TrimLSpaces(buffer, buffer);
2715 TrimRSpaces(buffer, buffer);
2718 if(buffer[0] == '-' || buffer[0] == '=')
2720 bool simple = buffer[0] == '-';
2723 TrimLSpaces(equal, equal);
2724 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
2726 if(!project.config.options.libraryDirs) project.config.options.libraryDirs = { };
2727 project.config.options.libraryDirs.Add(CopyString(equal));
2729 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
2731 if(!project.config.options.includeDirs) project.config.options.includeDirs = { };
2732 project.config.options.includeDirs.Add(CopyString(equal));
2734 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
2736 len = strlen(equal);
2739 char temp[MAX_LOCATION];
2740 ProjectNode child { };
2741 // We don't need to do this anymore, fileName is just a property that sets name & path
2742 // child.fileName = CopyString(equal);
2745 child.name = CopyString(equal);
2746 child.path = CopyString(parentPath);
2750 GetLastDirectory(equal, temp);
2751 child.name = CopyString(temp);
2752 StripLastDirectory(equal, temp);
2753 child.path = CopyString(temp);
2755 child.nodeType = file;
2756 child.parent = parent;
2757 child.indent = parent.indent + 1;
2759 child.icon = NodeIcons::SelectFileIcon(child.name);
2760 parent.files.Add(child);
2766 StripLastDirectory(parentPath, parentPath);
2767 parent = parent.parent;
2771 else if(buffer[0] == '+')
2775 TrimLSpaces(equal, equal);
2776 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
2778 char temp[MAX_LOCATION];
2779 ProjectNode child { };
2780 // NEW: Folders now have a path set like files
2781 child.name = CopyString(equal);
2782 strcpy(temp, parentPath);
2783 PathCatSlash(temp, child.name);
2784 child.path = CopyString(temp);
2786 child.parent = parent;
2787 child.indent = parent.indent + 1;
2788 child.type = folder;
2789 child.nodeType = folder;
2791 child.icon = folder;
2792 PathCatSlash(parentPath, child.name);
2793 parent.files.Add(child);
2798 else if(!strcmpi(section, "Configurations"))
2800 ProjectConfig newConfig
2802 makingModified = true;
2806 LegacyProjectConfigLoad(newConfig, f);
2807 project.configurations.Add(newConfig);
2810 else if(!strcmpi(buffer, "ECERE Project File"));
2811 else if(!strcmpi(buffer, "Version 0a"))
2812 ; //strcpy(version, "0a");
2813 else if(!strcmpi(buffer, "Version 0.1a"))
2814 ; //strcpy(version, "0.1a");
2815 else if(!strcmpi(buffer, "Configurations"))
2817 project.configurations.Free();
2818 project.config = null;
2819 strcpy(section, buffer);
2820 configurationsPresent = true;
2822 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
2824 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
2825 char topNodePath[MAX_LOCATION];
2826 // newConfig.defaultNameSpace = "";
2827 //newConfig.objDir.dir = "obj";
2828 //newConfig.targetDir.dir = "";
2829 project = Project { /*options = { }*/ };
2830 project.configurations = { [ newConfig ] };
2831 project.config = newConfig;
2832 // if(project.topNode.path) delete project.topNode.path;
2833 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2834 MakeSlashPath(topNodePath);
2835 PathCatSlash(topNodePath, filePath);
2836 project.filePath = topNodePath;
2837 parentPath[0] = '\0';
2838 parent = project.topNode;
2840 strcpy(section, "Target");
2845 if(equal[0] == '\"')
2847 StripQuotes(equal, equal);
2848 delete project.moduleName; project.moduleName = CopyString(equal);
2852 else if(!strcmpi(buffer, "Compiler Options"));
2853 else if(!strcmpi(buffer, "IncludeDirs"))
2854 strcpy(subSection, buffer);
2855 else if(!strcmpi(buffer, "Linker Options"));
2856 else if(!strcmpi(buffer, "LibraryDirs"))
2857 strcpy(subSection, buffer);
2858 else if(!strcmpi(buffer, "Files"))
2860 strcpy(section, "Target");
2861 strcpy(subSection, buffer);
2863 else if(!strcmpi(buffer, "Resources"))
2865 ProjectNode child { };
2866 parent.files.Add(child);
2867 child.parent = parent;
2868 child.indent = parent.indent + 1;
2869 child.name = CopyString(buffer);
2870 child.path = CopyString("");
2871 child.type = resources;
2873 child.icon = archiveFile;
2874 project.resNode = child;
2877 strcpy(subSection, buffer);
2881 equal = strstr(buffer, "=");
2885 TrimRSpaces(buffer, buffer);
2887 TrimLSpaces(equal, equal);
2889 if(!strcmpi(section, "Target"))
2891 if(!strcmpi(buffer, "Build Exclusions"))
2893 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
2895 /*if(node && node.type != NodeTypes::project)
2896 ParseListValue(node.buildExclusions, equal);*/
2899 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
2901 delete project.resNode.path;
2902 project.resNode.path = CopyString(equal);
2903 PathCatSlash(parentPath, equal);
2907 else if(!strcmpi(buffer, "Intermediate Directory"))
2908 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
2909 else if(!strcmpi(buffer, "Debug"))
2910 project.config.options.debug = ParseTrueFalseValue(equal);
2911 else if(!strcmpi(buffer, "Optimize"))
2913 if(!strcmpi(equal, "None"))
2914 project.config.options.optimization = none;
2915 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
2916 project.config.options.optimization = speed;
2917 else if(!strcmpi(equal, "Size"))
2918 project.config.options.optimization = size;
2920 project.config.options.optimization = none;
2922 else if(!strcmpi(buffer, "Profile"))
2923 project.config.options.profile = ParseTrueFalseValue(equal);
2924 else if(!strcmpi(buffer, "MemoryGuard"))
2925 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
2928 if(!project.options) project.options = { };
2930 // Project Wide Settings (All configs)
2931 if(!strcmpi(buffer, "Target Name"))
2932 project.options.targetFileName = /*CopyString(*/equal/*)*/;
2933 else if(!strcmpi(buffer, "Target Type"))
2935 if(!strcmpi(equal, "Executable"))
2936 project.options.targetType = executable;
2937 else if(!strcmpi(equal, "Shared"))
2938 project.options.targetType = sharedLibrary;
2939 else if(!strcmpi(equal, "Static"))
2940 project.options.targetType = staticLibrary;
2942 project.options.targetType = executable;
2944 else if(!strcmpi(buffer, "Target Directory"))
2945 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
2946 else if(!strcmpi(buffer, "Console"))
2947 project.options.console = ParseTrueFalseValue(equal);
2948 else if(!strcmpi(buffer, "Libraries"))
2950 if(!project.options.libraries) project.options.libraries = { };
2951 ParseArrayValue(project.options.libraries, equal);
2953 else if(!strcmpi(buffer, "AllWarnings"))
2954 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
2955 else if(!strcmpi(buffer, "Preprocessor Definitions"))
2957 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
2959 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
2960 ParseListValue(node.preprocessorDefs, equal);*/
2964 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
2965 ParseArrayValue(project.options.preprocessorDefinitions, equal);
2976 SplitPlatformLibraries(project);
2978 if(configurationsPresent)
2979 CombineIdenticalConfigOptions(project);
2983 void SplitPlatformLibraries(Project project)
2985 if(project && project.configurations)
2987 for(cfg : project.configurations)
2989 if(cfg.options.libraries && cfg.options.libraries.count)
2991 Iterator<String> it { cfg.options.libraries };
2995 char * platformName = strstr(l, ":");
2998 PlatformOptions platform = null;
3000 if(!cfg.platforms) cfg.platforms = { };
3001 for(p : cfg.platforms)
3003 if(!strcmpi(platformName, p.name))
3011 platform = { name = CopyString(platformName), options = { libraries = { } } };
3012 cfg.platforms.Add(platform);
3014 *(platformName-1) = 0;
3015 platform.options.libraries.Add(CopyString(l));
3017 cfg.options.libraries.Delete(it.pointer);
3026 void CombineIdenticalConfigOptions(Project project)
3028 if(project && project.configurations && project.configurations.count)
3031 ProjectOptions nullOptions { };
3032 ProjectConfig firstConfig = null;
3033 for(cfg : project.configurations)
3035 if(cfg.options.targetType != staticLibrary)
3042 firstConfig = project.configurations.firstIterator.data;
3044 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3046 if(!member.isProperty)
3048 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3053 for(cfg : project.configurations)
3055 if(cfg != firstConfig)
3057 if(cfg.options.targetType != staticLibrary)
3061 if(type.type == noHeadClass || type.type == normalClass)
3063 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3064 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3065 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3069 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3070 (byte *)firstConfig.options + member.offset + member._class.offset,
3071 (byte *)cfg.options + member.offset + member._class.offset);
3083 if(type.type == noHeadClass || type.type == normalClass)
3085 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3086 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3087 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3092 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3093 (byte *)firstConfig.options + member.offset + member._class.offset,
3094 (byte *)nullOptions + member.offset + member._class.offset))
3098 if(!project.options) project.options = { };
3100 /*if(type.type == noHeadClass || type.type == normalClass)
3102 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3103 (byte *)project.options + member.offset + member._class.offset,
3104 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3108 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3109 // TOFIX: ListBox::SetData / OnCopy mess
3110 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3111 (byte *)project.options + member.offset + member._class.offset,
3112 (type.typeSize > 4) ? address :
3113 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3114 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3115 (void *)*(byte *)address )));
3118 (byte *)project.options + member.offset + member._class.offset,
3119 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3121 for(cfg : project.configurations)
3123 if(cfg.options.targetType == staticLibrary)
3127 if(type.type == noHeadClass || type.type == normalClass)
3129 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3130 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3131 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3135 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3136 (byte *)firstConfig.options + member.offset + member._class.offset,
3137 (byte *)cfg.options + member.offset + member._class.offset);
3142 if(cfg != firstConfig)
3144 if(type.type == noHeadClass || type.type == normalClass)
3146 type._vTbl[__ecereVMethodID_class_OnFree](type,
3147 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3151 type._vTbl[__ecereVMethodID_class_OnFree](type,
3152 (byte *)cfg.options + member.offset + member._class.offset);
3154 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3157 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3164 // Compare Platform Specific Settings
3167 for(cfg : project.configurations)
3169 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3170 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3176 if(same && firstConfig.platforms)
3178 for(cfg : project.configurations)
3180 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3182 if(cfg != firstConfig)
3184 cfg.platforms.Free();
3185 delete cfg.platforms;
3188 project.platforms = firstConfig.platforms;
3189 firstConfig.platforms = null;
3193 // Static libraries can't contain libraries
3194 for(cfg : project.configurations)
3196 if(cfg.options.targetType == staticLibrary)
3198 if(!cfg.options.libraries) cfg.options.libraries = { };
3199 cfg.options.libraries.Free();
3205 Project LoadProject(char * filePath)
3207 Project project = null;
3208 File f = FileOpen(filePath, read);
3211 project = LegacyBinaryLoadProject(f, filePath);
3214 JSONParser parser { f = f };
3215 JSONResult result = parser.GetObject(class(Project), &project);
3218 char insidePath[MAX_LOCATION];
3220 delete project.topNode.files;
3221 if(!project.files) project.files = { };
3222 project.topNode.files = project.files;
3223 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3224 delete project.resNode.path;
3225 project.resNode.path = project.resourcesPath;
3226 project.resourcesPath = null;
3227 project.resNode.nodeType = (ProjectNodeType)-1;
3228 delete project.resNode.files;
3229 project.resNode.files = project.resources;
3230 project.files = null;
3231 project.resources = null;
3232 if(!project.configurations) project.configurations = { };
3235 char topNodePath[MAX_LOCATION];
3236 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3237 MakeSlashPath(topNodePath);
3238 PathCatSlash(topNodePath, filePath);
3239 project.filePath = topNodePath;//filePath;
3242 project.topNode.FixupNode(insidePath);
3247 project = LegacyAsciiLoadProject(f, filePath);
3253 if(!project.options) project.options = { };
3254 if(!project.config && project.configurations)
3255 project.config = project.configurations.firstIterator.data;
3257 if(!project.resNode)
3259 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3262 if(!project.moduleName)
3263 project.moduleName = CopyString(project.name);
3264 if(project.config &&
3265 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3266 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3268 //delete project.config.options.targetFileName;
3270 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
3271 project.config.options.optimization = none;
3272 project.config.options.debug = true;
3273 //project.config.options.warnings = unset;
3274 project.config.options.memoryGuard = false;
3275 project.config.compilingModified = true;
3276 project.config.linkingModified = true;
3278 else if(!project.topNode.name && project.config)
3280 project.topNode.name = CopyString(project.config.options.targetFileName);
3283 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3284 project.topNode.configurations = project.configurations;
3285 project.topNode.platforms = project.platforms;
3286 project.topNode.options = project.options;*/