2 public import static "ecere"
7 #ifndef MAKEFILE_GENERATOR
14 import "ProjectConfig"
20 static void DummyFunction()
28 extern int __ecereVMethodID_class_OnCompare;
29 extern int __ecereVMethodID_class_OnFree;
31 IDESettings ideSettings;
33 IDESettingsContainer settingsContainer
36 dataOwner = &ideSettings;
37 dataClass = class(IDESettings);
39 void OnLoad(GlobalSettingsData data)
41 IDESettings settings = (IDESettings)data;
42 #ifndef MAKEFILE_GENERATOR
43 globalSettingsDialog.ideSettings = settings;
44 ide.UpdateRecentMenus();
45 // ide.UpdateMakefiles(); -- can't really regenerate on Load since all recent menus changes will happen
50 #ifdef MAKEFILE_GENERATOR
51 CompilerConfig defaultCompiler;
54 // LEGACY BINARY EPJ LOADING
56 SetBool ParseTrueFalseValue(char * string)
58 if(!strcmpi(string, "True")) return true;
62 void ParseArrayValue(Array<String> array, char * equal)
64 char * start, * comma;
66 string = CopyString(equal);
70 comma = strstr(start, ",");
73 array.Add(CopyString(start));
83 void ProjectNode::LegacyBinaryLoadNode(File f)
88 f.Read(&len, sizeof(len), 1);
89 name = new char[len+1];
91 f.Read(name, sizeof(char), len+1);
92 f.Read(&len, sizeof(len), 1);
94 path = new char[len+1];
95 f.Read(path, sizeof(char), len+1);
98 fileName = new char[fileNameLen+2];
99 strcpy(fileName, path);
100 if(fileName[0]) strcat(fileName, "/");
101 strcat(fileName, name);
104 f.Read(&type, sizeof(type), 1);
105 f.Read(&count, sizeof(count), 1);
110 icon = NodeIcons::SelectFileIcon(name);
115 icon = NodeIcons::SelectNodeIcon(type);
118 if(count && !files) files = { };
119 for(c = 0; c < count; c++)
121 ProjectNode child { };
124 child.indent = indent + 1;
125 LegacyBinaryLoadNode(child, f);
129 /*void LegacyBinarySaveNode(File f)
134 f.Write(&len, sizeof(len), 1);
135 f.Write(name, sizeof(char), len+1);
139 // Projects Absolute Path Are Not Saved
141 f.Write(&len, sizeof(len), 1);
142 f.Write(&len, sizeof(char), 1);
147 f.Write(&len, sizeof(len), 1);
148 f.Write(path, sizeof(char), len+1);
150 f.Write(&type, sizeof(type), 1);
151 f.Write(&children.count, sizeof(children.count), 1);
152 for(child = children.first; child; child.next)
156 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
159 char printPath[MAX_LOCATION];
161 if(type == project && (files.count /*|| preprocessorDefs.first*/))
163 f.Printf("\n Files\n");
165 else if(type == file)
167 if(!strcmp(path, insidePath))
168 f.Printf("%s - %s\n", indentation, name);
171 strcpy(printPath, path);
172 len = strlen(printPath);
174 if(printPath[len-1] != '/')
175 strcat(printPath, "/");
176 strcat(printPath, name);
177 f.Printf("%s = %s\n", indentation, printPath);
180 f.Printf("\nError\n\n");
182 else if(type == folder)
184 f.Printf("%s + %s\n", indentation, name);
186 else if(type == resources && files.count)
188 PathCatSlash(insidePath, path);
189 f.Printf("\n%sResources\n", indentation);
191 f.Printf("%s Path = %s\n", indentation, path);
194 /*if(buildExclusions.first && type != project)
196 for(item = buildExclusions.first; item; item = item.next)
198 if(item == buildExclusions.first)
199 f.Printf("%s Build Exclusions = %s", indentation, item.name);
201 f.Printf(", %s", item.name);
206 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
208 for(item = preprocessorDefs.first; item; item = item.next)
210 if(item == preprocessorDefs.first)
211 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
213 f.Printf(", %s", item.name);
219 if(type == project && (files.count /*|| preprocessorDefs.first*/))
223 LegacyAsciiSaveNode(child, f, indentation, insidePath);
225 else if(type == folder)
227 strcat(indentation, " ");
228 // WHAT WAS THIS: strcpy(printPath, path);
229 // TOCHECK: why is Unix/PathCat not used here
230 len = strlen(insidePath);
232 if(insidePath[len-1] != '/')
233 strcat(insidePath, "/");
234 strcat(insidePath, name);
237 LegacyAsciiSaveNode(child, f, indentation, insidePath);
238 f.Printf("%s -\n", indentation);
239 indentation[strlen(indentation) - 3] = '\0';
240 StripLastDirectory(insidePath, insidePath);
242 else if(type == resources && files.count)
246 LegacyAsciiSaveNode(child, f, indentation, insidePath);
247 StripLastDirectory(insidePath, insidePath);
252 void ProjectConfig::LegacyProjectConfigSave(File f)
254 char * indentation = " ";
256 //f.Printf("\n * Common\n");
258 f.Printf("\n + %s\n", name);
259 f.Printf("\n Compiler\n\n");
260 if(objDir.expression[0])
261 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
262 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
263 switch(options.optimization)
265 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
266 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
267 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
269 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
271 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
272 if(options.memoryGuard == true)
273 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
274 if(options.strictNameSpaces == true)
275 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
276 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
277 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
278 TOFIX: Compiler Bug {
279 if(options.preprocessorDefinitions.count)
282 for(item : options.preprocessorDefinitions)
286 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
290 f.Printf(", %s", item);
295 if(options.includeDirs.count)
297 f.Printf("\n%sInclude Directories\n", indentation);
298 for(item : options.includeDirs)
299 f.Printf("%s - %s\n", indentation, name);
303 f.Printf("\n%sLinker\n\n", indentation);
304 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
305 switch(options.targetType)
307 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
308 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
309 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
311 if(targetDir.expression[0])
312 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
314 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
316 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
317 if(options.libraries.count)
320 for(item : options.libraries)
324 f.Printf("\n%sLibraries = %s", indentation, name);
328 f.Printf(", %s", item);
332 if(options.libraryDirs.count)
334 f.Printf("\n%sLibrary Directories\n\n", indentation);
335 for(item : options.libraryDirs)
336 f.Printf(" - %s\n", indentation, item);
340 void LegacyAsciiSaveProject(File f, Project project)
342 char indentation[128*3];
343 char path[MAX_LOCATION];
345 f.Printf("\nECERE Project File : Format Version 0.1b\n");
346 f.Printf("\nDescription\n%s\n.\n", project.description);
347 f.Printf("\nLicense\n%s\n.\n", project.license);
348 f.Printf("\nModule Name = %s\n", project.moduleName);
349 f.Printf("\n Configurations\n");
350 //////////////////////////////////////commonConfig.Save(f, true);
351 for(cfg : project.configurations)
352 LegacyProjectConfigSave(cfg, f);
354 strcpy(indentation, " ");
356 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
362 // *** NEW JSON PROJECT FORMAT ***
363 public enum ProjectNodeType { file, folder };
365 // *******************************
367 define PEEK_RESOLUTION = (18.2 * 10);
373 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
375 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources };
377 define WorkspaceExtension = "ews";
378 define ProjectExtension = "epj";
380 void ReplaceSpaces(char * output, char * source)
385 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
387 if(ch == ' ') output[dc++] = '\\';
390 if(ch == '(' || ch == ')') output[dc++] = '\\';
400 static void OutputNoSpace(File f, char * source)
402 char * output = new char[strlen(source)+1024];
403 ReplaceSpaces(output, source);
408 enum ListOutputMethod { inPlace, newLine, lineEach };
410 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs)
413 const int breakListLength = 1536;
414 const int breakLineLength = 78;
416 int c, len, itemCount = 0;
417 Array<int> breaks { };
421 MapNode<String, int> mn;
422 for(c=0; c<list.count; c++)
424 len = strlen(list[c]) + 3;
425 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
427 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
429 if(strstr(list[c], mn.key))
433 if(charCount + len > breakListLength)
435 breaks.Add(itemCount);
443 breaks.Add(itemCount);
444 numOfBreaks = breaks.count;
449 f.Printf("%s =", name);
450 for(c=0; c<numOfBreaks; c++)
451 f.Printf(" $(%s%d)", name, c+1);
455 f.Printf("%s =", name);
461 for(c=0; c<numOfBreaks; c++)
464 f.Printf("%s%d =", name, c+1);
467 itemCount = breaks[c];
468 for(n=offset; n<offset+itemCount; n++)
470 int itemLen = strlen(list[n]);
471 if(len > 3 && len + itemLen > breakLineLength)
473 f.Printf(" \\\n\t%s", list[n]);
479 f.Printf(" %s", list[n]);
495 void OutputCleanActions(File f, char * name, int parts)
500 for(c=0; c<parts; c++)
501 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
504 f.Printf("\t$(call rmq,$(%s))\n", name);
507 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
511 if(method == newLine)
515 if(method == lineEach)
517 f.Printf(" -%s", option);
519 OutputNoSpace(f, item);
521 f.Printf("%s", item);
526 static void OutputLibraries(File f, Array<String> libraries)
528 for(item : libraries)
530 char ext[MAX_EXTENSION];
531 char temp[MAX_LOCATION];
533 GetExtension(item, ext);
534 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
538 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
540 if(!strncmp(item, "lib", 3))
541 strcpy(temp, item + 3);
544 StripExtension(temp);
553 void CamelCase(char * string)
555 int c, len = strlen(string);
556 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
557 string[c] = (char)tolower(string[c]);
560 CompilerConfig GetCompilerConfig()
562 #ifndef MAKEFILE_GENERATOR
563 CompilerConfig compiler = null;
564 if(ide && ide.workspace)
565 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
568 incref defaultCompiler;
569 return defaultCompiler;
573 define localTargetType = config && config.options && config.options.targetType ?
574 config.options.targetType : options && options.targetType ?
575 options.targetType : TargetTypes::executable;
576 define localWarnings = config && config.options && config.options.warnings ?
577 config.options.warnings : options && options.warnings ?
578 options.warnings : WarningsOption::unset;
579 define localDebug = config && config.options && config.options.debug ?
580 config.options.debug : options && options.debug ?
581 options.debug : SetBool::unset;
582 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
583 config.options.memoryGuard : options && options.memoryGuard ?
584 options.memoryGuard : SetBool::unset;
585 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
586 config.options.noLineNumbers : options && options.noLineNumbers ?
587 options.noLineNumbers : SetBool::unset;
588 define localProfile = config && config.options && config.options.profile ?
589 config.options.profile : options && options.profile ?
590 options.profile : SetBool::unset;
591 define localOptimization = config && config.options && config.options.optimization ?
592 config.options.optimization : options && options.optimization ?
593 options.optimization : OptimizationStrategy::none;
594 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
595 config.options.defaultNameSpace : options && options.defaultNameSpace ?
596 options.defaultNameSpace : null;
597 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
598 config.options.strictNameSpaces : options && options.strictNameSpaces ?
599 options.strictNameSpaces : SetBool::unset;
600 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
601 define localTargetFileName = config && config.options && config.options.targetFileName ?
602 config.options.targetFileName : options && options.targetFileName ?
603 options.targetFileName : "";
604 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
605 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
606 options.targetDirectory : null;
607 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
608 ideSettings.projectDefaultIntermediateObjDir[0] ?
609 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
610 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
611 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
612 options.objectsDirectory : null;
613 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
614 ideSettings.projectDefaultIntermediateObjDir[0] ?
615 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
616 define localConsole = config && config.options && config.options.console ?
617 config.options.console : options && options.console ?
618 options.console : SetBool::unset;
619 define localCompress = config && config.options && config.options.compress ?
620 config.options.compress : options && options.compress ?
621 options.compress : SetBool::unset;
623 char * PlatformToMakefileVariable(Platform platform)
625 return platform == win32 ? "WINDOWS" : platform == tux ? "LINUX" : platform == apple ? "OSX"/*"APPLE"*/ : platform;
628 class Project : struct
630 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
631 // We might want to tweak this default behavior of regular classes ?
632 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
639 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
640 property Array<PlatformOptions> platforms
642 get { return platforms; }
645 if(platforms) { platforms.Free(); delete platforms; }
648 List<PlatformOptions> empty { };
649 Iterator<PlatformOptions> it { value };
651 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
652 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
662 if(p.options && !p.options.isEmpty)
669 List<ProjectConfig> configurations;
670 LinkList<ProjectNode> files;
671 String resourcesPath;
672 LinkList<ProjectNode> resources;
675 // topNode.name holds the file name (.epj)
676 ProjectOptions options;
677 Array<PlatformOptions> platforms;
678 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
681 ProjectConfig config;
683 // This is the file name stripped of the epj extension
684 // It should NOT be edited, saved or loaded anywhere
689 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
690 topNode.configurations = null;
691 topNode.platforms = null;
692 topNode.options = null;
695 if(platforms) { platforms.Free(); delete platforms; }
696 if(configurations) { configurations.Free(); delete configurations; }
697 if(files) { files.Free(); delete files; }
698 if(resources) { resources.Free(); delete resources; }
700 delete resourcesPath;
710 property char * configName { get { return config ? config.name : "Common"; } }
712 property ProjectConfig config
718 topNode.info = CopyString(configName);
721 property char * filePath
727 char string[MAX_LOCATION];
728 GetLastDirectory(value, string);
730 topNode.name = CopyString(string);
731 StripExtension(string);
733 name = CopyString(string);
734 StripLastDirectory(value, string);
736 topNode.path = CopyString(string);
738 filePath = CopyString(value);
743 property TargetTypes targetType
747 // TODO: Implement platform specific options?
748 TargetTypes targetType = localTargetType;
753 property char * objDirExpression
757 // TODO: Support platform options
758 char * expression = localObjectsDirectory;
760 expression = settingsObjectsDirectory;
764 property DirExpression objDir
768 char * expression = objDirExpression;
769 DirExpression objDir { type = intermediateObjectsDir };
770 objDir.Evaluate(expression, this);
774 property char * targetDirExpression
778 // TODO: Support platform options
779 char * expression = localTargetDirectory;
781 expression = settingsTargetDirectory;
785 property DirExpression targetDir
789 char * expression = targetDirExpression;
790 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
791 targetDir.Evaluate(expression, this);
796 property WarningsOption warnings
800 WarningsOption warnings = localWarnings;
808 SetBool debug = localDebug;
809 return debug == true;
812 property bool memoryGuard
816 SetBool memoryGuard = localMemoryGuard;
817 return memoryGuard == true;
820 property bool noLineNumbers
824 SetBool noLineNumbers = localNoLineNumbers;
825 return noLineNumbers == true;
828 property bool profile
832 SetBool profile = localProfile;
833 return profile == true;
836 property OptimizationStrategy optimization
840 OptimizationStrategy optimization = localOptimization;
844 property String defaultNameSpace
848 String defaultNameSpace = localDefaultNameSpace;
849 return defaultNameSpace;
852 property bool strictNameSpaces
856 SetBool strictNameSpaces = localStrictNameSpaces;
857 return strictNameSpaces == true;
860 property String targetFileName
864 String targetFileName = localTargetFileName;
865 return targetFileName;
868 //String targetDirectory;
869 //String objectsDirectory;
870 property bool console
874 SetBool console = localConsole;
875 return console == true;
878 property bool compress
882 SetBool compress = localCompress;
883 return compress == true;
886 //SetBool excludeFromBuild;
888 property bool configIsInActiveDebugSession
892 #ifndef MAKEFILE_GENERATOR
893 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
898 property bool configIsInDebugSession
902 #ifndef MAKEFILE_GENERATOR
903 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
908 void SetPath(bool projectsDirs)
910 #ifndef MAKEFILE_GENERATOR
911 ide.SetPath(projectsDirs);
915 #ifndef MAKEFILE_GENERATOR
916 bool Save(char * fileName)
919 /*char output[MAX_LOCATION];
920 ChangeExtension(fileName, "json", output);
921 f = FileOpen(output, write);*/
922 f = FileOpen(fileName, write);
925 files = topNode.files;
926 resources = resNode.files;
927 resourcesPath = resNode.path;
929 files.Remove(resNode);
932 WriteJSONObject(f, class(Project), this, 0);
938 resourcesPath = null;
945 #ifndef MAKEFILE_GENERATOR
946 bool GetRelativePath(char * filePath, char * relativePath)
949 char moduleName[MAX_FILENAME];
950 GetLastDirectory(filePath, moduleName);
951 // try with workspace dir first?
952 if((node = topNode.Find(moduleName, false)))
954 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
955 PathCatSlash(relativePath, node.name);
958 // WARNING: On failure, relative path is uninitialized
963 void CatTargetFileName(char * string)
965 CompilerConfig compiler = GetCompilerConfig();
967 if(targetType == staticLibrary)
969 PathCatSlash(string, "lib");
970 strcat(string, targetFileName);
972 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
974 PathCatSlash(string, "lib");
975 strcat(string, targetFileName);
978 PathCatSlash(string, targetFileName);
983 if(compiler.targetPlatform == win32)
984 strcat(string, ".exe");
987 if(compiler.targetPlatform == win32)
988 strcat(string, ".dll");
989 else if(compiler.targetPlatform == apple)
990 strcat(string, ".dylib");
992 strcat(string, ".so");
995 strcat(string, ".a");
1001 void CatMakeFileName(char * string)
1003 char projectName[MAX_LOCATION];
1004 CompilerConfig compiler = GetCompilerConfig();
1005 strcpy(projectName, name);
1006 if(strcmpi(compiler.name, defaultCompilerName))
1007 sprintf(string, "%s-%s-%s.Makefile", projectName, compiler.name, config.name);
1009 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1013 #ifndef MAKEFILE_GENERATOR
1014 void MarkChanges(ProjectNode node)
1016 for(cfg : topNode.configurations)
1018 ProjectConfig c = null;
1019 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1021 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1022 (!c.options || !cfg.options)))
1023 cfg.symbolGenModified = true;
1025 cfg.makingModified = true;
1029 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1031 for(cfg : configurations)
1034 cfg.makingModified = true;
1036 cfg.compilingModified = true;
1038 cfg.linkingModified = true;
1040 cfg.symbolGenModified = true;
1042 if(compiling || linking)
1044 ide.projectView.modifiedDocument = true;
1045 ide.workspace.modified = true;
1049 void RotateActiveConfig(bool forward)
1051 if(configurations.first && configurations.last != configurations.first)
1053 Iterator<ProjectConfig> cfg { configurations };
1054 while(forward ? cfg.Next() : cfg.Prev())
1055 if(cfg.data == config)
1069 property::config = cfg.data;
1070 ide.workspace.modified = true;
1071 ide.projectView.Update(null);
1075 void ProcessPipeOutputRaw(DualPipe f)
1078 while(!f.Eof() && !ide.ShouldStopBuild())
1081 double lastTime = GetTime();
1085 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1087 ide.outputView.buildBox.Logf("%s\n", line);
1089 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1091 //printf("Processing Input...\n");
1092 if(app.ProcessInput(true))
1094 app.UpdateDisplay();
1097 //printf("Waiting...\n");
1100 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1102 if(ide.ShouldStopBuild())
1104 ide.outputView.buildBox.Logf("\nBuild cancelled by user.\n", line);
1109 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode)
1112 bool compiling = false, linking = false, precompiling = false;
1113 int compilingEC = 0;
1114 int numErrors = 0, numWarnings = 0;
1115 bool loggedALine = false;
1116 CompilerConfig compiler = GetCompilerConfig();
1117 char * configName = this.configName;
1118 int lenMakeCommand = strlen(compiler.makeCommand);
1120 char cppCommand[MAX_LOCATION];
1121 char ccCommand[MAX_LOCATION];
1122 char ecpCommand[MAX_LOCATION];
1123 char eccCommand[MAX_LOCATION];
1124 char ecsCommand[MAX_LOCATION];
1125 char earCommand[MAX_LOCATION];
1127 char * cc = compiler.ccCommand;
1128 char * cpp = compiler.cppCommand;
1129 sprintf(cppCommand, "%s%s%s%s ",
1130 compiler.ccacheEnabled ? "ccache " : "",
1131 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1132 compiler.distccEnabled ? "distcc " : "",
1133 compiler.cppCommand);
1134 sprintf(ccCommand, "%s%s%s%s ",
1135 compiler.ccacheEnabled ? "ccache " : "",
1136 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1137 compiler.distccEnabled ? "distcc " : "",
1138 compiler.ccCommand);
1139 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1140 sprintf(eccCommand, "%s ", compiler.eccCommand);
1141 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1142 sprintf(earCommand, "%s ", compiler.earCommand);
1144 while(!f.Eof() && !ide.ShouldStopBuild())
1147 double lastTime = GetTime();
1151 //printf("Peeking and GetLine...\n");
1152 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1154 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1156 char * module = strstr(line, "No rule to make target `");
1160 module = strchr(module, '`') + 1;
1161 end = strchr(module, '\'');
1165 ide.outputView.buildBox.Logf(" %s: No such file or directory\n", module);
1166 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1172 //ide.outputView.buildBox.Logf("error: %s\n", line);
1176 else if(strstr(line, "ear ") == line);
1177 else if(strstr(line, "strip ") == line);
1178 else if(strstr(line, ccCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1180 char moduleName[MAX_FILENAME];
1183 bool isPrecomp = false;
1185 if(strstr(line, ccCommand) == line)
1187 module = strstr(line, " -c ");
1188 if(module) module += 4;
1190 else if(strstr(line, eccCommand) == line)
1192 module = strstr(line, " -c ");
1193 if(module) module += 4;
1194 //module = line + 3;
1195 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1196 compilingEC = 3;//2;
1198 else if(strstr(line, ecpCommand) == line)
1200 // module = line + 8;
1201 module = strstr(line, " -c ");
1202 if(module) module += 4;
1211 if(!compiling && !isPrecomp)
1213 ide.outputView.buildBox.Logf("Compiling...\n");
1216 else if(!precompiling && isPrecomp)
1218 ide.outputView.buildBox.Logf("Generating symbols...\n");
1219 precompiling = true;
1221 Tokenize(module, 1, tokens, false);
1222 GetLastDirectory(module, moduleName);
1223 ide.outputView.buildBox.Logf("%s\n", moduleName);
1225 else if((module = strstr(line, " -o ")))
1228 precompiling = false;
1230 ide.outputView.buildBox.Logf("Linking...\n");
1234 ide.outputView.buildBox.Logf("%s\n", line);
1238 if(compilingEC) compilingEC--;
1240 else if(strstr(line, "ar rcs") == line)
1241 ide.outputView.buildBox.Logf("Building library...\n");
1242 else if(strstr(line, ecsCommand) == line)
1243 ide.outputView.buildBox.Logf("Writing symbol loader...\n");
1246 if(linking || compiling || precompiling)
1248 char * colon = strstr(line, ":"); //, * bracket;
1249 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1250 colon = strstr(colon + 1, ":");
1253 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1255 int len = (int)(colon - line);
1256 len = Min(len, MAX_LOCATION-1);
1257 // Don't be mistaken by the drive letter colon
1259 // TODO: need to fix colon - line gives char *
1260 // warning: incompatible expression colon - line (char *); expected int
1262 strncpy(moduleName, line, (int)(colon - line));
1263 moduleName[colon - line] = '\0';
1265 strncpy(moduleName, line, len);
1266 moduleName[len] = '\0';
1267 // Remove stuff in brackets
1268 //bracket = strstr(moduleName, "(");
1269 //if(bracket) *bracket = '\0';
1271 GetLastDirectory(moduleName, temp);
1272 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1275 strcpy(moduleName, "Linker Error");
1279 strcpy(temp, topNode.path);
1280 PathCatSlash(temp, moduleName);
1281 MakePathRelative(temp, topNode.path, moduleName);
1283 if(strstr(line, "error:"))
1287 // Silence warnings for compiled EC
1288 char * objDir = strstr(moduleName, objDirExp.dir);
1292 if((pointer = strstr(line, "undefined")) ||
1293 (pointer = strstr(line, "No such file")) ||
1294 (pointer = strstr(line, "token")))
1296 strncat(moduleName, colon, pointer - colon);
1297 strcat(moduleName, "error: ");
1302 else if((pointer = strstr(line, "No such file")))
1304 strncat(moduleName, colon, pointer - colon);
1305 strcat(moduleName, "error: ");
1309 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1311 else if(strstr(line, "warning:"))
1316 if(this == ide.workspace.projects.firstIterator.data)
1317 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1320 char fullModuleName[MAX_LOCATION];
1321 strcpy(fullModuleName, topNode.path);
1322 PathCat(fullModuleName, moduleName);
1323 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1324 MakeSystemPath(fullModuleName);
1325 ide.outputView.buildBox.Logf(" %s%s\n", fullModuleName, colon);
1330 ide.outputView.buildBox.Logf("%s\n", line);
1331 linking = compiling = precompiling = false;
1335 ide.outputView.buildBox.Logf("%s\n", line);
1339 //printf("Done getting line\n");
1340 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1342 //printf("Processing Input...\n");
1343 if(app.ProcessInput(true))
1345 app.UpdateDisplay();
1348 //printf("Waiting...\n");
1351 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1353 if(ide.ShouldStopBuild())
1355 ide.outputView.buildBox.Logf("\nBuild cancelled by user.\n", line);
1358 else if(loggedALine || !isARun)
1360 if(f.GetExitCode() && !numErrors)
1362 bool result = f.GetLine(line, sizeof(line)-1);
1363 ide.outputView.buildBox.Logf("Fatal Error: child process terminated unexpectedly\n");
1368 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, configName);
1370 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? "errors" : "error");
1372 ide.outputView.buildBox.Logf("no error, ");
1375 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? "warnings" : "warning");
1377 ide.outputView.buildBox.Logf("no warning\n");
1382 return numErrors == 0;
1385 void ProcessCleanPipeOutput(DualPipe f)
1388 CompilerConfig compiler = GetCompilerConfig();
1389 int lenMakeCommand = strlen(compiler.makeCommand);
1394 double lastTime = GetTime();
1397 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1399 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1400 else if(strstr(line, "del") == line);
1401 else if(strstr(line, "rm") == line);
1402 else if(strstr(line, "Could Not Find") == line);
1405 ide.outputView.buildBox.Logf(line);
1406 ide.outputView.buildBox.Logf("\n");
1410 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1412 if(app.ProcessInput(true))
1414 app.UpdateDisplay();
1417 //Sleep(1.0 / PEEK_RESOLUTION);
1422 bool Build(bool isARun, ProjectNode onlyNode)
1424 bool result = false;
1426 char targetFileName[MAX_LOCATION] = "";
1427 char makeTarget[MAX_LOCATION] = "";
1428 char makeFile[MAX_LOCATION];
1429 char makeFilePath[MAX_LOCATION];
1430 char oldPath[MAX_LOCATION * 65];
1431 char configName[MAX_LOCATION];
1432 CompilerConfig compiler = GetCompilerConfig();
1433 DirExpression objDirExp = objDir;
1435 int numJobs = compiler.numJobs;
1436 char command[MAX_LOCATION];
1438 GetEnvironment("PATH", oldPath, sizeof(oldPath));
1440 strcpy(configName, this.configName);
1442 SetPath(false); //true
1443 CatTargetFileName(targetFileName);
1445 strcpy(makeFilePath, topNode.path);
1446 CatMakeFileName(makeFile);
1447 PathCatSlash(makeFilePath, makeFile);
1449 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1452 if(compiler.type.isVC)
1454 PrintLn("compiling a single file is not yet supported");
1459 char pushD[MAX_LOCATION];
1460 GetWorkingDir(pushD, sizeof(pushD));
1461 ChangeWorkingDir(topNode.path);
1462 // Create object dir if it does not exist already
1463 if(!FileExists(objDirExp.dir).isDirectory)
1464 Execute("%s objdir -C \"%s\" -f \"%s\"", compiler.makeCommand, topNode.path, makeFilePath);
1465 ChangeWorkingDir(pushD);
1467 PathCatSlash(makeTarget+1, objDirExp.dir);
1468 PathCatSlash(makeTarget+1, onlyNode.name);
1469 StripExtension(makeTarget+1);
1470 strcat(makeTarget+1, ".o");
1471 makeTarget[0] = '\"';
1472 len = strlen(makeTarget);
1473 makeTarget[len++] = '\"';
1474 makeTarget[len++] = '\0';
1478 if(compiler.type.isVC)
1480 bool result = false;
1481 char oldwd[MAX_LOCATION];
1482 GetWorkingDir(oldwd, sizeof(oldwd));
1483 ChangeWorkingDir(topNode.path);
1485 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1486 ide.outputView.buildBox.Logf("command: %s\n", command);
1487 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1489 ProcessPipeOutputRaw(f);
1493 ChangeWorkingDir(oldwd);
1497 sprintf(command, "%s -j%d %s%s%s -C \"%s\" -f \"%s\"", compiler.makeCommand, numJobs,
1498 compiler.ccacheEnabled ? "CCACHE=y " : "",
1499 compiler.distccEnabled ? "DISTCC=y " : "",
1500 makeTarget, topNode.path, makeFilePath);
1501 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1503 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode);
1507 ide.outputView.buildBox.Logf("Error executing make (%s) command\n", compiler.makeCommand);
1510 SetEnvironment("PATH", oldPath);
1519 char oldPath[MAX_LOCATION * 65];
1520 char makeFile[MAX_LOCATION];
1521 char makeFilePath[MAX_LOCATION];
1522 char command[MAX_LOCATION];
1524 CompilerConfig compiler = GetCompilerConfig();
1526 GetEnvironment("PATH", oldPath, sizeof(oldPath));
1530 strcpy(makeFilePath, topNode.path);
1531 CatMakeFileName(makeFile);
1532 PathCatSlash(makeFilePath, makeFile);
1534 if(compiler.type.isVC)
1536 bool result = false;
1537 char oldwd[MAX_LOCATION];
1538 GetWorkingDir(oldwd, sizeof(oldwd));
1539 ChangeWorkingDir(topNode.path);
1541 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1542 ide.outputView.buildBox.Logf("command: %s\n", command);
1543 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1545 ProcessPipeOutputRaw(f);
1549 ChangeWorkingDir(oldwd);
1554 sprintf(command, "%s clean -C \"%s\" -f \"%s\"", compiler.makeCommand, topNode.path, makeFilePath);
1555 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1557 ide.outputView.buildBox.Tell("Deleting target and object files...");
1558 ProcessCleanPipeOutput(f);
1561 ide.outputView.buildBox.Logf("Target and object files deleted\n");
1565 SetEnvironment("PATH", oldPath);
1569 void Run(char * args)
1571 char target[MAX_LOCATION * 65], oldDirectory[MAX_LOCATION];
1572 char oldPath[MAX_LOCATION * 65];
1573 DirExpression targetDirExp = targetDir;
1574 CompilerConfig compiler = GetCompilerConfig();
1576 GetEnvironment("PATH", oldPath, sizeof(oldPath));
1578 // Build(project, ideMain, true, null);
1580 #if defined(__WIN32__)
1581 strcpy(target, topNode.path);
1585 PathCatSlash(target, targetDirExp.dir);
1586 CatTargetFileName(target);
1587 sprintf(target, "%s %s", target, args);
1588 GetWorkingDir(oldDirectory, MAX_LOCATION);
1590 if(strlen(ide.workspace.debugDir))
1592 char temp[MAX_LOCATION];
1593 strcpy(temp, topNode.path);
1594 PathCatSlash(temp, ide.workspace.debugDir);
1595 ChangeWorkingDir(temp);
1598 ChangeWorkingDir(topNode.path);
1599 // ChangeWorkingDir(topNode.path);
1601 if(compiler.execPrefixCommand)
1603 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1604 prefixedTarget[0] = '\0';
1605 strcat(prefixedTarget, compiler.execPrefixCommand);
1606 strcat(prefixedTarget, " ");
1607 strcat(prefixedTarget, target);
1608 Execute(prefixedTarget);
1609 delete prefixedTarget;
1614 ChangeWorkingDir(oldDirectory);
1615 SetEnvironment("PATH", oldPath);
1617 delete targetDirExp;
1621 void Compile(ProjectNode node)
1627 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName)
1629 char s[MAX_LOCATION];
1631 if(targetType == staticLibrary || targetType == sharedLibrary)
1632 strcat(fileName, "$(LP)");
1633 ReplaceSpaces(s, targetFileName);
1634 strcat(fileName, s);
1638 strcat(fileName, "$(E)");
1641 strcat(fileName, "$(SO)");
1644 strcat(fileName, "$(A)");
1649 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath)
1651 bool result = false;
1652 char filePath[MAX_LOCATION];
1653 char makeFile[MAX_LOCATION];
1654 CompilerConfig compiler = GetCompilerConfig();
1655 /*char oldPath[MAX_LOCATION * 65];
1656 char oldDirectory[MAX_LOCATION];*/
1659 if(!altMakefilePath)
1661 strcpy(filePath, topNode.path);
1662 CatMakeFileName(makeFile);
1663 PathCatSlash(filePath, makeFile);
1666 #if defined(__WIN32__) && !defined(MAKEFILE_GENERATOR)
1667 if(compiler.type.isVC)
1669 GenerateVSSolutionFile(this);
1670 GenerateVCProjectFile(this);
1674 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
1676 /*GetEnvironment("PATH", oldPath, sizeof(oldPath));
1678 GetWorkingDir(oldDirectory, MAX_LOCATION);
1679 ChangeWorkingDir(topNode.path);*/
1683 char temp[MAX_LOCATION];
1684 char target[MAX_LOCATION];
1685 char targetNoSpaces[MAX_LOCATION];
1686 char objDirExpNoSpaces[MAX_LOCATION];
1687 char objDirNoSpaces[MAX_LOCATION];
1688 char resDirNoSpaces[MAX_LOCATION];
1689 char targetDirExpNoSpaces[MAX_LOCATION];
1690 char fixedModuleName[MAX_FILENAME];
1691 char fixedConfigName[MAX_FILENAME];
1692 char fixedCompilerName[MAX_FILENAME];
1694 int numCObjects = 0;
1695 bool sameObjTargetDirs;
1696 DirExpression objDirExp = objDir;
1698 bool crossCompiling = compiler.targetPlatform != GetRuntimePlatform();
1699 bool gccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "gcc") != null;
1700 bool tccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "tcc") != null;
1701 bool defaultPreprocessor = compiler.cppCommand && (strstr(compiler.cppCommand, "gcc") != null || compiler.cppCommand && strstr(compiler.cppCommand, "cpp") != null);
1703 int objectsParts, cobjectsParts, symbolsParts, importsParts;
1704 Array<String> listItems { };
1705 Map<String, int> varStringLenDiffs { };
1706 Map<String, NameCollisionInfo> namesInfo { };
1708 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
1709 strcpy(temp, targetDirExpression);
1710 ReplaceSpaces(targetDirExpNoSpaces, temp);
1711 GetMakefileTargetFileName(targetType, target);
1712 PathCatSlash(temp, target);
1713 ReplaceSpaces(targetNoSpaces, temp);
1715 strcpy(objDirExpNoSpaces, objDirExpression);
1716 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1717 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
1718 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
1719 //ReplaceSpaces(fixedPrjName, name);
1720 ReplaceSpaces(fixedModuleName, moduleName);
1721 ReplaceSpaces(fixedConfigName, configName);
1722 ReplaceSpaces(fixedCompilerName, compiler.name);
1723 //CamelCase(fixedModuleName); // case is important for static linking
1724 CamelCase(fixedConfigName);
1725 CamelCase(fixedCompilerName);
1727 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
1729 f.Printf(".PHONY: all objdir%s clean distclean\n\n", sameObjTargetDirs ? "" : " targetdir");
1731 f.Printf("# CONTENT\n\n");
1733 f.Printf("MODULE := %s\n", fixedModuleName);
1734 //f.Printf("VERSION = %s\n", version);
1735 f.Printf("CONFIG := %s\n", fixedConfigName);
1736 f.Printf("COMPILER := %s\n", fixedCompilerName);
1738 f.Printf("PLATFORM = %s\n", (char *)compiler.targetPlatform);
1739 f.Printf("TARGET_TYPE = %s\n", targetType == executable ? "executable" :
1740 (targetType == sharedLibrary ? "sharedlib" : (targetType == staticLibrary ? "staticlib" : "unknown")));
1743 f.Printf("OBJ = %s%s\n\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
1745 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
1747 if(targetType == executable)
1748 f.Printf("CONSOLE = %s\n\n", console ? "-mconsole" : "-mwindows");
1750 f.Printf("TARGET = %s\n\n", targetNoSpaces);
1752 varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
1754 topNode.GenMakefileGetNameCollisionInfo(namesInfo);
1756 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems);
1758 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
1759 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs);
1761 topNode.GenMakefilePrintNode(f, this, cObjects, namesInfo, listItems);
1762 cobjectsParts = OutputFileList(f, "COBJECTS", listItems, varStringLenDiffs);
1764 topNode.GenMakefilePrintNode(f, this, symbols, null, listItems);
1765 symbolsParts = OutputFileList(f, "SYMBOLS", listItems, varStringLenDiffs);
1767 topNode.GenMakefilePrintNode(f, this, imports, null, listItems);
1768 importsParts = OutputFileList(f, "IMPORTS", listItems, varStringLenDiffs);
1770 topNode.GenMakefilePrintNode(f, this, sources, null, listItems);
1771 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs);
1774 resNode.GenMakefilePrintNode(f, this, resources, null, listItems);
1775 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs);
1779 f.Printf("# CROSS-PLATFORM MAGIC\n\n");
1781 f.Printf("include %s\n\n", includemkPath);
1785 File include = FileOpen(":include.mk", read);
1788 for(; !include.Eof(); )
1791 int count = include.Read(buffer, 1, 4096);
1792 f.Write(buffer, 1, count);
1800 if(strcmpi(compiler.cppCommand, "cpp") ||
1801 strcmpi(compiler.ccCommand, "gcc") ||
1802 strcmpi(compiler.ecpCommand, "ecp") ||
1803 strcmpi(compiler.eccCommand, "ecc") ||
1804 strcmpi(compiler.ecsCommand, "ecs") || crossCompiling ||
1805 strcmpi(compiler.earCommand, "ear"))
1807 f.Printf("# TOOLCHAIN\n\n");
1809 //f.Printf("SHELL := %s\n", "ar"/*compiler.arCommand*/); // is this really needed?
1810 if(strcmpi(compiler.cppCommand, "cpp"))
1811 f.Printf("CPP := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.cppCommand);
1812 if(strcmpi(compiler.ccCommand, "gcc"))
1813 f.Printf("CC := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.ccCommand);
1814 if(strcmpi(compiler.ecpCommand, "ecp"))
1815 f.Printf("ECP := %s\n", compiler.ecpCommand);
1816 if(strcmpi(compiler.eccCommand, "ecc"))
1817 f.Printf("ECC := %s\n", compiler.eccCommand);
1818 if(strcmpi(compiler.ecsCommand, "ecs") || crossCompiling)
1820 f.Printf("ECS := %s%s%s\n", compiler.ecsCommand,
1821 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1823 if(strcmpi(compiler.earCommand, "ear"))
1824 f.Printf("EAR := %s\n", compiler.earCommand);
1828 f.Printf("# FLAGS\n\n");
1830 f.Printf("CFLAGS =");
1833 f.Printf(" -fmessage-length=0");
1834 switch(optimization)
1838 f.Printf(" -ffast-math");
1844 //if(compiler.targetPlatform.is32Bits)
1846 //else if(compiler.targetPlatform.is64Bits)
1847 // f.Printf(" -m64");
1848 f.Printf(" $(FPIC)");
1849 //f.Printf(" -fpack-struct");
1855 if(warnings == none)
1862 if(options && options.linkerOptions && options.linkerOptions.count)
1864 f.Printf(" \\\n\t -Wl");
1865 for(s : options.linkerOptions)
1869 if(options && options.preprocessorDefinitions)
1870 OutputListOption(f, "D", options.preprocessorDefinitions, newLine, false);
1871 if(config && config.options && config.options.preprocessorDefinitions)
1872 OutputListOption(f, "D", config.options.preprocessorDefinitions, newLine, false);
1874 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
1875 if(options && options.includeDirs)
1876 OutputListOption(f, "I", options.includeDirs, lineEach, true);
1877 if(config && config.options && config.options.includeDirs)
1878 OutputListOption(f, "I", config.options.includeDirs, lineEach, true);
1881 f.Printf("CECFLAGS =%s%s%s%s", defaultPreprocessor ? "" : " -cpp ", defaultPreprocessor ? "" : compiler.cppCommand,
1882 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1885 f.Printf("ECFLAGS =");
1887 f.Printf(" -memguard");
1888 if(strictNameSpaces)
1889 f.Printf(" -strictns");
1891 f.Printf(" -nolinenumbers");
1894 if((s = defaultNameSpace) && s[0])
1895 f.Printf(" -defaultns %s", s);
1899 if(targetType != staticLibrary)
1901 f.Printf("OFLAGS = -m32"); // TARGET_TYPE is fixed in a Makefile, we don't want this. $(if TARGET_TYPE_STATIC_LIBRARY,,-m32)");
1905 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
1906 if(options && options.libraryDirs)
1907 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
1908 if(config && config.options && config.options.libraryDirs)
1909 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
1914 if(targetType != staticLibrary)
1916 if(config && config.options && config.options.libraries)
1917 OutputLibraries(f, config.options.libraries);
1918 else if(options && options.libraries)
1919 OutputLibraries(f, options.libraries);
1921 f.Printf(" $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
1923 f.Printf("UPXFLAGS = -9\n\n"); // TOFEAT: Compression Level Option? Other UPX Options?
1925 f.Printf("# HARD CODED PLATFORM-SPECIFIC OPTIONS\n");
1926 f.Printf("ifdef %s\n", PlatformToMakefileVariable(tux));
1927 f.Printf("OFLAGS += -Wl,--no-undefined\n");
1928 f.Printf("endif\n\n");
1931 f.Printf("ifdef %s\n", PlatformToMakefileVariable(apple));
1932 f.Printf("OFLAGS += -framework cocoa -framework OpenGL\n");
1933 f.Printf("endif\n\n");
1935 if(platforms || (config && config.platforms))
1939 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
1940 //for(platform = win32; platform <= apple; platform++)
1942 f.Printf("# PLATFORM-SPECIFIC OPTIONS\n\n");
1943 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1945 PlatformOptions projectPlatformOptions = null;
1946 PlatformOptions configPlatformOptions = null;
1952 if(!strcmpi(p.name, platform))
1954 projectPlatformOptions = p;
1959 if(config && config.platforms)
1961 for(p : config.platforms)
1963 if(!strcmpi(p.name, platform))
1965 configPlatformOptions = p;
1970 if(projectPlatformOptions || configPlatformOptions)
1976 // we should have some kind of direct mapping between a platform and it's makefile variable
1977 f.Printf(PlatformToMakefileVariable(platform));
1980 if((projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions && projectPlatformOptions.options.preprocessorDefinitions.count) ||
1981 (configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions && configPlatformOptions.options.preprocessorDefinitions.count) ||
1982 (projectPlatformOptions && projectPlatformOptions.options.includeDirs && projectPlatformOptions.options.includeDirs.count) ||
1983 (configPlatformOptions && configPlatformOptions.options.includeDirs && configPlatformOptions.options.includeDirs.count))
1985 f.Printf("CFLAGS +=");
1986 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
1988 f.Printf(" \\\n\t -Wl");
1989 for(s : projectPlatformOptions.options.linkerOptions)
1992 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
1994 f.Printf(" \\\n\t -Wl");
1995 for(s : configPlatformOptions.options.linkerOptions)
1998 if(projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions)
1999 OutputListOption(f, "D", projectPlatformOptions.options.preprocessorDefinitions, newLine, false);
2000 if(configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions)
2001 OutputListOption(f, "D", configPlatformOptions.options.preprocessorDefinitions, newLine, false );
2002 if(projectPlatformOptions && projectPlatformOptions.options.includeDirs)
2003 OutputListOption(f, "I", projectPlatformOptions.options.includeDirs, lineEach, true);
2004 if(configPlatformOptions && configPlatformOptions.options.includeDirs)
2005 OutputListOption(f, "I", configPlatformOptions.options.includeDirs, lineEach, true);
2009 if(targetType != staticLibrary)
2011 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2012 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2014 f.Printf("OFLAGS +=");
2015 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2016 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2017 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2018 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2022 if(projectPlatformOptions && projectPlatformOptions.options.libraries &&
2023 projectPlatformOptions.options.libraries.count/* &&
2024 (!config || !config.options || !config.options.libraries)*/)
2026 f.Printf("LIBS +=");
2027 OutputLibraries(f, projectPlatformOptions.options.libraries);
2030 {/*TOFIX: EXTRA CURLIES FOR NASTY WARNING*/if((configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2032 f.Printf("LIBS +=");
2033 OutputLibraries(f, configPlatformOptions.options.libraries);
2041 for(c = 0; c < ifCount; c++)
2042 f.Printf("endif\n");
2048 f.Printf("# TARGETS\n\n");
2050 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
2052 f.Printf("objdir:\n");
2053 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2054 //f.Printf("# PRE-BUILD COMMANDS\n");
2055 if(options && options.prebuildCommands)
2057 for(s : options.prebuildCommands)
2058 if(s && s[0]) f.Printf("\t%s\n", s);
2060 if(config && config.options && config.options.prebuildCommands)
2062 for(s : config.options.prebuildCommands)
2063 if(s && s[0]) f.Printf("\t%s\n", s);
2065 if(platforms || (config && config.platforms))
2069 //f.Printf("# PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2070 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2072 PlatformOptions projectPOs = null;
2073 PlatformOptions configPOs = null;
2079 if(!strcmpi(p.name, platform))
2086 if(config && config.platforms)
2088 for(p : config.platforms)
2090 if(!strcmpi(p.name, platform))
2097 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2098 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2104 f.Printf(PlatformToMakefileVariable(platform));
2107 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2109 for(s : projectPOs.options.prebuildCommands)
2110 if(s && s[0]) f.Printf("\t%s\n", s);
2112 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2114 for(s : configPOs.options.prebuildCommands)
2115 if(s && s[0]) f.Printf("\t%s\n", s);
2122 for(c = 0; c < ifCount; c++)
2123 f.Printf("endif\n");
2129 if(!sameObjTargetDirs)
2131 f.Printf("targetdir:\n");
2132 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2137 // Main Module (Linking) for ECERE C modules
2138 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2139 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2140 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2141 console ? " -console" : "", objDirExpNoSpaces);
2142 // Main Module (Linking) for ECERE C modules
2143 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2144 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2145 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2146 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2147 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2152 // This would not rebuild the target on updated objects
2153 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2155 // This should fix it for good!
2156 f.Printf("$(SYMBOLS): | objdir\n");
2157 f.Printf("$(OBJECTS): | objdir\n");
2159 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2160 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2162 if(targetType == sharedLibrary || targetType == executable)
2164 // f.Printf("\tinstall_name_tool $(TARGET) $(LP)$(MODULE)%s\n", targetType == sharedLibrary ? "$(SO)" : "$(A)");
2165 //f.Printf("ifdef OSX\n");
2166 //f.Printf("ifeq \"$(TARGET_TYPE)\" \"sharedlib\"\n");
2167 //f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET) -install_name $(LP)$(MODULE)$(SO)\n");
2168 //f.Printf("endif\n");
2169 //f.Printf("else\n");
2170 //f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET)\n");
2171 //f.Printf("endif\n");
2172 f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET) $(INSTALLNAME)\n");
2176 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2180 f.Printf("ifndef WINDOWS\n");
2181 f.Printf("ifeq \"$(TARGET_TYPE)\" \"executable\"\n");
2182 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2183 f.Printf("endif\n");
2185 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2186 f.Printf("endif\n");
2189 if(resNode.files && resNode.files.count && !noResources)
2190 resNode.GenMakefileAddResources(f, resNode.path);
2193 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2195 //f.Printf("# POST-BUILD COMMANDS\n");
2196 if(options && options.postbuildCommands)
2198 for(s : options.postbuildCommands)
2199 if(s && s[0]) f.Printf("\t%s\n", s);
2201 if(config && config.options && config.options.postbuildCommands)
2203 for(s : config.options.postbuildCommands)
2204 if(s && s[0]) f.Printf("\t%s\n", s);
2206 if(platforms || (config && config.platforms))
2211 //f.Printf("# PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2212 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2214 PlatformOptions projectPOs = null;
2215 PlatformOptions configPOs = null;
2221 if(!strcmpi(p.name, platform))
2228 if(config && config.platforms)
2230 for(p : config.platforms)
2232 if(!strcmpi(p.name, platform))
2239 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2240 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2246 f.Printf(PlatformToMakefileVariable(platform));
2249 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2251 for(s : projectPOs.options.postbuildCommands)
2252 if(s && s[0]) f.Printf("\t%s\n", s);
2254 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2256 for(s : configPOs.options.postbuildCommands)
2257 if(s && s[0]) f.Printf("\t%s\n", s);
2264 for(c = 0; c < ifCount; c++)
2265 f.Printf("endif\n");
2271 f.Printf("# SYMBOL RULES\n\n");
2272 topNode.GenMakefilePrintSymbolRules(f, this);
2274 f.Printf("# C OBJECT RULES\n\n");
2275 topNode.GenMakefilePrintCObjectRules(f, this);
2279 f.Printf("# IMPLICIT OBJECT RULE\n\n");
2281 f.Printf("$(OBJ)%%$(O) : $(OBJ)%%.c\n");
2282 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $< -o $@\n\n");
2285 f.Printf("# OBJECT RULES\n\n");
2286 // todo call this still but only generate rules whith specific options
2287 // see we-have-file-specific-options in ProjectNode.ec
2288 topNode.GenMakefilePrintObjectRules(f, this, namesInfo);
2291 GenMakefilePrintMainObjectRule(f);
2293 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2294 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) " : "");
2295 OutputCleanActions(f, "OBJECTS", objectsParts);
2296 OutputCleanActions(f, "COBJECTS", cobjectsParts);
2299 OutputCleanActions(f, "IMPORTS", importsParts);
2300 OutputCleanActions(f, "SYMBOLS", symbolsParts);
2304 f.Printf("distclean: clean\n");
2305 f.Printf("\t$(call rmdirq,$(OBJ))\n");
2306 if(!sameObjTargetDirs)
2307 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2313 varStringLenDiffs.Free();
2314 delete varStringLenDiffs;
2321 /*ChangeWorkingDir(oldDirectory);
2322 SetEnvironment("PATH", oldPath);*/
2325 config.makingModified = false;
2332 void GenMakefilePrintMainObjectRule(File f)
2334 char extension[MAX_EXTENSION] = "c";
2335 char modulePath[MAX_LOCATION];
2336 char fixedModuleName[MAX_FILENAME];
2339 char objDirNoSpaces[MAX_LOCATION];
2340 DirExpression objDirExp = objDir;
2342 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
2343 ReplaceSpaces(fixedModuleName, moduleName);
2345 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2346 //strcat(fixedModuleName, ".main");
2348 #if 0 // TODO: Fix nospaces stuff
2349 // *** Dependency command ***
2350 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2352 // System Includes (from global settings)
2353 for(item : compiler.dirs[Includes])
2355 strcat(command, " -isystem ");
2356 if(strchr(item.name, ' '))
2358 strcat(command, "\"");
2359 strcat(command, item);
2360 strcat(command, "\"");
2363 strcat(command, item);
2366 for(item = includeDirs.first; item; item = item.next)
2368 strcat(command, " -I");
2369 if(strchr(item.name, ' '))
2371 strcat(command, "\"");
2372 strcat(command, item.name);
2373 strcat(command, "\"");
2376 strcat(command, item.name);
2378 for(item = preprocessorDefs.first; item; item = item.next)
2380 strcat(command, " -D");
2381 strcat(command, item.name);
2385 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2389 bool firstLine = true;
2391 // To do some time: auto save external dependencies?
2394 if(dep.GetLine(line, sizeof(line)-1))
2398 char * colon = strstr(line, ":");
2399 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2413 // If we failed to generate dependencies...
2417 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2423 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2429 Project LegacyBinaryLoadProject(File f, char * filePath)
2431 Project project = null;
2432 char signature[sizeof(epjSignature)];
2434 f.Read(signature, sizeof(signature), 1);
2435 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2437 char topNodePath[MAX_LOCATION];
2438 /*ProjectConfig newConfig
2440 name = CopyString("Default");
2441 makingModified = true;
2442 compilingModified = true;
2443 linkingModified = true;
2447 project = Project { options = { } };
2448 LegacyBinaryLoadNode(project.topNode, f);
2449 delete project.topNode.path;
2450 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2451 MakeSlashPath(topNodePath);
2453 PathCatSlash(topNodePath, filePath);
2454 project.filePath = topNodePath;
2456 /* THIS IS ALREADY DONE BY filePath property
2457 StripLastDirectory(topNodePath, topNodePath);
2458 project.topNode.path = CopyString(topNodePath);
2460 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2462 // newConfig.options.defaultNameSpace = "";
2463 /*newConfig.objDir.dir = "obj";
2464 newConfig.targetDir.dir = "";*/
2466 //project.configurations = { [ newConfig ] };
2467 //project.config = newConfig;
2475 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2476 f.Read(&temp, sizeof(int),1);
2479 case 0: project.options.targetType = executable; break;
2480 case 1: project.options.targetType = sharedLibrary; break;
2481 case 2: project.options.targetType = staticLibrary; break;
2484 f.Read(&len, sizeof(int),1);
2485 project.options.targetFileName = new char[len+1];
2486 f.Read(project.options.targetFileName, sizeof(char), len+1);
2488 f.Read(&len, sizeof(int),1);
2489 delete project.options.targetDirectory;
2490 project.options.targetDirectory = new char[len+1];
2491 f.Read(project.options.targetDirectory, sizeof(char), len+1);
2493 f.Read(&len, sizeof(int),1);
2494 delete project.options.objectsDirectory;
2495 project.options.objectsDirectory = new byte[len+1];
2496 f.Read(project.options.objectsDirectory, sizeof(char), len+1);
2498 f.Read(&temp, sizeof(int),1);
2499 project./*config.*/options.debug = temp ? true : false;
2500 f.Read(&temp, sizeof(int),1);
2501 project./*config.*/options.optimization = temp ? speed : none;
2502 f.Read(&temp, sizeof(int),1);
2503 project./*config.*/options.profile = temp ? true : false;
2504 f.Read(&temp, sizeof(int),1);
2505 project.options.warnings = temp ? all : unset;
2507 f.Read(&count, sizeof(int),1);
2510 project.options.includeDirs = { };
2511 for(c = 0; c < count; c++)
2514 f.Read(&len, sizeof(int),1);
2515 name = new char[len+1];
2516 f.Read(name, sizeof(char), len+1);
2517 project.options.includeDirs.Add(name);
2521 f.Read(&count, sizeof(int),1);
2524 project.options.libraryDirs = { };
2525 for(c = 0; c < count; c++)
2528 f.Read(&len, sizeof(int),1);
2529 name = new char[len+1];
2530 f.Read(name, sizeof(char), len+1);
2531 project.options.libraryDirs.Add(name);
2535 f.Read(&count, sizeof(int),1);
2538 project.options.libraries = { };
2539 for(c = 0; c < count; c++)
2542 f.Read(&len, sizeof(int),1);
2543 name = new char[len+1];
2544 f.Read(name, sizeof(char), len+1);
2545 project.options.libraries.Add(name);
2549 f.Read(&count, sizeof(int),1);
2552 project.options.preprocessorDefinitions = { };
2553 for(c = 0; c < count; c++)
2556 f.Read(&len, sizeof(int),1);
2557 name = new char[len+1];
2558 f.Read(name, sizeof(char), len+1);
2559 project.options.preprocessorDefinitions.Add(name);
2563 f.Read(&temp, sizeof(int),1);
2564 project.options.console = temp ? true : false;
2567 for(node : project.topNode.files)
2569 if(node.type == resources)
2571 project.resNode = node;
2581 void ProjectConfig::LegacyProjectConfigLoad(File f)
2589 char subSection[128];
2595 f.GetLine(buffer, 65536 - 1);
2596 TrimLSpaces(buffer, buffer);
2597 TrimRSpaces(buffer, buffer);
2600 if(buffer[0] == '-')
2604 TrimLSpaces(equal, equal);
2605 if(!strcmpi(subSection, "LibraryDirs"))
2607 if(!options.libraryDirs)
2608 options.libraryDirs = { [ CopyString(equal) ] };
2610 options.libraryDirs.Add(CopyString(equal));
2612 else if(!strcmpi(subSection, "IncludeDirs"))
2614 if(!options.includeDirs)
2615 options.includeDirs = { [ CopyString(equal) ] };
2617 options.includeDirs.Add(CopyString(equal));
2620 else if(buffer[0] == '+')
2631 TrimLSpaces(equal, equal);
2632 delete name; name = CopyString(equal); // property::name = equal;
2635 else if(!strcmpi(buffer, "Compiler Options"))
2636 strcpy(section, buffer);
2637 else if(!strcmpi(buffer, "IncludeDirs"))
2638 strcpy(subSection, buffer);
2639 else if(!strcmpi(buffer, "Linker Options"))
2640 strcpy(section, buffer);
2641 else if(!strcmpi(buffer, "LibraryDirs"))
2642 strcpy(subSection, buffer);
2643 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
2650 equal = strstr(buffer, "=");
2654 TrimRSpaces(buffer, buffer);
2656 TrimLSpaces(equal, equal);
2657 if(!strcmpi(buffer, "Target Name"))
2658 options.targetFileName = CopyString(equal);
2659 else if(!strcmpi(buffer, "Target Type"))
2661 if(!strcmpi(equal, "Executable"))
2662 options.targetType = executable;
2663 else if(!strcmpi(equal, "Shared"))
2664 options.targetType = sharedLibrary;
2665 else if(!strcmpi(equal, "Static"))
2666 options.targetType = staticLibrary;
2668 options.targetType = executable;
2670 else if(!strcmpi(buffer, "Target Directory"))
2671 options.targetDirectory = CopyString(equal);
2672 else if(!strcmpi(buffer, "Console"))
2673 options.console = ParseTrueFalseValue(equal);
2674 else if(!strcmpi(buffer, "Libraries"))
2676 if(!options.libraries) options.libraries = { };
2677 ParseArrayValue(options.libraries, equal);
2679 else if(!strcmpi(buffer, "Intermediate Directory"))
2680 options.objectsDirectory = CopyString(equal); //objDir.expression = equal;
2681 else if(!strcmpi(buffer, "Debug"))
2682 options.debug = ParseTrueFalseValue(equal);
2683 else if(!strcmpi(buffer, "Optimize"))
2685 if(!strcmpi(equal, "None"))
2686 options.optimization = none;
2687 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
2688 options.optimization = speed;
2689 else if(!strcmpi(equal, "Size"))
2690 options.optimization = size;
2692 options.optimization = none;
2694 else if(!strcmpi(buffer, "Compress"))
2695 options.compress = ParseTrueFalseValue(equal);
2696 else if(!strcmpi(buffer, "Profile"))
2697 options.profile = ParseTrueFalseValue(equal);
2698 else if(!strcmpi(buffer, "AllWarnings"))
2699 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
2700 else if(!strcmpi(buffer, "MemoryGuard"))
2701 options.memoryGuard = ParseTrueFalseValue(equal);
2702 else if(!strcmpi(buffer, "Default Name Space"))
2703 options.defaultNameSpace = CopyString(equal);
2704 else if(!strcmpi(buffer, "Strict Name Spaces"))
2705 options.strictNameSpaces = ParseTrueFalseValue(equal);
2706 else if(!strcmpi(buffer, "Preprocessor Definitions"))
2708 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
2709 ParseArrayValue(options.preprocessorDefinitions, equal);
2715 if(!options.targetDirectory && options.objectsDirectory)
2716 options.targetDirectory = CopyString(options.objectsDirectory);
2717 //if(!objDir.dir) objDir.dir = "obj";
2718 //if(!targetDir.dir) targetDir.dir = "";
2719 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
2720 // if(!defaultNameSpace) property::defaultNameSpace = "";
2721 makingModified = true;
2724 Project LegacyAsciiLoadProject(File f, char * filePath)
2726 Project project = null;
2727 ProjectNode node = null;
2729 char parentPath[MAX_LOCATION];
2730 char section[128] = "";
2731 char subSection[128] = "";
2733 bool configurationsPresent = false;
2743 f.GetLine(buffer, 65536 - 1);
2744 TrimLSpaces(buffer, buffer);
2745 TrimRSpaces(buffer, buffer);
2748 if(buffer[0] == '-' || buffer[0] == '=')
2750 bool simple = buffer[0] == '-';
2753 TrimLSpaces(equal, equal);
2754 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
2756 if(!project.config.options.libraryDirs) project.config.options.libraryDirs = { };
2757 project.config.options.libraryDirs.Add(CopyString(equal));
2759 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
2761 if(!project.config.options.includeDirs) project.config.options.includeDirs = { };
2762 project.config.options.includeDirs.Add(CopyString(equal));
2764 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
2766 len = strlen(equal);
2769 char temp[MAX_LOCATION];
2770 ProjectNode child { };
2771 // We don't need to do this anymore, fileName is just a property that sets name & path
2772 // child.fileName = CopyString(equal);
2775 child.name = CopyString(equal);
2776 child.path = CopyString(parentPath);
2780 GetLastDirectory(equal, temp);
2781 child.name = CopyString(temp);
2782 StripLastDirectory(equal, temp);
2783 child.path = CopyString(temp);
2785 child.nodeType = file;
2786 child.parent = parent;
2787 child.indent = parent.indent + 1;
2789 child.icon = NodeIcons::SelectFileIcon(child.name);
2790 parent.files.Add(child);
2796 StripLastDirectory(parentPath, parentPath);
2797 parent = parent.parent;
2801 else if(buffer[0] == '+')
2805 TrimLSpaces(equal, equal);
2806 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
2808 char temp[MAX_LOCATION];
2809 ProjectNode child { };
2810 // NEW: Folders now have a path set like files
2811 child.name = CopyString(equal);
2812 strcpy(temp, parentPath);
2813 PathCatSlash(temp, child.name);
2814 child.path = CopyString(temp);
2816 child.parent = parent;
2817 child.indent = parent.indent + 1;
2818 child.type = folder;
2819 child.nodeType = folder;
2821 child.icon = folder;
2822 PathCatSlash(parentPath, child.name);
2823 parent.files.Add(child);
2828 else if(!strcmpi(section, "Configurations"))
2830 ProjectConfig newConfig
2832 makingModified = true;
2836 LegacyProjectConfigLoad(newConfig, f);
2837 project.configurations.Add(newConfig);
2840 else if(!strcmpi(buffer, "ECERE Project File"));
2841 else if(!strcmpi(buffer, "Version 0a"))
2842 ; //strcpy(version, "0a");
2843 else if(!strcmpi(buffer, "Version 0.1a"))
2844 ; //strcpy(version, "0.1a");
2845 else if(!strcmpi(buffer, "Configurations"))
2847 project.configurations.Free();
2848 project.config = null;
2849 strcpy(section, buffer);
2850 configurationsPresent = true;
2852 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
2854 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
2855 char topNodePath[MAX_LOCATION];
2856 // newConfig.defaultNameSpace = "";
2857 //newConfig.objDir.dir = "obj";
2858 //newConfig.targetDir.dir = "";
2859 project = Project { /*options = { }*/ };
2860 project.configurations = { [ newConfig ] };
2861 project.config = newConfig;
2862 // if(project.topNode.path) delete project.topNode.path;
2863 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2864 MakeSlashPath(topNodePath);
2865 PathCatSlash(topNodePath, filePath);
2866 project.filePath = topNodePath;
2867 parentPath[0] = '\0';
2868 parent = project.topNode;
2870 strcpy(section, "Target");
2875 if(equal[0] == '\"')
2877 StripQuotes(equal, equal);
2878 delete project.moduleName; project.moduleName = CopyString(equal);
2882 else if(!strcmpi(buffer, "Compiler Options"));
2883 else if(!strcmpi(buffer, "IncludeDirs"))
2884 strcpy(subSection, buffer);
2885 else if(!strcmpi(buffer, "Linker Options"));
2886 else if(!strcmpi(buffer, "LibraryDirs"))
2887 strcpy(subSection, buffer);
2888 else if(!strcmpi(buffer, "Files"))
2890 strcpy(section, "Target");
2891 strcpy(subSection, buffer);
2893 else if(!strcmpi(buffer, "Resources"))
2895 ProjectNode child { };
2896 parent.files.Add(child);
2897 child.parent = parent;
2898 child.indent = parent.indent + 1;
2899 child.name = CopyString(buffer);
2900 child.path = CopyString("");
2901 child.type = resources;
2903 child.icon = archiveFile;
2904 project.resNode = child;
2907 strcpy(subSection, buffer);
2911 equal = strstr(buffer, "=");
2915 TrimRSpaces(buffer, buffer);
2917 TrimLSpaces(equal, equal);
2919 if(!strcmpi(section, "Target"))
2921 if(!strcmpi(buffer, "Build Exclusions"))
2923 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
2925 /*if(node && node.type != NodeTypes::project)
2926 ParseListValue(node.buildExclusions, equal);*/
2929 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
2931 delete project.resNode.path;
2932 project.resNode.path = CopyString(equal);
2933 PathCatSlash(parentPath, equal);
2937 else if(!strcmpi(buffer, "Intermediate Directory"))
2938 project.config.options.objectsDirectory = CopyString(equal); //objDir.expression = equal;
2939 else if(!strcmpi(buffer, "Debug"))
2940 project.config.options.debug = ParseTrueFalseValue(equal);
2941 else if(!strcmpi(buffer, "Optimize"))
2943 if(!strcmpi(equal, "None"))
2944 project.config.options.optimization = none;
2945 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
2946 project.config.options.optimization = speed;
2947 else if(!strcmpi(equal, "Size"))
2948 project.config.options.optimization = size;
2950 project.config.options.optimization = none;
2952 else if(!strcmpi(buffer, "Profile"))
2953 project.config.options.profile = ParseTrueFalseValue(equal);
2954 else if(!strcmpi(buffer, "MemoryGuard"))
2955 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
2958 if(!project.options) project.options = { };
2960 // Project Wide Settings (All configs)
2961 if(!strcmpi(buffer, "Target Name"))
2962 project.options.targetFileName = CopyString(equal);
2963 else if(!strcmpi(buffer, "Target Type"))
2965 if(!strcmpi(equal, "Executable"))
2966 project.options.targetType = executable;
2967 else if(!strcmpi(equal, "Shared"))
2968 project.options.targetType = sharedLibrary;
2969 else if(!strcmpi(equal, "Static"))
2970 project.options.targetType = staticLibrary;
2972 project.options.targetType = executable;
2974 else if(!strcmpi(buffer, "Target Directory"))
2975 project.options.targetDirectory = CopyString(equal);
2976 else if(!strcmpi(buffer, "Console"))
2977 project.options.console = ParseTrueFalseValue(equal);
2978 else if(!strcmpi(buffer, "Libraries"))
2980 if(!project.options.libraries) project.options.libraries = { };
2981 ParseArrayValue(project.options.libraries, equal);
2983 else if(!strcmpi(buffer, "AllWarnings"))
2984 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
2985 else if(!strcmpi(buffer, "Preprocessor Definitions"))
2987 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
2989 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
2990 ParseListValue(node.preprocessorDefs, equal);*/
2994 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
2995 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3006 SplitPlatformLibraries(project);
3008 if(configurationsPresent)
3009 CombineIdenticalConfigOptions(project);
3013 void SplitPlatformLibraries(Project project)
3015 if(project && project.configurations)
3017 for(cfg : project.configurations)
3019 if(cfg.options.libraries && cfg.options.libraries.count)
3021 Iterator<String> it { cfg.options.libraries };
3025 char * platformName = strstr(l, ":");
3028 PlatformOptions platform = null;
3030 if(!cfg.platforms) cfg.platforms = { };
3031 for(p : cfg.platforms)
3033 if(!strcmpi(platformName, p.name))
3041 platform = { name = CopyString(platformName), options = { libraries = { } } };
3042 cfg.platforms.Add(platform);
3044 *(platformName-1) = 0;
3045 platform.options.libraries.Add(CopyString(l));
3047 cfg.options.libraries.Delete(it.pointer);
3056 void CombineIdenticalConfigOptions(Project project)
3058 if(project && project.configurations && project.configurations.count)
3061 ProjectOptions nullOptions { };
3062 ProjectConfig firstConfig = null;
3063 for(cfg : project.configurations)
3065 if(cfg.options.targetType != staticLibrary)
3072 firstConfig = project.configurations.firstIterator.data;
3074 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3076 if(!member.isProperty)
3078 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3083 for(cfg : project.configurations)
3085 if(cfg != firstConfig)
3087 if(cfg.options.targetType != staticLibrary)
3091 if(type.type == noHeadClass || type.type == normalClass)
3093 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3094 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3095 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3099 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3100 (byte *)firstConfig.options + member.offset + member._class.offset,
3101 (byte *)cfg.options + member.offset + member._class.offset);
3113 if(type.type == noHeadClass || type.type == normalClass)
3115 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3116 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3117 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3122 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3123 (byte *)firstConfig.options + member.offset + member._class.offset,
3124 (byte *)nullOptions + member.offset + member._class.offset))
3128 if(!project.options) project.options = { };
3130 /*if(type.type == noHeadClass || type.type == normalClass)
3132 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3133 (byte *)project.options + member.offset + member._class.offset,
3134 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3138 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3139 // TOFIX: ListBox::SetData / OnCopy mess
3140 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3141 (byte *)project.options + member.offset + member._class.offset,
3142 (type.typeSize > 4) ? address :
3143 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3144 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3145 (void *)*(byte *)address )));
3148 (byte *)project.options + member.offset + member._class.offset,
3149 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3151 for(cfg : project.configurations)
3153 if(cfg.options.targetType == staticLibrary)
3157 if(type.type == noHeadClass || type.type == normalClass)
3159 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3160 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3161 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3165 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3166 (byte *)firstConfig.options + member.offset + member._class.offset,
3167 (byte *)cfg.options + member.offset + member._class.offset);
3172 if(cfg != firstConfig)
3174 if(type.type == noHeadClass || type.type == normalClass)
3176 type._vTbl[__ecereVMethodID_class_OnFree](type,
3177 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3181 type._vTbl[__ecereVMethodID_class_OnFree](type,
3182 (byte *)cfg.options + member.offset + member._class.offset);
3184 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3187 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3194 // Compare Platform Specific Settings
3197 for(cfg : project.configurations)
3199 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3200 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3206 if(same && firstConfig.platforms)
3208 for(cfg : project.configurations)
3210 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3212 if(cfg != firstConfig)
3214 cfg.platforms.Free();
3215 delete cfg.platforms;
3218 project.platforms = firstConfig.platforms;
3219 firstConfig.platforms = null;
3223 // Static libraries can't contain libraries
3224 for(cfg : project.configurations)
3226 if(cfg.options.targetType == staticLibrary)
3228 if(!cfg.options.libraries) cfg.options.libraries = { };
3229 cfg.options.libraries.Free();
3235 Project LoadProject(char * filePath)
3237 Project project = null;
3238 File f = FileOpen(filePath, read);
3241 project = LegacyBinaryLoadProject(f, filePath);
3244 JSONParser parser { f = f };
3245 JSONResult result = parser.GetObject(class(Project), &project);
3248 char insidePath[MAX_LOCATION];
3250 delete project.topNode.files;
3251 if(!project.files) project.files = { };
3252 project.topNode.files = project.files;
3253 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3254 delete project.resNode.path;
3255 project.resNode.path = project.resourcesPath;
3256 project.resourcesPath = null;
3257 project.resNode.nodeType = (ProjectNodeType)-1;
3258 delete project.resNode.files;
3259 project.resNode.files = project.resources;
3260 project.files = null;
3261 project.resources = null;
3262 if(!project.configurations) project.configurations = { };
3265 char topNodePath[MAX_LOCATION];
3266 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3267 MakeSlashPath(topNodePath);
3268 PathCatSlash(topNodePath, filePath);
3269 project.filePath = topNodePath;//filePath;
3272 project.topNode.FixupNode(insidePath);
3277 project = LegacyAsciiLoadProject(f, filePath);
3283 if(!project.options) project.options = { };
3284 if(!project.config && project.configurations)
3285 project.config = project.configurations.firstIterator.data;
3287 if(!project.resNode)
3289 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3292 if(!project.moduleName)
3293 project.moduleName = CopyString(project.name);
3294 if(project.config &&
3295 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3296 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3298 delete project.config.options.targetFileName;
3300 project.options.targetFileName = CopyString(project.moduleName);
3301 project.config.options.optimization = none;
3302 project.config.options.debug = true;
3303 //project.config.options.warnings = unset;
3304 project.config.options.memoryGuard = false;
3305 project.config.compilingModified = true;
3306 project.config.linkingModified = true;
3308 else if(!project.topNode.name && project.config)
3310 project.topNode.name = CopyString(project.config.options.targetFileName);
3313 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3314 project.topNode.configurations = project.configurations;
3315 project.topNode.platforms = project.platforms;
3316 project.topNode.options = project.options;*/