1 #ifndef MAKEFILE_GENERATOR
12 static define app = ((GuiApplication)__thisModule);
15 bool eString_PathInsideOfMore(char * path, char * of, char * pathRest)
17 if(!path[0] || !of[0])
18 return false; // What to do here? Ever used?
21 char ofPart[MAX_FILENAME], ofRest[MAX_LOCATION];
22 char pathPart[MAX_FILENAME]; //, pathRest[MAX_LOCATION];
24 strcpy(pathRest, path);
25 for(; ofRest[0] && pathRest[0];)
27 SplitDirectory(ofRest, ofPart, ofRest);
28 SplitDirectory(pathRest, pathPart, pathRest);
29 if(fstrcmp(pathPart, ofPart))
32 if(!ofRest[0] && !pathRest[0])
34 else if(!pathRest[0]) // not inside of, it's the other way around
40 enum NodeTypes { project, file, folder, resources, folderOpen };
43 genFile, ewsFile, epjFile, folder, openFolder, ecFile, ehFile,
44 cFile, hFile, cppFile, hppFile, textFile, webFile, pictureFile, soundFile,
45 archiveFile, packageFile, opticalMediaImageFile, mFile;
47 NodeIcons ::SelectFileIcon(char * filePath)
50 if(filePath && filePath[0])
52 char extension[MAX_EXTENSION];
53 GetExtension(filePath, extension);
56 if(!strcmpi(extension, WorkspaceExtension))
58 else if(!strcmpi(extension, ProjectExtension))
60 else if(!strcmpi(extension, "ec"))
62 else if(!strcmpi(extension, "eh"))
64 else if(!strcmpi(extension, "cpp") || !strcmpi(extension, "cc") ||
65 !strcmpi(extension, "cxx"))
67 else if(!strcmpi(extension, "hpp") || !strcmpi(extension, "hh") ||
68 !strcmpi(extension, "hxx"))
70 else if(!strcmpi(extension, "c"))
72 else if(!strcmpi(extension, "h"))
74 else if(!strcmpi(extension, "m"))
76 else if(!strcmpi(extension, "txt") || !strcmpi(extension, "text") ||
77 !strcmpi(extension, "nfo") || !strcmpi(extension, "info"))
79 else if(!strcmpi(extension, "htm") || !strcmpi(extension, "html") ||
80 !strcmpi(extension, "css") || !strcmpi(extension, "php") ||
81 !strcmpi(extension, "js"))
83 else if(!strcmpi(extension, "bmp") || !strcmpi(extension, "pcx") ||
84 !strcmpi(extension, "jpg") || !strcmpi(extension, "jpeg") ||
85 !strcmpi(extension, "gif") || !strcmpi(extension, "png") ||
86 !strcmpi(extension, "ico"))
88 else if(!strcmpi(extension, "wav") || !strcmpi(extension, "mp3") ||
89 !strcmpi(extension, "ogg") || !strcmpi(extension, "snd"))
91 else if(!strcmpi(extension, "ear") || !strcmpi(extension, "7z") ||
92 !strcmpi(extension, "rar") || !strcmpi(extension, "zip") ||
93 !strcmpi(extension, "gz") || !strcmpi(extension, "bz2") ||
94 !strcmpi(extension, "tar") || !strcmpi(extension, "arj") ||
95 !strcmpi(extension, "lza") || !strcmpi(extension, "lzh") ||
96 !strcmpi(extension, "cpio") || !strcmpi(extension, "z"))
98 else if(!strcmpi(extension, "cab") || !strcmpi(extension, "deb") ||
99 !strcmpi(extension, "rpm"))
101 else if(!strcmpi(extension, "iso") || !strcmpi(extension, "mds") ||
102 !strcmpi(extension, "cue") || !strcmpi(extension, "bin") ||
103 !strcmpi(extension, "ccd") || !strcmpi(extension, "bwt") ||
104 !strcmpi(extension, "cdi") || !strcmpi(extension, "nrg"))
105 icon = opticalMediaImageFile;
113 icon = genFile; // tocheck: error icon?
117 NodeIcons ::SelectNodeIcon(NodeTypes type)
136 #define SELECTION_COLOR Color { 10, 36, 106 }
142 // this is so not working, why!
144 // return result was not even executed (did not step on while debugging)
145 class TwoStrings : struct
165 class ProjectNode : ListItem
170 set { return { fileName = value }; }
171 // TOCHECK: Is this isset necessary at all?
172 isset { return nodeType == file && !options && !configurations && !platforms && !files; }
174 property String folder
179 if(strchr(value, '/'))
181 char p[MAX_LOCATION];
182 char n[MAX_FILENAME];
183 GetLastDirectory(value, n);
184 StripLastDirectory(value, p);
185 name = CopyString(n);
186 path = CopyString(p);
189 name = CopyString(value);
193 // TOCHECK: Non Reentrant
194 static char insidePath[MAX_LOCATION];
196 strcpy(insidePath, (parent.type == project) ? "" : parent.path);
197 PathCatSlash(insidePath, name);
199 if(!fstrcmp(path, insidePath))
203 strcpy(insidePath, path);
204 if(!insidePath[0]) strcpy(insidePath, ".");
205 PathCatSlash(insidePath, name);
209 isset { return nodeType == folder; }
211 property String fileName
216 if(strchr(value, '/'))
218 char p[MAX_LOCATION];
219 char n[MAX_FILENAME];
220 GetLastDirectory(value, n);
221 StripLastDirectory(value, p);
222 name = CopyValidateMakefilePath(n);
223 path = CopyValidateMakefilePath(p);
226 name = CopyValidateMakefilePath(value);
230 // TOCHECK: Non Reentrant
231 static char insidePath[MAX_LOCATION];
233 strcpy(insidePath, (parent.type == project) ? "" : parent.path);
234 if(!fstrcmp(path, insidePath))
238 strcpy(insidePath, path);
239 if(!insidePath[0]) strcpy(insidePath, ".");
240 PathCatSlash(insidePath, name);
244 isset { return nodeType == file && (options || configurations || platforms); }
247 LinkList<ProjectNode> files;
248 ProjectOptions options;
249 Array<PlatformOptions> platforms;
250 List<ProjectConfig> configurations;
252 property ProjectConfig config
257 ProjectConfig result = null;
262 if(configurations && (prj = property::project) && prj.config)
264 const char * projectConfigName = prj.config.name;
265 for(config : configurations)
267 if(!strcmpi(config.name, projectConfigName))
278 ProjectConfig GetMatchingNodeConfig(ProjectConfig config)
280 ProjectConfig nodeConfig = null;
283 const char * configName = config.name;
284 for(cfg : configurations)
286 if(!strcmpi(cfg.name, configName))
296 property bool ecflags
300 ProjectConfig config = this.config;
301 ProjectOptions options = this.options;
302 SetBool memoryGuard = localMemoryGuard;
303 String defaultNameSpace = localDefaultNameSpace;
304 SetBool strictNameSpaces = localStrictNameSpaces;
305 SetBool noLineNumbers = localNoLineNumbers;
307 if(memoryGuard || defaultNameSpace || strictNameSpaces || noLineNumbers)
309 else if(parent.parent)
310 return parent.ecflags;
315 property bool memoryGuard
319 ProjectConfig config = this.config;
320 ProjectOptions options = this.options;
321 SetBool memoryGuard = localMemoryGuard;
325 return parent.memoryGuard;
327 return memoryGuard == true;
330 property String defaultNameSpace
334 ProjectConfig config = this.config;
335 ProjectOptions options = this.options;
336 String defaultNameSpace = localDefaultNameSpace;
337 if(!defaultNameSpace)
340 return parent.defaultNameSpace;
342 return defaultNameSpace;
345 property bool strictNameSpaces
349 ProjectConfig config = this.config;
350 ProjectOptions options = this.options;
351 SetBool strictNameSpaces = localStrictNameSpaces;
352 if(!strictNameSpaces)
355 return parent.strictNameSpaces;
357 return strictNameSpaces == true;
360 property bool noLineNumbers
364 ProjectConfig config = this.config;
365 ProjectOptions options = this.options;
366 SetBool noLineNumbers = localNoLineNumbers;
370 return parent.noLineNumbers;
372 return noLineNumbers == true;
376 property ProjectNode root { get { ProjectNode n; for(n = this; n.parent; n = n.parent); return n; } }
378 property bool containsFile
387 if(child.type == file ||
388 ((child.type == folder || child.type == folderOpen) && child.containsFile))
401 char * GetFullFilePath(char * buffer)
405 strcpy(buffer, root.path);
406 PathCatSlash(buffer, path);
407 PathCatSlash(buffer, name);
412 char * GetFileSysMatchingPath(char * buffer)
416 ProjectNode n, root = this.root;
417 for(n = this; n && (n.type == folder || n.type == project); n = n.parent)
419 strcpy(buffer, root.path);
421 PathCatSlash(buffer, n.path);
422 if(FileExists(buffer).isDirectory)
425 if(!(n && (n.type == folder || n.type == project)))
431 void CollectPerFileAndDirOptions(ProjectConfig projectConfig, Array<String> perFilePreprocessorDefs, Array<DirPath> perFileIncludeDirs)
433 ProjectNode node = null;
434 ProjectConfig config = GetMatchingNodeConfig(projectConfig);
435 List<ProjectNode> nodeStack { };
437 for(node = this; node && node.parent; node = node.parent)
440 // Should we reverse this stack to give priority to the per-file includes? Does the following technique already reverse?
442 // TODO: Check how to fix duplication of following options when configuration is made per-config-per-file
443 while((node = nodeStack.lastIterator.data))
445 if(node.options && node.options.preprocessorDefinitions)
447 for(def : node.options.preprocessorDefinitions)
448 perFilePreprocessorDefs.Add(CopyString(def));
450 if(config && config.options && config.options.preprocessorDefinitions)
452 for(def : config.options.preprocessorDefinitions)
453 perFilePreprocessorDefs.Add(CopyString(def));
455 if(node.options && node.options.includeDirs)
457 for(dir : node.options.includeDirs)
458 perFileIncludeDirs.Add(CopySystemPath(dir));
460 if(config && config.options && config.options.includeDirs)
462 for(dir : config.options.includeDirs)
463 perFileIncludeDirs.Add(CopySystemPath(dir));
465 nodeStack.lastIterator.Remove();
471 ProjectNodeType nodeType;
476 // This holds the absolute path of the .epj for the project topnode (without the filename)
477 // It holds a relative path to the topNode (project) for other nodes (folders and files)
478 // For folders, it includes the folder it refers to. If there is a name difference between the
479 // file system folder and the grouping folder of the project view, it maps to that folder.
489 // This is only set for Top Nodes
492 property Project project
496 ProjectNode n = this;
497 while(n && n.type != project) n = n.parent;
498 return n ? (*&n.project) : null;
502 void RenameConfig(char * oldName, char * newName)
506 for(f : files; (f.configurations || f.files)) { f.RenameConfig(oldName, newName); }
510 for(c : configurations; !strcmp(c.name, oldName))
513 c.name = CopyString(newName);
518 void DeleteConfig(ProjectConfig configToDelete)
522 for(f : files; (f.configurations || f.files)) { f.DeleteConfig(configToDelete); }
526 Iterator<ProjectConfig> c { configurations };
529 ProjectConfig config = c.data;
530 if(!strcmp(configToDelete.name, config.name))
537 if(!configurations.count)
539 delete configurations;
546 ProjectNode backupNode { };
550 backupNode.files = { };
551 for(f : files) backupNode.files.Add(f.Backup());
554 backupNode.options = options.Copy();
558 backupNode.platforms = { };
560 backupNode.platforms.Add(p.Copy());
565 backupNode.configurations = { };
566 for(c : configurations)
567 backupNode.configurations.Add(c.Copy());
572 void Revert(ProjectNode backupNode)
576 Iterator<ProjectNode> it { backupNode.files };
592 configurations.Free();
593 delete configurations;
596 options = backupNode.options ? backupNode.options.Copy() : null;
597 if(backupNode.platforms)
600 for(p : backupNode.platforms)
601 platforms.Add(p.Copy());
603 if(backupNode.configurations)
605 configurations = { };
606 for(c : backupNode.configurations)
607 configurations.Add(c.Copy());
611 void FixupNode(char * parentPath)
617 else if(nodeType == file)
622 path = CopyString((parent.type == folder || parent.type == resources) ? parentPath : "");
625 else if(nodeType == folder)
631 char temp[MAX_LOCATION];
632 strcpy(temp, (parent.type == folder || parent.type == resources) ? parentPath : "");
633 PathCatSlash(temp, name);
634 path = CopyString(temp);
638 indent = parent ? parent.indent + 1 : 0;
641 icon = NodeIcons::SelectFileIcon(name);
643 icon = NodeIcons::SelectNodeIcon(type);
652 parentPath[0] = '\0';
653 else if(type == resources || type == folder)
654 strcpy(parentPath, path);
656 f.FixupNode(parentPath);
661 char * OnGetString(char * tempString, void * fieldData, bool * needClass)
665 // TOCHECK: Called from JSON writer
666 if(nodeType == file && !options && !configurations && !platforms && name)
668 strcpy(tempString, "\"");
669 strcat(tempString, property::fileName);
670 strcat(tempString, "\"");
677 // TOCHECK: Called from ProjectView rendering
678 return name ? name : "";
697 configurations.Free();
698 delete configurations;
701 /////////////////////////////
707 property bool isInResources
712 for(node = this; node; node = node.parent)
714 if(node.type == resources)
721 property TwoStrings platformSpecificExclusionFu
725 // TODO: Proper folder exclusion fix: collect platform names across parents and then build exclusion expression
726 // Find solution to excluding a drivers folder for all platforms and overriting that exclusion on children files/folders
727 TwoStrings result { };
728 int nestingCount = 0, c, len;
730 ProjectConfig config = property::config;
731 Map<String, bool> platformNames { };
735 if(p.options.excludeFromBuild == true)
736 platformNames[p.name] = true;
738 if(config && config.platforms)
740 for(p : config.platforms)
741 if(p.options.excludeFromBuild == true)
742 platformNames[p.name] = true;
744 if(platformNames.count)
747 result.a = new char[1];
749 for(s : platformNames)
751 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
752 if(!strcmpi(&s, platform))
754 if(platform < Platform::enumSize)
756 const char * opening = "$(if $(";
757 const char * close = "),,";
758 char * t = PlatformToMakefileVariable(platform);
760 len += strlen(t) + strlen(opening) + strlen(close);
761 result.a = renew result.a char[len + 1];
762 strcat(result.a, opening);
764 strcat(result.a, close);
767 result.b = new char[nestingCount + 1];
768 for(c = 0; c < nestingCount; c++)
770 result.b[nestingCount] = '\0';
774 result.a = CopyString("");
775 result.b = CopyString("");
777 delete platformNames;
780 TwoStrings parentResult = parent.platformSpecificExclusionFu;
781 if(parentResult.a && parentResult.a[0])
783 len = strlen(result.a) + strlen(parentResult.a);
784 result.a = renew result.a char[len + 1];
785 strcat(result.a, parentResult.a);
786 len = strlen(result.b) + strlen(parentResult.b);
787 result.b = renew result.b char[len + 1];
788 strcat(result.b, parentResult.b);
796 property bool isExcluded
800 // THIS IS THE GENERIC (ALL PLATFORMS) EXCLUDED FROM BUILD
801 // TODO: We can also have platform specific exclusion...
802 ProjectConfig config = property::config;
803 if(config && config.options && config.options.excludeFromBuild)
804 return config.options.excludeFromBuild == true;
805 if(options && options.excludeFromBuild)
806 return options.excludeFromBuild == true;
808 return parent.isExcluded;
816 parent.EnsureVisible();
817 row.collapsed = false;
823 parent.files.Delete(this);
826 ProjectNode Find(char * name, bool includeResources)
828 ProjectNode result = null;
833 if(includeResources || child.type != resources)
835 if(child.type != folder && child.name && !strcmpi(child.name, name))
840 result = child.Find(name, includeResources);
849 ProjectNode FindWithPath(char * name, bool includeResources)
851 ProjectNode result = null;
856 if(includeResources || child.type != resources)
858 char path[MAX_LOCATION];
859 strcpy(path, child.path);
860 if(child.type != folder && child.name)
862 PathCatSlash(path, child.name);
863 if(!strcmpi(path, name))
869 result = child.FindWithPath(name, includeResources);
878 ProjectNode FindSpecial(char * name, bool recursive, bool includeResources, bool includeFolders)
880 ProjectNode result = null;
885 if(includeResources || child.type != resources)
887 if((includeFolders || child.type != folder) && child.name && !strcmpi(child.name, name))
893 result = child.FindSpecial(name, recursive, includeResources, includeFolders);
902 ProjectNode Add(Project project, char * filePath, ProjectNode after, NodeTypes type, NodeIcons icon, bool checkIfExists)
904 ProjectNode node = null;
905 char temp[MAX_LOCATION];
907 GetLastDirectory(filePath, temp);
908 if(!checkIfExists || !project.topNode.Find(temp, false))
910 // Do the check for folder in the same parent or resource files only here
911 if(type == folder || !checkIfExists)
915 if(node.name && !strcmpi(node.name, temp))
920 node = ProjectNode { parent = this, indent = indent + 1, type = type, icon = icon, name = CopyString(temp) };
924 node.nodeType = folder;
930 StripLastDirectory(filePath, temp);
931 MakePathRelative(temp, project.topNode.path, temp);
932 node.path = CopyUnixPath(temp);
934 node.nodeType = file;
938 strcpy(temp, (type == NodeTypes::project) ? "" : path);
939 PathCatSlash(temp, node.name);
940 node.path = CopyString(temp);
942 files.Insert(after, node);
947 #ifndef MAKEFILE_GENERATOR
948 void OnDisplay(Surface surface, int x, int y, int width, ProjectView projectView, Alignment alignment, DataDisplayFlags displayFlags)
950 char label[MAX_FILENAME];
956 bool showConfig = true;
961 projectView = ide.projectView;
964 bmp = projectView.icons[icon].bitmap;
965 xStart = /*indent * indent + */x + (bmp ? (bmp.width + 5) : 0);
967 GetLastDirectory(name, label);
968 if(!showConfig || projectView.drawingInProjectSettingsDialogHeader)
970 if(projectView.drawingInProjectSettingsDialogHeader || (type == project && info))
972 if(projectView.projectSettingsDialog && projectView.projectSettingsDialog.buildTab)
975 addendum = projectView.projectSettingsDialog.buildTab.selectedConfigName;
979 strcat(label, addendum);
982 addendum = projectView.projectSettingsDialog.buildTab.selectedPlatformName;
986 strcat(label, addendum);
992 else if(!projectView.drawingInProjectSettingsDialog)
996 if(type == project && info)
998 int len = strlen(info) + 4;
999 char * more = new char[len];
1000 sprintf(more, " (%s)", info);
1001 strcat(label, more);
1005 len = strlen(label);
1009 if(type == folder || type == folderOpen)
1010 surface.SetForeground(yellow);
1014 surface.TextOpacity(false);
1015 surface.TextExtent(label, len, &w, &h);
1018 // Draw the current row stipple
1019 if(displayFlags.selected)
1020 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1021 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1022 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1024 surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
1028 if(displayFlags.current)
1030 if(displayFlags.active)
1032 surface.LineStipple(0x5555);
1033 if(displayFlags.selected)
1034 surface.SetForeground(0xFFFFFF80);
1036 surface.SetForeground(black);
1040 surface.SetForeground(SELECTION_COLOR);
1042 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
1043 surface.LineStipple(0);
1048 surface.SetForeground(white);
1049 surface.Blit(bmp, x /*+ indent * indent*/,y,0,0, bmp.width, bmp.height);
1055 int OnCompare(ProjectNode b)
1058 if(type == b.type /*|| type >= TYPE_DRIVE*/)
1059 result = strcmpi(name, b.name);
1062 if(type == folder && b.type == file) result = -1;
1063 else if(type == file && b.type == folder) result = 1;
1068 void GenFileFlags(File f, Project project)
1070 ProjectNode node = null;
1071 List<ProjectNode> nodeStack { };
1073 for(node = this; node && node.parent; node = node.parent)
1074 nodeStack.Add(node);
1076 // Should we reverse this stack to give priority to the per-file includes?
1078 while((node = nodeStack.lastIterator.data))
1080 ProjectConfig config = node.config;
1081 if(node.options && node.options.preprocessorDefinitions)
1082 OutputListOption(f, "D", node.options.preprocessorDefinitions, inPlace, false);
1083 if(config && config.options && config.options.preprocessorDefinitions)
1084 OutputListOption(f, "D", config.options.preprocessorDefinitions, inPlace, false);
1085 if(node.options && node.options.includeDirs)
1086 OutputListOption(f, "I", node.options.includeDirs, inPlace, true);
1087 if(config && config.options && config.options.includeDirs)
1088 OutputListOption(f, "I", config.options.includeDirs, inPlace, true);
1090 nodeStack.lastIterator.Remove();
1095 void GenMakefileGetNameCollisionInfo(Map<String, NameCollisionInfo> namesInfo)
1099 char extension[MAX_EXTENSION];
1100 GetExtension(name, extension);
1101 if(!strcmpi(extension, "ec") || !strcmpi(extension, "c") ||
1102 !strcmpi(extension, "cpp") || !strcmpi(extension, "cc") ||
1103 !strcmpi(extension, "cxx") || !strcmpi(extension, "m"))
1105 char moduleName[MAX_FILENAME];
1106 NameCollisionInfo info;
1107 ReplaceSpaces(moduleName, name);
1108 StripExtension(moduleName);
1109 info = namesInfo[moduleName];
1111 info = NameCollisionInfo { };
1112 info.count++; // += 1; unless this is for a bug?
1113 if(!strcmpi(extension, "ec"))
1115 else if(!strcmpi(extension, "c"))
1117 else if(!strcmpi(extension, "cpp"))
1119 else if(!strcmpi(extension, "cc"))
1121 else if(!strcmpi(extension, "cxx"))
1123 else if(!strcmpi(extension, "m"))
1125 namesInfo[moduleName] = info;
1132 if(child.type != resources && (child.type == folder || !child.isExcluded))
1133 child.GenMakefileGetNameCollisionInfo(namesInfo);
1138 int GenMakefilePrintNode(File f, Project project, GenMakefilePrintTypes printType, Map<String, NameCollisionInfo> namesInfo, Array<String> items)
1144 // TOCHECK: Does this take care of parent folder platform specific exclusions?
1145 TwoStrings ts = platformSpecificExclusionFu;
1146 char moduleName[MAX_FILENAME];
1147 char extension[MAX_EXTENSION];
1148 GetExtension(name, extension);
1149 if(printType == resources)
1152 char tempPath[MAX_LOCATION];
1153 char modulePath[MAX_LOCATION];
1156 if(eString_PathInsideOfMore(path, project.resNode.path, tempPath))
1159 PathCatSlash(tempPath, name);
1164 strcpy(tempPath, path);
1165 PathCatSlash(tempPath, name);
1167 ReplaceSpaces(modulePath, tempPath);
1168 sprintf(s, "%s%s%s%s", ts.a, useRes ? "$(RES)" : "", modulePath, ts.b);
1169 items.Add(CopyString(s));
1171 else if(printType == sources)
1173 if(!strcmpi(extension, "c") || !strcmpi(extension, "cpp") ||
1174 !strcmpi(extension, "cc") || !strcmpi(extension, "cxx") ||
1175 !strcmpi(extension, "ec") || !strcmpi(extension, "m"))
1177 char modulePath[MAX_LOCATION];
1179 ReplaceSpaces(modulePath, path);
1180 ReplaceSpaces(moduleName, name);
1181 sprintf(s, "%s%s%s%s%s", ts.a, modulePath, path[0] ? SEPS : "", moduleName, ts.b);
1182 items.Add(CopyString(s));
1185 else if(!strcmpi(extension, "c") || !strcmpi(extension, "cpp") ||
1186 !strcmpi(extension, "cc") || !strcmpi(extension, "cxx") ||
1187 !strcmpi(extension, "m"))
1189 if(printType == objects)
1192 NameCollisionInfo info;
1193 ReplaceSpaces(moduleName, name);
1194 StripExtension(moduleName);
1195 info = namesInfo[moduleName];
1196 collision = info ? info.IsExtensionColliding(extension) : false;
1197 sprintf(s, "%s$(OBJ)%s%s%s.o%s", ts.a, moduleName, collision ? "." : "", collision ? extension : "", ts.b);
1198 items.Add(CopyString(s));
1201 else if(!strcmpi(extension, "ec"))
1203 ReplaceSpaces(moduleName, name);
1204 StripExtension(moduleName);
1205 if(printType == objects)
1208 if(printType == objects)
1209 sprintf(s, "%s$(OBJ)%s.o%s", ts.a, moduleName, ts.b);
1210 else if(printType == cObjects)
1211 sprintf(s, "%s$(OBJ)%s.c%s", ts.a, moduleName, ts.b);
1212 else if(printType == symbols)
1213 sprintf(s, "%s$(OBJ)%s.sym%s", ts.a, moduleName, ts.b);
1214 else if(printType == imports)
1215 sprintf(s, "%s$(OBJ)%s.imp%s", ts.a, moduleName, ts.b);
1217 items.Add(CopyString(s));
1225 if(child.type != resources && (child.type == folder || !child.isExcluded))
1226 count += child.GenMakefilePrintNode(f, project, printType, namesInfo, items);
1232 void GenMakefilePrintSymbolRules(File f, Project project)
1234 //ProjectNode child;
1235 //char objDir[MAX_LOCATION];
1236 CompilerConfig compiler = GetCompilerConfig();
1237 //ReplaceSpaces(objDir, project.config.objDir.dir);
1239 //eSystem_Log("Printing Symbol Rules\n");
1242 char extension[MAX_EXTENSION];
1243 char modulePath[MAX_LOCATION];
1244 char moduleName[MAX_FILENAME];
1246 GetExtension(name, extension);
1247 if(!strcmpi(extension, "ec"))
1252 ReplaceSpaces(moduleName, name);
1253 StripExtension(moduleName);
1255 ReplaceSpaces(modulePath, path);
1256 if(modulePath[0]) strcat(modulePath, SEPS);
1259 // *** Dependency command ***
1260 sprintf(command, "gcc -MT $(OBJ)%s.o -MM %s%s.%s", moduleName,
1261 modulePath, moduleName, extension);
1263 // System Includes (from global settings)
1264 for(item : compiler.dirs[Includes])
1266 strcat(command, " -isystem ");
1267 if(strchr(item, ' '))
1269 strcat(command, "\"");
1270 strcat(command, item);
1271 strcat(command, "\"");
1274 strcat(command, item);
1277 for(item : project.includeDirs)
1279 strcat(command, " -I");
1280 if(strchr(item, ' '))
1282 strcat(command, "\"");
1283 strcat(command, item);
1284 strcat(command, "\"");
1287 strcat(command, item);
1289 for(item : project.preprocessorDefs)
1291 strcat(command, " -D");
1292 strcat(command, item);
1296 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1299 bool firstLine = true;
1302 // To do some time: auto save external dependencies?
1305 if(dep.GetLine(line, sizeof(line)-1))
1309 char * colon = strstr(line, ":");
1310 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
1324 // If we failed to generate dependencies...
1328 f.Printf("$(OBJ)%s.sym: %s%s.%s\n",
1329 moduleName, modulePath, moduleName, extension);
1335 f.Printf("\t$(ECP) %s%s.%s %s.sym\n\n",
1336 modulePath, moduleName, extension, moduleName);
1339 f.Printf("\t$(ECP) $(CECFLAGS)");
1343 f.Printf(" -memguard");
1344 if(strictNameSpaces)
1345 f.Printf(" -strictns");
1347 char * s = defaultNameSpace;
1349 f.Printf(" -defaultns %s", s);
1353 f.Printf(" $(ECFLAGS)");
1354 f.Printf(" $(CFLAGS)");
1355 GenFileFlags(f, project);
1356 f.Printf(" -c %s%s.%s -o $(OBJ)%s.sym\n\n",
1357 modulePath, moduleName, extension, moduleName);
1364 // TODO: Platform specific options
1365 if(child.type != resources && (child.type == folder || !child.isExcluded))
1366 child.GenMakefilePrintSymbolRules(f, project);
1372 void GenMakefilePrintCObjectRules(File f, Project project)
1374 //ProjectNode child;
1375 //char objDir[MAX_LOCATION];
1376 CompilerConfig compiler = GetCompilerConfig();
1377 //ReplaceSpaces(objDir, project.config.objDir.dir);
1378 //eSystem_Log("Printing C Object Rules\n");
1381 char extension[MAX_EXTENSION];
1382 char modulePath[MAX_LOCATION];
1383 char moduleName[MAX_FILENAME];
1385 GetExtension(name, extension);
1386 if(!strcmpi(extension, "ec"))
1391 ReplaceSpaces(moduleName, name);
1392 StripExtension(moduleName);
1394 ReplaceSpaces(modulePath, path);
1395 if(modulePath[0]) strcat(modulePath, SEPS);
1398 // *** Dependency command ***
1399 sprintf(command, "gcc -MT $(OBJ)%s.o -MM %s%s.%s",
1400 moduleName, modulePath, moduleName, extension);
1402 // System Includes (from global settings)
1403 for(item : compiler.dirs[Includes])
1405 strcat(command, " -isystem ");
1406 if(strchr(item, ' '))
1408 strcat(command, "\"");
1409 strcat(command, item);
1410 strcat(command, "\"");
1413 strcat(command, item);
1416 for(item : project.config.includeDirs)
1418 strcat(command, " -I");
1419 if(strchr(item, ' '))
1421 strcat(command, "\"");
1422 strcat(command, item);
1423 strcat(command, "\"");
1426 strcat(command, item);
1428 for(item : project.config.preprocessorDefs)
1430 strcat(command, " -D");
1431 strcat(command, item);
1435 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1439 bool firstLine = true;
1441 // To do some time: auto save external dependencies?
1444 if(dep.GetLine(line, sizeof(line)-1))
1448 char * colon = strstr(line, ":");
1449 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
1463 // If we failed to generate dependencies...
1466 /* COMMENTED OUT FOR NOW
1467 f.Printf("$(OBJ)%s.c: %s%s.%s $(Symbols)\n",
1468 moduleName, modulePath, moduleName, extension);
1471 f.Printf("$(OBJ)%s.c: %s%s.%s $(OBJ)%s.sym | $(SYMBOLS)\n",
1472 moduleName, modulePath, moduleName, extension, moduleName);
1478 f.Printf("\t$(ECC) %s%s.%s $(OBJ)%s.c\n\n",
1479 modulePath, moduleName, extension, moduleName);
1482 f.Printf("\t$(ECC)");
1485 f.Printf("%s $(CECFLAGS)", noLineNumbers ? " -nolinenumbers" : "");
1487 f.Printf(" -memguard");
1488 if(strictNameSpaces)
1489 f.Printf(" -strictns");
1491 char * s = defaultNameSpace;
1493 f.Printf(" -defaultns %s", s);
1497 f.Printf(" $(CECFLAGS) $(ECFLAGS)");
1498 f.Printf(" $(CFLAGS) $(FVISIBILITY)");
1499 GenFileFlags(f, project);
1500 f.Printf(" -c %s%s.%s -o $(OBJ)%s.c -symbols $(OBJ)\n\n",
1501 modulePath, moduleName, extension, moduleName);
1508 // TODO: Platform specific options
1509 if(child.type != resources && (child.type == folder || !child.isExcluded))
1510 child.GenMakefilePrintCObjectRules(f, project);
1516 void GenMakefilePrintObjectRules(File f, Project project, Map<String, NameCollisionInfo> namesInfo)
1518 //ProjectNode child;
1519 //char objDir[MAX_LOCATION];
1520 CompilerConfig compiler = GetCompilerConfig();
1521 //ReplaceSpaces(objDir, project.config.objDir.dir);
1522 //eSystem_Log("Printing Object Rules\n");
1526 char extension[MAX_EXTENSION];
1527 char modulePath[MAX_LOCATION];
1528 char moduleName[MAX_FILENAME];
1530 GetExtension(name, extension);
1531 /*if(!strcmpi(extension, "c") || !strcmpi(extension, "cpp") ||
1532 !strcmpi(extension, "ec") || !strcmpi(extension, "cc") ||
1533 !strcmpi(extension, "cxx"))*/
1534 if((!strcmpi(extension, "c") || !strcmpi(extension, "cpp") ||
1535 !strcmpi(extension, "cc") || !strcmpi(extension, "cxx")) ||
1536 !strcmpi(extension, "ec"))
1540 NameCollisionInfo info;
1542 ReplaceSpaces(moduleName, name);
1543 StripExtension(moduleName);
1545 info = namesInfo[moduleName];
1546 collision = info ? info.IsExtensionColliding(extension) : false;
1548 ReplaceSpaces(modulePath, path);
1549 if(modulePath[0]) strcat(modulePath, SEPS);
1551 // *** Dependency command ***
1552 if(!strcmpi(extension, "ec"))
1553 sprintf(command, "%s -MT $(OBJ)%s.o -MM $(OBJ)%s.c", compiler.ccCommand, moduleName, moduleName);
1555 sprintf(command, "%s -MT $(OBJ)%s.o -MM %s%s.%s", compiler.ccCommand, moduleName, modulePath, moduleName, extension);
1557 if(!strcmpi(extension, "ec"))
1558 f.Printf("$(OBJ)%s.o: $(OBJ)%s.c\n", moduleName, moduleName);
1562 // System Includes (from global settings)
1563 for(item : compiler.dirs[includes])
1565 strcat(command, " -isystem ");
1566 if(strchr(item, ' '))
1568 strcat(command, "\"");
1569 strcat(command, item);
1570 strcat(command, "\"");
1573 strcat(command, item);
1576 for(item : project.config.includeDirs)
1578 strcat(command, " -I");
1579 if(strchr(item, ' '))
1581 strcat(command, "\"");
1582 strcat(command, item);
1583 strcat(command, "\"");
1586 strcat(command, item);
1588 for(item : project.config.preprocessorDefs)
1590 strcat(command, " -D");
1591 strcat(command, item);
1595 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1598 bool firstLine = true;
1601 // To do some time: auto save external dependencies?
1605 if(dep.GetLine(line, sizeof(line)-1))
1609 char * colon = strstr(line, ":");
1610 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
1624 // If we failed to generate dependencies...
1628 /*if(!strcmpi(extension, "ec"))
1629 f.Printf("$(OBJ)%s.o: $(OBJ)%s.c\n", moduleName, moduleName);
1631 f.Printf("$(OBJ)%s%s%s.o: %s%s.%s\n", moduleName,
1632 collision ? "." : "", collision ? extension : "", modulePath, moduleName, extension);
1638 f.Printf("\t$(CC) $(CFLAGS)");
1639 GenFileFlags(f, project);
1640 if(!strcmpi(extension, "ec"))
1641 f.Printf(" $(FVISIBILITY) -c $(OBJ)%s.c -o $(OBJ)%s.o\n\n", moduleName, moduleName);
1643 f.Printf(" -c %s%s.%s -o $(OBJ)%s%s%s.o\n\n",
1644 modulePath, moduleName, !strcmpi(extension, "ec") ? "c" : extension, moduleName,
1645 collision ? "." : "", collision ? extension : "");
1652 // TODO: Platform specific options
1653 if(child.type != resources && (child.type == folder || !child.isExcluded))
1654 child.GenMakefilePrintObjectRules(f, project, namesInfo);
1660 void GenMakefileAddResources(File f, String resourcesPath)
1667 //Iterator<ProjectNode> i { files };
1668 //Iterator<ProjectNode> prev { files };
1669 //for(child : files)
1671 for(c = 0; c < files.count; c++)
1673 ProjectNode child = files[c];
1674 TwoStrings ts = child.platformSpecificExclusionFu;
1677 if(child.type == file && !child.isExcluded && !(count > 0 && ts))
1680 char tempPath[MAX_LOCATION];
1681 char resPath[MAX_LOCATION];
1685 // $(EAR) aw%s --- /*quiet ? "q" : */""
1687 f.Printf("\t%s$(EAR) aw $(TARGET)", ts.a);
1690 if(eString_PathInsideOfMore(child.path, resourcesPath, tempPath))
1693 PathCatSlash(tempPath, child.name);
1698 strcpy(tempPath, child.path);
1699 PathCatSlash(tempPath, child.name);
1701 ReplaceSpaces(resPath, tempPath);
1702 if(strchr(tempPath, ' '))
1706 f.Printf(" %s%s%s%s", quotes, useRes ? "$(RES)" : "", resPath, quotes);
1709 if(count == 10 || (count > 0 && (ts || !child.next)))
1711 char path[MAX_LOCATION] = "", temp[MAX_LOCATION];
1714 for(parent = this; parent.type == folder; parent = parent.parent)
1717 strcpy(path, parent.name);
1724 f.Printf(" \"%s\"%s\n", path, ts.b);
1736 if(child.type == folder)
1737 child.GenMakefileAddResources(f, resourcesPath);
1743 class NameCollisionInfo
1753 bool IsExtensionColliding(char * extension)
1756 if(count > 1 && ((!strcmpi(extension, "c") && ec) ||
1757 (!strcmpi(extension, "cpp") && (ec || c)) ||
1758 (!strcmpi(extension, "cc") && (ec || c || cpp)) ||
1759 (!strcmpi(extension, "cxx") && (ec || c || cpp || cc)) ||
1760 !strcmpi(extension, "m")))