2 public import static "ecere"
7 #ifndef MAKEFILE_GENERATOR
14 import "ProjectConfig"
22 static void DummyFunction()
30 extern int __ecereVMethodID_class_OnCompare;
31 extern int __ecereVMethodID_class_OnFree;
33 IDESettings ideSettings;
35 IDESettingsContainer settingsContainer
38 dataOwner = &ideSettings;
39 dataClass = class(IDESettings);
41 void OnLoad(GlobalSettingsData data)
43 IDESettings settings = (IDESettings)data;
44 #ifndef MAKEFILE_GENERATOR
45 globalSettingsDialog.ideSettings = settings;
46 ide.UpdateRecentMenus();
47 // ide.UpdateMakefiles(); -- can't really regenerate on Load since all recent menus changes will happen
52 #ifdef MAKEFILE_GENERATOR
53 CompilerConfig defaultCompiler;
56 // LEGACY BINARY EPJ LOADING
58 SetBool ParseTrueFalseValue(char * string)
60 if(!strcmpi(string, "True")) return true;
64 void ParseArrayValue(Array<String> array, char * equal)
66 char * start, * comma;
68 string = CopyString(equal);
72 comma = strstr(start, ",");
75 array.Add(CopyString(start));
85 void ProjectNode::LegacyBinaryLoadNode(File f)
90 f.Read(&len, sizeof(len), 1);
91 name = new char[len+1];
93 f.Read(name, sizeof(char), len+1);
94 f.Read(&len, sizeof(len), 1);
96 path = new char[len+1];
97 f.Read(path, sizeof(char), len+1);
100 fileName = new char[fileNameLen+2];
101 strcpy(fileName, path);
102 if(fileName[0]) strcat(fileName, "/");
103 strcat(fileName, name);
106 f.Read(&type, sizeof(type), 1);
107 f.Read(&count, sizeof(count), 1);
112 icon = NodeIcons::SelectFileIcon(name);
117 icon = NodeIcons::SelectNodeIcon(type);
120 if(count && !files) files = { };
121 for(c = 0; c < count; c++)
123 ProjectNode child { };
126 child.indent = indent + 1;
127 LegacyBinaryLoadNode(child, f);
131 /*void LegacyBinarySaveNode(File f)
136 f.Write(&len, sizeof(len), 1);
137 f.Write(name, sizeof(char), len+1);
141 // Projects Absolute Path Are Not Saved
143 f.Write(&len, sizeof(len), 1);
144 f.Write(&len, sizeof(char), 1);
149 f.Write(&len, sizeof(len), 1);
150 f.Write(path, sizeof(char), len+1);
152 f.Write(&type, sizeof(type), 1);
153 f.Write(&children.count, sizeof(children.count), 1);
154 for(child = children.first; child; child.next)
158 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
161 char printPath[MAX_LOCATION];
163 if(type == project && (files.count /*|| preprocessorDefs.first*/))
165 f.Printf("\n Files\n");
167 else if(type == file)
169 if(!strcmp(path, insidePath))
170 f.Printf("%s - %s\n", indentation, name);
173 strcpy(printPath, path);
174 len = strlen(printPath);
176 if(printPath[len-1] != '/')
177 strcat(printPath, "/");
178 strcat(printPath, name);
179 f.Printf("%s = %s\n", indentation, printPath);
182 f.Printf("\nError\n\n");
184 else if(type == folder)
186 f.Printf("%s + %s\n", indentation, name);
188 else if(type == resources && files.count)
190 PathCatSlash(insidePath, path);
191 f.Printf("\n%sResources\n", indentation);
193 f.Printf("%s Path = %s\n", indentation, path);
196 /*if(buildExclusions.first && type != project)
198 for(item = buildExclusions.first; item; item = item.next)
200 if(item == buildExclusions.first)
201 f.Printf("%s Build Exclusions = %s", indentation, item.name);
203 f.Printf(", %s", item.name);
208 if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
210 for(item = preprocessorDefs.first; item; item = item.next)
212 if(item == preprocessorDefs.first)
213 f.Printf("%s%s Preprocessor Definitions = %s", indentation, type == project ? "" : " ", item.name);
215 f.Printf(", %s", item.name);
221 if(type == project && (files.count /*|| preprocessorDefs.first*/))
225 LegacyAsciiSaveNode(child, f, indentation, insidePath);
227 else if(type == folder)
229 strcat(indentation, " ");
230 // WHAT WAS THIS: strcpy(printPath, path);
231 // TOCHECK: why is Unix/PathCat not used here
232 len = strlen(insidePath);
234 if(insidePath[len-1] != '/')
235 strcat(insidePath, "/");
236 strcat(insidePath, name);
239 LegacyAsciiSaveNode(child, f, indentation, insidePath);
240 f.Printf("%s -\n", indentation);
241 indentation[strlen(indentation) - 3] = '\0';
242 StripLastDirectory(insidePath, insidePath);
244 else if(type == resources && files.count)
248 LegacyAsciiSaveNode(child, f, indentation, insidePath);
249 StripLastDirectory(insidePath, insidePath);
254 void ProjectConfig::LegacyProjectConfigSave(File f)
256 char * indentation = " ";
258 //f.Printf("\n * Common\n");
260 f.Printf("\n + %s\n", name);
261 f.Printf("\n Compiler\n\n");
262 if(objDir.expression[0])
263 f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
264 f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
265 switch(options.optimization)
267 // case none: f.Printf("%sOptimize = %s\n", indentation, "None"); break;
268 case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
269 case size: f.Printf("%sOptimize = %s\n", indentation, "Size"); break;
271 f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
273 f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
274 if(options.memoryGuard == true)
275 f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
276 if(options.strictNameSpaces == true)
277 f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
278 if(options.defaultNameSpace && strlen(options.defaultNameSpace))
279 f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
280 TOFIX: Compiler Bug {
281 if(options.preprocessorDefinitions.count)
284 for(item : options.preprocessorDefinitions)
288 f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
292 f.Printf(", %s", item);
297 if(options.includeDirs.count)
299 f.Printf("\n%sInclude Directories\n", indentation);
300 for(item : options.includeDirs)
301 f.Printf("%s - %s\n", indentation, name);
305 f.Printf("\n%sLinker\n\n", indentation);
306 f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
307 switch(options.targetType)
309 case executable: f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
310 case sharedLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Shared"); break;
311 case staticLibrary: f.Printf("%sTarget Type = %s\n", indentation, "Static"); break;
313 if(targetDir.expression[0])
314 f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
316 f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
318 f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
319 if(options.libraries.count)
322 for(item : options.libraries)
326 f.Printf("\n%sLibraries = %s", indentation, name);
330 f.Printf(", %s", item);
334 if(options.libraryDirs.count)
336 f.Printf("\n%sLibrary Directories\n\n", indentation);
337 for(item : options.libraryDirs)
338 f.Printf(" - %s\n", indentation, item);
342 void LegacyAsciiSaveProject(File f, Project project)
344 char indentation[128*3];
345 char path[MAX_LOCATION];
347 f.Printf("\nECERE Project File : Format Version 0.1b\n");
348 f.Printf("\nDescription\n%s\n.\n", project.description);
349 f.Printf("\nLicense\n%s\n.\n", project.license);
350 f.Printf("\nModule Name = %s\n", project.moduleName);
351 f.Printf("\n Configurations\n");
352 //////////////////////////////////////commonConfig.Save(f, true);
353 for(cfg : project.configurations)
354 LegacyProjectConfigSave(cfg, f);
356 strcpy(indentation, " ");
358 LegacyAsciiSaveNode(project.topNode, f, indentation, path);
364 // *** NEW JSON PROJECT FORMAT ***
365 public enum ProjectNodeType { file, folder };
367 // *******************************
369 define PEEK_RESOLUTION = (18.2 * 10);
375 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
377 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources };
379 define WorkspaceExtension = "ews";
380 define ProjectExtension = "epj";
382 void ReplaceSpaces(char * output, char * source)
387 for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
389 if(ch == ' ') output[dc++] = '\\';
392 if(ch == '(' || ch == ')') output[dc++] = '\\';
402 static void OutputNoSpace(File f, char * source)
404 char * output = new char[strlen(source)+1024];
405 ReplaceSpaces(output, source);
410 enum ListOutputMethod { inPlace, newLine, lineEach };
412 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs)
415 const int breakListLength = 1536;
416 const int breakLineLength = 78;
418 int c, len, itemCount = 0;
419 Array<int> breaks { };
423 MapNode<String, int> mn;
424 for(c=0; c<list.count; c++)
426 len = strlen(list[c]) + 3;
427 if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
429 for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
431 if(strstr(list[c], mn.key))
435 if(charCount + len > breakListLength)
437 breaks.Add(itemCount);
445 breaks.Add(itemCount);
446 numOfBreaks = breaks.count;
451 f.Printf("%s =", name);
452 for(c=0; c<numOfBreaks; c++)
453 f.Printf(" $(%s%d)", name, c+1);
457 f.Printf("%s =", name);
463 for(c=0; c<numOfBreaks; c++)
466 f.Printf("%s%d =", name, c+1);
469 itemCount = breaks[c];
470 for(n=offset; n<offset+itemCount; n++)
472 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]);
497 void OutputCleanActions(File f, char * name, int parts)
502 for(c=0; c<parts; c++)
503 f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
506 f.Printf("\t$(call rmq,$(%s))\n", name);
509 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace)
513 if(method == newLine)
517 if(method == lineEach)
519 f.Printf(" -%s", option);
521 OutputNoSpace(f, item);
523 f.Printf("%s", item);
528 static void OutputLibraries(File f, Array<String> libraries)
530 for(item : libraries)
532 char ext[MAX_EXTENSION];
533 char temp[MAX_LOCATION];
535 GetExtension(item, ext);
536 if(!strcmp(ext, "o") || !strcmp(ext, "a"))
540 if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
542 if(!strncmp(item, "lib", 3))
543 strcpy(temp, item + 3);
546 StripExtension(temp);
555 void CamelCase(char * string)
557 int c, len = strlen(string);
558 for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
559 string[c] = (char)tolower(string[c]);
562 CompilerConfig GetCompilerConfig()
564 #ifndef MAKEFILE_GENERATOR
565 CompilerConfig compiler = null;
566 if(ide && ide.workspace)
567 compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
570 incref defaultCompiler;
571 return defaultCompiler;
575 define localTargetType = config && config.options && config.options.targetType ?
576 config.options.targetType : options && options.targetType ?
577 options.targetType : TargetTypes::executable;
578 define localWarnings = config && config.options && config.options.warnings ?
579 config.options.warnings : options && options.warnings ?
580 options.warnings : WarningsOption::unset;
581 define localDebug = config && config.options && config.options.debug ?
582 config.options.debug : options && options.debug ?
583 options.debug : SetBool::unset;
584 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
585 config.options.memoryGuard : options && options.memoryGuard ?
586 options.memoryGuard : SetBool::unset;
587 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
588 config.options.noLineNumbers : options && options.noLineNumbers ?
589 options.noLineNumbers : SetBool::unset;
590 define localProfile = config && config.options && config.options.profile ?
591 config.options.profile : options && options.profile ?
592 options.profile : SetBool::unset;
593 define localOptimization = config && config.options && config.options.optimization ?
594 config.options.optimization : options && options.optimization ?
595 options.optimization : OptimizationStrategy::none;
596 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
597 config.options.defaultNameSpace : options && options.defaultNameSpace ?
598 options.defaultNameSpace : null;
599 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
600 config.options.strictNameSpaces : options && options.strictNameSpaces ?
601 options.strictNameSpaces : SetBool::unset;
602 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
603 define localTargetFileName = config && config.options && config.options.targetFileName ?
604 config.options.targetFileName : options && options.targetFileName ?
605 options.targetFileName : "";
606 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
607 config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
608 options.targetDirectory : null;
609 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
610 ideSettings.projectDefaultIntermediateObjDir[0] ?
611 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
612 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
613 config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
614 options.objectsDirectory : null;
615 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
616 ideSettings.projectDefaultIntermediateObjDir[0] ?
617 ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
618 define localConsole = config && config.options && config.options.console ?
619 config.options.console : options && options.console ?
620 options.console : SetBool::unset;
621 define localCompress = config && config.options && config.options.compress ?
622 config.options.compress : options && options.compress ?
623 options.compress : SetBool::unset;
625 char * PlatformToMakefileVariable(Platform platform)
627 return platform == win32 ? "WINDOWS" : platform == tux ? "LINUX" : platform == apple ? "OSX"/*"APPLE"*/ : platform;
630 class Project : struct
632 class_no_expansion; // To use Find on the Container<Project> in Workspace::projects
633 // We might want to tweak this default behavior of regular classes ?
634 // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
641 ProjectOptions options;
642 Array<PlatformOptions> platforms;
643 List<ProjectConfig> configurations;
644 LinkList<ProjectNode> files;
645 String resourcesPath;
646 LinkList<ProjectNode> resources;
649 // topNode.name holds the file name (.epj)
650 ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
653 ProjectConfig config;
655 // This is the file name stripped of the epj extension
656 // It should NOT be edited, saved or loaded anywhere
661 topNode.configurations = null;
662 topNode.platforms = null;
663 topNode.options = null;
665 if(platforms) { platforms.Free(); delete platforms; }
666 if(configurations) { configurations.Free(); delete configurations; }
667 if(files) { files.Free(); delete files; }
668 if(resources) { resources.Free(); delete resources; }
670 delete resourcesPath;
680 property char * configName { get { return config ? config.name : "Common"; } }
682 property ProjectConfig config
688 topNode.info = CopyString(configName);
691 property char * filePath
697 char string[MAX_LOCATION];
698 GetLastDirectory(value, string);
700 topNode.name = CopyString(string);
701 StripExtension(string);
703 name = CopyString(string);
704 StripLastDirectory(value, string);
706 topNode.path = CopyString(string);
708 filePath = CopyString(value);
713 property TargetTypes targetType
717 // TODO: Implement platform specific options?
718 TargetTypes targetType = localTargetType;
723 property char * objDirExpression
727 // TODO: Support platform options
728 char * expression = localObjectsDirectory;
730 expression = settingsObjectsDirectory;
734 property DirExpression objDir
738 char * expression = objDirExpression;
739 DirExpression objDir { type = intermediateObjectsDir };
740 objDir.Evaluate(expression, this);
744 property char * targetDirExpression
748 // TODO: Support platform options
749 char * expression = localObjectsDirectory;
751 expression = settingsObjectsDirectory;
755 property DirExpression targetDir
759 char * expression = targetDirExpression;
760 DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
761 targetDir.Evaluate(expression, this);
766 property WarningsOption warnings
770 WarningsOption warnings = localWarnings;
778 SetBool debug = localDebug;
779 return debug == true;
782 property bool memoryGuard
786 SetBool memoryGuard = localMemoryGuard;
787 return memoryGuard == true;
790 property bool noLineNumbers
794 SetBool noLineNumbers = localNoLineNumbers;
795 return noLineNumbers == true;
798 property bool profile
802 SetBool profile = localProfile;
803 return profile == true;
806 property OptimizationStrategy optimization
810 OptimizationStrategy optimization = localOptimization;
814 property String defaultNameSpace
818 String defaultNameSpace = localDefaultNameSpace;
819 return defaultNameSpace;
822 property bool strictNameSpaces
826 SetBool strictNameSpaces = localStrictNameSpaces;
827 return strictNameSpaces == true;
830 property String targetFileName
834 String targetFileName = localTargetFileName;
835 return targetFileName;
838 //String targetDirectory;
839 //String objectsDirectory;
840 property bool console
844 SetBool console = localConsole;
845 return console == true;
848 property bool compress
852 SetBool compress = localCompress;
853 return compress == true;
856 //SetBool excludeFromBuild;
858 property bool configIsInActiveDebugSession
862 #ifndef MAKEFILE_GENERATOR
863 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
868 property bool configIsInDebugSession
872 #ifndef MAKEFILE_GENERATOR
873 return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
878 void SetPath(bool projectsDirs)
880 #ifndef MAKEFILE_GENERATOR
881 ide.SetPath(projectsDirs);
885 #ifndef MAKEFILE_GENERATOR
886 bool Save(char * fileName)
889 /*char output[MAX_LOCATION];
890 ChangeExtension(fileName, "json", output);
891 f = FileOpen(output, write);*/
892 f = FileOpen(fileName, write);
895 files = topNode.files;
896 resources = resNode.files;
897 resourcesPath = resNode.path;
899 files.Remove(resNode);
902 WriteJSONObject(f, class(Project), this, 0);
908 resourcesPath = null;
915 #ifndef MAKEFILE_GENERATOR
916 bool GetRelativePath(char * filePath, char * relativePath)
919 char moduleName[MAX_FILENAME];
920 GetLastDirectory(filePath, moduleName);
921 // try with workspace dir first?
922 if((node = topNode.Find(moduleName, false)))
924 strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
925 PathCatSlash(relativePath, node.name);
928 // WARNING: On failure, relative path is uninitialized
933 void CatTargetFileName(char * string)
935 CompilerConfig compiler = GetCompilerConfig();
937 if(targetType == staticLibrary)
939 PathCatSlash(string, "lib");
940 strcat(string, targetFileName);
942 else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
944 PathCatSlash(string, "lib");
945 strcat(string, targetFileName);
948 PathCatSlash(string, targetFileName);
953 if(compiler.targetPlatform == win32)
954 strcat(string, ".exe");
957 if(compiler.targetPlatform == win32)
958 strcat(string, ".dll");
959 else if(compiler.targetPlatform == apple)
960 strcat(string, ".dylib");
962 strcat(string, ".so");
965 strcat(string, ".a");
971 void CatMakeFileName(char * string)
973 char projectName[MAX_LOCATION];
974 CompilerConfig compiler = GetCompilerConfig();
975 strcpy(projectName, name);
976 if(strcmpi(compiler.name, defaultCompilerName))
977 sprintf(string, "%s-%s-%s.Makefile", projectName, compiler.name, config.name);
979 sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
983 #ifndef MAKEFILE_GENERATOR
984 void MarkChanges(ProjectNode node)
986 for(cfg : topNode.configurations)
988 ProjectConfig c = null;
989 for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
991 if(c && cfg.options.console != c.options.console)
992 cfg.symbolGenModified = true;
994 cfg.makingModified = true;
998 void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1000 for(cfg : configurations)
1003 cfg.makingModified = true;
1005 cfg.compilingModified = true;
1007 cfg.linkingModified = true;
1009 cfg.symbolGenModified = true;
1011 if(compiling || linking)
1013 ide.projectView.modifiedDocument = true;
1014 ide.workspace.modified = true;
1018 void RotateActiveConfig(bool forward)
1020 if(configurations.first && configurations.last != configurations.first)
1022 Iterator<ProjectConfig> cfg { configurations };
1023 while(forward ? cfg.Next() : cfg.Prev())
1024 if(cfg.data == config)
1038 property::config = cfg.data;
1039 ide.workspace.modified = true;
1040 ide.projectView.Update(null);
1044 void ProcessPipeOutputRaw(DualPipe f)
1047 while(!f.Eof() && !ide.ShouldStopBuild())
1050 double lastTime = GetTime();
1054 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1056 ide.outputView.buildBox.Logf("%s\n", line);
1058 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1060 //printf("Processing Input...\n");
1061 if(app.ProcessInput(true))
1063 app.UpdateDisplay();
1066 //printf("Waiting...\n");
1069 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1071 if(ide.ShouldStopBuild())
1073 ide.outputView.buildBox.Logf("\nBuild cancelled by user.\n", line);
1078 bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, ProjectNode onlyNode)
1081 bool compiling = false, linking = false, precompiling = false;
1082 int compilingEC = 0;
1083 int numErrors = 0, numWarnings = 0;
1084 bool loggedALine = false;
1085 CompilerConfig compiler = GetCompilerConfig();
1086 int lenMakeCommand = strlen(compiler.makeCommand);
1088 char cppCommand[MAX_LOCATION];
1089 char ccCommand[MAX_LOCATION];
1090 char ecpCommand[MAX_LOCATION];
1091 char eccCommand[MAX_LOCATION];
1092 char ecsCommand[MAX_LOCATION];
1093 char earCommand[MAX_LOCATION];
1095 sprintf(cppCommand, "%s ", compiler.cppCommand);
1096 sprintf(ccCommand, "%s ", compiler.ccCommand);
1097 sprintf(ecpCommand, "%s ", compiler.ecpCommand);
1098 sprintf(eccCommand, "%s ", compiler.eccCommand);
1099 sprintf(ecsCommand, "%s ", compiler.ecsCommand);
1100 sprintf(earCommand, "%s ", compiler.earCommand);
1102 while(!f.Eof() && !ide.ShouldStopBuild())
1105 double lastTime = GetTime();
1109 //printf("Peeking and GetLine...\n");
1110 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1112 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1114 char * module = strstr(line, "No rule to make target `");
1118 module = strchr(module, '`') + 1;
1119 end = strchr(module, '\'');
1123 ide.outputView.buildBox.Logf(" %s: No such file or directory\n", module);
1124 // ide.outputView.buildBox.Logf("error: %s\n No such file or directory\n", module);
1130 //ide.outputView.buildBox.Logf("error: %s\n", line);
1134 else if(strstr(line, "ear ") == line);
1135 else if(strstr(line, "strip ") == line);
1136 else if(strstr(line, ccCommand) == line || strstr(line, ecpCommand) == line || strstr(line, eccCommand) == line)
1138 char moduleName[MAX_FILENAME];
1141 bool isPrecomp = false;
1143 if(strstr(line, ccCommand) == line)
1145 module = strstr(line, " -c ");
1146 if(module) module += 4;
1148 else if(strstr(line, eccCommand) == line)
1150 module = strstr(line, " -c ");
1151 if(module) module += 4;
1152 //module = line + 3;
1153 // Don't show GCC warnings about generated C code because it does not compile clean yet...
1154 compilingEC = 3;//2;
1156 else if(strstr(line, ecpCommand) == line)
1158 // module = line + 8;
1159 module = strstr(line, " -c ");
1160 if(module) module += 4;
1169 if(!compiling && !isPrecomp)
1171 ide.outputView.buildBox.Logf("Compiling...\n");
1174 else if(!precompiling && isPrecomp)
1176 ide.outputView.buildBox.Logf("Generating symbols...\n");
1177 precompiling = true;
1179 Tokenize(module, 1, tokens, false);
1180 GetLastDirectory(module, moduleName);
1181 ide.outputView.buildBox.Logf("%s\n", moduleName);
1183 else if((module = strstr(line, " -o ")))
1186 precompiling = false;
1188 ide.outputView.buildBox.Logf("Linking...\n");
1192 ide.outputView.buildBox.Logf("%s\n", line);
1196 if(compilingEC) compilingEC--;
1198 else if(strstr(line, "ar rcs") == line)
1199 ide.outputView.buildBox.Logf("Building library...\n");
1200 else if(strstr(line, ecsCommand) == line)
1201 ide.outputView.buildBox.Logf("Writing symbol loader...\n");
1204 if(linking || compiling || precompiling)
1206 char * colon = strstr(line, ":"); //, * bracket;
1207 if(colon && (colon[1] == '/' || colon[1] == '\\'))
1208 colon = strstr(colon + 1, ":");
1211 char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1213 int len = (int)(colon - line);
1214 len = Min(len, MAX_LOCATION-1);
1215 // Don't be mistaken by the drive letter colon
1217 // TODO: need to fix colon - line gives char *
1218 // warning: incompatible expression colon - line (char *); expected int
1220 strncpy(moduleName, line, (int)(colon - line));
1221 moduleName[colon - line] = '\0';
1223 strncpy(moduleName, line, len);
1224 moduleName[len] = '\0';
1225 // Remove stuff in brackets
1226 //bracket = strstr(moduleName, "(");
1227 //if(bracket) *bracket = '\0';
1229 GetLastDirectory(moduleName, temp);
1230 if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1233 strcpy(moduleName, "Linker Error");
1237 strcpy(temp, topNode.path);
1238 PathCatSlash(temp, moduleName);
1239 MakePathRelative(temp, topNode.path, moduleName);
1241 if(strstr(line, "error:"))
1245 // Silence warnings for compiled EC
1246 char * objDir = strstr(moduleName, objDirExp.dir);
1250 if((pointer = strstr(line, "undefined")) ||
1251 (pointer = strstr(line, "No such file")) ||
1252 (pointer = strstr(line, "token")))
1254 strncat(moduleName, colon, pointer - colon);
1255 strcat(moduleName, "error: ");
1260 else if((pointer = strstr(line, "No such file")))
1262 strncat(moduleName, colon, pointer - colon);
1263 strcat(moduleName, "error: ");
1267 else if(compilingEC == 1 || (objDir && objDir == moduleName))
1269 else if(strstr(line, "warning:"))
1274 if(this == ide.workspace.projects.firstIterator.data)
1275 ide.outputView.buildBox.Logf(" %s%s\n", moduleName, colon);
1278 char fullModuleName[MAX_LOCATION];
1279 strcpy(fullModuleName, topNode.path);
1280 PathCat(fullModuleName, moduleName);
1281 MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1282 MakeSystemPath(fullModuleName);
1283 ide.outputView.buildBox.Logf(" %s%s\n", fullModuleName, colon);
1288 ide.outputView.buildBox.Logf("%s\n", line);
1289 linking = compiling = precompiling = false;
1293 ide.outputView.buildBox.Logf("%s\n", line);
1297 //printf("Done getting line\n");
1298 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1300 //printf("Processing Input...\n");
1301 if(app.ProcessInput(true))
1303 app.UpdateDisplay();
1306 //printf("Waiting...\n");
1309 //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1311 if(ide.ShouldStopBuild())
1313 ide.outputView.buildBox.Logf("\nBuild cancelled by user.\n", line);
1316 else if(loggedALine || !isARun)
1318 if(f.GetExitCode() && !numErrors)
1320 bool result = f.GetLine(line, sizeof(line)-1);
1321 ide.outputView.buildBox.Logf("Fatal Error: child process terminated unexpectedly\n");
1326 ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, configName);
1328 ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? "errors" : "error");
1330 ide.outputView.buildBox.Logf("no error, ");
1333 ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? "warnings" : "warning");
1335 ide.outputView.buildBox.Logf("no warning\n");
1340 return numErrors == 0;
1343 void ProcessCleanPipeOutput(DualPipe f)
1346 CompilerConfig compiler = GetCompilerConfig();
1347 int lenMakeCommand = strlen(compiler.makeCommand);
1352 double lastTime = GetTime();
1355 if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1357 if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1358 else if(strstr(line, "del") == line);
1359 else if(strstr(line, "rm") == line);
1360 else if(strstr(line, "Could Not Find") == line);
1363 ide.outputView.buildBox.Logf(line);
1364 ide.outputView.buildBox.Logf("\n");
1368 if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1370 if(app.ProcessInput(true))
1372 app.UpdateDisplay();
1375 //Sleep(1.0 / PEEK_RESOLUTION);
1380 bool Build(bool isARun, ProjectNode onlyNode)
1382 bool result = false;
1384 char targetFileName[MAX_LOCATION] = "";
1385 char makeTarget[MAX_LOCATION] = "";
1386 char makeFile[MAX_LOCATION];
1387 char makeFilePath[MAX_LOCATION];
1388 char oldPath[MAX_LOCATION * 65];
1389 char configName[MAX_LOCATION];
1390 CompilerConfig compiler = GetCompilerConfig();
1391 DirExpression objDirExp = objDir;
1393 int numJobs = compiler.numJobs;
1394 char command[MAX_LOCATION];
1396 GetEnvironment("PATH", oldPath, sizeof(oldPath));
1398 strcpy(configName, this.configName);
1400 SetPath(false); //true
1401 CatTargetFileName(targetFileName);
1403 strcpy(makeFilePath, topNode.path);
1404 CatMakeFileName(makeFile);
1405 PathCatSlash(makeFilePath, makeFile);
1407 // TODO: TEST ON UNIX IF \" around makeTarget is ok
1410 if(compiler.type.isVC)
1412 PrintLn("compiling a single file is not yet supported");
1417 char pushD[MAX_LOCATION];
1418 GetWorkingDir(pushD, sizeof(pushD));
1419 ChangeWorkingDir(topNode.path);
1420 // Create object dir if it does not exist already
1421 if(!FileExists(objDirExp.dir).isDirectory)
1422 Execute("%s objdir -C \"%s\" -f \"%s\"", compiler.makeCommand, topNode.path, makeFilePath);
1423 ChangeWorkingDir(pushD);
1425 PathCatSlash(makeTarget+1, objDirExp.dir);
1426 PathCatSlash(makeTarget+1, onlyNode.name);
1427 StripExtension(makeTarget+1);
1428 strcat(makeTarget+1, ".o");
1429 makeTarget[0] = '\"';
1430 len = strlen(makeTarget);
1431 makeTarget[len++] = '\"';
1432 makeTarget[len++] = '\0';
1436 if(compiler.type.isVC)
1438 bool result = false;
1439 char oldwd[MAX_LOCATION];
1440 GetWorkingDir(oldwd, sizeof(oldwd));
1441 ChangeWorkingDir(topNode.path);
1443 sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1444 ide.outputView.buildBox.Logf("command: %s\n", command);
1445 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1447 ProcessPipeOutputRaw(f);
1451 ChangeWorkingDir(oldwd);
1455 sprintf(command, "%s -j%d %s -C \"%s\" -f \"%s\"", compiler.makeCommand, numJobs, makeTarget, topNode.path, makeFilePath);
1456 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1458 result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNode);
1462 ide.outputView.buildBox.Logf("Error executing make (%s) command\n", compiler.makeCommand);
1465 SetEnvironment("PATH", oldPath);
1474 char oldPath[MAX_LOCATION * 65];
1475 char makeFile[MAX_LOCATION];
1476 char makeFilePath[MAX_LOCATION];
1477 char command[MAX_LOCATION];
1479 CompilerConfig compiler = GetCompilerConfig();
1481 GetEnvironment("PATH", oldPath, sizeof(oldPath));
1485 strcpy(makeFilePath, topNode.path);
1486 CatMakeFileName(makeFile);
1487 PathCatSlash(makeFilePath, makeFile);
1489 if(compiler.type.isVC)
1491 bool result = false;
1492 char oldwd[MAX_LOCATION];
1493 GetWorkingDir(oldwd, sizeof(oldwd));
1494 ChangeWorkingDir(topNode.path);
1496 sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
1497 ide.outputView.buildBox.Logf("command: %s\n", command);
1498 if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
1500 ProcessPipeOutputRaw(f);
1504 ChangeWorkingDir(oldwd);
1509 sprintf(command, "%s clean -C \"%s\" -f \"%s\"", compiler.makeCommand, topNode.path, makeFilePath);
1510 if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
1512 ide.outputView.buildBox.Tell("Deleting target and object files...");
1513 ProcessCleanPipeOutput(f);
1516 ide.outputView.buildBox.Logf("Target and object files deleted\n");
1520 SetEnvironment("PATH", oldPath);
1524 void Run(char * args)
1526 char target[MAX_LOCATION * 65], oldDirectory[MAX_LOCATION];
1527 char oldPath[MAX_LOCATION * 65];
1528 DirExpression targetDirExp = targetDir;
1529 CompilerConfig compiler = GetCompilerConfig();
1531 GetEnvironment("PATH", oldPath, sizeof(oldPath));
1533 // Build(project, ideMain, true, null);
1535 #if defined(__WIN32__)
1536 strcpy(target, topNode.path);
1540 PathCatSlash(target, targetDirExp.dir);
1541 CatTargetFileName(target);
1542 sprintf(target, "%s %s", target, args);
1543 GetWorkingDir(oldDirectory, MAX_LOCATION);
1545 if(strlen(ide.workspace.debugDir))
1547 char temp[MAX_LOCATION];
1548 strcpy(temp, topNode.path);
1549 PathCatSlash(temp, ide.workspace.debugDir);
1550 ChangeWorkingDir(temp);
1553 ChangeWorkingDir(topNode.path);
1554 // ChangeWorkingDir(topNode.path);
1556 if(compiler.execPrefixCommand)
1558 char * prefixedTarget = new char[strlen(compiler.execPrefixCommand) + strlen(target) + 2];
1559 prefixedTarget[0] = '\0';
1560 strcat(prefixedTarget, compiler.execPrefixCommand);
1561 strcat(prefixedTarget, " ");
1562 strcat(prefixedTarget, target);
1563 Execute(prefixedTarget);
1564 delete prefixedTarget;
1569 ChangeWorkingDir(oldDirectory);
1570 SetEnvironment("PATH", oldPath);
1572 delete targetDirExp;
1576 void Compile(ProjectNode node)
1582 void GetMakefileTargetFileName(TargetTypes targetType, char * fileName)
1584 char s[MAX_LOCATION];
1586 if(targetType == staticLibrary || targetType == sharedLibrary)
1587 strcat(fileName, "$(LP)");
1588 ReplaceSpaces(s, targetFileName);
1589 strcat(fileName, s);
1593 strcat(fileName, "$(E)");
1596 strcat(fileName, "$(SO)");
1599 strcat(fileName, "$(A)");
1604 bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath)
1606 bool result = false;
1607 char filePath[MAX_LOCATION];
1608 char makeFile[MAX_LOCATION];
1609 CompilerConfig compiler = GetCompilerConfig();
1610 /*char oldPath[MAX_LOCATION * 65];
1611 char oldDirectory[MAX_LOCATION];*/
1614 if(!altMakefilePath)
1616 strcpy(filePath, topNode.path);
1617 CatMakeFileName(makeFile);
1618 PathCatSlash(filePath, makeFile);
1621 #if defined(__WIN32__) && !defined(MAKEFILE_GENERATOR)
1622 if(compiler.type.isVC)
1624 GenerateVSSolutionFile(this);
1625 GenerateVCProjectFile(this);
1629 f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
1631 /*GetEnvironment("PATH", oldPath, sizeof(oldPath));
1633 GetWorkingDir(oldDirectory, MAX_LOCATION);
1634 ChangeWorkingDir(topNode.path);*/
1638 char temp[MAX_LOCATION];
1639 char target[MAX_LOCATION];
1640 char targetNoSpaces[MAX_LOCATION];
1641 char objDirExpNoSpaces[MAX_LOCATION];
1642 char objDirNoSpaces[MAX_LOCATION];
1643 char resDirNoSpaces[MAX_LOCATION];
1644 char targetDirExpNoSpaces[MAX_LOCATION];
1645 char fixedModuleName[MAX_FILENAME];
1646 char fixedConfigName[MAX_FILENAME];
1647 char fixedCompilerName[MAX_FILENAME];
1649 int numCObjects = 0;
1650 bool sameObjTargetDirs;
1651 DirExpression objDirExp = objDir;
1653 bool crossCompiling = compiler.targetPlatform != GetRuntimePlatform();
1654 bool gccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "gcc") != null;
1655 bool tccCompiler = compiler.ccCommand && strstr(compiler.ccCommand, "tcc") != null;
1656 bool defaultPreprocessor = compiler.cppCommand && (strstr(compiler.cppCommand, "gcc") != null || compiler.cppCommand && strstr(compiler.cppCommand, "cpp") != null);
1658 int objectsParts, cobjectsParts, symbolsParts, importsParts;
1659 Array<String> listItems { };
1660 Map<String, int> varStringLenDiffs { };
1661 Map<String, NameCollisionInfo> namesInfo { };
1663 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
1664 strcpy(temp, targetDirExpression);
1665 ReplaceSpaces(targetDirExpNoSpaces, temp);
1666 GetMakefileTargetFileName(targetType, target);
1667 PathCatSlash(temp, target);
1668 ReplaceSpaces(targetNoSpaces, temp);
1670 strcpy(objDirExpNoSpaces, objDirExpression);
1671 ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1672 ReplaceSpaces(objDirExpNoSpaces, objDirExpNoSpaces);
1673 ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
1674 //ReplaceSpaces(fixedPrjName, name);
1675 ReplaceSpaces(fixedModuleName, moduleName);
1676 ReplaceSpaces(fixedConfigName, configName);
1677 ReplaceSpaces(fixedCompilerName, compiler.name);
1678 //CamelCase(fixedModuleName); // case is important for static linking
1679 CamelCase(fixedConfigName);
1680 CamelCase(fixedCompilerName);
1682 sameObjTargetDirs = !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
1684 f.Printf(".PHONY: all objdir%s clean distclean\n\n", sameObjTargetDirs ? "" : " targetdir");
1686 f.Printf("# CONTENT\n\n");
1688 f.Printf("MODULE := %s\n", fixedModuleName);
1689 //f.Printf("VERSION = %s\n", version);
1690 f.Printf("CONFIG := %s\n", fixedConfigName);
1691 f.Printf("COMPILER := %s\n", fixedCompilerName);
1693 f.Printf("PLATFORM = %s\n", (char *)compiler.targetPlatform);
1694 f.Printf("TARGET_TYPE = %s\n", targetType == executable ? "executable" :
1695 (targetType == sharedLibrary ? "sharedlib" : (targetType == staticLibrary ? "staticlib" : "unknown")));
1698 f.Printf("OBJ = %s%s\n\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
1700 f.Printf("RES = %s%s\n\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
1702 if(targetType == executable)
1703 f.Printf("CONSOLE = %s\n\n", console ? "-mconsole" : "-mwindows");
1705 f.Printf("TARGET = %s\n\n", targetNoSpaces);
1707 varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
1709 topNode.GenMakefileGetNameCollisionInfo(namesInfo);
1711 numCObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems);
1713 listItems.Add(CopyString("$(OBJ)$(MODULE).main$(O)"));
1714 objectsParts = OutputFileList(f, "OBJECTS", listItems, varStringLenDiffs);
1716 topNode.GenMakefilePrintNode(f, this, cObjects, namesInfo, listItems);
1717 cobjectsParts = OutputFileList(f, "COBJECTS", listItems, varStringLenDiffs);
1719 topNode.GenMakefilePrintNode(f, this, symbols, null, listItems);
1720 symbolsParts = OutputFileList(f, "SYMBOLS", listItems, varStringLenDiffs);
1722 topNode.GenMakefilePrintNode(f, this, imports, null, listItems);
1723 importsParts = OutputFileList(f, "IMPORTS", listItems, varStringLenDiffs);
1725 topNode.GenMakefilePrintNode(f, this, sources, null, listItems);
1726 OutputFileList(f, "SOURCES", listItems, varStringLenDiffs);
1729 resNode.GenMakefilePrintNode(f, this, resources, null, listItems);
1730 OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs);
1734 f.Printf("# CROSS-PLATFORM MAGIC\n\n");
1736 f.Printf("include %s\n\n", includemkPath);
1740 File include = FileOpen(":include.mk", read);
1743 for(; !include.Eof(); )
1746 int count = include.Read(buffer, 1, 4096);
1747 f.Write(buffer, 1, count);
1753 f.Printf("# TOOLCHAIN\n\n");
1755 //f.Printf("SHELL := %s\n", "ar"/*compiler.arCommand*/); // is this really needed?
1756 f.Printf("CPP := %s\n", compiler.cppCommand);
1757 f.Printf("CC := %s\n", compiler.ccCommand);
1758 f.Printf("ECP := %s\n", compiler.ecpCommand);
1759 f.Printf("ECC := %s\n", compiler.eccCommand);
1760 f.Printf("ECS := %s%s%s\n", compiler.ecsCommand,
1761 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1762 f.Printf("EAR := %s\n", compiler.earCommand);
1763 f.Printf("LD := %s\n", compiler.ccCommand);
1764 f.Printf("AR := %s\n", "ar"/*compiler.arCommand*/);
1765 f.Printf("STRIP := %s\n", "strip"/*compiler.stripCommand*/);
1766 f.Printf("UPX := %s\n", "upx"/*compiler.upxCommand*/);
1769 f.Printf("# FLAGS\n\n");
1771 f.Printf("CFLAGS =");
1774 f.Printf(" -fmessage-length=0");
1775 switch(optimization)
1779 f.Printf(" -ffast-math");
1785 //if(compiler.targetPlatform.is32Bits)
1787 //else if(compiler.targetPlatform.is64Bits)
1788 // f.Printf(" -m64");
1789 f.Printf(" $(FPIC)");
1790 //f.Printf(" -fpack-struct");
1796 if(warnings == none)
1803 if(options && options.linkerOptions && options.linkerOptions.count)
1805 f.Printf(" \\\n\t -Wl");
1806 for(s : options.linkerOptions)
1810 if(options && options.preprocessorDefinitions)
1811 OutputListOption(f, "D", options.preprocessorDefinitions, newLine, false);
1812 if(config && config.options && config.options.preprocessorDefinitions)
1813 OutputListOption(f, "D", config.options.preprocessorDefinitions, newLine, false);
1815 OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true);
1816 if(options && options.includeDirs)
1817 OutputListOption(f, "I", options.includeDirs, lineEach, true);
1818 if(config && config.options && config.options.includeDirs)
1819 OutputListOption(f, "I", config.options.includeDirs, lineEach, true);
1822 f.Printf("CECFLAGS =%s%s%s%s", defaultPreprocessor ? "" : " -cpp ", defaultPreprocessor ? "" : compiler.cppCommand,
1823 crossCompiling ? " -t " : "", crossCompiling ? (char*)compiler.targetPlatform : "");
1826 f.Printf("ECFLAGS =");
1828 f.Printf(" -memguard");
1829 if(strictNameSpaces)
1830 f.Printf(" -strictns");
1832 f.Printf(" -nolinenumbers");
1835 if((s = defaultNameSpace) && s[0])
1836 f.Printf(" -defaultns %s", s);
1840 if(targetType != staticLibrary)
1842 f.Printf("OFLAGS = -m32"); // TARGET_TYPE is fixed in a Makefile, we don't want this. $(if TARGET_TYPE_STATIC_LIBRARY,,-m32)");
1846 OutputListOption(f, "L", compiler.libraryDirs, lineEach, true);
1847 if(options && options.libraryDirs)
1848 OutputListOption(f, "L", options.libraryDirs, lineEach, true);
1849 if(config && config.options && config.options.libraryDirs)
1850 OutputListOption(f, "L", config.options.libraryDirs, lineEach, true);
1855 if(targetType != staticLibrary)
1857 if(config && config.options && config.options.libraries)
1858 OutputLibraries(f, config.options.libraries);
1859 else if(options && options.libraries)
1860 OutputLibraries(f, options.libraries);
1862 f.Printf(" $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n\n");
1864 f.Printf("UPXFLAGS = -9\n\n"); // TOFEAT: Compression Level Option? Other UPX Options?
1866 f.Printf("# HARD CODED PLATFORM-SPECIFIC OPTIONS\n");
1867 f.Printf("ifdef %s\n", PlatformToMakefileVariable(tux));
1868 f.Printf("OFLAGS += -Wl,--no-undefined\n");
1869 f.Printf("endif\n\n");
1872 f.Printf("ifdef %s\n", PlatformToMakefileVariable(apple));
1873 f.Printf("OFLAGS += -framework cocoa -framework OpenGL\n");
1874 f.Printf("endif\n\n");
1876 if(platforms || (config && config.platforms))
1880 //for(platform = firstPlatform; platform <= lastPlatform; platform++)
1881 //for(platform = win32; platform <= apple; platform++)
1883 f.Printf("# PLATFORM-SPECIFIC OPTIONS\n\n");
1884 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1886 PlatformOptions projectPlatformOptions = null;
1887 PlatformOptions configPlatformOptions = null;
1893 if(!strcmpi(p.name, platform))
1895 projectPlatformOptions = p;
1900 if(config && config.platforms)
1902 for(p : config.platforms)
1904 if(!strcmpi(p.name, platform))
1906 configPlatformOptions = p;
1911 if(projectPlatformOptions || configPlatformOptions)
1917 // we should have some kind of direct mapping between a platform and it's makefile variable
1918 f.Printf(PlatformToMakefileVariable(platform));
1921 if((projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions && projectPlatformOptions.options.preprocessorDefinitions.count) ||
1922 (configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions && configPlatformOptions.options.preprocessorDefinitions.count) ||
1923 (projectPlatformOptions && projectPlatformOptions.options.includeDirs && projectPlatformOptions.options.includeDirs.count) ||
1924 (configPlatformOptions && configPlatformOptions.options.includeDirs && configPlatformOptions.options.includeDirs.count))
1926 f.Printf("CFLAGS +=");
1927 if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
1929 f.Printf(" \\\n\t -Wl");
1930 for(s : projectPlatformOptions.options.linkerOptions)
1933 if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
1935 f.Printf(" \\\n\t -Wl");
1936 for(s : configPlatformOptions.options.linkerOptions)
1939 if(projectPlatformOptions && projectPlatformOptions.options.preprocessorDefinitions)
1940 OutputListOption(f, "D", projectPlatformOptions.options.preprocessorDefinitions, newLine, false);
1941 if(configPlatformOptions && configPlatformOptions.options.preprocessorDefinitions)
1942 OutputListOption(f, "D", configPlatformOptions.options.preprocessorDefinitions, newLine, false );
1943 if(projectPlatformOptions && projectPlatformOptions.options.includeDirs)
1944 OutputListOption(f, "I", projectPlatformOptions.options.includeDirs, lineEach, true);
1945 if(configPlatformOptions && configPlatformOptions.options.includeDirs)
1946 OutputListOption(f, "I", configPlatformOptions.options.includeDirs, lineEach, true);
1950 if(targetType != staticLibrary)
1952 if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
1953 (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
1955 f.Printf("OFLAGS +=");
1956 if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
1957 OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true);
1958 if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
1959 OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true);
1963 if(projectPlatformOptions && projectPlatformOptions.options.libraries &&
1964 projectPlatformOptions.options.libraries.count/* &&
1965 (!config || !config.options || !config.options.libraries)*/)
1967 f.Printf("LIBS +=");
1968 OutputLibraries(f, projectPlatformOptions.options.libraries);
1971 {/*TOFIX: EXTRA CURLIES FOR NASTY WARNING*/if((configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
1973 f.Printf("LIBS +=");
1974 OutputLibraries(f, configPlatformOptions.options.libraries);
1982 for(c = 0; c < ifCount; c++)
1983 f.Printf("endif\n");
1989 f.Printf("# TARGETS\n\n");
1991 f.Printf("all: objdir%s $(TARGET)\n\n", sameObjTargetDirs ? "" : " targetdir");
1993 f.Printf("objdir:\n");
1994 f.Printf("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
1995 //f.Printf("# PRE-BUILD COMMANDS\n");
1996 if(options && options.prebuildCommands)
1998 for(s : options.prebuildCommands)
1999 if(s && s[0]) f.Printf("\t%s\n", s);
2001 if(config && config.options && config.options.prebuildCommands)
2003 for(s : config.options.prebuildCommands)
2004 if(s && s[0]) f.Printf("\t%s\n", s);
2006 if(platforms || (config && config.platforms))
2010 //f.Printf("# PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
2011 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2013 PlatformOptions projectPOs = null;
2014 PlatformOptions configPOs = null;
2020 if(!strcmpi(p.name, platform))
2027 if(config && config.platforms)
2029 for(p : config.platforms)
2031 if(!strcmpi(p.name, platform))
2038 if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
2039 (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
2045 f.Printf(PlatformToMakefileVariable(platform));
2048 if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
2050 for(s : projectPOs.options.prebuildCommands)
2051 if(s && s[0]) f.Printf("\t%s\n", s);
2053 if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
2055 for(s : configPOs.options.prebuildCommands)
2056 if(s && s[0]) f.Printf("\t%s\n", s);
2063 for(c = 0; c < ifCount; c++)
2064 f.Printf("endif\n");
2070 if(!sameObjTargetDirs)
2072 f.Printf("targetdir:\n");
2073 f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
2078 // Main Module (Linking) for ECERE C modules
2079 f.Printf("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
2080 // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
2081 f.Printf("\t$(ECS)%s $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $(OBJ)$(MODULE).main.ec\n\n",
2082 console ? " -console" : "", objDirExpNoSpaces);
2083 // Main Module (Linking) for ECERE C modules
2084 f.Printf("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
2085 f.Printf("\t$(ECP) $(CECFLAGS) $(ECFLAGS) $(CFLAGS)"
2086 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
2087 f.Printf("\t$(ECC) $(CECFLAGS) $(ECFLAGS) $(CFLAGS) $(FVISIBILITY)"
2088 " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.c -symbols $(OBJ)\n\n");
2092 // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameObjTargetDirs ? "" : " targetdir");
2093 f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2094 if(targetType == sharedLibrary || targetType == executable)
2096 // f.Printf("\tinstall_name_tool $(TARGET) $(LP)$(MODULE)%s\n", targetType == sharedLibrary ? "$(SO)" : "$(A)");
2097 //f.Printf("ifdef OSX\n");
2098 //f.Printf("ifeq \"$(TARGET_TYPE)\" \"sharedlib\"\n");
2099 //f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET) -install_name $(LP)$(MODULE)$(SO)\n");
2100 //f.Printf("endif\n");
2101 //f.Printf("else\n");
2102 //f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET)\n");
2103 //f.Printf("endif\n");
2104 f.Printf("\t$(CC) $(OFLAGS) $(OBJECTS) $(LIBS) -o $(TARGET) $(INSTALLNAME)\n");
2108 f.Printf("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
2112 f.Printf("ifndef WINDOWS\n");
2113 f.Printf("ifeq \"$(TARGET_TYPE)\" \"executable\"\n");
2114 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2115 f.Printf("endif\n");
2117 f.Printf("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
2118 f.Printf("endif\n");
2121 if(resNode.files && resNode.files.count && !noResources)
2122 resNode.GenMakefileAddResources(f, resNode.path);
2125 f.Printf("\t$(AR) rcs $(TARGET) $(OBJECTS) $(LIBS)\n");
2127 //f.Printf("# POST-BUILD COMMANDS\n");
2128 if(options && options.postbuildCommands)
2130 for(s : options.postbuildCommands)
2131 if(s && s[0]) f.Printf("\t%s\n", s);
2133 if(config && config.options && config.options.postbuildCommands)
2135 for(s : config.options.postbuildCommands)
2136 if(s && s[0]) f.Printf("\t%s\n", s);
2138 if(platforms || (config && config.platforms))
2143 //f.Printf("# PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
2144 for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2146 PlatformOptions projectPOs = null;
2147 PlatformOptions configPOs = null;
2153 if(!strcmpi(p.name, platform))
2160 if(config && config.platforms)
2162 for(p : config.platforms)
2164 if(!strcmpi(p.name, platform))
2171 if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
2172 (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
2178 f.Printf(PlatformToMakefileVariable(platform));
2181 if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
2183 for(s : projectPOs.options.postbuildCommands)
2184 if(s && s[0]) f.Printf("\t%s\n", s);
2186 if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
2188 for(s : configPOs.options.postbuildCommands)
2189 if(s && s[0]) f.Printf("\t%s\n", s);
2196 for(c = 0; c < ifCount; c++)
2197 f.Printf("endif\n");
2203 f.Printf("# SYMBOL RULES\n\n");
2204 topNode.GenMakefilePrintSymbolRules(f, this);
2206 f.Printf("# C OBJECT RULES\n\n");
2207 topNode.GenMakefilePrintCObjectRules(f, this);
2211 f.Printf("# IMPLICIT OBJECT RULE\n\n");
2213 f.Printf("$(OBJ)%%$(O) : $(OBJ)%%.c\n");
2214 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $< -o $@\n\n");
2217 f.Printf("# OBJECT RULES\n\n");
2218 // todo call this still but only generate rules whith specific options
2219 // see we-have-file-specific-options in ProjectNode.ec
2220 topNode.GenMakefilePrintObjectRules(f, this, namesInfo);
2223 GenMakefilePrintMainObjectRule(f);
2225 f.Printf("clean: objdir%s\n", sameObjTargetDirs ? "" : " targetdir");
2226 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) " : "");
2227 OutputCleanActions(f, "OBJECTS", objectsParts);
2228 OutputCleanActions(f, "COBJECTS", cobjectsParts);
2231 OutputCleanActions(f, "IMPORTS", importsParts);
2232 OutputCleanActions(f, "SYMBOLS", symbolsParts);
2236 f.Printf("distclean: clean\n");
2237 f.Printf("\t$(call rmdirq,$(OBJ))\n");
2238 if(!sameObjTargetDirs)
2239 f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
2245 varStringLenDiffs.Free();
2246 delete varStringLenDiffs;
2253 /*ChangeWorkingDir(oldDirectory);
2254 SetEnvironment("PATH", oldPath);*/
2257 config.makingModified = false;
2264 void GenMakefilePrintMainObjectRule(File f)
2266 char extension[MAX_EXTENSION] = "c";
2267 char modulePath[MAX_LOCATION];
2268 char fixedModuleName[MAX_FILENAME];
2271 char objDirNoSpaces[MAX_LOCATION];
2272 DirExpression objDirExp = objDir;
2274 ReplaceSpaces(objDirNoSpaces, objDirExp.dir);
2275 ReplaceSpaces(fixedModuleName, moduleName);
2277 //sprintf(fixedModuleName, "%s.main", fixedPrjName);
2278 //strcat(fixedModuleName, ".main");
2280 #if 0 // TODO: Fix nospaces stuff
2281 // *** Dependency command ***
2282 sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
2284 // System Includes (from global settings)
2285 for(item : compiler.dirs[Includes])
2287 strcat(command, " -isystem ");
2288 if(strchr(item.name, ' '))
2290 strcat(command, "\"");
2291 strcat(command, item);
2292 strcat(command, "\"");
2295 strcat(command, item);
2298 for(item = includeDirs.first; item; item = item.next)
2300 strcat(command, " -I");
2301 if(strchr(item.name, ' '))
2303 strcat(command, "\"");
2304 strcat(command, item.name);
2305 strcat(command, "\"");
2308 strcat(command, item.name);
2310 for(item = preprocessorDefs.first; item; item = item.next)
2312 strcat(command, " -D");
2313 strcat(command, item.name);
2317 if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2321 bool firstLine = true;
2323 // To do some time: auto save external dependencies?
2326 if(dep.GetLine(line, sizeof(line)-1))
2330 char * colon = strstr(line, ":");
2331 if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
2345 // If we failed to generate dependencies...
2349 f.Printf("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
2355 f.Printf("\t$(CC) $(CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $(OBJ)$(MODULE).main$(O)\n\n", extension);
2361 Project LegacyBinaryLoadProject(File f, char * filePath)
2363 Project project = null;
2364 char signature[sizeof(epjSignature)];
2366 f.Read(signature, sizeof(signature), 1);
2367 if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
2369 char topNodePath[MAX_LOCATION];
2370 /*ProjectConfig newConfig
2372 name = CopyString("Default");
2373 makingModified = true;
2374 compilingModified = true;
2375 linkingModified = true;
2379 project = Project { options = { } };
2380 LegacyBinaryLoadNode(project.topNode, f);
2381 delete project.topNode.path;
2382 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2383 MakeSlashPath(topNodePath);
2385 PathCatSlash(topNodePath, filePath);
2386 project.filePath = topNodePath;
2388 /* THIS IS ALREADY DONE BY filePath property
2389 StripLastDirectory(topNodePath, topNodePath);
2390 project.topNode.path = CopyString(topNodePath);
2392 // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
2394 // newConfig.options.defaultNameSpace = "";
2395 /*newConfig.objDir.dir = "obj";
2396 newConfig.targetDir.dir = "";*/
2398 //project.configurations = { [ newConfig ] };
2399 //project.config = newConfig;
2407 // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
2408 f.Read(&temp, sizeof(int),1);
2411 case 0: project.options.targetType = executable; break;
2412 case 1: project.options.targetType = sharedLibrary; break;
2413 case 2: project.options.targetType = staticLibrary; break;
2416 f.Read(&len, sizeof(int),1);
2417 project.options.targetFileName = new char[len+1];
2418 f.Read(project.options.targetFileName, sizeof(char), len+1);
2420 f.Read(&len, sizeof(int),1);
2421 delete project.options.targetDirectory;
2422 project.options.targetDirectory = new char[len+1];
2423 f.Read(project.options.targetDirectory, sizeof(char), len+1);
2425 f.Read(&len, sizeof(int),1);
2426 delete project.options.objectsDirectory;
2427 project.options.objectsDirectory = new byte[len+1];
2428 f.Read(project.options.objectsDirectory, sizeof(char), len+1);
2430 f.Read(&temp, sizeof(int),1);
2431 project./*config.*/options.debug = temp ? true : false;
2432 f.Read(&temp, sizeof(int),1);
2433 project./*config.*/options.optimization = temp ? speed : none;
2434 f.Read(&temp, sizeof(int),1);
2435 project./*config.*/options.profile = temp ? true : false;
2436 f.Read(&temp, sizeof(int),1);
2437 project.options.warnings = temp ? all : unset;
2439 f.Read(&count, sizeof(int),1);
2442 project.options.includeDirs = { };
2443 for(c = 0; c < count; c++)
2446 f.Read(&len, sizeof(int),1);
2447 name = new char[len+1];
2448 f.Read(name, sizeof(char), len+1);
2449 project.options.includeDirs.Add(name);
2453 f.Read(&count, sizeof(int),1);
2456 project.options.libraryDirs = { };
2457 for(c = 0; c < count; c++)
2460 f.Read(&len, sizeof(int),1);
2461 name = new char[len+1];
2462 f.Read(name, sizeof(char), len+1);
2463 project.options.libraryDirs.Add(name);
2467 f.Read(&count, sizeof(int),1);
2470 project.options.libraries = { };
2471 for(c = 0; c < count; c++)
2474 f.Read(&len, sizeof(int),1);
2475 name = new char[len+1];
2476 f.Read(name, sizeof(char), len+1);
2477 project.options.libraries.Add(name);
2481 f.Read(&count, sizeof(int),1);
2484 project.options.preprocessorDefinitions = { };
2485 for(c = 0; c < count; c++)
2488 f.Read(&len, sizeof(int),1);
2489 name = new char[len+1];
2490 f.Read(name, sizeof(char), len+1);
2491 project.options.preprocessorDefinitions.Add(name);
2495 f.Read(&temp, sizeof(int),1);
2496 project.options.console = temp ? true : false;
2499 for(node : project.topNode.files)
2501 if(node.type == resources)
2503 project.resNode = node;
2513 void ProjectConfig::LegacyProjectConfigLoad(File f)
2521 char subSection[128];
2527 f.GetLine(buffer, 65536 - 1);
2528 TrimLSpaces(buffer, buffer);
2529 TrimRSpaces(buffer, buffer);
2532 if(buffer[0] == '-')
2536 TrimLSpaces(equal, equal);
2537 if(!strcmpi(subSection, "LibraryDirs"))
2539 if(!options.libraryDirs)
2540 options.libraryDirs = { [ CopyString(equal) ] };
2542 options.libraryDirs.Add(CopyString(equal));
2544 else if(!strcmpi(subSection, "IncludeDirs"))
2546 if(!options.includeDirs)
2547 options.includeDirs = { [ CopyString(equal) ] };
2549 options.includeDirs.Add(CopyString(equal));
2552 else if(buffer[0] == '+')
2563 TrimLSpaces(equal, equal);
2564 delete name; name = CopyString(equal); // property::name = equal;
2567 else if(!strcmpi(buffer, "Compiler Options"))
2568 strcpy(section, buffer);
2569 else if(!strcmpi(buffer, "IncludeDirs"))
2570 strcpy(subSection, buffer);
2571 else if(!strcmpi(buffer, "Linker Options"))
2572 strcpy(section, buffer);
2573 else if(!strcmpi(buffer, "LibraryDirs"))
2574 strcpy(subSection, buffer);
2575 else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
2582 equal = strstr(buffer, "=");
2586 TrimRSpaces(buffer, buffer);
2588 TrimLSpaces(equal, equal);
2589 if(!strcmpi(buffer, "Target Name"))
2590 options.targetFileName = CopyString(equal);
2591 else if(!strcmpi(buffer, "Target Type"))
2593 if(!strcmpi(equal, "Executable"))
2594 options.targetType = executable;
2595 else if(!strcmpi(equal, "Shared"))
2596 options.targetType = sharedLibrary;
2597 else if(!strcmpi(equal, "Static"))
2598 options.targetType = staticLibrary;
2600 options.targetType = executable;
2602 else if(!strcmpi(buffer, "Target Directory"))
2603 options.targetDirectory = CopyString(equal);
2604 else if(!strcmpi(buffer, "Console"))
2605 options.console = ParseTrueFalseValue(equal);
2606 else if(!strcmpi(buffer, "Libraries"))
2608 if(!options.libraries) options.libraries = { };
2609 ParseArrayValue(options.libraries, equal);
2611 else if(!strcmpi(buffer, "Intermediate Directory"))
2612 options.objectsDirectory = CopyString(equal); //objDir.expression = equal;
2613 else if(!strcmpi(buffer, "Debug"))
2614 options.debug = ParseTrueFalseValue(equal);
2615 else if(!strcmpi(buffer, "Optimize"))
2617 if(!strcmpi(equal, "None"))
2618 options.optimization = none;
2619 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
2620 options.optimization = speed;
2621 else if(!strcmpi(equal, "Size"))
2622 options.optimization = size;
2624 options.optimization = none;
2626 else if(!strcmpi(buffer, "Compress"))
2627 options.compress = ParseTrueFalseValue(equal);
2628 else if(!strcmpi(buffer, "Profile"))
2629 options.profile = ParseTrueFalseValue(equal);
2630 else if(!strcmpi(buffer, "AllWarnings"))
2631 options.warnings = ParseTrueFalseValue(equal) ? all : unset;
2632 else if(!strcmpi(buffer, "MemoryGuard"))
2633 options.memoryGuard = ParseTrueFalseValue(equal);
2634 else if(!strcmpi(buffer, "Default Name Space"))
2635 options.defaultNameSpace = CopyString(equal);
2636 else if(!strcmpi(buffer, "Strict Name Spaces"))
2637 options.strictNameSpaces = ParseTrueFalseValue(equal);
2638 else if(!strcmpi(buffer, "Preprocessor Definitions"))
2640 if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
2641 ParseArrayValue(options.preprocessorDefinitions, equal);
2647 if(!options.targetDirectory && options.objectsDirectory)
2648 options.targetDirectory = CopyString(options.objectsDirectory);
2649 //if(!objDir.dir) objDir.dir = "obj";
2650 //if(!targetDir.dir) targetDir.dir = "";
2651 // if(!targetName) property::targetName = ""; // How can a targetFileName be nothing???
2652 // if(!defaultNameSpace) property::defaultNameSpace = "";
2653 makingModified = true;
2656 Project LegacyAsciiLoadProject(File f, char * filePath)
2658 Project project = null;
2659 ProjectNode node = null;
2661 char parentPath[MAX_LOCATION];
2662 char section[128] = "";
2663 char subSection[128] = "";
2665 bool configurationsPresent = false;
2675 f.GetLine(buffer, 65536 - 1);
2676 TrimLSpaces(buffer, buffer);
2677 TrimRSpaces(buffer, buffer);
2680 if(buffer[0] == '-' || buffer[0] == '=')
2682 bool simple = buffer[0] == '-';
2685 TrimLSpaces(equal, equal);
2686 if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
2688 if(!project.config.options.libraryDirs) project.config.options.libraryDirs = { };
2689 project.config.options.libraryDirs.Add(CopyString(equal));
2691 else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
2693 if(!project.config.options.includeDirs) project.config.options.includeDirs = { };
2694 project.config.options.includeDirs.Add(CopyString(equal));
2696 else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
2698 len = strlen(equal);
2701 char temp[MAX_LOCATION];
2702 ProjectNode child { };
2703 // We don't need to do this anymore, fileName is just a property that sets name & path
2704 // child.fileName = CopyString(equal);
2707 child.name = CopyString(equal);
2708 child.path = CopyString(parentPath);
2712 GetLastDirectory(equal, temp);
2713 child.name = CopyString(temp);
2714 StripLastDirectory(equal, temp);
2715 child.path = CopyString(temp);
2717 child.nodeType = file;
2718 child.parent = parent;
2719 child.indent = parent.indent + 1;
2721 child.icon = NodeIcons::SelectFileIcon(child.name);
2722 parent.files.Add(child);
2728 StripLastDirectory(parentPath, parentPath);
2729 parent = parent.parent;
2733 else if(buffer[0] == '+')
2737 TrimLSpaces(equal, equal);
2738 if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
2740 char temp[MAX_LOCATION];
2741 ProjectNode child { };
2742 // NEW: Folders now have a path set like files
2743 child.name = CopyString(equal);
2744 strcpy(temp, parentPath);
2745 PathCatSlash(temp, child.name);
2746 child.path = CopyString(temp);
2748 child.parent = parent;
2749 child.indent = parent.indent + 1;
2750 child.type = folder;
2751 child.nodeType = folder;
2753 child.icon = folder;
2754 PathCatSlash(parentPath, child.name);
2755 parent.files.Add(child);
2760 else if(!strcmpi(section, "Configurations"))
2762 ProjectConfig newConfig
2764 makingModified = true;
2768 LegacyProjectConfigLoad(newConfig, f);
2769 project.configurations.Add(newConfig);
2772 else if(!strcmpi(buffer, "ECERE Project File"));
2773 else if(!strcmpi(buffer, "Version 0a"))
2774 ; //strcpy(version, "0a");
2775 else if(!strcmpi(buffer, "Version 0.1a"))
2776 ; //strcpy(version, "0.1a");
2777 else if(!strcmpi(buffer, "Configurations"))
2779 project.configurations.Free();
2780 project.config = null;
2781 strcpy(section, buffer);
2782 configurationsPresent = true;
2784 else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
2786 ProjectConfig newConfig { name = CopyString("Default"), options = { } };
2787 char topNodePath[MAX_LOCATION];
2788 // newConfig.defaultNameSpace = "";
2789 //newConfig.objDir.dir = "obj";
2790 //newConfig.targetDir.dir = "";
2791 project = Project { /*options = { }*/ };
2792 project.configurations = { [ newConfig ] };
2793 project.config = newConfig;
2794 // if(project.topNode.path) delete project.topNode.path;
2795 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
2796 MakeSlashPath(topNodePath);
2797 PathCatSlash(topNodePath, filePath);
2798 project.filePath = topNodePath;
2799 parentPath[0] = '\0';
2800 parent = project.topNode;
2802 strcpy(section, "Target");
2807 if(equal[0] == '\"')
2809 StripQuotes(equal, equal);
2810 delete project.moduleName; project.moduleName = CopyString(equal);
2814 else if(!strcmpi(buffer, "Compiler Options"));
2815 else if(!strcmpi(buffer, "IncludeDirs"))
2816 strcpy(subSection, buffer);
2817 else if(!strcmpi(buffer, "Linker Options"));
2818 else if(!strcmpi(buffer, "LibraryDirs"))
2819 strcpy(subSection, buffer);
2820 else if(!strcmpi(buffer, "Files"))
2822 strcpy(section, "Target");
2823 strcpy(subSection, buffer);
2825 else if(!strcmpi(buffer, "Resources"))
2827 ProjectNode child { };
2828 parent.files.Add(child);
2829 child.parent = parent;
2830 child.indent = parent.indent + 1;
2831 child.name = CopyString(buffer);
2832 child.path = CopyString("");
2833 child.type = resources;
2835 child.icon = archiveFile;
2836 project.resNode = child;
2839 strcpy(subSection, buffer);
2843 equal = strstr(buffer, "=");
2847 TrimRSpaces(buffer, buffer);
2849 TrimLSpaces(equal, equal);
2851 if(!strcmpi(section, "Target"))
2853 if(!strcmpi(buffer, "Build Exclusions"))
2855 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
2857 /*if(node && node.type != NodeTypes::project)
2858 ParseListValue(node.buildExclusions, equal);*/
2861 else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
2863 delete project.resNode.path;
2864 project.resNode.path = CopyString(equal);
2865 PathCatSlash(parentPath, equal);
2869 else if(!strcmpi(buffer, "Intermediate Directory"))
2870 project.config.options.objectsDirectory = CopyString(equal); //objDir.expression = equal;
2871 else if(!strcmpi(buffer, "Debug"))
2872 project.config.options.debug = ParseTrueFalseValue(equal);
2873 else if(!strcmpi(buffer, "Optimize"))
2875 if(!strcmpi(equal, "None"))
2876 project.config.options.optimization = none;
2877 else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
2878 project.config.options.optimization = speed;
2879 else if(!strcmpi(equal, "Size"))
2880 project.config.options.optimization = size;
2882 project.config.options.optimization = none;
2884 else if(!strcmpi(buffer, "Profile"))
2885 project.config.options.profile = ParseTrueFalseValue(equal);
2886 else if(!strcmpi(buffer, "MemoryGuard"))
2887 project.config.options.memoryGuard = ParseTrueFalseValue(equal);
2890 if(!project.options) project.options = { };
2892 // Project Wide Settings (All configs)
2893 if(!strcmpi(buffer, "Target Name"))
2894 project.options.targetFileName = CopyString(equal);
2895 else if(!strcmpi(buffer, "Target Type"))
2897 if(!strcmpi(equal, "Executable"))
2898 project.options.targetType = executable;
2899 else if(!strcmpi(equal, "Shared"))
2900 project.options.targetType = sharedLibrary;
2901 else if(!strcmpi(equal, "Static"))
2902 project.options.targetType = staticLibrary;
2904 project.options.targetType = executable;
2906 else if(!strcmpi(buffer, "Target Directory"))
2907 project.options.targetDirectory = CopyString(equal);
2908 else if(!strcmpi(buffer, "Console"))
2909 project.options.console = ParseTrueFalseValue(equal);
2910 else if(!strcmpi(buffer, "Libraries"))
2912 if(!project.options.libraries) project.options.libraries = { };
2913 ParseArrayValue(project.options.libraries, equal);
2915 else if(!strcmpi(buffer, "AllWarnings"))
2916 project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
2917 else if(!strcmpi(buffer, "Preprocessor Definitions"))
2919 if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
2921 /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
2922 ParseListValue(node.preprocessorDefs, equal);*/
2926 if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
2927 ParseArrayValue(project.options.preprocessorDefinitions, equal);
2938 SplitPlatformLibraries(project);
2940 if(configurationsPresent)
2941 CombineIdenticalConfigOptions(project);
2945 void SplitPlatformLibraries(Project project)
2947 if(project && project.configurations)
2949 for(cfg : project.configurations)
2951 if(cfg.options.libraries && cfg.options.libraries.count)
2953 Iterator<String> it { cfg.options.libraries };
2957 char * platformName = strstr(l, ":");
2960 PlatformOptions platform = null;
2962 if(!cfg.platforms) cfg.platforms = { };
2963 for(p : cfg.platforms)
2965 if(!strcmpi(platformName, p.name))
2973 platform = { name = CopyString(platformName), options = { libraries = { } } };
2974 cfg.platforms.Add(platform);
2976 *(platformName-1) = 0;
2977 platform.options.libraries.Add(CopyString(l));
2979 cfg.options.libraries.Delete(it.pointer);
2988 void CombineIdenticalConfigOptions(Project project)
2990 if(project && project.configurations && project.configurations.count)
2993 ProjectOptions nullOptions { };
2994 ProjectConfig firstConfig = null;
2995 for(cfg : project.configurations)
2997 if(cfg.options.targetType != staticLibrary)
3004 firstConfig = project.configurations.firstIterator.data;
3006 for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
3008 if(!member.isProperty)
3010 Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
3015 for(cfg : project.configurations)
3017 if(cfg != firstConfig)
3019 if(cfg.options.targetType != staticLibrary)
3023 if(type.type == noHeadClass || type.type == normalClass)
3025 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3026 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3027 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3031 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3032 (byte *)firstConfig.options + member.offset + member._class.offset,
3033 (byte *)cfg.options + member.offset + member._class.offset);
3045 if(type.type == noHeadClass || type.type == normalClass)
3047 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3048 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3049 *(void **)((byte *)nullOptions + member.offset + member._class.offset)))
3054 if(!type._vTbl[__ecereVMethodID_class_OnCompare](type,
3055 (byte *)firstConfig.options + member.offset + member._class.offset,
3056 (byte *)nullOptions + member.offset + member._class.offset))
3060 if(!project.options) project.options = { };
3062 /*if(type.type == noHeadClass || type.type == normalClass)
3064 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3065 (byte *)project.options + member.offset + member._class.offset,
3066 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
3070 void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
3071 // TOFIX: ListBox::SetData / OnCopy mess
3072 type._vTbl[__ecereVMethodID_class_OnCopy](type,
3073 (byte *)project.options + member.offset + member._class.offset,
3074 (type.typeSize > 4) ? address :
3075 ((type.typeSize == 4) ? (void *)*(uint32 *)address :
3076 ((type.typeSize == 2) ? (void *)*(uint16*)address :
3077 (void *)*(byte *)address )));
3080 (byte *)project.options + member.offset + member._class.offset,
3081 (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
3083 for(cfg : project.configurations)
3085 if(cfg.options.targetType == staticLibrary)
3089 if(type.type == noHeadClass || type.type == normalClass)
3091 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3092 *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
3093 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3097 result = type._vTbl[__ecereVMethodID_class_OnCompare](type,
3098 (byte *)firstConfig.options + member.offset + member._class.offset,
3099 (byte *)cfg.options + member.offset + member._class.offset);
3104 if(cfg != firstConfig)
3106 if(type.type == noHeadClass || type.type == normalClass)
3108 type._vTbl[__ecereVMethodID_class_OnFree](type,
3109 *(void **)((byte *)cfg.options + member.offset + member._class.offset));
3113 type._vTbl[__ecereVMethodID_class_OnFree](type,
3114 (byte *)cfg.options + member.offset + member._class.offset);
3116 memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
3119 memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
3126 // Compare Platform Specific Settings
3129 for(cfg : project.configurations)
3131 if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
3132 ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
3138 if(same && firstConfig.platforms)
3140 for(cfg : project.configurations)
3142 if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
3144 if(cfg != firstConfig)
3146 cfg.platforms.Free();
3147 delete cfg.platforms;
3150 project.platforms = firstConfig.platforms;
3151 firstConfig.platforms = null;
3155 // Static libraries can't contain libraries
3156 for(cfg : project.configurations)
3158 if(cfg.options.targetType == staticLibrary)
3160 if(!cfg.options.libraries) cfg.options.libraries = { };
3161 cfg.options.libraries.Free();
3167 Project LoadProject(char * filePath)
3169 Project project = null;
3170 File f = FileOpen(filePath, read);
3173 project = LegacyBinaryLoadProject(f, filePath);
3176 JSONParser parser { f = f };
3177 JSONResult result = parser.GetObject(class(Project), &project);
3180 char insidePath[MAX_LOCATION];
3182 delete project.topNode.files;
3183 if(!project.files) project.files = { };
3184 project.topNode.files = project.files;
3185 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3186 delete project.resNode.path;
3187 project.resNode.path = project.resourcesPath;
3188 project.resourcesPath = null;
3189 project.resNode.nodeType = (ProjectNodeType)-1;
3190 delete project.resNode.files;
3191 project.resNode.files = project.resources;
3192 project.files = null;
3193 project.resources = null;
3194 if(!project.configurations) project.configurations = { };
3197 char topNodePath[MAX_LOCATION];
3198 GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3199 MakeSlashPath(topNodePath);
3200 PathCatSlash(topNodePath, filePath);
3201 project.filePath = topNodePath;//filePath;
3204 project.topNode.FixupNode(insidePath);
3209 project = LegacyAsciiLoadProject(f, filePath);
3215 if(!project.options) project.options = { };
3216 if(!project.config && project.configurations)
3217 project.config = project.configurations.firstIterator.data;
3219 if(!project.resNode)
3221 project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
3224 if(!project.moduleName)
3225 project.moduleName = CopyString(project.name);
3226 if(project.config &&
3227 (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
3228 (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
3230 delete project.config.options.targetFileName;
3232 project.options.targetFileName = CopyString(project.moduleName);
3233 project.config.options.optimization = none;
3234 project.config.options.debug = true;
3235 //project.config.options.warnings = unset;
3236 project.config.options.memoryGuard = false;
3237 project.config.compilingModified = true;
3238 project.config.linkingModified = true;
3240 else if(!project.topNode.name && project.config)
3242 project.topNode.name = CopyString(project.config.options.targetFileName);
3245 project.topNode.configurations = project.configurations;
3246 project.topNode.platforms = project.platforms;
3247 project.topNode.options = project.options;