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; // TODO: turn this into an option.
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 if(false) // TODO: turn this into an option.
472 int itemLen = strlen(list[n]);
473 if(len > 3 && len + itemLen > breakLineLength)
475 f.Printf(" \\\n\t%s", list[n]);
481 f.Printf(" %s", list[n]);
485 f.Printf(" \\\n\t%s", list[n]);
500 void OutputCleanActions(File f, char * name, int parts)
505 for(c=0; c<parts; c++)
506 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
509 f.Printf("\t$(call rmq,$(%s))\n", name);
512 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
516 if(method == newLine)
520 if(method == lineEach)
522 f.Printf(" -%s", option);
524 OutputNoSpace(f, item);
526 f.Printf("%s", item);
531 static void OutputLibraries(File f, Array<String> libraries)
533 for(item : libraries)
535 char ext[MAX_EXTENSION];
536 char temp[MAX_LOCATION];
538 GetExtension(item, ext);
539 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
543 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
545 if(!strncmp(item, "lib", 3))
546 strcpy(temp, item + 3);
549 StripExtension(temp);
558 void CamelCase(char * string)
560 int c, len = strlen(string);
561 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
562 string[c] = (char)tolower(string[c]);
565 CompilerConfig GetCompilerConfig()
567 #ifndef MAKEFILE_GENERATOR
568 CompilerConfig compiler = null;
569 if(ide && ide.workspace)
570 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
573 incref defaultCompiler;
574 return defaultCompiler;
578 define localTargetType = config && config.options && config.options.targetType ?
579 config.options.targetType : options && options.targetType ?
580 options.targetType : TargetTypes::executable;
581 define localWarnings = config && config.options && config.options.warnings ?
582 config.options.warnings : options && options.warnings ?
583 options.warnings : WarningsOption::unset;
584 define localDebug = config && config.options && config.options.debug ?
585 config.options.debug : options && options.debug ?
586 options.debug : SetBool::unset;
587 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
588 config.options.memoryGuard : options && options.memoryGuard ?
589 options.memoryGuard : SetBool::unset;
590 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
591 config.options.noLineNumbers : options && options.noLineNumbers ?
592 options.noLineNumbers : SetBool::unset;
593 define localProfile = config && config.options && config.options.profile ?
594 config.options.profile : options && options.profile ?
595 options.profile : SetBool::unset;
596 define localOptimization = config && config.options && config.options.optimization ?
597 config.options.optimization : options && options.optimization ?
598 options.optimization : OptimizationStrategy::none;
599 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
600 config.options.defaultNameSpace : options && options.defaultNameSpace ?
601 options.defaultNameSpace : null;
602 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
603 config.options.strictNameSpaces : options && options.strictNameSpaces ?
604 options.strictNameSpaces : SetBool::unset;
605 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
606 define localTargetFileName = config && config.options && config.options.targetFileName ?
607 config.options.targetFileName : options && options.targetFileName ?
608 options.targetFileName : "";
609 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
610 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
611 options.targetDirectory : null;
612 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
613 ideSettings.projectDefaultIntermediateObjDir[0] ?
614 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
615 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
616 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
617 options.objectsDirectory : null;
618 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
619 ideSettings.projectDefaultIntermediateObjDir[0] ?
620 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
621 define localConsole = config && config.options && config.options.console ?
622 config.options.console : options && options.console ?
623 options.console : SetBool::unset;
624 define localCompress = config && config.options && config.options.compress ?
625 config.options.compress : options && options.compress ?
626 options.compress : SetBool::unset;
628 char * PlatformToMakefileVariable(Platform platform)
630 return platform == win32 ? "WINDOWS" : platform == tux ? "LINUX" : platform == apple ? "OSX"/*"APPLE"*/ : platform;
633 class Project : struct
635 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
636 // We might want to tweak this default behavior of regular classes ?
637 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
642 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
643 property Array<PlatformOptions> platforms
645 get { return platforms; }
648 if(platforms) { platforms.Free(); delete platforms; }
651 List<PlatformOptions> empty { };
652 Iterator<PlatformOptions> it { value };
654 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
655 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
665 if(p.options && !p.options.isEmpty)
672 List<ProjectConfig> configurations;
673 LinkList<ProjectNode> files;
674 String resourcesPath;
675 LinkList<ProjectNode> resources;
677 property char * description
679 set { delete description; if(value && value[0]) description = CopyString(value); }
680 get { return description ? description : ""; }
681 isset { return description != null && description[0]; }
684 property char * license
686 set { delete license; if(value && value[0]) license = CopyString(value); }
687 get { return license ? license : ""; }
688 isset { return license != null && license[0]; }
692 // topNode.name holds the file name (.epj)
693 ProjectOptions options;
694 Array<PlatformOptions> platforms;
695 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
698 ProjectConfig config;
700 // This is the file name stripped of the epj extension
701 // It should NOT be edited, saved or loaded anywhere
709 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
710 topNode.configurations = null;
711 topNode.platforms = null;
712 topNode.options = null;
715 if(platforms) { platforms.Free(); delete platforms; }
716 if(configurations) { configurations.Free(); delete configurations; }
717 if(files) { files.Free(); delete files; }
718 if(resources) { resources.Free(); delete resources; }
720 delete resourcesPath;
730 property char * configName { get { return config ? config.name : "Common"; } }
732 property ProjectConfig config
738 topNode.info = CopyString(configName);
741 property char * filePath
747 char string[MAX_LOCATION];
748 GetLastDirectory(value, string);
750 topNode.name = CopyString(string);
751 StripExtension(string);
753 name = CopyString(string);
754 StripLastDirectory(value, string);
756 topNode.path = CopyString(string);
758 filePath = CopyString(value);
763 property TargetTypes targetType
767 // TODO: Implement platform specific options?
768 TargetTypes targetType = localTargetType;
773 property char * objDirExpression
777 // TODO: Support platform options
778 char * expression = localObjectsDirectory;
780 expression = settingsObjectsDirectory;
784 property DirExpression objDir
788 char * expression = objDirExpression;
789 DirExpression objDir { type = intermediateObjectsDir };
790 objDir.Evaluate(expression, this);
794 property char * targetDirExpression
798 // TODO: Support platform options
799 char * expression = localTargetDirectory;
801 expression = settingsTargetDirectory;
805 property DirExpression targetDir
809 char * expression = targetDirExpression;
810 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
811 targetDir.Evaluate(expression, this);
816 property WarningsOption warnings
820 WarningsOption warnings = localWarnings;
828 SetBool debug = localDebug;
829 return debug == true;
832 property bool memoryGuard
836 SetBool memoryGuard = localMemoryGuard;
837 return memoryGuard == true;
840 property bool noLineNumbers
844 SetBool noLineNumbers = localNoLineNumbers;
845 return noLineNumbers == true;
848 property bool profile
852 SetBool profile = localProfile;
853 return profile == true;
856 property OptimizationStrategy optimization
860 OptimizationStrategy optimization = localOptimization;
864 property String defaultNameSpace
868 String defaultNameSpace = localDefaultNameSpace;
869 return defaultNameSpace;
872 property bool strictNameSpaces
876 SetBool strictNameSpaces = localStrictNameSpaces;
877 return strictNameSpaces == true;
880 property String targetFileName
884 String targetFileName = localTargetFileName;
885 return targetFileName;
888 //String targetDirectory;
889 //String objectsDirectory;
890 property bool console
894 SetBool console = localConsole;
895 return console == true;
898 property bool compress
902 SetBool compress = localCompress;
903 return compress == true;
906 //SetBool excludeFromBuild;
908 property bool configIsInActiveDebugSession
912 #ifndef MAKEFILE_GENERATOR
913 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
918 property bool configIsInDebugSession
922 #ifndef MAKEFILE_GENERATOR
923 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
928 void SetPath(bool projectsDirs)
930 #ifndef MAKEFILE_GENERATOR
931 ide.SetPath(projectsDirs);
935 #ifndef MAKEFILE_GENERATOR
936 bool Save(char * fileName)
939 /*char output[MAX_LOCATION];
940 ChangeExtension(fileName, "json", output);
941 f = FileOpen(output, write);*/
942 f = FileOpen(fileName, write);
945 files = topNode.files;
946 resources = resNode.files;
947 resourcesPath = resNode.path;
949 files.Remove(resNode);
952 WriteJSONObject(f, class(Project), this, 0);
958 resourcesPath = null;
965 #ifndef MAKEFILE_GENERATOR
966 bool GetRelativePath(char * filePath, char * relativePath)
969 char moduleName[MAX_FILENAME];
970 GetLastDirectory(filePath, moduleName);
971 // try with workspace dir first?
972 if((node = topNode.Find(moduleName, false)))
974 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
975 PathCatSlash(relativePath, node.name);
978 // WARNING: On failure, relative path is uninitialized
983 void CatTargetFileName(char * string)
985 CompilerConfig compiler = GetCompilerConfig();
987 if(targetType == staticLibrary)
989 PathCatSlash(string, "lib");
990 strcat(string, targetFileName);
992 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
994 PathCatSlash(string, "lib");
995 strcat(string, targetFileName);
998 PathCatSlash(string, targetFileName);
1003 if(compiler.targetPlatform == win32)
1004 strcat(string, ".exe");
1007 if(compiler.targetPlatform == win32)
1008 strcat(string, ".dll");
1009 else if(compiler.targetPlatform == apple)
1010 strcat(string, ".dylib");
1012 strcat(string, ".so");
1015 strcat(string, ".a");
1021 void CatMakeFileName(char * string)
1023 char projectName[MAX_LOCATION];
1024 CompilerConfig compiler = GetCompilerConfig();
1025 strcpy(projectName, name);
1026 if(strcmpi(compiler.name, defaultCompilerName))
1027 sprintf(string, "%s-%s-%s.Makefile", projectName, compiler.name, config.name);
1029 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1033 #ifndef MAKEFILE_GENERATOR
1034 void MarkChanges(ProjectNode node)
1036 for(cfg : topNode.configurations)
1038 ProjectConfig c = null;
1039 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1041 if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1042 (!c.options || !cfg.options)))
1043 cfg.symbolGenModified = true;
1045 cfg.makingModified = true;
1049 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1051 for(cfg : configurations)
1054 cfg.makingModified = true;
1056 cfg.compilingModified = true;
1058 cfg.linkingModified = true;
1060 cfg.symbolGenModified = true;
1062 if(compiling || linking)
1064 ide.projectView.modifiedDocument = true;
1065 ide.workspace.modified = true;
1069 void RotateActiveConfig(bool forward)
1071 if(configurations.first && configurations.last != configurations.first)
1073 Iterator<ProjectConfig> cfg { configurations };
1074 while(forward ? cfg.Next() : cfg.Prev())
1075 if(cfg.data == config)
1089 property::config = cfg.data;
1090 ide.workspace.modified = true;
1091 ide.projectView.Update(null);
1095 void ProcessPipeOutputRaw(DualPipe f)
1098 while(!f.Eof() && !ide.ShouldStopBuild())
1101 double lastTime = GetTime();
1105 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1107 ide.outputView.buildBox.Logf("%s\n", line);
1109 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1111 //printf("Processing Input...\n");
1112 if(app.ProcessInput(true))
1114 app.UpdateDisplay();
1117 //printf("Waiting...\n");
1120 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1122 if(ide.ShouldStopBuild())
1124 ide.outputView.buildBox.Logf("\nBuild cancelled by user.\n", line);
1129 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode)
1132 bool compiling = false, linking = false, precompiling = false;
1133 int compilingEC = 0;
1134 int numErrors = 0, numWarnings = 0;
1135 bool loggedALine = false;
1136 CompilerConfig compiler = GetCompilerConfig();
1137 char * configName = this.configName;
1138 int lenMakeCommand = strlen(compiler.makeCommand);
1140 char cppCommand[MAX_LOCATION];
1141 char ccCommand[MAX_LOCATION];
1142 char ecpCommand[MAX_LOCATION];
1143 char eccCommand[MAX_LOCATION];
1144 char ecsCommand[MAX_LOCATION];
1145 char earCommand[MAX_LOCATION];
1147 char * cc = compiler.ccCommand;
1148 char * cpp = compiler.cppCommand;
1149 sprintf(cppCommand, "%s%s%s%s ",
1150 compiler.ccacheEnabled ? "ccache " : "",
1151 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1152 compiler.distccEnabled ? "distcc " : "",
1153 compiler.cppCommand);
1154 sprintf(ccCommand, "%s%s%s%s ",
1155 compiler.ccacheEnabled ? "ccache " : "",
1156 compiler.ccacheEnabled && !compiler.distccEnabled ? " " : "",
1157 compiler.distccEnabled ? "distcc " : "",
1158 compiler.ccCommand);
1159 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1160 sprintf(eccCommand, "%s ", compiler.eccCommand);
1161 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1162 sprintf(earCommand, "%s ", compiler.earCommand);
1164 while(!f.Eof() && !ide.ShouldStopBuild())
1167 double lastTime = GetTime();
1171 //printf("Peeking and GetLine...\n");
1172 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1174 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1176 char * module = strstr(line, "No rule to make target `");
1180 module = strchr(module, '`') + 1;
1181 end = strchr(module, '\'');
1185 ide.outputView.buildBox.Logf(" %s: No such file or directory\n", module);
1186 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1192 //ide.outputView.buildBox.Logf("error: %s\n", line);
1196 else if(strstr(line, "ear ") == line);
1197 else if(strstr(line, "strip ") == line);
1198 else if(strstr(line, ccCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1200 char moduleName[MAX_FILENAME];
1203 bool isPrecomp = false;
1205 if(strstr(line, ccCommand) == line)
1207 module = strstr(line, " -c ");
1208 if(module) module += 4;
1210 else if(strstr(line, eccCommand) == line)
1212 module = strstr(line, " -c ");
1213 if(module) module += 4;
1214 //module = line + 3;
1215 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1216 compilingEC = 3;//2;
1218 else if(strstr(line, ecpCommand) == line)
1220 // module = line + 8;
1221 module = strstr(line, " -c ");
1222 if(module) module += 4;
1231 if(!compiling && !isPrecomp)
1233 ide.outputView.buildBox.Logf("Compiling...\n");
1236 else if(!precompiling && isPrecomp)
1238 ide.outputView.buildBox.Logf("Generating symbols...\n");
1239 precompiling = true;
1241 Tokenize(module, 1, tokens, false);
1242 GetLastDirectory(module, moduleName);
1243 ide.outputView.buildBox.Logf("%s\n", moduleName);
1245 else if((module = strstr(line, " -o ")))
1248 precompiling = false;
1250 ide.outputView.buildBox.Logf("Linking...\n");
1254 ide.outputView.buildBox.Logf("%s\n", line);
1258 if(compilingEC) compilingEC--;
1260 else if(strstr(line, "ar rcs") == line)
1261 ide.outputView.buildBox.Logf("Building library...\n");
1262 else if(strstr(line, ecsCommand) == line)
1263 ide.outputView.buildBox.Logf("Writing symbol loader...\n");
1266 if(linking || compiling || precompiling)
1268 char * colon = strstr(line, ":"); //, * bracket;
1269 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1270 colon = strstr(colon + 1, ":");
1273 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1275 int len = (int)(colon - line);
1276 len = Min(len, MAX_LOCATION-1);
1277 // Don't be mistaken by the drive letter colon
1279 // TODO: need to fix colon - line gives char *
1280 // warning: incompatible expression colon - line (char *); expected int
1282 strncpy(moduleName, line, (int)(colon - line));
1283 moduleName[colon - line] = '\0';
1285 strncpy(moduleName, line, len);
1286 moduleName[len] = '\0';
1287 // Remove stuff in brackets
1288 //bracket = strstr(moduleName, "(");
1289 //if(bracket) *bracket = '\0';
1291 GetLastDirectory(moduleName, temp);
1292 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1295 strcpy(moduleName, "Linker Error");
1299 strcpy(temp, topNode.path);
1300 PathCatSlash(temp, moduleName);
1301 MakePathRelative(temp, topNode.path, moduleName);
1303 if(strstr(line, "error:"))
1307 // Silence warnings for compiled EC
1308 char * objDir = strstr(moduleName, objDirExp.dir);
1312 if((pointer = strstr(line, "undefined")) ||
1313 (pointer = strstr(line, "No such file")) ||
1314 (pointer = strstr(line, "token")))
1316 strncat(moduleName, colon, pointer - colon);
1317 strcat(moduleName, "error: ");
1322 else if((pointer = strstr(line, "No such file")))
1324 strncat(moduleName, colon, pointer - colon);
1325 strcat(moduleName, "error: ");
1329 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1331 else if(strstr(line, "warning:"))
1336 if(this == ide.workspace.projects.firstIterator.data)
1337 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1340 char fullModuleName[MAX_LOCATION];
1341 strcpy(fullModuleName, topNode.path);
1342 PathCat(fullModuleName, moduleName);
1343 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1344 MakeSystemPath(fullModuleName);
1345 ide.outputView.buildBox.Logf(" %s%s\n", fullModuleName, colon);
1350 ide.outputView.buildBox.Logf("%s\n", line);
1351 linking = compiling = precompiling = false;
1355 ide.outputView.buildBox.Logf("%s\n", line);
1359 //printf("Done getting line\n");
1360 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1362 //printf("Processing Input...\n");
1363 if(app.ProcessInput(true))
1365 app.UpdateDisplay();
1368 //printf("Waiting...\n");
1371 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1373 if(ide.ShouldStopBuild())
1375 ide.outputView.buildBox.Logf("\nBuild cancelled by user.\n", line);
1378 else if(loggedALine || !isARun)
1380 if(f.GetExitCode() && !numErrors)
1382 bool result = f.GetLine(line, sizeof(line)-1);
1383 ide.outputView.buildBox.Logf("Fatal Error: child process terminated unexpectedly\n");
1388 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, configName);
1390 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? "errors" : "error");
1392 ide.outputView.buildBox.Logf("no error, ");
1395 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? "warnings" : "warning");
1397 ide.outputView.buildBox.Logf("no warning\n");
1402 return numErrors == 0;
1405 void ProcessCleanPipeOutput(DualPipe f)
1408 CompilerConfig compiler = GetCompilerConfig();
1409 int lenMakeCommand = strlen(compiler.makeCommand);
1414 double lastTime = GetTime();
1417 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1419 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1420 else if(strstr(line, "del") == line);
1421 else if(strstr(line, "rm") == line);
1422 else if(strstr(line, "Could Not Find") == line);
1425 ide.outputView.buildBox.Logf(line);
1426 ide.outputView.buildBox.Logf("\n");
1430 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1432 if(app.ProcessInput(true))
1434 app.UpdateDisplay();
1437 //Sleep(1.0 / PEEK_RESOLUTION);
1442 bool Build(bool isARun, ProjectNode onlyNode)
1444 bool result = false;
1446 char targetFileName[MAX_LOCATION] = "";
1447 char makeTarget[MAX_LOCATION] = "";
1448 char makeFile[MAX_LOCATION];
1449 char makeFilePath[MAX_LOCATION];
1450 char configName[MAX_LOCATION];
1451 CompilerConfig compiler = GetCompilerConfig();
1452 DirExpression objDirExp = objDir;
1453 PathBackup pathBackup { };
1455 int numJobs = compiler.numJobs;
1456 char command[MAX_LOCATION];
1458 strcpy(configName, this.configName);
1460 SetPath(false); //true
1461 CatTargetFileName(targetFileName);
1463 strcpy(makeFilePath, topNode.path);
1464 CatMakeFileName(makeFile);
1465 PathCatSlash(makeFilePath, makeFile);
1467 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1470 if(compiler.type.isVC)
1472 PrintLn("compiling a single file is not yet supported");
1477 char pushD[MAX_LOCATION];
1478 GetWorkingDir(pushD, sizeof(pushD));
1479 ChangeWorkingDir(topNode.path);
1480 // Create object dir if it does not exist already
1481 if(!FileExists(objDirExp.dir).isDirectory)
1482 Execute("%s objdir -C \"%s\" -f \"%s\"", compiler.makeCommand, topNode.path, makeFilePath);
1483 ChangeWorkingDir(pushD);
1485 PathCatSlash(makeTarget+1, objDirExp.dir);
1486 PathCatSlash(makeTarget+1, onlyNode.name);
1487 StripExtension(makeTarget+1);
1488 strcat(makeTarget+1, ".o");
1489 makeTarget[0] = '\"';
1490 len = strlen(makeTarget);
1491 makeTarget[len++] = '\"';
1492 makeTarget[len++] = '\0';
1496 if(compiler.type.isVC)
1498 bool result = false;
1499 char oldwd[MAX_LOCATION];
1500 GetWorkingDir(oldwd, sizeof(oldwd));
1501 ChangeWorkingDir(topNode.path);
1503 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1504 ide.outputView.buildBox.Logf("command: %s\n", command);
1505 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1507 ProcessPipeOutputRaw(f);
1511 ChangeWorkingDir(oldwd);
1515 sprintf(command, "%s -j%d %s%s%s -C \"%s\" -f \"%s\"", compiler.makeCommand, numJobs,
1516 compiler.ccacheEnabled ? "CCACHE=y " : "",
1517 compiler.distccEnabled ? "DISTCC=y " : "",
1518 makeTarget, topNode.path, makeFilePath);
1519 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1521 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode);
1525 ide.outputView.buildBox.Logf("Error executing make (%s) command\n", compiler.makeCommand);
1537 char makeFile[MAX_LOCATION];
1538 char makeFilePath[MAX_LOCATION];
1539 char command[MAX_LOCATION];
1541 CompilerConfig compiler = GetCompilerConfig();
1542 PathBackup pathBackup { };
1546 strcpy(makeFilePath, topNode.path);
1547 CatMakeFileName(makeFile);
1548 PathCatSlash(makeFilePath, makeFile);
1550 if(compiler.type.isVC)
1552 bool result = false;
1553 char oldwd[MAX_LOCATION];
1554 GetWorkingDir(oldwd, sizeof(oldwd));
1555 ChangeWorkingDir(topNode.path);
1557 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1558 ide.outputView.buildBox.Logf("command: %s\n", command);
1559 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1561 ProcessPipeOutputRaw(f);
1565 ChangeWorkingDir(oldwd);
1570 sprintf(command, "%s clean -C \"%s\" -f \"%s\"", compiler.makeCommand, topNode.path, makeFilePath);
1571 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1573 ide.outputView.buildBox.Tell("Deleting target and object files...");
1574 ProcessCleanPipeOutput(f);
1577 ide.outputView.buildBox.Logf("Target and object files deleted\n");
1585 void Run(char * args)
1587 String target = new char[maxPathLen];
1588 char oldDirectory[MAX_LOCATION];
1589 DirExpression targetDirExp = targetDir;
1590 CompilerConfig compiler = GetCompilerConfig();
1591 PathBackup pathBackup { };
1593 // Build(project, ideMain, true, null);
1595 #if defined(__WIN32__)
1596 strcpy(target, topNode.path);
1600 PathCatSlash(target, targetDirExp.dir);
1601 CatTargetFileName(target);
1602 sprintf(target, "%s %s", target, args);
1603 GetWorkingDir(oldDirectory, MAX_LOCATION);
1605 if(strlen(ide.workspace.debugDir))
1607 char temp[MAX_LOCATION];
1608 strcpy(temp, topNode.path);
1609 PathCatSlash(temp, ide.workspace.debugDir);
1610 ChangeWorkingDir(temp);
1613 ChangeWorkingDir(topNode.path);
1614 // ChangeWorkingDir(topNode.path);
1616 if(compiler.execPrefixCommand)
1618 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1619 prefixedTarget[0] = '\0';
1620 strcat(prefixedTarget, compiler.execPrefixCommand);
1621 strcat(prefixedTarget, " ");
1622 strcat(prefixedTarget, target);
1623 Execute(prefixedTarget);
1624 delete prefixedTarget;
1629 ChangeWorkingDir(oldDirectory);
1632 delete targetDirExp;
1637 void Compile(ProjectNode node)
1643 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName)
1645 char s[MAX_LOCATION];
1647 if(targetType == staticLibrary || targetType == sharedLibrary)
1648 strcat(fileName, "$(LP)");
1649 ReplaceSpaces(s, targetFileName);
1650 strcat(fileName, s);
1654 strcat(fileName, "$(E)");
1657 strcat(fileName, "$(SO)");
1660 strcat(fileName, "$(A)");
1665 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath)
1667 bool result = false;
1668 char filePath[MAX_LOCATION];
1669 char makeFile[MAX_LOCATION];
1670 CompilerConfig compiler = GetCompilerConfig();
1671 // PathBackup pathBackup { };
1672 // char oldDirectory[MAX_LOCATION];
1675 if(!altMakefilePath)
1677 strcpy(filePath, topNode.path);
1678 CatMakeFileName(makeFile);
1679 PathCatSlash(filePath, makeFile);
1682 #if defined(__WIN32__) && !defined(MAKEFILE_GENERATOR)
1683 if(compiler.type.isVC)
1685 GenerateVSSolutionFile(this);
1686 GenerateVCProjectFile(this);
1690 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
1693 GetWorkingDir(oldDirectory, MAX_LOCATION);
1694 ChangeWorkingDir(topNode.path);*/
1698 char temp[MAX_LOCATION];
1699 char target[MAX_LOCATION];
1700 char targetNoSpaces[MAX_LOCATION];
1701 char objDirExpNoSpaces[MAX_LOCATION];
1702 char objDirNoSpaces[MAX_LOCATION];
1703 char resDirNoSpaces[MAX_LOCATION];
1704 char targetDirExpNoSpaces[MAX_LOCATION];
1705 char fixedModuleName[MAX_FILENAME];
1706 char fixedConfigName[MAX_FILENAME];
1707 char fixedCompilerName[MAX_FILENAME];
1709 int numCObjects = 0;
1710 bool sameObjTargetDirs;
1711 DirExpression objDirExp = objDir;
1713 bool crossCompiling = compiler.targetPlatform != GetRuntimePlatform();
1714 bool gccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "gcc") != null;
1715 bool tccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "tcc") != null;
1716 bool defaultPreprocessor = compiler.cppCommand && (strstr(compiler.cppCommand, "gcc") != null || compiler.cppCommand && strstr(compiler.cppCommand, "cpp") != null);
1718 int objectsParts, cobjectsParts, symbolsParts, importsParts;
1719 Array<String> listItems { };
1720 Map<String, int> varStringLenDiffs { };
1721 Map<String, NameCollisionInfo> namesInfo { };
1723 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
1724 strcpy(temp, targetDirExpression);
1725 ReplaceSpaces(targetDirExpNoSpaces, temp);
1726 GetMakefileTargetFileName(targetType, target);
1727 PathCatSlash(temp, target);
1728 ReplaceSpaces(targetNoSpaces, temp);
1730 strcpy(objDirExpNoSpaces, objDirExpression);
1731 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1732 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
1733 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
1734 //ReplaceSpaces(fixedPrjName, name);
1735 ReplaceSpaces(fixedModuleName, moduleName);
1736 ReplaceSpaces(fixedConfigName, configName);
1737 ReplaceSpaces(fixedCompilerName, compiler.name);
1738 //CamelCase(fixedModuleName); // case is important for static linking
1739 CamelCase(fixedConfigName);
1740 CamelCase(fixedCompilerName);
1742 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
1744 f.Printf(".PHONY: all objdir%s clean distclean\n\n", sameObjTargetDirs ? "" : " targetdir");
1746 f.Printf("# CONTENT\n\n");
1748 f.Printf("MODULE := %s\n", fixedModuleName);
1749 //f.Printf("VERSION = %s\n", version);
1750 f.Printf("CONFIG := %s\n", fixedConfigName);
1751 f.Printf("COMPILER := %s\n", fixedCompilerName);
1753 f.Printf("PLATFORM = %s\n", (char *)compiler.targetPlatform);
1754 f.Printf("TARGET_TYPE = %s\n", targetType == executable ? "executable" :
1755 (targetType == sharedLibrary ? "sharedlib" : (targetType == staticLibrary ? "staticlib" : "unknown")));
1758 f.Printf("OBJ = %s%s\n\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
1760 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
1762 if(targetType == executable)
1763 f.Printf("CONSOLE = %s\n\n", console ? "-mconsole" : "-mwindows");
1765 f.Printf("TARGET = %s\n\n", targetNoSpaces);
1767 varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
1769 topNode.GenMakefileGetNameCollisionInfo(namesInfo);
1771 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems);
1773 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
1774 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs);
1776 topNode.GenMakefilePrintNode(f, this, cObjects, namesInfo, listItems);
1777 cobjectsParts = OutputFileList(f, "COBJECTS", listItems, varStringLenDiffs);
1779 topNode.GenMakefilePrintNode(f, this, symbols, null, listItems);
1780 symbolsParts = OutputFileList(f, "SYMBOLS", listItems, varStringLenDiffs);
1782 topNode.GenMakefilePrintNode(f, this, imports, null, listItems);
1783 importsParts = OutputFileList(f, "IMPORTS", listItems, varStringLenDiffs);
1785 topNode.GenMakefilePrintNode(f, this, sources, null, listItems);
1786 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs);
1789 resNode.GenMakefilePrintNode(f, this, resources, null, listItems);
1790 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs);
1794 f.Printf("# CROSS-PLATFORM MAGIC\n\n");
1796 f.Printf("include %s\n\n", includemkPath);
1800 File include = FileOpen(":include.mk", read);
1803 for(; !include.Eof(); )
1806 int count = include.Read(buffer, 1, 4096);
1807 f.Write(buffer, 1, count);
1815 if(strcmpi(compiler.cppCommand, "cpp") ||
1816 strcmpi(compiler.ccCommand, "gcc") ||
1817 strcmpi(compiler.ecpCommand, "ecp") ||
1818 strcmpi(compiler.eccCommand, "ecc") ||
1819 strcmpi(compiler.ecsCommand, "ecs") || crossCompiling ||
1820 strcmpi(compiler.earCommand, "ear"))
1822 f.Printf("# TOOLCHAIN\n\n");
1824 //f.Printf("SHELL := %s\n", "ar"/*compiler.arCommand*/); // is this really needed?
1825 if(strcmpi(compiler.cppCommand, "cpp"))
1826 f.Printf("CPP := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.cppCommand);
1827 if(strcmpi(compiler.ccCommand, "gcc"))
1828 f.Printf("CC := $(CCACHE_COMPILE) $(DISTCC_COMPILE) %s\n", compiler.ccCommand);
1829 if(strcmpi(compiler.ecpCommand, "ecp"))
1830 f.Printf("ECP := %s\n", compiler.ecpCommand);
1831 if(strcmpi(compiler.eccCommand, "ecc"))
1832 f.Printf("ECC := %s\n", compiler.eccCommand);
1833 if(strcmpi(compiler.ecsCommand, "ecs") || crossCompiling)
1835 f.Printf("ECS := %s%s%s\n", compiler.ecsCommand,
1836 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1838 if(strcmpi(compiler.earCommand, "ear"))
1839 f.Printf("EAR := %s\n", compiler.earCommand);
1843 f.Printf("# FLAGS\n\n");
1845 f.Printf("CFLAGS =");
1848 f.Printf(" -fmessage-length=0");
1849 switch(optimization)
1853 f.Printf(" -ffast-math");
1859 //if(compiler.targetPlatform.is32Bits)
1861 //else if(compiler.targetPlatform.is64Bits)
1862 // f.Printf(" -m64");
1863 f.Printf(" $(FPIC)");
1864 //f.Printf(" -fpack-struct");
1870 if(warnings == none)
1877 if(options && options.linkerOptions && options.linkerOptions.count)
1879 f.Printf(" \\\n\t -Wl");
1880 for(s : options.linkerOptions)
1884 if(options && options.preprocessorDefinitions)
1885 OutputListOption(f, "D", options.preprocessorDefinitions, newLine, false);
1886 if(config && config.options && config.options.preprocessorDefinitions)
1887 OutputListOption(f, "D", config.options.preprocessorDefinitions, newLine, false);
1889 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
1890 if(options && options.includeDirs)
1891 OutputListOption(f, "I", options.includeDirs, lineEach, true);
1892 if(config && config.options && config.options.includeDirs)
1893 OutputListOption(f, "I", config.options.includeDirs, lineEach, true);
1896 f.Printf("CECFLAGS =%s%s%s%s", defaultPreprocessor ? "" : " -cpp ", defaultPreprocessor ? "" : compiler.cppCommand,
1897 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1900 f.Printf("ECFLAGS =");
1902 f.Printf(" -memguard");
1903 if(strictNameSpaces)
1904 f.Printf(" -strictns");
1906 f.Printf(" -nolinenumbers");
1909 if((s = defaultNameSpace) && s[0])
1910 f.Printf(" -defaultns %s", s);
1914 if(targetType != staticLibrary)
1916 f.Printf("OFLAGS = -m32"); // TARGET_TYPE is fixed in a Makefile, we don't want this. $(if TARGET_TYPE_STATIC_LIBRARY,,-m32)");
1920 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
1921 if(options && options.libraryDirs)
1922 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
1923 if(config && config.options && config.options.libraryDirs)
1924 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
1929 if(targetType != staticLibrary)
1931 if(config && config.options && config.options.libraries)
1932 OutputLibraries(f, config.options.libraries);
1933 else if(options && options.libraries)
1934 OutputLibraries(f, options.libraries);
1936 f.Printf(" $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
1938 f.Printf("UPXFLAGS = -9\n\n"); // TOFEAT: Compression Level Option? Other UPX Options?
1940 f.Printf("# HARD CODED PLATFORM-SPECIFIC OPTIONS\n");
1941 f.Printf("ifdef %s\n", PlatformToMakefileVariable(tux));
1942 f.Printf("OFLAGS += -Wl,--no-undefined\n");
1943 f.Printf("endif\n\n");
1946 f.Printf("ifdef %s\n", PlatformToMakefileVariable(apple));
1947 f.Printf("OFLAGS += -framework cocoa -framework OpenGL\n");
1948 f.Printf("endif\n\n");
1950 if(platforms || (config && config.platforms))
1954 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
1955 //for(platform = win32; platform <= apple; platform++)
1957 f.Printf("# PLATFORM-SPECIFIC OPTIONS\n\n");
1958 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1960 PlatformOptions projectPlatformOptions = null;
1961 PlatformOptions configPlatformOptions = null;
1967 if(!strcmpi(p.name, platform))
1969 projectPlatformOptions = p;
1974 if(config && config.platforms)
1976 for(p : config.platforms)
1978 if(!strcmpi(p.name, platform))
1980 configPlatformOptions = p;
1985 if(projectPlatformOptions || configPlatformOptions)
1991 // we should have some kind of direct mapping between a platform and it's makefile variable
1992 f.Printf(PlatformToMakefileVariable(platform));
1995 if((projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions && projectPlatformOptions.options.preprocessorDefinitions.count) ||
1996 (configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions && configPlatformOptions.options.preprocessorDefinitions.count) ||
1997 (projectPlatformOptions && projectPlatformOptions.options.includeDirs && projectPlatformOptions.options.includeDirs.count) ||
1998 (configPlatformOptions && configPlatformOptions.options.includeDirs && configPlatformOptions.options.includeDirs.count))
2000 f.Printf("CFLAGS +=");
2001 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2003 f.Printf(" \\\n\t -Wl");
2004 for(s : projectPlatformOptions.options.linkerOptions)
2007 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2009 f.Printf(" \\\n\t -Wl");
2010 for(s : configPlatformOptions.options.linkerOptions)
2013 if(projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions)
2014 OutputListOption(f, "D", projectPlatformOptions.options.preprocessorDefinitions, newLine, false);
2015 if(configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions)
2016 OutputListOption(f, "D", configPlatformOptions.options.preprocessorDefinitions, newLine, false );
2017 if(projectPlatformOptions && projectPlatformOptions.options.includeDirs)
2018 OutputListOption(f, "I", projectPlatformOptions.options.includeDirs, lineEach, true);
2019 if(configPlatformOptions && configPlatformOptions.options.includeDirs)
2020 OutputListOption(f, "I", configPlatformOptions.options.includeDirs, lineEach, true);
2024 if(targetType != staticLibrary)
2026 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2027 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2029 f.Printf("OFLAGS +=");
2030 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2031 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
2032 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2033 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
2037 if(projectPlatformOptions && projectPlatformOptions.options.libraries &&
2038 projectPlatformOptions.options.libraries.count/* &&
2039 (!config || !config.options || !config.options.libraries)*/)
2041 f.Printf("LIBS +=");
2042 OutputLibraries(f, projectPlatformOptions.options.libraries);
2045 {/*TOFIX: EXTRA CURLIES FOR NASTY WARNING*/if((configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2047 f.Printf("LIBS +=");
2048 OutputLibraries(f, configPlatformOptions.options.libraries);
2056 for(c = 0; c < ifCount; c++)
2057 f.Printf("endif\n");
2063 f.Printf("# TARGETS\n\n");
2065 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
2067 f.Printf("objdir:\n");
2068 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
2069 //f.Printf("# PRE-BUILD COMMANDS\n");
2070 if(options && options.prebuildCommands)
2072 for(s : options.prebuildCommands)
2073 if(s && s[0]) f.Printf("\t%s\n", s);
2075 if(config && config.options && config.options.prebuildCommands)
2077 for(s : config.options.prebuildCommands)
2078 if(s && s[0]) f.Printf("\t%s\n", s);
2080 if(platforms || (config && config.platforms))
2084 //f.Printf("# PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2085 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2087 PlatformOptions projectPOs = null;
2088 PlatformOptions configPOs = null;
2094 if(!strcmpi(p.name, platform))
2101 if(config && config.platforms)
2103 for(p : config.platforms)
2105 if(!strcmpi(p.name, platform))
2112 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2113 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2119 f.Printf(PlatformToMakefileVariable(platform));
2122 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2124 for(s : projectPOs.options.prebuildCommands)
2125 if(s && s[0]) f.Printf("\t%s\n", s);
2127 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2129 for(s : configPOs.options.prebuildCommands)
2130 if(s && s[0]) f.Printf("\t%s\n", s);
2137 for(c = 0; c < ifCount; c++)
2138 f.Printf("endif\n");
2144 if(!sameObjTargetDirs)
2146 f.Printf("targetdir:\n");
2147 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2152 // Main Module (Linking) for ECERE C modules
2153 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2154 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2155 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2156 console ? " -console" : "", objDirExpNoSpaces);
2157 // Main Module (Linking) for ECERE C modules
2158 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2159 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2160 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2161 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2162 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2167 // This would not rebuild the target on updated objects
2168 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2170 // This should fix it for good!
2171 f.Printf("$(SYMBOLS): | objdir\n");
2172 f.Printf("$(OBJECTS): | objdir\n");
2174 // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
2175 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2177 if(targetType == sharedLibrary || targetType == executable)
2179 // f.Printf("\tinstall_name_tool $(TARGET) $(LP)$(MODULE)%s\n", targetType == sharedLibrary ? "$(SO)" : "$(A)");
2180 //f.Printf("ifdef OSX\n");
2181 //f.Printf("ifeq \"$(TARGET_TYPE)\" \"sharedlib\"\n");
2182 //f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET) -install_name $(LP)$(MODULE)$(SO)\n");
2183 //f.Printf("endif\n");
2184 //f.Printf("else\n");
2185 //f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET)\n");
2186 //f.Printf("endif\n");
2187 f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET) $(INSTALLNAME)\n");
2191 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2195 f.Printf("ifndef WINDOWS\n");
2196 f.Printf("ifeq \"$(TARGET_TYPE)\" \"executable\"\n");
2197 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2198 f.Printf("endif\n");
2200 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2201 f.Printf("endif\n");
2204 if(resNode.files && resNode.files.count && !noResources)
2205 resNode.GenMakefileAddResources(f, resNode.path);
2208 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2210 //f.Printf("# POST-BUILD COMMANDS\n");
2211 if(options && options.postbuildCommands)
2213 for(s : options.postbuildCommands)
2214 if(s && s[0]) f.Printf("\t%s\n", s);
2216 if(config && config.options && config.options.postbuildCommands)
2218 for(s : config.options.postbuildCommands)
2219 if(s && s[0]) f.Printf("\t%s\n", s);
2221 if(platforms || (config && config.platforms))
2226 //f.Printf("# PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2227 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2229 PlatformOptions projectPOs = null;
2230 PlatformOptions configPOs = null;
2236 if(!strcmpi(p.name, platform))
2243 if(config && config.platforms)
2245 for(p : config.platforms)
2247 if(!strcmpi(p.name, platform))
2254 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2255 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2261 f.Printf(PlatformToMakefileVariable(platform));
2264 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2266 for(s : projectPOs.options.postbuildCommands)
2267 if(s && s[0]) f.Printf("\t%s\n", s);
2269 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2271 for(s : configPOs.options.postbuildCommands)
2272 if(s && s[0]) f.Printf("\t%s\n", s);
2279 for(c = 0; c < ifCount; c++)
2280 f.Printf("endif\n");
2286 f.Printf("# SYMBOL RULES\n\n");
2287 topNode.GenMakefilePrintSymbolRules(f, this);
2289 f.Printf("# C OBJECT RULES\n\n");
2290 topNode.GenMakefilePrintCObjectRules(f, this);
2294 f.Printf("# IMPLICIT OBJECT RULE\n\n");
2296 f.Printf("$(OBJ)%%$(O) : $(OBJ)%%.c\n");
2297 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $< -o $@\n\n");
2300 f.Printf("# OBJECT RULES\n\n");
2301 // todo call this still but only generate rules whith specific options
2302 // see we-have-file-specific-options in ProjectNode.ec
2303 topNode.GenMakefilePrintObjectRules(f, this, namesInfo);
2306 GenMakefilePrintMainObjectRule(f);
2308 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2309 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) " : "");
2310 OutputCleanActions(f, "OBJECTS", objectsParts);
2311 OutputCleanActions(f, "COBJECTS", cobjectsParts);
2314 OutputCleanActions(f, "IMPORTS", importsParts);
2315 OutputCleanActions(f, "SYMBOLS", symbolsParts);
2319 f.Printf("distclean: clean\n");
2320 f.Printf("\t$(call rmdirq,$(OBJ))\n");
2321 if(!sameObjTargetDirs)
2322 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2328 varStringLenDiffs.Free();
2329 delete varStringLenDiffs;
2336 // ChangeWorkingDir(oldDirectory);
2337 // delete pathBackup;
2340 config.makingModified = false;
2347 void GenMakefilePrintMainObjectRule(File f)
2349 char extension[MAX_EXTENSION] = "c";
2350 char modulePath[MAX_LOCATION];
2351 char fixedModuleName[MAX_FILENAME];
2354 char objDirNoSpaces[MAX_LOCATION];
2355 DirExpression objDirExp = objDir;
2357 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
2358 ReplaceSpaces(fixedModuleName, moduleName);
2360 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2361 //strcat(fixedModuleName, ".main");
2363 #if 0 // TODO: Fix nospaces stuff
2364 // *** Dependency command ***
2365 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2367 // System Includes (from global settings)
2368 for(item : compiler.dirs[Includes])
2370 strcat(command, " -isystem ");
2371 if(strchr(item.name, ' '))
2373 strcat(command, "\"");
2374 strcat(command, item);
2375 strcat(command, "\"");
2378 strcat(command, item);
2381 for(item = includeDirs.first; item; item = item.next)
2383 strcat(command, " -I");
2384 if(strchr(item.name, ' '))
2386 strcat(command, "\"");
2387 strcat(command, item.name);
2388 strcat(command, "\"");
2391 strcat(command, item.name);
2393 for(item = preprocessorDefs.first; item; item = item.next)
2395 strcat(command, " -D");
2396 strcat(command, item.name);
2400 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2404 bool firstLine = true;
2406 // To do some time: auto save external dependencies?
2409 if(dep.GetLine(line, sizeof(line)-1))
2413 char * colon = strstr(line, ":");
2414 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2428 // If we failed to generate dependencies...
2432 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2438 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2444 Project LegacyBinaryLoadProject(File f, char * filePath)
2446 Project project = null;
2447 char signature[sizeof(epjSignature)];
2449 f.Read(signature, sizeof(signature), 1);
2450 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2452 char topNodePath[MAX_LOCATION];
2453 /*ProjectConfig newConfig
2455 name = CopyString("Default");
2456 makingModified = true;
2457 compilingModified = true;
2458 linkingModified = true;
2462 project = Project { options = { } };
2463 LegacyBinaryLoadNode(project.topNode, f);
2464 delete project.topNode.path;
2465 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2466 MakeSlashPath(topNodePath);
2468 PathCatSlash(topNodePath, filePath);
2469 project.filePath = topNodePath;
2471 /* THIS IS ALREADY DONE BY filePath property
2472 StripLastDirectory(topNodePath, topNodePath);
2473 project.topNode.path = CopyString(topNodePath);
2475 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2477 // newConfig.options.defaultNameSpace = "";
2478 /*newConfig.objDir.dir = "obj";
2479 newConfig.targetDir.dir = "";*/
2481 //project.configurations = { [ newConfig ] };
2482 //project.config = newConfig;
2489 String targetFileName, targetDirectory, objectsDirectory;
2491 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2492 f.Read(&temp, sizeof(int),1);
2495 case 0: project.options.targetType = executable; break;
2496 case 1: project.options.targetType = sharedLibrary; break;
2497 case 2: project.options.targetType = staticLibrary; break;
2500 f.Read(&len, sizeof(int),1);
2501 targetFileName = new char[len+1];
2502 f.Read(targetFileName, sizeof(char), len+1);
2503 project.options.targetFileName = targetFileName;
2504 delete targetFileName;
2506 f.Read(&len, sizeof(int),1);
2507 targetDirectory = new char[len+1];
2508 f.Read(targetDirectory, sizeof(char), len+1);
2509 project.options.targetDirectory = targetDirectory;
2510 delete targetDirectory;
2512 f.Read(&len, sizeof(int),1);
2513 objectsDirectory = new byte[len+1];
2514 f.Read(objectsDirectory, sizeof(char), len+1);
2515 project.options.objectsDirectory = objectsDirectory;
2516 delete objectsDirectory;
2518 f.Read(&temp, sizeof(int),1);
2519 project./*config.*/options.debug = temp ? true : false;
2520 f.Read(&temp, sizeof(int),1);
2521 project./*config.*/options.optimization = temp ? speed : none;
2522 f.Read(&temp, sizeof(int),1);
2523 project./*config.*/options.profile = temp ? true : false;
2524 f.Read(&temp, sizeof(int),1);
2525 project.options.warnings = temp ? all : unset;
2527 f.Read(&count, sizeof(int),1);
2530 project.options.includeDirs = { };
2531 for(c = 0; c < count; c++)
2534 f.Read(&len, sizeof(int),1);
2535 name = new char[len+1];
2536 f.Read(name, sizeof(char), len+1);
2537 project.options.includeDirs.Add(name);
2541 f.Read(&count, sizeof(int),1);
2544 project.options.libraryDirs = { };
2545 for(c = 0; c < count; c++)
2548 f.Read(&len, sizeof(int),1);
2549 name = new char[len+1];
2550 f.Read(name, sizeof(char), len+1);
2551 project.options.libraryDirs.Add(name);
2555 f.Read(&count, sizeof(int),1);
2558 project.options.libraries = { };
2559 for(c = 0; c < count; c++)
2562 f.Read(&len, sizeof(int),1);
2563 name = new char[len+1];
2564 f.Read(name, sizeof(char), len+1);
2565 project.options.libraries.Add(name);
2569 f.Read(&count, sizeof(int),1);
2572 project.options.preprocessorDefinitions = { };
2573 for(c = 0; c < count; c++)
2576 f.Read(&len, sizeof(int),1);
2577 name = new char[len+1];
2578 f.Read(name, sizeof(char), len+1);
2579 project.options.preprocessorDefinitions.Add(name);
2583 f.Read(&temp, sizeof(int),1);
2584 project.options.console = temp ? true : false;
2587 for(node : project.topNode.files)
2589 if(node.type == resources)
2591 project.resNode = node;
2601 void ProjectConfig::LegacyProjectConfigLoad(File f)
2609 char subSection[128];
2615 f.GetLine(buffer, 65536 - 1);
2616 TrimLSpaces(buffer, buffer);
2617 TrimRSpaces(buffer, buffer);
2620 if(buffer[0] == '-')
2624 TrimLSpaces(equal, equal);
2625 if(!strcmpi(subSection, "LibraryDirs"))
2627 if(!options.libraryDirs)
2628 options.libraryDirs = { [ CopyString(equal) ] };
2630 options.libraryDirs.Add(CopyString(equal));
2632 else if(!strcmpi(subSection, "IncludeDirs"))
2634 if(!options.includeDirs)
2635 options.includeDirs = { [ CopyString(equal) ] };
2637 options.includeDirs.Add(CopyString(equal));
2640 else if(buffer[0] == '+')
2651 TrimLSpaces(equal, equal);
2652 delete name; name = CopyString(equal); // property::name = equal;
2655 else if(!strcmpi(buffer, "Compiler Options"))
2656 strcpy(section, buffer);
2657 else if(!strcmpi(buffer, "IncludeDirs"))
2658 strcpy(subSection, buffer);
2659 else if(!strcmpi(buffer, "Linker Options"))
2660 strcpy(section, buffer);
2661 else if(!strcmpi(buffer, "LibraryDirs"))
2662 strcpy(subSection, buffer);
2663 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
2670 equal = strstr(buffer, "=");
2674 TrimRSpaces(buffer, buffer);
2676 TrimLSpaces(equal, equal);
2677 if(!strcmpi(buffer, "Target Name"))
2678 options.targetFileName = /*CopyString(*/equal/*)*/;
2679 else if(!strcmpi(buffer, "Target Type"))
2681 if(!strcmpi(equal, "Executable"))
2682 options.targetType = executable;
2683 else if(!strcmpi(equal, "Shared"))
2684 options.targetType = sharedLibrary;
2685 else if(!strcmpi(equal, "Static"))
2686 options.targetType = staticLibrary;
2688 options.targetType = executable;
2690 else if(!strcmpi(buffer, "Target Directory"))
2691 options.targetDirectory = /*CopyString(*/equal/*)*/;
2692 else if(!strcmpi(buffer, "Console"))
2693 options.console = ParseTrueFalseValue(equal);
2694 else if(!strcmpi(buffer, "Libraries"))
2696 if(!options.libraries) options.libraries = { };
2697 ParseArrayValue(options.libraries, equal);
2699 else if(!strcmpi(buffer, "Intermediate Directory"))
2700 options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
2701 else if(!strcmpi(buffer, "Debug"))
2702 options.debug = ParseTrueFalseValue(equal);
2703 else if(!strcmpi(buffer, "Optimize"))
2705 if(!strcmpi(equal, "None"))
2706 options.optimization = none;
2707 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
2708 options.optimization = speed;
2709 else if(!strcmpi(equal, "Size"))
2710 options.optimization = size;
2712 options.optimization = none;
2714 else if(!strcmpi(buffer, "Compress"))
2715 options.compress = ParseTrueFalseValue(equal);
2716 else if(!strcmpi(buffer, "Profile"))
2717 options.profile = ParseTrueFalseValue(equal);
2718 else if(!strcmpi(buffer, "AllWarnings"))
2719 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
2720 else if(!strcmpi(buffer, "MemoryGuard"))
2721 options.memoryGuard = ParseTrueFalseValue(equal);
2722 else if(!strcmpi(buffer, "Default Name Space"))
2723 options.defaultNameSpace = CopyString(equal);
2724 else if(!strcmpi(buffer, "Strict Name Spaces"))
2725 options.strictNameSpaces = ParseTrueFalseValue(equal);
2726 else if(!strcmpi(buffer, "Preprocessor Definitions"))
2728 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
2729 ParseArrayValue(options.preprocessorDefinitions, equal);
2735 if(!options.targetDirectory && options.objectsDirectory)
2736 options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
2737 //if(!objDir.dir) objDir.dir = "obj";
2738 //if(!targetDir.dir) targetDir.dir = "";
2739 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
2740 // if(!defaultNameSpace) property::defaultNameSpace = "";
2741 makingModified = true;
2744 Project LegacyAsciiLoadProject(File f, char * filePath)
2746 Project project = null;
2747 ProjectNode node = null;
2749 char parentPath[MAX_LOCATION];
2750 char section[128] = "";
2751 char subSection[128] = "";
2753 bool configurationsPresent = false;
2763 f.GetLine(buffer, 65536 - 1);
2764 TrimLSpaces(buffer, buffer);
2765 TrimRSpaces(buffer, buffer);
2768 if(buffer[0] == '-' || buffer[0] == '=')
2770 bool simple = buffer[0] == '-';
2773 TrimLSpaces(equal, equal);
2774 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
2776 if(!project.config.options.libraryDirs) project.config.options.libraryDirs = { };
2777 project.config.options.libraryDirs.Add(CopyString(equal));
2779 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
2781 if(!project.config.options.includeDirs) project.config.options.includeDirs = { };
2782 project.config.options.includeDirs.Add(CopyString(equal));
2784 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
2786 len = strlen(equal);
2789 char temp[MAX_LOCATION];
2790 ProjectNode child { };
2791 // We don't need to do this anymore, fileName is just a property that sets name & path
2792 // child.fileName = CopyString(equal);
2795 child.name = CopyString(equal);
2796 child.path = CopyString(parentPath);
2800 GetLastDirectory(equal, temp);
2801 child.name = CopyString(temp);
2802 StripLastDirectory(equal, temp);
2803 child.path = CopyString(temp);
2805 child.nodeType = file;
2806 child.parent = parent;
2807 child.indent = parent.indent + 1;
2809 child.icon = NodeIcons::SelectFileIcon(child.name);
2810 parent.files.Add(child);
2816 StripLastDirectory(parentPath, parentPath);
2817 parent = parent.parent;
2821 else if(buffer[0] == '+')
2825 TrimLSpaces(equal, equal);
2826 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
2828 char temp[MAX_LOCATION];
2829 ProjectNode child { };
2830 // NEW: Folders now have a path set like files
2831 child.name = CopyString(equal);
2832 strcpy(temp, parentPath);
2833 PathCatSlash(temp, child.name);
2834 child.path = CopyString(temp);
2836 child.parent = parent;
2837 child.indent = parent.indent + 1;
2838 child.type = folder;
2839 child.nodeType = folder;
2841 child.icon = folder;
2842 PathCatSlash(parentPath, child.name);
2843 parent.files.Add(child);
2848 else if(!strcmpi(section, "Configurations"))
2850 ProjectConfig newConfig
2852 makingModified = true;
2856 LegacyProjectConfigLoad(newConfig, f);
2857 project.configurations.Add(newConfig);
2860 else if(!strcmpi(buffer, "ECERE Project File"));
2861 else if(!strcmpi(buffer, "Version 0a"))
2862 ; //strcpy(version, "0a");
2863 else if(!strcmpi(buffer, "Version 0.1a"))
2864 ; //strcpy(version, "0.1a");
2865 else if(!strcmpi(buffer, "Configurations"))
2867 project.configurations.Free();
2868 project.config = null;
2869 strcpy(section, buffer);
2870 configurationsPresent = true;
2872 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
2874 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
2875 char topNodePath[MAX_LOCATION];
2876 // newConfig.defaultNameSpace = "";
2877 //newConfig.objDir.dir = "obj";
2878 //newConfig.targetDir.dir = "";
2879 project = Project { /*options = { }*/ };
2880 project.configurations = { [ newConfig ] };
2881 project.config = newConfig;
2882 // if(project.topNode.path) delete project.topNode.path;
2883 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2884 MakeSlashPath(topNodePath);
2885 PathCatSlash(topNodePath, filePath);
2886 project.filePath = topNodePath;
2887 parentPath[0] = '\0';
2888 parent = project.topNode;
2890 strcpy(section, "Target");
2895 if(equal[0] == '\"')
2897 StripQuotes(equal, equal);
2898 delete project.moduleName; project.moduleName = CopyString(equal);
2902 else if(!strcmpi(buffer, "Compiler Options"));
2903 else if(!strcmpi(buffer, "IncludeDirs"))
2904 strcpy(subSection, buffer);
2905 else if(!strcmpi(buffer, "Linker Options"));
2906 else if(!strcmpi(buffer, "LibraryDirs"))
2907 strcpy(subSection, buffer);
2908 else if(!strcmpi(buffer, "Files"))
2910 strcpy(section, "Target");
2911 strcpy(subSection, buffer);
2913 else if(!strcmpi(buffer, "Resources"))
2915 ProjectNode child { };
2916 parent.files.Add(child);
2917 child.parent = parent;
2918 child.indent = parent.indent + 1;
2919 child.name = CopyString(buffer);
2920 child.path = CopyString("");
2921 child.type = resources;
2923 child.icon = archiveFile;
2924 project.resNode = child;
2927 strcpy(subSection, buffer);
2931 equal = strstr(buffer, "=");
2935 TrimRSpaces(buffer, buffer);
2937 TrimLSpaces(equal, equal);
2939 if(!strcmpi(section, "Target"))
2941 if(!strcmpi(buffer, "Build Exclusions"))
2943 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
2945 /*if(node && node.type != NodeTypes::project)
2946 ParseListValue(node.buildExclusions, equal);*/
2949 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
2951 delete project.resNode.path;
2952 project.resNode.path = CopyString(equal);
2953 PathCatSlash(parentPath, equal);
2957 else if(!strcmpi(buffer, "Intermediate Directory"))
2958 project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
2959 else if(!strcmpi(buffer, "Debug"))
2960 project.config.options.debug = ParseTrueFalseValue(equal);
2961 else if(!strcmpi(buffer, "Optimize"))
2963 if(!strcmpi(equal, "None"))
2964 project.config.options.optimization = none;
2965 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
2966 project.config.options.optimization = speed;
2967 else if(!strcmpi(equal, "Size"))
2968 project.config.options.optimization = size;
2970 project.config.options.optimization = none;
2972 else if(!strcmpi(buffer, "Profile"))
2973 project.config.options.profile = ParseTrueFalseValue(equal);
2974 else if(!strcmpi(buffer, "MemoryGuard"))
2975 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
2978 if(!project.options) project.options = { };
2980 // Project Wide Settings (All configs)
2981 if(!strcmpi(buffer, "Target Name"))
2982 project.options.targetFileName = /*CopyString(*/equal/*)*/;
2983 else if(!strcmpi(buffer, "Target Type"))
2985 if(!strcmpi(equal, "Executable"))
2986 project.options.targetType = executable;
2987 else if(!strcmpi(equal, "Shared"))
2988 project.options.targetType = sharedLibrary;
2989 else if(!strcmpi(equal, "Static"))
2990 project.options.targetType = staticLibrary;
2992 project.options.targetType = executable;
2994 else if(!strcmpi(buffer, "Target Directory"))
2995 project.options.targetDirectory = /*CopyString(*/equal/*)*/;
2996 else if(!strcmpi(buffer, "Console"))
2997 project.options.console = ParseTrueFalseValue(equal);
2998 else if(!strcmpi(buffer, "Libraries"))
3000 if(!project.options.libraries) project.options.libraries = { };
3001 ParseArrayValue(project.options.libraries, equal);
3003 else if(!strcmpi(buffer, "AllWarnings"))
3004 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3005 else if(!strcmpi(buffer, "Preprocessor Definitions"))
3007 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
3009 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
3010 ParseListValue(node.preprocessorDefs, equal);*/
3014 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
3015 ParseArrayValue(project.options.preprocessorDefinitions, equal);
3026 SplitPlatformLibraries(project);
3028 if(configurationsPresent)
3029 CombineIdenticalConfigOptions(project);
3033 void SplitPlatformLibraries(Project project)
3035 if(project && project.configurations)
3037 for(cfg : project.configurations)
3039 if(cfg.options.libraries && cfg.options.libraries.count)
3041 Iterator<String> it { cfg.options.libraries };
3045 char * platformName = strstr(l, ":");
3048 PlatformOptions platform = null;
3050 if(!cfg.platforms) cfg.platforms = { };
3051 for(p : cfg.platforms)
3053 if(!strcmpi(platformName, p.name))
3061 platform = { name = CopyString(platformName), options = { libraries = { } } };
3062 cfg.platforms.Add(platform);
3064 *(platformName-1) = 0;
3065 platform.options.libraries.Add(CopyString(l));
3067 cfg.options.libraries.Delete(it.pointer);
3076 void CombineIdenticalConfigOptions(Project project)
3078 if(project && project.configurations && project.configurations.count)
3081 ProjectOptions nullOptions { };
3082 ProjectConfig firstConfig = null;
3083 for(cfg : project.configurations)
3085 if(cfg.options.targetType != staticLibrary)
3092 firstConfig = project.configurations.firstIterator.data;
3094 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3096 if(!member.isProperty)
3098 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3103 for(cfg : project.configurations)
3105 if(cfg != firstConfig)
3107 if(cfg.options.targetType != staticLibrary)
3111 if(type.type == noHeadClass || type.type == normalClass)
3113 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3114 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3115 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3119 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3120 (byte *)firstConfig.options + member.offset + member._class.offset,
3121 (byte *)cfg.options + member.offset + member._class.offset);
3133 if(type.type == noHeadClass || type.type == normalClass)
3135 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3136 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3137 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3142 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3143 (byte *)firstConfig.options + member.offset + member._class.offset,
3144 (byte *)nullOptions + member.offset + member._class.offset))
3148 if(!project.options) project.options = { };
3150 /*if(type.type == noHeadClass || type.type == normalClass)
3152 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3153 (byte *)project.options + member.offset + member._class.offset,
3154 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3158 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3159 // TOFIX: ListBox::SetData / OnCopy mess
3160 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3161 (byte *)project.options + member.offset + member._class.offset,
3162 (type.typeSize > 4) ? address :
3163 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3164 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3165 (void *)*(byte *)address )));
3168 (byte *)project.options + member.offset + member._class.offset,
3169 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3171 for(cfg : project.configurations)
3173 if(cfg.options.targetType == staticLibrary)
3177 if(type.type == noHeadClass || type.type == normalClass)
3179 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3180 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3181 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3185 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3186 (byte *)firstConfig.options + member.offset + member._class.offset,
3187 (byte *)cfg.options + member.offset + member._class.offset);
3192 if(cfg != firstConfig)
3194 if(type.type == noHeadClass || type.type == normalClass)
3196 type._vTbl[__ecereVMethodID_class_OnFree](type,
3197 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3201 type._vTbl[__ecereVMethodID_class_OnFree](type,
3202 (byte *)cfg.options + member.offset + member._class.offset);
3204 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3207 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3214 // Compare Platform Specific Settings
3217 for(cfg : project.configurations)
3219 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3220 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3226 if(same && firstConfig.platforms)
3228 for(cfg : project.configurations)
3230 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3232 if(cfg != firstConfig)
3234 cfg.platforms.Free();
3235 delete cfg.platforms;
3238 project.platforms = firstConfig.platforms;
3239 firstConfig.platforms = null;
3243 // Static libraries can't contain libraries
3244 for(cfg : project.configurations)
3246 if(cfg.options.targetType == staticLibrary)
3248 if(!cfg.options.libraries) cfg.options.libraries = { };
3249 cfg.options.libraries.Free();
3255 Project LoadProject(char * filePath)
3257 Project project = null;
3258 File f = FileOpen(filePath, read);
3261 project = LegacyBinaryLoadProject(f, filePath);
3264 JSONParser parser { f = f };
3265 JSONResult result = parser.GetObject(class(Project), &project);
3268 char insidePath[MAX_LOCATION];
3270 delete project.topNode.files;
3271 if(!project.files) project.files = { };
3272 project.topNode.files = project.files;
3273 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3274 delete project.resNode.path;
3275 project.resNode.path = project.resourcesPath;
3276 project.resourcesPath = null;
3277 project.resNode.nodeType = (ProjectNodeType)-1;
3278 delete project.resNode.files;
3279 project.resNode.files = project.resources;
3280 project.files = null;
3281 project.resources = null;
3282 if(!project.configurations) project.configurations = { };
3285 char topNodePath[MAX_LOCATION];
3286 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3287 MakeSlashPath(topNodePath);
3288 PathCatSlash(topNodePath, filePath);
3289 project.filePath = topNodePath;//filePath;
3292 project.topNode.FixupNode(insidePath);
3297 project = LegacyAsciiLoadProject(f, filePath);
3303 if(!project.options) project.options = { };
3304 if(!project.config && project.configurations)
3305 project.config = project.configurations.firstIterator.data;
3307 if(!project.resNode)
3309 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3312 if(!project.moduleName)
3313 project.moduleName = CopyString(project.name);
3314 if(project.config &&
3315 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3316 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3318 //delete project.config.options.targetFileName;
3320 project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
3321 project.config.options.optimization = none;
3322 project.config.options.debug = true;
3323 //project.config.options.warnings = unset;
3324 project.config.options.memoryGuard = false;
3325 project.config.compilingModified = true;
3326 project.config.linkingModified = true;
3328 else if(!project.topNode.name && project.config)
3330 project.topNode.name = CopyString(project.config.options.targetFileName);
3333 /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
3334 project.topNode.configurations = project.configurations;
3335 project.topNode.platforms = project.platforms;
3336 project.topNode.options = project.options;*/