buildsystem, ide; fixed OUTPUT_POT makefile option. related to #858.
[sdk] / ide / src / project / Project.ec
1 #ifdef ECERE_STATIC
2 public import static "ecere"
3 #else
4 public import "ecere"
5 #endif
6
7 import "DynamicString"
8
9 #ifndef MAKEFILE_GENERATOR
10 import "ide"
11 // We should have the .sln/.vcproj generation even on other platforms
12 // e.g. detect from an environment variable pointing to a Windows drive
13 #ifdef __WIN32__
14 import "vsSupport"
15 #endif
16 #endif
17
18 import "ProjectConfig"
19 import "ProjectNode"
20 import "IDESettings"
21
22 default:
23
24 static void DummyFunction()
25 {
26 int a;
27 a.OnFree();
28 }
29
30 private:
31
32 extern int __ecereVMethodID_class_OnCompare;
33 extern int __ecereVMethodID_class_OnFree;
34
35 IDESettings ideSettings;
36
37 IDESettingsContainer settingsContainer
38 {
39    driver = "JSON";
40    dataOwner = &ideSettings;
41    dataClass = class(IDESettings);
42
43    void OnLoad(GlobalSettingsData data)
44    {
45       IDESettings settings = (IDESettings)data;
46 #ifndef MAKEFILE_GENERATOR
47       globalSettingsDialog.ideSettings = settings;
48       ide.UpdateRecentMenus();
49       ide.UpdateCompilerConfigs(true);
50 #endif
51    }
52 };
53
54 #ifdef MAKEFILE_GENERATOR
55 CompilerConfig defaultCompiler;
56 #endif
57
58 // LEGACY BINARY EPJ LOADING
59
60 SetBool ParseTrueFalseValue(char * string)
61 {
62    if(!strcmpi(string, "True")) return true;
63    return false;
64 }
65
66 void ParseArrayValue(Array<String> array, char * equal)
67 {
68    char * start, * comma;
69    char * string;
70    string = CopyString(equal);
71    start = string;
72    while(start)
73    {
74       comma = strstr(start, ",");
75       if(comma)
76          comma[0] = '\0';
77       array.Add(CopyString(start));
78       if(comma)
79          comma++;
80       if(comma)
81          comma++;
82       start = comma;
83    }
84    delete string;
85 }
86
87 void ProjectNode::LegacyBinaryLoadNode(File f)
88 {
89    int len, count, c;
90    int fileNameLen;
91
92    f.Read(&len, sizeof(len), 1);
93    name = new char[len+1];
94    fileNameLen = len;
95    f.Read(name, sizeof(char), len+1);
96    f.Read(&len, sizeof(len), 1);
97    fileNameLen += len;
98    path = new char[len+1];
99    f.Read(path, sizeof(char), len+1);
100    
101    /*
102    fileName = new char[fileNameLen+2];
103    strcpy(fileName, path);
104    if(fileName[0]) strcat(fileName, "/");
105    strcat(fileName, name);
106    */
107
108    f.Read(&type, sizeof(type), 1);
109    f.Read(&count, sizeof(count), 1);
110    
111    if(type == file)
112    {
113       nodeType = file;
114       icon = NodeIcons::SelectFileIcon(name);
115    }
116    else
117    {
118       nodeType = folder;
119       icon = NodeIcons::SelectNodeIcon(type);
120    }
121
122    if(count && !files) files = { };
123    for(c = 0; c < count; c++)
124    {
125       ProjectNode child { };
126       files.Add(child);
127       child.parent = this;
128       child.indent = indent + 1;
129       LegacyBinaryLoadNode(child, f);
130    }
131 }
132
133 /*void LegacyBinarySaveNode(File f)
134 {
135    int len;
136    ProjectNode child;
137    len = strlen(name);
138    f.Write(&len, sizeof(len), 1);
139    f.Write(name, sizeof(char), len+1);
140
141    if(type == project)
142    {
143       // Projects Absolute Path Are Not Saved
144       len = 0;
145       f.Write(&len, sizeof(len), 1);
146       f.Write(&len, sizeof(char), 1);
147    }
148    else
149    {
150       len = strlen(path);
151       f.Write(&len, sizeof(len), 1);
152       f.Write(path, sizeof(char), len+1);
153    }
154    f.Write(&type, sizeof(type), 1);
155    f.Write(&children.count, sizeof(children.count), 1);
156    for(child = children.first; child; child.next)
157       child.SaveNode(f);
158 }*/
159
160 void ProjectNode::LegacyAsciiSaveNode(File f, char * indentation, char * insidePath)
161 {
162    int len;
163    char printPath[MAX_LOCATION];
164
165    if(type == project && (files.count /*|| preprocessorDefs.first*/))
166    {
167       f.Printf("\n   Files\n");
168    }
169    else if(type == file)
170    {
171       if(!strcmp(path, insidePath))
172          f.Printf("%s - %s\n", indentation, name);
173       else
174       {
175          strcpy(printPath, path);
176          len = strlen(printPath);
177          if(len)
178             if(printPath[len-1] != '/')
179                strcat(printPath, "/");
180          strcat(printPath, name);
181          f.Printf("%s = %s\n", indentation, printPath);
182       }
183       if(files.count)
184          f.Printf("\nError\n\n");
185    }
186    else if(type == folder)
187    {
188       f.Printf("%s + %s\n", indentation, name);
189    }
190    else if(type == resources && files.count)
191    {
192       PathCatSlash(insidePath, path);
193       f.Printf("\n%sResources\n", indentation);
194       if(path && path[0])
195          f.Printf("%s   Path = %s\n", indentation, path);
196    }
197    
198    /*if(buildExclusions.first && type != project)
199    {
200       for(item = buildExclusions.first; item; item = item.next)
201       {
202          if(item == buildExclusions.first)
203             f.Printf("%s      Build Exclusions = %s", indentation, item.name);
204          else
205             f.Printf(", %s", item.name);
206       }
207       f.Printf("\n");
208    }
209
210    if(preprocessorDefs.first && (type == project || ((type == file || type == folder) && !isInResources)))
211    {
212       for(item = preprocessorDefs.first; item; item = item.next)
213       {
214          if(item == preprocessorDefs.first)
215             f.Printf("%s%s   Preprocessor Definitions = %s", indentation, type == project ? "" : "   ", item.name);
216          else
217             f.Printf(", %s", item.name);
218       }
219       f.Printf("\n");
220    }
221    */
222    
223    if(type == project && (files.count /*|| preprocessorDefs.first*/))
224    {
225       f.Printf("\n");
226       for(child : files)
227          LegacyAsciiSaveNode(child, f, indentation, insidePath);
228    }
229    else if(type == folder)
230    {
231       strcat(indentation, "   ");
232       // WHAT WAS THIS: strcpy(printPath, path);
233       // TOCHECK: why is Unix/PathCat not used here
234       len = strlen(insidePath);
235       if(len)
236          if(insidePath[len-1] != '/')
237             strcat(insidePath, "/");
238       strcat(insidePath, name);
239
240       for(child : files)
241          LegacyAsciiSaveNode(child, f, indentation, insidePath);
242       f.Printf("%s -\n", indentation);
243       indentation[strlen(indentation) - 3] = '\0';
244       StripLastDirectory(insidePath, insidePath);
245    }
246    else if(type == resources && files.count)
247    {
248       f.Printf("\n");
249       for(child : files)
250          LegacyAsciiSaveNode(child, f, indentation, insidePath);
251       StripLastDirectory(insidePath, insidePath);
252    }
253 }
254
255 /*
256 void ProjectConfig::LegacyProjectConfigSave(File f)
257 {
258    char * indentation = "      ";
259    //if(isCommonConfig)
260       //f.Printf("\n * Common\n");
261    //else
262       f.Printf("\n + %s\n", name);
263    f.Printf("\n   Compiler\n\n");
264    if(objDir.expression[0])
265       f.Printf("%sIntermediate Directory = %s\n", indentation, objDir.expression);
266    f.Printf("%sDebug = %s\n", indentation, (options.debug == true) ? "True" : "False");
267    switch(options.optimization)
268    {
269       // case none:   f.Printf("%sOptimize = %s\n", indentation, "None"); break;
270       case speed: f.Printf("%sOptimize = %s\n", indentation, "Speed"); break;
271       case size:  f.Printf("%sOptimize = %s\n", indentation, "Size");  break;
272    }
273    f.Printf("%sAllWarnings = %s\n", indentation, (options.warnings == all) ? "True" : "False");
274    if(options.profile)
275       f.Printf("%sProfile = %s\n", indentation, (options.profile == true) ? "True" : "False");
276    if(options.memoryGuard == true)
277       f.Printf("%sMemoryGuard = %s\n", indentation, (options.memoryGuard == true) ? "True" : "False");
278    if(options.strictNameSpaces == true)
279       f.Printf("%sStrict Name Spaces = %s\n", indentation, (options.strictNameSpaces == true) ? "True" : "False");
280    if(options.defaultNameSpace && strlen(options.defaultNameSpace))
281       f.Printf("%sDefault Name Space = %s\n", indentation, options.defaultNameSpace);
282     TOFIX: Compiler Bug {
283       if(options.preprocessorDefinitions.count)
284       {
285          bool isFirst = true;
286          for(item : options.preprocessorDefinitions)
287          {
288             if(isFirst)
289             {
290                f.Printf("\n%sPreprocessor Definitions = %s", indentation, item);
291                isFirst = false;
292             }
293             else
294                f.Printf(", %s", item);
295          }
296          f.Printf("\n");
297       }
298    }
299    if(options.includeDirs.count)
300    {
301       f.Printf("\n%sInclude Directories\n", indentation);
302       for(item : options.includeDirs)
303          f.Printf("%s - %s\n", indentation, name);
304       f.Printf("\n");
305    }
306
307    f.Printf("\n%sLinker\n\n", indentation);
308    f.Printf("%sTarget Name = %s\n", indentation, options.targetFileName);
309    switch(options.targetType)
310    {
311       case executable:     f.Printf("%sTarget Type = %s\n", indentation, "Executable"); break;
312       case sharedLibrary:  f.Printf("%sTarget Type = %s\n", indentation, "Shared");     break;
313       case staticLibrary:  f.Printf("%sTarget Type = %s\n", indentation, "Static");     break;
314    }
315    if(targetDir.expression[0])
316       f.Printf("%sTarget Directory = %s\n", indentation, targetDir.expression);
317    if(options.console)
318       f.Printf("%sConsole = %s\n", indentation, options.console ? "True" : "False");
319    if(options.compress)
320       f.Printf("%sCompress = %s\n", indentation, options.compress ? "True" : "False");
321    if(options.libraries.count)
322    {
323       bool isFirst = true;
324       for(item : options.libraries)
325       {
326          if(isFirst)
327          {
328             f.Printf("\n%sLibraries = %s", indentation, name);
329             isFirst = false;
330          }
331          else
332             f.Printf(", %s", item);
333       }
334       f.Printf("\n");
335    }
336    if(options.libraryDirs.count)
337    {
338       f.Printf("\n%sLibrary Directories\n\n", indentation);
339       for(item : options.libraryDirs)
340          f.Printf("       - %s\n", indentation, item);
341    }
342 }
343
344 void LegacyAsciiSaveProject(File f, Project project)
345 {
346    char indentation[128*3];
347    char path[MAX_LOCATION];
348
349    f.Printf("\nECERE Project File : Format Version 0.1b\n");
350    f.Printf("\nDescription\n%s\n.\n", project.description);
351    f.Printf("\nLicense\n%s\n.\n", project.license);
352    f.Printf("\nModule Name = %s\n", project.moduleName);
353    f.Printf("\n   Configurations\n");
354    //////////////////////////////////////commonConfig.Save(f, true);
355    for(cfg : project.configurations)
356       LegacyProjectConfigSave(cfg, f);
357
358    strcpy(indentation, "   ");
359    path[0] = '\0';
360    LegacyAsciiSaveNode(project.topNode, f, indentation, path);
361    // f.Printf("\n");
362    delete f;
363 }
364 */
365
366 // *** NEW JSON PROJECT FORMAT ***
367 public enum ProjectNodeType { file, folder };
368
369 // *******************************
370
371 define PEEK_RESOLUTION = (18.2 * 10);
372
373 // On Windows & UNIX
374 #define SEPS    "/"
375 #define SEP     '/'
376
377 static Array<String> notLinkerOptions
378 { [
379    "-static-libgcc",
380    "-shared",
381    "-static",
382    "-s",
383    "-shared-libgcc",
384    "-nostartfiles",
385    "-nodefaultlibs",
386    "-nostdlib",
387    "-pie",
388    "-rdynamic",
389    "-static-libasan",
390    "-static-libtsan",
391    "-static libstdc++",
392    "-symbolic",
393    "-Wl,"
394    //"-T ",
395    //"-Xlinker ",
396    //"-u "
397 ] };
398
399 static bool IsLinkerOption(String s)
400 {
401    for(i : notLinkerOptions)
402       if(strstr(s, "-Wl,") || !strcmp(s, i))
403          return false;
404    return true;
405 }
406
407 static byte epjSignature[] = { 'E', 'P', 'J', 0x04, 0x01, 0x12, 0x03, 0x12 };
408
409 enum GenMakefilePrintTypes { objects, cObjects, symbols, imports, sources, resources, eCsources, rcSources };
410
411 define WorkspaceExtension = "ews";
412 define ProjectExtension = "epj";
413
414 define stringInFileIncludedFrom = "In file included from ";
415 define stringFrom =               "                 from ";
416
417 // This function cannot accept same pointer for source and output
418 void ReplaceSpaces(char * output, char * source)
419 {
420    int c, dc;
421    char ch, pch = 0;
422
423    for(c = 0, dc = 0; (ch = source[c]); c++, dc++)
424    {
425       if(ch == ' ') output[dc++] = '\\';
426       if(ch == '\"') output[dc++] = '\\';
427       if(ch == '&') output[dc++] = '\\';
428       if(pch != '$')
429       {
430          if(ch == '(' || ch == ')') output[dc++] = '\\';
431          pch = ch;
432       }
433       else if(ch == ')')
434          pch = 0;
435       output[dc] = ch;
436    }
437    output[dc] = '\0';
438 }
439
440 // This function cannot accept same pointer for source and output
441 void ReplaceUnwantedMakeChars(char * output, char * source)
442 {
443    char ch;
444    char * s = source, * d = output;
445    bool inVar = false;
446    while((ch = *s++))
447    {
448       if(ch == '(')
449       {
450          if(s != source && *(s-1) == '$')
451             inVar = true;
452          else
453             *d++ = '\\';
454       }
455       else if(ch == ')')
456       {
457          if(inVar == true)
458             inVar = false;
459          else
460             *d++ = '\\';
461       }
462       else if(ch == '$' && *(s+1) != '(')
463          *d++ = '$';
464       if(ch == ' ')
465          *d++ = 127;
466       else
467          *d++ = ch;
468    }
469    *d = '\0';
470 }
471
472 static void OutputNoSpace(File f, char * source)
473 {
474    char * output = new char[strlen(source)+1024];
475    ReplaceSpaces(output, source);
476    f.Puts(output);
477    delete output;
478 }
479
480 enum ListOutputMethod { inPlace, newLine, lineEach };
481
482 int OutputFileList(File f, char * name, Array<String> list, Map<String, int> varStringLenDiffs, char * prefix)
483 {
484    int numOfBreaks = 0;
485    const int breakListLength = 1536;
486    const int breakLineLength = 78; // TODO: turn this into an option.
487
488    int c, len, itemCount = 0;
489    Array<int> breaks { };
490    if(list.count)
491    {
492       int charCount = 0;
493       MapNode<String, int> mn;
494       for(c=0; c<list.count; c++)
495       {
496          len = strlen(list[c]) + 3;
497          if(strstr(list[c], "$(") && varStringLenDiffs && varStringLenDiffs.count)
498          {
499             for(mn = varStringLenDiffs.root.minimum; mn; mn = mn.next)
500             {
501                if(strstr(list[c], mn.key))
502                   len += mn.value;
503             }
504          }
505          if(charCount + len > breakListLength)
506          {
507             breaks.Add(itemCount);
508             itemCount = 0;
509             charCount = len;
510          }
511          itemCount++;
512          charCount += len;
513       }
514       if(itemCount)
515          breaks.Add(itemCount);
516       numOfBreaks = breaks.count;
517    }
518
519    if(numOfBreaks > 1)
520    {
521       f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
522       for(c=0; c<numOfBreaks; c++)
523          f.Printf(" $(%s%d)", name, c+1);
524       f.Puts("\n");
525    }
526    else
527       f.Printf("%s =%s%s", name, prefix ? " " : "", prefix ? prefix : "");
528
529    if(numOfBreaks)
530    {
531       int n, offset = 0;
532
533       for(c=0; c<numOfBreaks; c++)
534       {
535          if(numOfBreaks > 1)
536             f.Printf("%s%d =", name, c+1);
537          
538          len = 3;
539          itemCount = breaks[c];
540          for(n=offset; n<offset+itemCount; n++)
541          {
542             if(false) // TODO: turn this into an option.
543             {
544                int itemLen = strlen(list[n]);
545                if(len > 3 && len + itemLen > breakLineLength)
546                {
547                   f.Printf(" \\\n\t%s", list[n]);
548                   len = 3;
549                }
550                else
551                {
552                   len += itemLen;
553                   f.Printf(" %s", list[n]);
554                }
555             }
556             else
557                f.Printf(" \\\n\t%s", list[n]);
558          }
559          offset += itemCount;
560          f.Puts("\n");
561       }
562       list.Free();
563       list.count = 0;
564    }
565    else
566       f.Puts("\n");
567    f.Puts("\n");
568    delete breaks;
569    return numOfBreaks;
570 }
571
572 void OutputLinkObjectActions(File f, char * name, int parts)
573 {
574    if(parts > 1)
575    {
576       int c;
577       for(c=0; c<parts; c++)
578          f.Printf("\t@$(call echo,$(%s%d)) >> $(OBJ)linkobjects.lst\n", name, c+1);
579    } else if(parts) {
580       f.Printf("\t@$(call echo,$(%s)) >> $(OBJ)linkobjects.lst\n", name);
581    }
582 }
583
584 void OutputCleanActions(File f, char * name, int parts)
585 {
586    if(parts > 1)
587    {
588       int c;
589       for(c=0; c<parts; c++)
590          f.Printf("\t$(call rmq,$(%s%d))\n", name, c+1);
591    }
592    else
593       f.Printf("\t$(call rmq,$(%s))\n", name);
594 }
595
596 void OutputListOption(File f, char * option, Array<String> list, ListOutputMethod method, bool noSpace, bool noDash)
597 {
598    if(list.count)
599    {
600       if(method == newLine)
601          f.Puts(" \\\n\t");
602       for(item : list)
603       {
604          if(method == lineEach)
605             f.Puts(" \\\n\t");
606          f.Printf(" %s%s", noDash ? "" : "-", option);
607          if(noSpace)
608             OutputNoSpace(f, item);
609          else
610             f.Printf("%s", item);
611       }
612    }
613 }
614
615 void StringNoSpaceToDynamicString(DynamicString s, char * path)
616 {
617    char * output = new char[strlen(path)+1024];
618    ReplaceSpaces(output, path);
619    s.concat(output);
620    delete output;
621 }
622
623 static void OutputLibraries(File f, Array<String> libraries)
624 {
625    for(item : libraries)
626    {
627       char ext[MAX_EXTENSION];
628       char temp[MAX_LOCATION];
629       char * s = item;
630       bool usedFunction = false;
631       GetExtension(item, ext);
632       if(!strcmp(ext, "o") || !strcmp(ext, "a"))
633          f.Puts(" ");
634       else
635       {
636          if(!strcmp(ext, "so") || !strcmp(ext, "dylib"))
637          {
638             if(!strncmp(item, "lib", 3))
639                strcpy(temp, item + 3);
640             else
641                strcpy(temp, item);
642             StripExtension(temp);
643             s = temp;
644          } 
645          f.Puts(" \\\n\t$(call _L,");
646          usedFunction = true;
647       }
648       OutputNoSpace(f, s);
649       if(usedFunction)
650          f.Puts(")");
651    }
652 }
653
654 void CamelCase(char * string)
655 {
656    int c, len = strlen(string);
657    for(c=0; c<len && string[c] >= 'A' && string[c] <= 'Z'; c++)
658       string[c] = (char)tolower(string[c]);
659 }
660
661 CompilerConfig GetCompilerConfig()
662 {
663 #ifndef MAKEFILE_GENERATOR
664    CompilerConfig compiler = null;
665    if(ide && ide.workspace)
666       compiler = ideSettings.GetCompilerConfig(ide.workspace.compiler);
667    return compiler;
668 #else
669    incref defaultCompiler;
670    return defaultCompiler;
671 #endif
672 }
673
674 define localTargetType = config && config.options && config.options.targetType ?
675             config.options.targetType : options && options.targetType ?
676             options.targetType : TargetTypes::executable;
677 define localWarnings = config && config.options && config.options.warnings ?
678             config.options.warnings : options && options.warnings ?
679             options.warnings : WarningsOption::unset;
680 define localDebug = config && config.options && config.options.debug ?
681             config.options.debug : options && options.debug ?
682             options.debug : SetBool::unset;
683 define localMemoryGuard = config && config.options && config.options.memoryGuard ?
684             config.options.memoryGuard : options && options.memoryGuard ?
685             options.memoryGuard : SetBool::unset;
686 define localNoLineNumbers = config && config.options && config.options.noLineNumbers ?
687             config.options.noLineNumbers : options && options.noLineNumbers ?
688             options.noLineNumbers : SetBool::unset;
689 define localProfile = config && config.options && config.options.profile ?
690             config.options.profile : options && options.profile ?
691             options.profile : SetBool::unset;
692 define localOptimization = config && config.options && config.options.optimization ?
693             config.options.optimization : options && options.optimization ?
694             options.optimization : OptimizationStrategy::none;
695 define localFastMath = config && config.options && config.options.fastMath ?
696             config.options.fastMath : options && options.fastMath ?
697             options.fastMath : SetBool::unset;
698 define localDefaultNameSpace = config && config.options && config.options.defaultNameSpace ?
699             config.options.defaultNameSpace : options && options.defaultNameSpace ?
700             options.defaultNameSpace : null;
701 define localStrictNameSpaces = config && config.options && config.options.strictNameSpaces ?
702             config.options.strictNameSpaces : options && options.strictNameSpaces ?
703             options.strictNameSpaces : SetBool::unset;
704 // TODO: I would rather have null here, check if it'll be ok, have the property return "" if required
705 define localTargetFileName = config && config.options && config.options.targetFileName ?
706             config.options.targetFileName : options && options.targetFileName ?
707             options.targetFileName : "";
708 define localTargetDirectory = config && config.options && config.options.targetDirectory && config.options.targetDirectory[0] ?
709             config.options.targetDirectory : options && options.targetDirectory && options.targetDirectory[0] ?
710             options.targetDirectory : null;
711 define settingsTargetDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
712             ideSettings.projectDefaultIntermediateObjDir[0] ?
713             ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
714 define localObjectsDirectory = config && config.options && config.options.objectsDirectory && config.options.objectsDirectory[0] ?
715             config.options.objectsDirectory : options && options.objectsDirectory && options.objectsDirectory[0] ?
716             options.objectsDirectory : null;
717 define settingsObjectsDirectory = ideSettings && ideSettings.projectDefaultIntermediateObjDir &&
718             ideSettings.projectDefaultIntermediateObjDir[0] ?
719             ideSettings.projectDefaultIntermediateObjDir : defaultObjDirExpression;
720 define localConsole = config && config.options && config.options.console ?
721             config.options.console : options && options.console ?
722             options.console : SetBool::unset;
723 define localCompress = config && config.options && config.options.compress ?
724             config.options.compress : options && options.compress ?
725             options.compress : SetBool::unset;
726
727 define platformTargetType =
728          configPOs && configPOs.options && configPOs.options.targetType && configPOs.options.targetType != localTargetType ?
729                configPOs.options.targetType :
730          projectPOs && projectPOs.options && projectPOs.options.targetType && projectPOs.options.targetType != localTargetType ?
731                projectPOs.options.targetType : TargetTypes::unset;
732
733
734 char * PlatformToMakefileTargetVariable(Platform platform)
735 {
736    return platform == win32 ? "WINDOWS_TARGET" :
737           platform == tux   ? "LINUX_TARGET"   :
738           platform == apple ? "OSX_TARGET"     :
739                               "ERROR_BAD_TARGET";
740 }
741
742 char * TargetTypeToMakefileVariable(TargetTypes targetType)
743 {
744    return targetType == executable    ? "executable" :
745           targetType == sharedLibrary ? "sharedlib"  :
746           targetType == staticLibrary ? "staticlib"  :
747                                         "unknown";
748 }
749
750 // Move this to ProjectConfig? null vs Common to consider...
751 char * GetConfigName(ProjectConfig config)
752 {
753    return config ? config.name : "Common";
754 }
755
756 public enum SingleFileCompileMode
757 {
758    normal, debugPrecompile, debugCompile, debugGenerateSymbols, cObject;
759
760    property bool eC_ToolsDebug { get { return this == debugCompile || this == debugGenerateSymbols || this == debugPrecompile; } }
761 };
762
763 class Project : struct
764 {
765    class_no_expansion;  // To use Find on the Container<Project> in Workspace::projects
766                         // We might want to tweak this default behavior of regular classes ?
767                         // Expansion/the current default kind of Find matching we want for things like BitmapResource, FontResource (Also regular classes)
768 public:
769    float version;
770    String moduleName;
771
772    property char * moduleVersion
773    {
774       set { delete moduleVersion; if(value && value[0]) moduleVersion = CopyString(value); } // TODO: use CopyString function that filters chars
775       get { return moduleVersion ? moduleVersion : ""; }                                     //       version number should only use digits and dots
776       isset { return moduleVersion != null && moduleVersion[0]; }                            //       add leading/trailing 0 if value start/ends with dot(s)
777    }
778
779    property char * description
780    {
781       set { delete description; if(value && value[0]) description = CopyString(value); }
782       get { return description ? description : ""; }
783       isset { return description != null && description[0]; }
784    }
785
786    property char * license
787    {
788       set { delete license; if(value && value[0]) license = CopyString(value); }
789       get { return license ? license : ""; }
790       isset { return license != null && license[0]; }
791    }
792
793    property char * compilerConfigsDir
794    {
795       set { delete compilerConfigsDir; if(value && value[0]) compilerConfigsDir = CopyString(value); }
796       get { return compilerConfigsDir ? compilerConfigsDir : ""; }
797       isset { return compilerConfigsDir && compilerConfigsDir[0]; }
798    }
799
800    property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
801    property Array<PlatformOptions> platforms
802    {
803       get { return platforms; }
804       set
805       {
806          if(platforms) { platforms.Free(); delete platforms; }
807          if(value)
808          {
809             List<PlatformOptions> empty { };
810             Iterator<PlatformOptions> it { value };
811             platforms = value;
812             for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
813             for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
814             delete empty;
815          }
816       }
817       isset
818       {
819          if(platforms)
820          {
821             for(p : platforms)
822             {
823                if(p.options && !p.options.isEmpty)
824                   return true;
825             }
826          }
827          return false;
828       }
829    }
830    List<ProjectConfig> configurations;
831    LinkList<ProjectNode> files;
832    String resourcesPath;
833    LinkList<ProjectNode> resources;
834
835 private:
836    // topNode.name holds the file name (.epj)
837    ProjectOptions options;
838    Array<PlatformOptions> platforms;
839    ProjectNode topNode { type = project, icon = epjFile, files = LinkList<ProjectNode>{ }, project = this };
840    ProjectNode resNode;
841
842    ProjectConfig config;
843    String filePath;
844    // This is the file name stripped of the epj extension
845    // It should NOT be edited, saved or loaded anywhere
846    String name;
847
848    String description;
849    String license;
850    String compilerConfigsDir;
851    String moduleVersion;
852
853    String lastBuildConfigName;
854    String lastBuildCompilerName;
855
856    Map<String, NameCollisionInfo> lastBuildNamesInfo;
857
858 #ifndef MAKEFILE_GENERATOR
859    FileMonitor fileMonitor
860    {
861       this, FileChange { modified = true };
862       bool OnFileNotify(FileChange action, char * param)
863       {
864          fileMonitor.StopMonitoring();
865          if(OnProjectModified(action, param))
866             fileMonitor.StartMonitoring();
867          return true;
868       }
869    };
870
871    bool StartMonitoring()
872    {
873       fileMonitor.fileName = filePath;
874       fileMonitor.StartMonitoring();
875       return true;
876    }
877
878    bool StopMonitoring()
879    {
880       fileMonitor.StopMonitoring();
881       return true;
882    }
883
884    bool OnProjectModified(FileChange fileChange, char * param)
885    {
886       char temp[4096];
887       sprintf(temp, $"The project %s was modified by another application.\n"
888             "Would you like to reload it and lose your changes?", name);
889       if(MessageBox { type = yesNo, master = ide,
890             text = $"Project has been modified", contents = temp }.Modal() == yes)
891       {
892          Project project = LoadProject(filePath, config.name);
893          if(project)
894          {
895             ProjectView projectView = ide.projectView;
896             DataRow prev = topNode.row ? topNode.row.previous : null;
897             FileMonitor fm = fileMonitor;
898             bool confirmation = true;
899
900             if(projectView)
901             {
902                if(projectView.projectSettingsDialog)
903                {
904                   confirmation = projectView.projectSettingsDialog.CloseConfirmation(true);
905                   if(confirmation)
906                      projectView.projectSettingsDialog.Destroy(0);
907                }
908                if(confirmation)
909                   projectView.DeleteNode(topNode);
910             }
911             if(confirmation)
912             {
913                *this = *project;
914                delete fileMonitor;
915                fileMonitor = fm;
916                topNode.project = this;
917
918                if(projectView)
919                {
920                   CompilerConfig compiler = ideSettings.GetCompilerConfig(projectView.workspace.compiler);
921                   projectView.AddNode(topNode, null);
922                   topNode.row.Move(prev);
923
924                   projectView.ShowOutputBuildLog(true);
925                   projectView.DisplayCompiler(compiler, false);
926                   projectView.ProjectUpdateMakefileForAllConfigs(this);
927                   delete compiler;
928                }
929                eSystem_Delete(project);
930             }
931             else
932                delete project;
933          }
934          return true;
935       }
936       return true;
937    }
938
939 #endif
940
941    // This frees contents without freeing the instance
942    // For use from destructor and for file monitor reloading
943    // (To work around JSON loader (LoadProject) always returning a new instance)
944    void Free()
945    {
946       if(platforms) { platforms.Free(); delete platforms; }
947       if(configurations) { configurations.Free(); delete configurations; }
948       if(files) { files.Free(); delete files; }
949       if(resources) { resources.Free(); delete resources; }
950       delete options;
951       delete resourcesPath;
952
953       delete description;
954       delete license;
955       delete compilerConfigsDir;
956       delete moduleName;
957       delete moduleVersion;
958       delete filePath;
959       delete topNode;
960       delete name;
961       delete lastBuildConfigName;
962       delete lastBuildCompilerName;
963       if(lastBuildNamesInfo) { lastBuildNamesInfo.Free(); delete lastBuildNamesInfo; }
964    }
965
966    ~Project()
967    {
968       /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
969       topNode.configurations = null;
970       topNode.platforms = null;
971       topNode.options = null;
972       */
973       Free();
974    }
975
976    property ProjectConfig config
977    {
978       set
979       {
980          config = value;
981          delete topNode.info;
982          topNode.info = CopyString(GetConfigName(config));
983       }
984    }
985
986    property char * filePath
987    {
988       set
989       {
990          if(value)
991          {
992             char string[MAX_LOCATION];
993             GetLastDirectory(value, string);
994             delete topNode.name;
995             topNode.name = CopyString(string);
996             StripExtension(string);
997             delete name;
998             name = CopyString(string);
999             StripLastDirectory(value, string);
1000             delete topNode.path;
1001             topNode.path = CopyString(string);
1002             delete filePath;
1003             filePath = CopyString(value);
1004          }
1005       }
1006    }
1007
1008    ProjectConfig GetConfig(char * configName)
1009    {
1010       ProjectConfig result = null;
1011       if(configName && configName[0] && configurations.count)
1012       {
1013          for(cfg : configurations; !strcmpi(cfg.name, configName))
1014          {
1015             result = cfg;
1016             break;
1017          }
1018       }
1019       return result;
1020    }
1021
1022    ProjectNode FindNodeByObjectFileName(char * fileName, IntermediateFileType type, bool dotMain, ProjectConfig config)
1023    {
1024       ProjectNode result;
1025       if(!lastBuildNamesInfo)
1026          ProjectLoadLastBuildNamesInfo(this, config);
1027       result = topNode.FindByObjectFileName(fileName, type, dotMain, lastBuildNamesInfo);
1028       return result;
1029    }
1030
1031    TargetTypes GetTargetType(ProjectConfig config)
1032    {
1033       TargetTypes targetType = localTargetType;
1034       return targetType;
1035    }
1036
1037    bool GetTargetTypeIsSetByPlatform(ProjectConfig config)
1038    {
1039       Platform platform;
1040       for(platform = (Platform)1; platform < Platform::enumSize; platform++)
1041       {
1042          PlatformOptions projectPOs, configPOs;
1043          MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
1044          if(platformTargetType)
1045             return true;
1046       }
1047       return false;
1048    }
1049
1050    char * GetObjDirExpression(ProjectConfig config)
1051    {
1052       // TODO: Support platform options
1053       char * expression = localObjectsDirectory;
1054       if(!expression)
1055          expression = settingsObjectsDirectory;
1056       return expression;
1057    }
1058
1059    DirExpression GetObjDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1060    {
1061       char * expression = GetObjDirExpression(config);
1062       DirExpression objDir { type = intermediateObjectsDir };
1063       objDir.Evaluate(expression, this, compiler, config, bitDepth);
1064       return objDir;
1065    }
1066
1067    char * GetTargetDirExpression(ProjectConfig config)
1068    {
1069       // TODO: Support platform options
1070       char * expression = localTargetDirectory;
1071       if(!expression)
1072          expression = settingsTargetDirectory;
1073       return expression;
1074    }
1075
1076    DirExpression GetTargetDir(CompilerConfig compiler, ProjectConfig config, int bitDepth)
1077    {
1078       char * expression = GetTargetDirExpression(config);
1079       DirExpression targetDir { type = DirExpressionType::targetDir /*intermediateObjectsDir*/};
1080       targetDir.Evaluate(expression, this, compiler, config, bitDepth);
1081       return targetDir;
1082    }
1083
1084    WarningsOption GetWarnings(ProjectConfig config)
1085    {
1086       WarningsOption warnings = localWarnings;
1087       return warnings;
1088    }
1089
1090    bool GetDebug(ProjectConfig config)
1091    {
1092       SetBool debug = localDebug;
1093       return debug == true;
1094    }
1095
1096    bool GetMemoryGuard(ProjectConfig config)
1097    {
1098       SetBool memoryGuard = localMemoryGuard;
1099       return memoryGuard == true;
1100    }
1101
1102    bool GetNoLineNumbers(ProjectConfig config)
1103    {
1104       SetBool noLineNumbers = localNoLineNumbers;
1105       return noLineNumbers == true;
1106    }
1107
1108    bool GetProfile(ProjectConfig config)
1109    {
1110       SetBool profile = localProfile;
1111       return profile == true;
1112    }
1113
1114    OptimizationStrategy GetOptimization(ProjectConfig config)
1115    {
1116       OptimizationStrategy optimization = localOptimization;
1117       return optimization;
1118    }
1119
1120    bool GetFastMath(ProjectConfig config)
1121    {
1122       SetBool fastMath = localFastMath;
1123       return fastMath == true;
1124    }
1125
1126    String GetDefaultNameSpace(ProjectConfig config)
1127    {
1128       String defaultNameSpace = localDefaultNameSpace;
1129       return defaultNameSpace;
1130    }
1131
1132    bool GetStrictNameSpaces(ProjectConfig config)
1133    {
1134       SetBool strictNameSpaces = localStrictNameSpaces;
1135       return strictNameSpaces == true;
1136    }
1137
1138    String GetTargetFileName(ProjectConfig config)
1139    {
1140       String targetFileName = localTargetFileName;
1141       return targetFileName;
1142    }
1143
1144    //String targetDirectory;
1145    //String objectsDirectory;
1146    bool GetConsole(ProjectConfig config)
1147    {
1148       SetBool console = localConsole;
1149       return console == true;
1150    }
1151
1152    bool GetCompress(ProjectConfig config)
1153    {
1154       SetBool compress = localCompress;
1155       return compress == true;
1156    }
1157    //SetBool excludeFromBuild;
1158
1159    bool GetConfigIsInActiveDebugSession(ProjectConfig config)
1160    {
1161 #ifndef MAKEFILE_GENERATOR
1162       return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isActive;
1163 #endif
1164    }
1165
1166    bool GetConfigIsInDebugSession(ProjectConfig config)
1167    {
1168 #ifndef MAKEFILE_GENERATOR
1169       return ide.project == this && ide.debugger && ide.debugger.prjConfig == config && ide.debugger.isPrepared;
1170 #endif
1171    }
1172
1173    void SetPath(bool projectsDirs, CompilerConfig compiler, ProjectConfig config, int bitDepth)
1174    {
1175 #ifndef MAKEFILE_GENERATOR
1176       ide.SetPath(projectsDirs, compiler, config, bitDepth);
1177 #endif
1178    }
1179
1180 #ifndef MAKEFILE_GENERATOR
1181    bool Save(char * fileName)
1182    {
1183       File f;
1184       /*char output[MAX_LOCATION];
1185        ChangeExtension(fileName, "json", output);
1186       f = FileOpen(output, write);*/
1187       f = FileOpen(fileName, write);
1188       if(f)
1189       {
1190          files = topNode.files;
1191          resources = resNode.files;
1192          resourcesPath = resNode.path;
1193
1194          files.Remove(resNode);
1195          version = 0.2f;
1196
1197          WriteJSONObject(f, class(Project), this, 0);
1198
1199          files.Add(resNode);
1200
1201          files = null;
1202          resources = null;
1203          resourcesPath = null;
1204          delete f;
1205       }
1206       return true;
1207    }
1208 #endif
1209
1210    // This method is only called from Debugger, should be moved to Debugger class?
1211 #ifndef MAKEFILE_GENERATOR
1212    bool GetRelativePath(char * filePath, char * relativePath)
1213    {
1214       ProjectNode node;
1215       char moduleName[MAX_FILENAME];
1216       GetLastDirectory(filePath, moduleName);
1217       // try with workspace dir first?
1218       if((node = topNode.Find(moduleName, false)))
1219       {
1220          strcpy(relativePath, strcmp(node.path, ".") ? node.path : "");
1221          PathCatSlash(relativePath, node.name);
1222          return true;
1223       }
1224       else
1225       {
1226          // Tweak for automatically resolving symbol loader modules
1227          char * sl = strstr(moduleName, ".main.ec");
1228          if(sl && (*sl = 0, !strcmpi(moduleName, name)))
1229          {
1230             char objDir[MAX_LOCATION];
1231             DirExpression objDirExp;
1232             CompilerConfig compiler = ide.debugger.currentCompiler;
1233             ProjectConfig config = ide.debugger.prjConfig;
1234             int bitDepth = ide.debugger.bitDepth;
1235             // This is not perfect, as multiple source files exist for the symbol loader module...
1236             // We try to set it in the debug config object directory.
1237             if(!compiler || !config)
1238             {
1239                // If we're not currently debugging, set a breakpoint in the active compiler/config
1240                compiler = GetCompilerConfig();
1241                config = this.config;
1242                // If the current config is not debuggable, set it in the first debuggable config found
1243                if(config && !config.options.debug)
1244                {
1245                   for(c : configurations; c.options.debug)
1246                   {
1247                      config = c;
1248                      break;
1249                   }
1250                }
1251             }
1252             objDirExp = GetObjDir(compiler, config, bitDepth);
1253             strcpy(objDir, objDirExp.dir);
1254             delete objDirExp;
1255             ChangeCh(objDir, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
1256             ReplaceSpaces(relativePath, objDir);
1257             *sl = '.';
1258             PathCatSlash(relativePath, moduleName);
1259             return true;
1260          }
1261       }
1262       // WARNING: On failure, relative path is uninitialized
1263       return false;   
1264    }
1265 #endif
1266
1267    void CatTargetFileName(char * string, CompilerConfig compiler, ProjectConfig config)
1268    {
1269       TargetTypes targetType = GetTargetType(config);
1270       String targetFileName = GetTargetFileName(config);
1271       if(targetType == staticLibrary)
1272       {
1273          PathCatSlash(string, "lib");
1274          strcat(string, targetFileName);
1275       }
1276       else if(compiler.targetPlatform != win32 && targetType == sharedLibrary)
1277       {
1278          PathCatSlash(string, "lib");
1279          strcat(string, targetFileName);
1280       }
1281       else
1282          PathCatSlash(string, targetFileName);
1283       
1284       switch(targetType)
1285       {
1286          case executable:
1287             if(compiler.targetPlatform == win32)
1288                strcat(string, ".exe");
1289             break;
1290          case sharedLibrary:
1291             if(compiler.targetPlatform == win32)
1292                strcat(string, ".dll");
1293             else if(compiler.targetPlatform == apple)
1294                strcat(string, ".dylib");
1295             else
1296                strcat(string, ".so");
1297             if(compiler.targetPlatform == tux && GetRuntimePlatform() == tux && moduleVersion && moduleVersion[0])
1298             {
1299                strcat(string, ".");
1300                strcat(string, moduleVersion);
1301             }
1302             break;
1303          case staticLibrary:
1304             strcat(string, ".a");
1305             break;
1306       }
1307    }
1308
1309    bool GetProjectCompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1310    {
1311       bool result = false;
1312       char temp[MAX_LOCATION];
1313       strcpy(cfDir, topNode.path);
1314       if(compilerConfigsDir && compilerConfigsDir[0])
1315       {
1316          PathCatSlash(cfDir, compilerConfigsDir);
1317          result = true;
1318       }
1319       if(makeRelative)
1320       {
1321          strcpy(temp, cfDir);
1322          // Using a relative path makes it less likely to run into spaces issues
1323          // Even with escaped spaces, there still seems to be issues including a config file
1324          // in a path containing spaces
1325
1326          MakePathRelative(temp, topNode.path, cfDir);
1327       }
1328
1329       if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1330          strcat(cfDir, "/");
1331       if(replaceSpaces)
1332       {
1333          strcpy(temp, cfDir);
1334          ReplaceSpaces(cfDir, temp);
1335       }
1336       return result;
1337    }
1338
1339    bool GetIDECompilerConfigsDir(char * cfDir, bool replaceSpaces, bool makeRelative)
1340    {
1341       char temp[MAX_LOCATION];
1342       bool result = false;
1343       strcpy(cfDir, topNode.path);
1344       if(ideSettings && ideSettings.compilerConfigsDir && ideSettings.compilerConfigsDir[0])
1345       {
1346          PathCatSlash(cfDir, ideSettings.compilerConfigsDir);
1347          result = true;
1348       }
1349       else
1350       {
1351          // Default to <ProjectDir>/.configs if unset
1352          PathCatSlash(cfDir, ".configs");
1353          result = true;
1354       }
1355       if(makeRelative)
1356       {
1357          strcpy(temp, cfDir);
1358          // Using a relative path makes it less likely to run into spaces issues
1359          // Even with escaped spaces, there still seems to be issues including a config file
1360          // in a path containing spaces
1361          if(IsPathInsideOf(cfDir, topNode.path))
1362             MakePathRelative(temp, topNode.path, cfDir);
1363       }
1364       if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
1365          strcat(cfDir, "/");
1366       if(replaceSpaces)
1367       {
1368          strcpy(temp, cfDir);
1369          ReplaceSpaces(cfDir, temp);
1370       }
1371       return result;
1372    }
1373
1374    void CatMakeFileName(char * string, ProjectConfig config)
1375    {
1376       char projectName[MAX_LOCATION];
1377       strcpy(projectName, name);
1378       sprintf(string, "%s%s%s.Makefile", projectName, config ? "-" : "", config ? config.name : "");
1379    }
1380
1381 #ifndef MAKEFILE_GENERATOR
1382    void MarkChanges(ProjectNode node)
1383    {
1384       for(cfg : topNode.configurations)
1385       {
1386          ProjectConfig c = null;
1387          for(i : node.configurations; !strcmpi(i.name, cfg.name)) { c = i; break; }
1388
1389          if(c && ((c.options && cfg.options && cfg.options.console != c.options.console) ||
1390                (!c.options || !cfg.options)))
1391             cfg.symbolGenModified = true;
1392          if(c && ((c.options && cfg.options && 
1393                ( (cfg.options.libraries && c.options.libraries && cfg.options.libraries.OnCompare(c.options.libraries)) || (!cfg.options.libraries || !c.options.libraries)) ) 
1394             || (!c.options || !cfg.options)))
1395             cfg.linkingModified = true;
1396
1397          cfg.makingModified = true;
1398       }
1399    }
1400
1401    void ModifiedAllConfigs(bool making, bool compiling, bool linking, bool symbolGen)
1402    {
1403       for(cfg : configurations)
1404       {
1405          if(making)
1406             cfg.makingModified = true;
1407          if(compiling)
1408             cfg.compilingModified = true;
1409          if(linking)
1410             cfg.linkingModified = true;
1411          if(symbolGen)
1412             cfg.symbolGenModified = true;
1413       }
1414       if(compiling || linking)
1415       {
1416          ide.projectView.modifiedDocument = true;
1417          ide.workspace.modified = true;
1418       }
1419    }
1420    
1421    void RotateActiveConfig(bool forward)
1422    {
1423       if(configurations.first && configurations.last != configurations.first)
1424       {
1425          Iterator<ProjectConfig> cfg { configurations };
1426          while(forward ? cfg.Next() : cfg.Prev())
1427             if(cfg.data == config)
1428                break;
1429
1430          if(forward)
1431          {
1432             if(!cfg.Next())
1433                cfg.Next();
1434          }
1435          else
1436          {
1437             if(!cfg.Prev())
1438                cfg.Prev();
1439          }
1440
1441          property::config = cfg.data;
1442          ide.UpdateToolBarActiveConfigs(true);
1443          ide.workspace.modified = true;
1444          ide.projectView.Update(null);
1445       }
1446    }
1447
1448    bool ProcessPipeOutputRaw(DualPipe f)
1449    {
1450       char line[65536];
1451       while(!f.Eof() && !ide.projectView.stopBuild)
1452       {
1453          bool result = true;
1454          double lastTime = GetTime();
1455          bool wait = true;
1456          while(result)
1457          {
1458             if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)))
1459             {
1460                ide.outputView.buildBox.Logf("%s\n", line);
1461             }
1462             if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1463          }
1464          //printf("Processing Input...\n");
1465          if(app.ProcessInput(true))
1466             wait = false;
1467          app.UpdateDisplay();
1468          if(wait)
1469          {
1470             //printf("Waiting...\n");
1471             app.Wait();
1472          }
1473          //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1474       }
1475       if(ide.projectView.stopBuild)
1476       {
1477          ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1478          f.Terminate();
1479       }
1480       return !ide.projectView.stopBuild;
1481    }
1482
1483    bool ProcessBuildPipeOutput(DualPipe f, DirExpression objDirExp, bool isARun, List<ProjectNode> onlyNodes,
1484       CompilerConfig compiler, ProjectConfig config, int bitDepth)
1485    {
1486       char line[65536];
1487       bool compiling = false, linking = false, precompiling = false;
1488       int compilingEC = 0;
1489       int numErrors = 0, numWarnings = 0;
1490       bool loggedALine = false;
1491       int lenMakeCommand = strlen(compiler.makeCommand);
1492       int testLen = 0;
1493       char * t;
1494       char moduleName[MAX_FILENAME];
1495       char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
1496
1497       DynamicString test { };
1498       DynamicString ecp { };
1499       DynamicString ecc { };
1500       DynamicString ecs { };
1501       DynamicString ear { };
1502       DynamicString prefix { };
1503       DynamicString cpp { };
1504       DynamicString cc { };
1505       DynamicString cxx { };
1506       DynamicString strip { };
1507       DynamicString ar { };
1508       DynamicString windres { };
1509       /*
1510       if(bitDepth == 64 && compiler.targetPlatform == win32) 
1511          gnuToolchainPrefix = "x86_64-w64-mingw32-";
1512       else if(bitDepth == 32 && compiler.targetPlatform == win32)
1513          gnuToolchainPrefix = "i686-w64-mingw32-";
1514       */
1515       ecp.concatx(compiler.ecpCommand, " ");
1516       ecc.concatx(compiler.eccCommand, " ");
1517       ecs.concatx(compiler.ecsCommand, " ");
1518       ear.concatx(compiler.earCommand, " ");
1519
1520       prefix.concatx(
1521             compiler.ccacheEnabled ? "ccache " : "",
1522             compiler.distccEnabled ? "distcc " : "",
1523             gnuToolchainPrefix);
1524
1525       cpp.concatx((String)prefix, compiler.cppCommand, " ");
1526       cc.concatx((String)prefix, compiler.ccCommand,  " ");
1527       cxx.concatx((String)prefix, compiler.cxxCommand, " ");
1528
1529       strip.concatx(gnuToolchainPrefix, "strip ");
1530       ar.concatx(gnuToolchainPrefix, "ar rcs");
1531       windres.concatx(gnuToolchainPrefix, "windres ");
1532
1533       testLen = Max(testLen, ecp.size);
1534       testLen = Max(testLen, ecc.size);
1535       testLen = Max(testLen, ecs.size);
1536       testLen = Max(testLen, ear.size);
1537       testLen = Max(testLen, cpp.size);
1538       testLen = Max(testLen, cc.size);
1539       testLen = Max(testLen, cxx.size);
1540       testLen = Max(testLen, strip.size);
1541       testLen = Max(testLen, ar.size);
1542       testLen = Max(testLen, windres.size);
1543       testLen = Max(testLen, strlen("mkdir "));
1544       testLen++;
1545
1546       while(!f.Eof() && !ide.projectView.stopBuild)
1547       {
1548          bool result = true;
1549          double lastTime = GetTime();
1550          bool wait = true;
1551          while(result)
1552          {
1553             //printf("Peeking and GetLine...\n");
1554             if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1555             {
1556                char * message = null;
1557                char * inFileIncludedFrom = strstr(line, stringInFileIncludedFrom);
1558                char * from = strstr(line, stringFrom);
1559                test.copyLenSingleBlankReplTrim(line, ' ', true, testLen);
1560                if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':')
1561                {
1562                   char * module = strstr(line, "No rule to make target `");
1563                   if(module)
1564                   {
1565                      char * end;
1566                      module = strchr(module, '`') + 1;
1567                      end = strchr(module, '\'');
1568                      if(end)
1569                      {
1570                         *end = '\0';
1571                         ide.outputView.buildBox.Logf($"   %s: No such file or directory\n", module);
1572                         // ide.outputView.buildBox.Logf("error: %s\n   No such file or directory\n", module);
1573                         numErrors++;
1574                      }
1575                   }
1576                   //else
1577                   //{
1578                      //ide.outputView.buildBox.Logf("error: %s\n", line);
1579                      //numErrors++;
1580                   //}
1581                }
1582                else if(strstr(test, "mkdir ") == test);
1583                else if((t = strstr(line, "cd ")) && (t = strstr(line, "type ")) && (t = strstr(line, "nul ")) && (t = strstr(line, "copy ")) && (t = strstr(line, "cd ")));
1584                else if(strstr(test, ear) == test);
1585                else if(strstr(test, strip) == test);
1586                else if(strstr(test, cc) == test || strstr(test, cxx) == test || strstr(test, ecp) == test || strstr(test, ecc) == test)
1587                {
1588                   char * module;
1589                   bool isPrecomp = false;
1590                   bool gotCC = false;
1591
1592                   if(strstr(test, cc) == test || strstr(test, cxx) == test)
1593                   {
1594                      module = strstr(line, " -c ");
1595                      if(module) module += 4;
1596                      gotCC = true;
1597                   }
1598                   else if(strstr(test, ecc) == test)
1599                   {
1600                      module = strstr(line, " -c ");
1601                      if(module) module += 4;
1602                      //module = line + 3;
1603                      // Don't show GCC warnings about generated C code because it does not compile clean yet...
1604                      compilingEC = 3;//2;
1605                      gotCC = true;
1606                   }
1607                   else if(strstr(test, ecp) == test)
1608                   {
1609                      // module = line + 8;
1610                      module = strstr(line, " -c ");
1611                      if(module) module += 4;
1612                      isPrecomp = true;
1613                      compilingEC = 0;
1614                      gotCC = true;
1615                   }
1616
1617                   loggedALine = true;
1618
1619                   if(module)
1620                   {
1621                      byte * tokens[1];
1622                      if(!compiling && !isPrecomp)
1623                      {
1624                         ide.outputView.buildBox.Logf($"Compiling...\n");
1625                         compiling = true;
1626                      }
1627                      else if(!precompiling && isPrecomp)
1628                      {
1629                         ide.outputView.buildBox.Logf($"Generating symbols...\n");
1630                         precompiling = true;
1631                      }
1632                      // Changed escapeBackSlashes here to handle paths with spaces
1633                      Tokenize(module, 1, tokens, true); // false);
1634                      GetLastDirectory(module, moduleName);
1635                      ide.outputView.buildBox.Logf("%s\n", moduleName);
1636                   }
1637                   else if((module = strstr(line, " -o ")))
1638                   {
1639                      compiling = false;
1640                      precompiling = false;
1641                      linking = true;
1642                      ide.outputView.buildBox.Logf($"Linking...\n");
1643                   }
1644                   else
1645                   {
1646                      ide.outputView.buildBox.Logf("%s\n", line);
1647                      if(strstr(line, "warning:") || strstr(line, "note:"))
1648                         numWarnings++;
1649                      else if(!gotCC && !strstr(line, "At top level") && !strstr(line, "In file included from") && !strstr(line, stringFrom))
1650                         numErrors++;
1651                   }
1652
1653                   if(compilingEC) compilingEC--;
1654                }
1655                else if(strstr(test, windres) == test)
1656                {
1657                   char * module;
1658                   module = strstr(line, " ");
1659                   if(module) module++;
1660                   if(module)
1661                   {
1662                      byte * tokens[1];
1663                      Tokenize(module, 1, tokens, true);
1664                      GetLastDirectory(module, moduleName);
1665                      ide.outputView.buildBox.Logf("%s\n", moduleName);
1666                   }
1667                }
1668                else if(strstr(test, ar) == test)
1669                   ide.outputView.buildBox.Logf($"Building library...\n");
1670                else if(strstr(test, ecs) == test)
1671                   ide.outputView.buildBox.Logf($"Writing symbol loader...\n");
1672                else
1673                {
1674                   if(linking || compiling || precompiling)
1675                   {
1676                      char * start = inFileIncludedFrom ? inFileIncludedFrom + strlen(stringInFileIncludedFrom) : from ? from + strlen(stringFrom) : line;
1677                      char * colon = strstr(start, ":"); //, * bracket;
1678                      if(colon && (colon[1] == '/' || colon[1] == '\\'))
1679                         colon = strstr(colon + 1, ":");
1680                      if(colon)
1681                      {
1682                         char * sayError = "";
1683                         char moduleName[MAX_LOCATION], temp[MAX_LOCATION];
1684                         char * pointer;
1685                         char * error;
1686                         int len = (int)(colon - start);
1687                         char ext[MAX_EXTENSION];
1688                         len = Min(len, MAX_LOCATION-1);
1689                         // Don't be mistaken by the drive letter colon
1690                         // Cut module name
1691                         // TODO: need to fix colon - line gives char *
1692                         // warning: incompatible expression colon - line (char *); expected int
1693                         /*
1694                         strncpy(moduleName, line, (int)(colon - line));
1695                         moduleName[colon - line] = '\0';
1696                         */
1697                         strncpy(moduleName, start, len);
1698                         moduleName[len] = '\0';
1699                         // Remove stuff in brackets
1700                         //bracket = strstr(moduleName, "(");
1701                         //if(bracket) *bracket = '\0';
1702
1703                         GetLastDirectory(moduleName, temp);
1704                         GetExtension(temp, ext);
1705
1706                         if(linking && (!strcmp(ext, "o") || !strcmp(ext, "a") || !strcmp(ext, "lib")))
1707                         {
1708                            char * cColon = strstr(colon+1, ":");
1709                            if(cColon && (cColon[1] == '/' || cColon[1] == '\\'))
1710                               cColon = strstr(cColon + 1, ":");
1711                            if(cColon)
1712                            {
1713                               int len = (int)(cColon - (colon+1));
1714                               char mName[MAX_LOCATION];
1715                               len = Min(len, MAX_LOCATION-1);
1716                               strncpy(mName, colon+1, len);
1717                               mName[len] = '\0';
1718                               GetLastDirectory(mName, temp);
1719                               GetExtension(temp, ext);
1720                               if(!strcmp(ext, "c") || !strcmp(ext, "cpp") || !strcmp(ext, "cxx") || !strcmp(ext, "ec"))
1721                               {
1722                                  colon = cColon;
1723                                  strcpy(moduleName, mName);
1724                               }
1725                            }
1726                         }
1727                         if(linking && (!strcmp(temp, "ld") || !strcmp(temp, "ld.exe")))
1728                         {
1729                            moduleName[0] = 0;
1730                            if(strstr(colon, "skipping incompatible") || strstr(colon, "Recognised but unhandled"))
1731                            {
1732                               message = $"Linker Message: ";
1733                               colon = line;
1734                            }
1735                            else
1736                            {
1737                               numErrors++;
1738                               message = $"Linker Error";
1739                            }
1740                         }
1741                         else if(linking && (!strcmp(ext, "") || !strcmp(ext, "exe")))
1742                         {
1743                            moduleName[0] = 0;
1744                            colon = line;
1745                            if(!strstr(line, "error:"))
1746                            {
1747                               message = $"Linker Error: ";
1748                               numErrors++;
1749                            }
1750                         }
1751                         else
1752                         {
1753                            strcpy(temp, topNode.path);
1754                            PathCatSlash(temp, moduleName);
1755                            MakePathRelative(temp, topNode.path, moduleName);
1756                         }
1757                         error = strstr(line, "error:");
1758                         if(!message && error && error > colon)
1759                            numErrors++;
1760                         else
1761                         {
1762                            // Silence warnings for compiled eC
1763                            char * objDir = strstr(moduleName, objDirExp.dir);
1764                         
1765                            if(linking)
1766                            {
1767                               if((pointer = strstr(line, "undefined"))  ||
1768                                    (pointer = strstr(line, "multiple definition")) ||
1769                                    (pointer = strstr(line, "No such file")) ||
1770                                    (pointer = strstr(line, "token")))
1771                               {
1772                                  strncat(moduleName, colon, pointer - colon);
1773                                  sayError = "error: ";
1774                                  colon = pointer;
1775                                  numErrors++;
1776                               }
1777                            }
1778                            else if((pointer = strstr(line, "No such file")))
1779                            {
1780                               strncat(moduleName, colon, pointer - colon);
1781                               sayError = "error: ";
1782                               colon = pointer;
1783                               numErrors++;
1784                            }
1785                            else if(compilingEC == 1 || (objDir && objDir == moduleName))
1786                               continue;
1787                            else if(strstr(line, "warning:"))
1788                            {
1789                               numWarnings++;
1790                            }
1791                         }
1792                         if(message)
1793                            ide.outputView.buildBox.Logf("   %s%s\n", message, colon);
1794                         /*else if(this == ide.workspace.projects.firstIterator.data)
1795                            ide.outputView.buildBox.Logf("   %s%s%s\n", moduleName, sayError, colon);*/
1796                         else
1797                         {
1798                            char fullModuleName[MAX_LOCATION];
1799                            FileAttribs found = 0;
1800                            Project foundProject = this;
1801                            if(moduleName[0])
1802                            {
1803                               char * loc = strstr(moduleName, ":");
1804                               if(loc) *loc = 0;
1805                               strcpy(fullModuleName, topNode.path);
1806                               PathCat(fullModuleName, moduleName);
1807                               found = FileExists(fullModuleName);
1808                               if(!found && !strcmp(ext, "c"))
1809                               {
1810                                  char ecName[MAX_LOCATION];
1811                                  ChangeExtension(fullModuleName, "ec", ecName);
1812                                  found = FileExists(ecName);
1813                               }
1814                               if(!found)
1815                               {
1816                                  char path[MAX_LOCATION];
1817                                  if(ide && ide.workspace)
1818                                  {
1819                                     for(prj : ide.workspace.projects)
1820                                     {
1821                                        ProjectNode node;
1822                                        MakePathRelative(fullModuleName, prj.topNode.path, path);
1823
1824                                        if((node = prj.topNode.FindWithPath(path, false)))
1825                                        {
1826                                           strcpy(fullModuleName, prj.topNode.path);
1827                                           PathCatSlash(fullModuleName, node.path);
1828                                           PathCatSlash(fullModuleName, node.name);
1829                                           found = FileExists(fullModuleName);
1830                                           if(found)
1831                                           {
1832                                              foundProject = prj;
1833                                              break;
1834                                           }
1835                                        }
1836                                     }
1837                                     if(!found && !strchr(moduleName, '/') && !strchr(moduleName, '\\'))
1838                                     {
1839                                        for(prj : ide.workspace.projects)
1840                                        {
1841                                           ProjectNode node;
1842                                           if((node = prj.topNode.Find(moduleName, false)))
1843                                           {
1844                                              strcpy(fullModuleName, prj.topNode.path);
1845                                              PathCatSlash(fullModuleName, node.path);
1846                                              PathCatSlash(fullModuleName, node.name);
1847                                              found = FileExists(fullModuleName);
1848                                              if(found)
1849                                              {
1850                                                 foundProject = prj;
1851                                                 break;
1852                                              }
1853                                           }
1854                                        }
1855                                     }
1856                                  }
1857                               }
1858                               if(found)
1859                               {
1860                                  MakePathRelative(fullModuleName, ide.workspace.projects.firstIterator.data.topNode.path, fullModuleName);
1861                                  MakeSystemPath(fullModuleName);
1862                               }
1863                               else
1864                                  strcpy(fullModuleName, moduleName);
1865                               if(loc)
1866                               {
1867                                  strcat(fullModuleName, ":");
1868                                  strcat(fullModuleName, loc + 1);
1869                               }
1870                            }
1871                            else
1872                               fullModuleName[0] = 0;
1873                            ide.outputView.buildBox.Logf("   %s%s%s%s\n", inFileIncludedFrom ? stringInFileIncludedFrom : from ? stringFrom : "", fullModuleName, sayError, colon);
1874                         }
1875                      }
1876                      else
1877                      {
1878                         ide.outputView.buildBox.Logf("%s\n", line);
1879                         linking = compiling = precompiling = false;
1880                      }
1881                   }
1882                   else
1883                      ide.outputView.buildBox.Logf("%s\n", line);
1884                }
1885                wait = false;
1886             }
1887             //printf("Done getting line\n");
1888             if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1889          }
1890          //printf("Processing Input...\n");
1891          if(app.ProcessInput(true))
1892             wait = false;
1893          app.UpdateDisplay();
1894          if(wait)
1895          {
1896             //printf("Waiting...\n");
1897             app.Wait();
1898          }
1899          //if(!result) Sleep(1.0 / PEEK_RESOLUTION);
1900       }
1901       if(ide.projectView.stopBuild)
1902       {
1903          ide.outputView.buildBox.Logf($"\nBuild cancelled by user.\n", line);
1904          f.Terminate();
1905       }
1906       else if(loggedALine || !isARun)
1907       {
1908          if(f.GetExitCode() && !numErrors)
1909          {
1910             bool result = f.GetLine(line, sizeof(line)-1);
1911             ide.outputView.buildBox.Logf($"Fatal Error: child process terminated unexpectedly\n");
1912          }
1913          else
1914          {
1915             if(!onlyNodes)
1916             {
1917                char targetFileName[MAX_LOCATION];
1918                targetFileName[0] = '\0';
1919                CatTargetFileName(targetFileName, compiler, config);
1920                ide.outputView.buildBox.Logf("\n%s (%s) - ", targetFileName, lastBuildConfigName);
1921             }
1922             if(numErrors)
1923                ide.outputView.buildBox.Logf("%d %s, ", numErrors, (numErrors > 1) ? $"errors" : $"error");
1924             else
1925                ide.outputView.buildBox.Logf($"no error, ");
1926    
1927             if(numWarnings)
1928                ide.outputView.buildBox.Logf("%d %s\n", numWarnings, (numWarnings > 1) ? $"warnings" : $"warning");
1929             else
1930                ide.outputView.buildBox.Logf($"no warning\n");
1931          }
1932       }
1933
1934       delete test;
1935       delete ecp;
1936       delete ecc;
1937       delete ecs;
1938       delete ear;
1939       delete prefix;
1940       delete cpp;
1941       delete cc;
1942       delete cxx;
1943       delete strip;
1944       delete ar;
1945
1946       return numErrors == 0 && !ide.projectView.stopBuild;
1947    }
1948
1949    void ProcessCleanPipeOutput(DualPipe f, CompilerConfig compiler, ProjectConfig config)
1950    {
1951       char line[65536];
1952       int lenMakeCommand = strlen(compiler.makeCommand);
1953       while(!f.Eof())
1954       {
1955          bool result = true;
1956          bool wait = true;
1957          double lastTime = GetTime();
1958          while(result)
1959          {
1960             if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
1961             {
1962                if(strstr(line, compiler.makeCommand) == line && line[lenMakeCommand] == ':');
1963                else if(strstr(line, "mkdir") == line);
1964                else if(strstr(line, "del") == line);
1965                else if(strstr(line, "rm") == line);
1966                else if(strstr(line, "Could Not Find") == line);
1967                else
1968                {
1969                   ide.outputView.buildBox.Logf(line);
1970                   ide.outputView.buildBox.Logf("\n");
1971                }
1972                wait = false;
1973             }
1974             if(GetTime() - lastTime > 1.0 / PEEK_RESOLUTION) break;
1975          }
1976          if(app.ProcessInput(true))
1977             wait = false;
1978          app.UpdateDisplay();
1979          if(wait)
1980             app.Wait();
1981          //Sleep(1.0 / PEEK_RESOLUTION);
1982       }
1983    }
1984
1985    bool Build(bool isARun, List<ProjectNode> onlyNodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
1986    {
1987       bool result = false;
1988       DualPipe f;
1989       char targetFileName[MAX_LOCATION] = "";
1990       DynamicString makeTargets { };
1991       char makeFile[MAX_LOCATION];
1992       char makeFilePath[MAX_LOCATION];
1993       char configName[MAX_LOCATION];
1994       DirExpression objDirExp = GetObjDir(compiler, config, bitDepth);
1995       PathBackup pathBackup { };
1996       bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
1997       char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
1998
1999       bool eC_Debug = mode.eC_ToolsDebug;
2000       bool singleProjectOnlyNode = onlyNodes && onlyNodes.count == 1 && onlyNodes[0].type == project;
2001       int numJobs = compiler.numJobs;
2002       char command[MAX_F_STRING*4];
2003       char * compilerName = CopyString(compiler.name);
2004
2005       delete lastBuildConfigName;
2006       lastBuildConfigName = CopyString(config ? config.name : "Common");
2007       delete lastBuildCompilerName;
2008       lastBuildCompilerName = CopyString(compiler.name);
2009       ProjectLoadLastBuildNamesInfo(this, config);
2010
2011       CamelCase(compilerName);
2012
2013       strcpy(configName, config ? config.name : "Common");
2014
2015       SetPath(false, compiler, config, bitDepth); //true
2016       CatTargetFileName(targetFileName, compiler, config);
2017
2018       strcpy(makeFilePath, topNode.path);
2019       CatMakeFileName(makeFile, config);
2020       PathCatSlash(makeFilePath, makeFile);
2021
2022       // TODO: TEST ON UNIX IF \" around makeTarget is ok
2023       if(onlyNodes)
2024       {
2025          if(compiler.type.isVC)
2026          {
2027             PrintLn("compiling a single file is not yet supported");
2028          }
2029          else
2030          {
2031             int len;
2032             char pushD[MAX_LOCATION];
2033             char cfDir[MAX_LOCATION];
2034             GetIDECompilerConfigsDir(cfDir, true, true);
2035             GetWorkingDir(pushD, sizeof(pushD));
2036             ChangeWorkingDir(topNode.path);
2037             // Create object dir if it does not exist already
2038             if(!FileExists(objDirExp.dir).isDirectory)
2039             {
2040                sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s objdir -C \"%s\"%s -f \"%s\"",
2041                      compiler.makeCommand, cfDir,
2042                      crossCompiling ? " TARGET_PLATFORM=" : "",
2043                      targetPlatform,
2044                      bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2045                      /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" : */"",
2046
2047                      compilerName, topNode.path, justPrint ? " -n" : "", makeFilePath);
2048                if(justPrint)
2049                   ide.outputView.buildBox.Logf("%s\n", command);
2050                Execute(command);
2051             }
2052
2053             ChangeWorkingDir(pushD);
2054
2055             for(node : onlyNodes)
2056             {
2057                if(node.GetIsExcluded(config))
2058                   ide.outputView.buildBox.Logf($"File %s is excluded from current build configuration.\n", node.name);
2059                else
2060                {
2061                   if(!eC_Debug)
2062                      node.DeleteIntermediateFiles(compiler, config, bitDepth, lastBuildNamesInfo, mode == cObject ? true : false);
2063                   node.GetTargets(config, lastBuildNamesInfo, objDirExp.dir, makeTargets);
2064                }
2065             }
2066          }
2067       }
2068
2069       if(compiler.type.isVC)
2070       {
2071          bool result = false;
2072          char oldwd[MAX_LOCATION];
2073          GetWorkingDir(oldwd, sizeof(oldwd));
2074          ChangeWorkingDir(topNode.path);
2075
2076          // TODO: support justPrint
2077          sprintf(command, "%s /useenv /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2078          if(justPrint)
2079             ide.outputView.buildBox.Logf("%s\n", command);
2080          if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2081          {
2082             ProcessPipeOutputRaw(f);
2083             delete f;
2084             result = true;
2085          }
2086          ChangeWorkingDir(oldwd);
2087       }
2088       else if(onlyNodes && strlen(makeTargets) == 0)
2089       {
2090          ide.outputView.buildBox.Log("No targets to compile.\n");
2091       }
2092       else
2093       {
2094          char cfDir[MAX_LOCATION];
2095          GetIDECompilerConfigsDir(cfDir, true, true);
2096          sprintf(command, "%s %sCF_DIR=\"%s\"%s%s%s%s%s COMPILER=%s %s-j%d %s%s%s -C \"%s\"%s -f \"%s\"",
2097                compiler.makeCommand,
2098                mode == debugPrecompile ? "ECP_DEBUG=y " : mode == debugCompile ? "ECC_DEBUG=y " : mode == debugGenerateSymbols ? "ECS_DEBUG=y " : "",
2099                cfDir,
2100                crossCompiling ? " TARGET_PLATFORM=" : "",
2101                targetPlatform,
2102                bitDepth ? " ARCH=" : "",
2103                bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2104                /*(bitDepth == 64 && compiler.targetPlatform == win32) ? " GCC_PREFIX=x86_64-w64-mingw32-" : (bitDepth == 32 && compiler.targetPlatform == win32) ? " GCC_PREFIX=i686-w64-mingw32-" :*/ "",
2105                compilerName, eC_Debug ? "--always-make " : "", numJobs,
2106                (compiler.ccacheEnabled && !eC_Debug) ? "CCACHE=y " : "",
2107                (compiler.distccEnabled && !eC_Debug) ? "DISTCC=y " : "",
2108                (String)makeTargets, topNode.path, (justPrint || eC_Debug) ? " -n" : "", makeFilePath);
2109          if(justPrint)
2110             ide.outputView.buildBox.Logf("%s\n", command);
2111
2112          if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2113          {
2114             bool found = false;
2115             bool error = false;
2116             if(eC_Debug)
2117             {
2118                char line[65536];
2119                if(justPrint)
2120                   ide.outputView.buildBox.Logf($"\nMake outputs the following list of commands to choose from:\n");
2121                while(!f.Eof())
2122                {
2123                   bool result = true;
2124                   while(result)
2125                   {
2126                      if((result = f.Peek()) && (result = f.GetLine(line, sizeof(line)-1)) && line[0])
2127                      {
2128                         if(justPrint)
2129                            ide.outputView.buildBox.Logf("%s\n", line);
2130                         if(!error && !found && strstr(line, "echo ") == line)
2131                         {
2132                            strcpy(command, line+5);
2133                            error = true;
2134                         }
2135                         if(!error && (singleProjectOnlyNode || !found) && strstr(line, "ide ") == line)
2136                         {
2137                            strcpy(command, line);
2138                            found = true;
2139                         }
2140                      }
2141                   }
2142                }
2143                if(found)
2144                   result = true;
2145             }
2146             else if(justPrint)
2147                result = ProcessPipeOutputRaw(f);
2148             else
2149                result = ProcessBuildPipeOutput(f, objDirExp, isARun, onlyNodes, compiler, config, bitDepth);
2150             delete f;
2151             if(error)
2152                ide.outputView.buildBox.Logf("%s\n", command);
2153             else if(justPrint && found)
2154                ide.outputView.buildBox.Logf($"\nThe following command was chosen to be executed:\n%s\n", command);
2155             else if(found)
2156                Execute(command);
2157          }
2158          else
2159             ide.outputView.buildBox.Logf($"Error executing make (%s) command\n", compiler.makeCommand);
2160       }
2161
2162       delete pathBackup;
2163       delete objDirExp;
2164       delete compilerName;
2165       delete makeTargets;
2166       return result;
2167    }
2168
2169    void Clean(CompilerConfig compiler, ProjectConfig config, int bitDepth, CleanType cleanType, bool justPrint)
2170    {
2171       char makeFile[MAX_LOCATION];
2172       char makeFilePath[MAX_LOCATION];
2173       char command[MAX_LOCATION];
2174       char * compilerName;
2175       DualPipe f;
2176       PathBackup pathBackup { };
2177       bool crossCompiling = (compiler.targetPlatform != GetRuntimePlatform());
2178       char * targetPlatform = crossCompiling ? (char *)compiler.targetPlatform : "";
2179
2180       compilerName = CopyString(compiler.name);
2181       CamelCase(compilerName);
2182
2183       SetPath(false, compiler, config, bitDepth);
2184
2185       strcpy(makeFilePath, topNode.path);
2186       CatMakeFileName(makeFile, config);
2187       PathCatSlash(makeFilePath, makeFile);
2188       
2189       if(compiler.type.isVC)
2190       {
2191          bool result = false;
2192          char oldwd[MAX_LOCATION];
2193          GetWorkingDir(oldwd, sizeof(oldwd));
2194          ChangeWorkingDir(topNode.path);
2195          
2196          // TODO: justPrint support
2197          sprintf(command, "%s /useenv /clean /nologo /logcommands %s.sln %s|Win32", compiler.makeCommand, name, config.name);
2198          if(justPrint)
2199             ide.outputView.buildBox.Logf("%s\n", command);
2200          if((f = DualPipeOpen(PipeOpenMode { output = true, error = true, input = true }, command)))
2201          {
2202             ProcessPipeOutputRaw(f);
2203             delete f;
2204             result = true;
2205          }
2206          ChangeWorkingDir(oldwd);
2207          return result;
2208       }
2209       else
2210       {
2211          char cfDir[MAX_LOCATION];
2212          GetIDECompilerConfigsDir(cfDir, true, true);
2213          sprintf(command, "%s CF_DIR=\"%s\"%s%s%s%s COMPILER=%s %sclean%s -C \"%s\"%s -f \"%s\"",
2214                compiler.makeCommand, cfDir,
2215                crossCompiling ? " TARGET_PLATFORM=" : "", targetPlatform,
2216                bitDepth ? " ARCH=" : "", bitDepth == 32 ? "32" : bitDepth == 64 ? "64" : "",
2217                compilerName,
2218                cleanType == realClean ? "real" : "", cleanType == cleanTarget ? "target" : "",
2219                topNode.path, justPrint ? " -n": "", makeFilePath);
2220          if(justPrint)
2221             ide.outputView.buildBox.Logf("%s\n", command);
2222          if((f = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
2223          {
2224             ide.outputView.buildBox.Tellf($"Deleting %s%s...",
2225                   cleanType == realClean ? $"intermediate objects directory" : $"target",
2226                   cleanType == clean ? $" and object files" : "");
2227             if(justPrint)
2228                ProcessPipeOutputRaw(f);
2229             else
2230                ProcessCleanPipeOutput(f, compiler, config);
2231             ide.outputView.buildBox.Logf($"%s%s deleted\n",
2232                   cleanType == realClean ? $"Intermediate objects directory" : $"Target",
2233                   cleanType == clean ? $" and object files" : "");
2234             delete f;
2235          }
2236       }
2237
2238       delete pathBackup;
2239       delete compilerName;
2240    }
2241
2242    void Run(char * args, CompilerConfig compiler, ProjectConfig config, int bitDepth)
2243    {   
2244       String target = new char[maxPathLen];
2245       char oldDirectory[MAX_LOCATION];
2246       char * executableLauncher = compiler.executableLauncher;
2247       DirExpression targetDirExp = GetTargetDir(compiler, config, bitDepth);
2248       PathBackup pathBackup { };
2249
2250       // Build(project, ideMain, true, null, false);
2251
2252       strcpy(target, topNode.path);
2253       PathCatSlash(target, targetDirExp.dir);
2254       CatTargetFileName(target, compiler, config);
2255       sprintf(target, "%s %s", target, args);
2256       GetWorkingDir(oldDirectory, MAX_LOCATION);
2257
2258       if(strlen(ide.workspace.debugDir))
2259       {
2260          char temp[MAX_LOCATION];
2261          strcpy(temp, topNode.path);
2262          PathCatSlash(temp, ide.workspace.debugDir);
2263          ChangeWorkingDir(temp);
2264       }
2265       else
2266          ChangeWorkingDir(topNode.path);
2267       // ChangeWorkingDir(topNode.path);
2268       SetPath(true, compiler, config, bitDepth);
2269       if(executableLauncher)
2270       {
2271          char * prefixedTarget = new char[strlen(executableLauncher) + strlen(target) + 2];
2272          prefixedTarget[0] = '\0';
2273          strcat(prefixedTarget, executableLauncher);
2274          strcat(prefixedTarget, " ");
2275          strcat(prefixedTarget, target);
2276          Execute(prefixedTarget);
2277          delete prefixedTarget;
2278       }
2279       else
2280          Execute(target);
2281
2282       ChangeWorkingDir(oldDirectory);
2283       delete pathBackup;
2284
2285       delete targetDirExp;
2286       delete target;
2287    }
2288
2289    bool Compile(List<ProjectNode> nodes, CompilerConfig compiler, ProjectConfig config, int bitDepth, bool justPrint, SingleFileCompileMode mode)
2290    {
2291       return Build(false, nodes, compiler, config, bitDepth, justPrint, mode);
2292    }
2293 #endif
2294
2295    void GetMakefileTargetFileName(TargetTypes targetType, char * fileName, ProjectConfig config)
2296    {
2297       fileName[0] = '\0';
2298       if(targetType == staticLibrary || targetType == sharedLibrary)
2299          strcat(fileName, "$(LP)");
2300       // !!! ReplaceSpaces must be done after all PathCat calls !!!
2301       // ReplaceSpaces(s, GetTargetFileName(config));
2302       strcat(fileName, GetTargetFileName(config));
2303       switch(targetType)
2304       {
2305          case executable:
2306             strcat(fileName, "$(E)");
2307             break;
2308          case sharedLibrary:
2309             strcat(fileName, "$(SO)$(VER)");
2310             break;
2311          case staticLibrary:
2312             strcat(fileName, "$(A)");
2313             break;
2314       }
2315    }
2316
2317    bool GenerateCrossPlatformMk(File altCrossPlatformMk)
2318    {
2319       bool result = false;
2320       char path[MAX_LOCATION];
2321
2322       if(!GetProjectCompilerConfigsDir(path, false, false))
2323          GetIDECompilerConfigsDir(path, false, false);
2324
2325       if(!FileExists(path).isDirectory)
2326       {
2327          MakeDir(path);
2328          {
2329             char dirName[MAX_FILENAME];
2330             GetLastDirectory(path, dirName);
2331             if(!strcmp(dirName, ".configs"))
2332                FileSetAttribs(path, FileAttribs { isHidden = true });
2333          }
2334       }
2335       PathCatSlash(path, "crossplatform.mk");
2336
2337       if(FileExists(path))
2338          DeleteFile(path);
2339       {
2340          File include = altCrossPlatformMk ? altCrossPlatformMk : FileOpen(":crossplatform.mk", read);
2341          if(include)
2342          {
2343             File f = FileOpen(path, write);
2344             if(f)
2345             {
2346                include.Seek(0, start);
2347                for(; !include.Eof(); )
2348                {
2349                   char buffer[4096];
2350                   int count = include.Read(buffer, 1, 4096);
2351                   f.Write(buffer, 1, count);
2352                }
2353                delete f;
2354
2355                result = true;
2356             }
2357             if(!altCrossPlatformMk)
2358                delete include;
2359          }
2360       }
2361       return result;
2362    }
2363
2364    bool GenerateCompilerCf(CompilerConfig compiler)
2365    {
2366       bool result = false;
2367       char path[MAX_LOCATION];
2368       char * name;
2369       char * compilerName;
2370       bool gccCompiler = compiler.ccCommand && (strstr(compiler.ccCommand, "gcc") != null || strstr(compiler.ccCommand, "g++") != null);
2371       char * gnuToolchainPrefix = compiler.gnuToolchainPrefix ? compiler.gnuToolchainPrefix : "";
2372       Platform platform = compiler.targetPlatform;
2373
2374       compilerName = CopyString(compiler.name);
2375       CamelCase(compilerName);
2376       name = PrintString(platform, "-", compilerName, ".cf");
2377
2378       if(!GetProjectCompilerConfigsDir(path, false, false))
2379          GetIDECompilerConfigsDir(path, false, false);
2380
2381       if(!FileExists(path).isDirectory)
2382       {
2383          MakeDir(path);
2384          {
2385             char dirName[MAX_FILENAME];
2386             GetLastDirectory(path, dirName);
2387             if(!strcmp(dirName, ".configs"))
2388                FileSetAttribs(path, FileAttribs { isHidden = true });
2389          }
2390       }
2391       PathCatSlash(path, name);
2392
2393       if(FileExists(path))
2394          DeleteFile(path);
2395       {
2396          File f = FileOpen(path, write);
2397          if(f)
2398          {
2399             if(compiler.environmentVars && compiler.environmentVars.count)
2400             {
2401                f.Puts("# ENVIRONMENT VARIABLES\n");
2402                f.Puts("\n");
2403                for(e : compiler.environmentVars)
2404                {
2405                   f.Printf("export %s := %s\n", e.name, e.string);
2406                }
2407                f.Puts("\n");
2408             }
2409
2410             f.Puts("# TOOLCHAIN\n");
2411             f.Puts("\n");
2412
2413             if(gnuToolchainPrefix && gnuToolchainPrefix[0])
2414             {
2415                f.Printf("GCC_PREFIX := %s\n", gnuToolchainPrefix);
2416                f.Puts("\n");
2417             }
2418             if(compiler.sysroot && compiler.sysroot[0])
2419             {
2420                f.Printf("SYSROOT := %s\n", compiler.sysroot);
2421                // Moved this to crossplatform.mk
2422                //f.Puts("_SYSROOT := $(space)--sysroot=$(SYSROOT)\n");
2423                f.Puts("\n");
2424             }
2425
2426             //f.Printf("SHELL := %s\n", "sh"/*compiler.shellCommand*/); // is this really needed?
2427             f.Printf("CPP := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cppCommand);
2428             f.Printf("CC := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.ccCommand);
2429             f.Printf("CXX := $(CCACHE_COMPILE)$(DISTCC_COMPILE)$(GCC_PREFIX)%s$(_SYSROOT)\n", compiler.cxxCommand);
2430             f.Printf("ECP := $(if $(ECP_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecp/ecp.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)\n", compiler.ecpCommand);
2431             f.Printf("ECC := $(if $(ECC_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecc/ecc.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)\n", compiler.eccCommand);
2432             f.Printf("ECS := $(if $(ECS_DEBUG),ide -debug-start \"$(ECERE_SDK_SRC)/compiler/ecs/ecs.epj\" -debug-work-dir \"${CURDIR}\" -@,%s)$(if $(CROSS_TARGET), -t $(TARGET_PLATFORM),)$(if $(OUTPUT_POT), -outputpot,)\n", compiler.ecsCommand);
2433             f.Printf("EAR := %s\n", compiler.earCommand);
2434
2435             f.Puts("AS := $(GCC_PREFIX)as\n");
2436             f.Puts("LD := $(GCC_PREFIX)ld\n");
2437             f.Puts("AR := $(GCC_PREFIX)ar\n");
2438             f.Puts("STRIP := $(GCC_PREFIX)strip\n");
2439             f.Puts("ifdef WINDOWS_TARGET\n");
2440             f.Puts("WINDRES := $(GCC_PREFIX)windres\n");
2441             f.Puts(" ifdef ARCH\n");
2442             f.Puts("  ifeq \"$(ARCH)\" \"x32\"\n");
2443             f.Puts("WINDRES_FLAGS := -F pe-i386\n");
2444             f.Puts("  else\n");
2445             f.Puts("   ifeq \"$(ARCH)\" \"x64\"\n");
2446             f.Puts("WINDRES_FLAGS := -F pe-x86-64\n");
2447             f.Puts("   endif\n");
2448             f.Puts("  endif\n");
2449             f.Puts(" endif\n");
2450             f.Puts("endif\n");
2451             f.Puts("UPX := upx\n");
2452             f.Puts("\n");
2453
2454             f.Puts("UPXFLAGS = -9\n"); // TOFEAT: Compression Level Option? Other UPX Options?
2455             f.Puts("\n");
2456
2457             f.Puts("EARFLAGS = \n");
2458             f.Puts("\n");
2459
2460             f.Puts("ifndef ARCH\n");
2461             f.Puts("TARGET_ARCH :=$(shell $(CC) -dumpmachine)\n");
2462             f.Puts(" ifdef WINDOWS_HOST\n");
2463             f.Puts("  ifneq ($(filter x86_64%,$(TARGET_ARCH)),)\n");
2464             f.Puts("     TARGET_ARCH := x86_64\n");
2465             f.Puts("  else\n");
2466             f.Puts("     TARGET_ARCH := i386\n");
2467             f.Puts("  endif\n");
2468             f.Puts(" endif\n");
2469             f.Puts("endif\n\n");
2470
2471             f.Puts("# HARD CODED TARGET_PLATFORM-SPECIFIC OPTIONS\n");
2472             f.Printf("LDFLAGS +=$(if $(%s), -Wl$(comma)--no-undefined,)\n", PlatformToMakefileTargetVariable(tux));
2473             f.Puts("\n");
2474
2475             // JF's
2476             f.Printf("LDFLAGS +=$(if $(%s), -framework cocoa -framework OpenGL,)\n", PlatformToMakefileTargetVariable(apple));
2477
2478             if(gccCompiler)
2479             {
2480                f.Puts("\nCFLAGS += -fmessage-length=0\n");
2481             }
2482
2483             if(compiler.includeDirs && compiler.includeDirs.count)
2484             {
2485                f.Puts("\nCFLAGS +=");
2486                OutputListOption(f, gccCompiler ? "isystem " : "I", compiler.includeDirs, lineEach, true, false);
2487                f.Puts("\n");
2488             }
2489             if(compiler.prepDirectives && compiler.prepDirectives.count)
2490             {
2491                f.Puts("\nCFLAGS +=");
2492                OutputListOption(f, "D", compiler.prepDirectives, inPlace, true, false);
2493                f.Puts("\n");
2494             }
2495             if(compiler.libraryDirs && compiler.libraryDirs.count)
2496             {
2497                f.Puts("\nLDFLAGS +=");
2498                OutputListOption(f, "L", compiler.libraryDirs, lineEach, true, false);
2499                // We would need a bool option to know whether we want to add to rpath as well...
2500                // OutputListOption(f, "Wl,-rpath ", compiler.libraryDirs, lineEach, true, false);
2501                f.Puts("\n");
2502             }
2503             if(compiler.excludeLibs && compiler.excludeLibs.count)
2504             {
2505                f.Puts("\nEXCLUDED_LIBS =");
2506                for(l : compiler.excludeLibs)
2507                {
2508                   f.Puts(" ");
2509                   f.Puts(l);
2510                }
2511             }
2512             if(compiler.compilerFlags && compiler.compilerFlags.count)
2513             {
2514                f.Puts("\nCFLAGS +=");
2515                OutputListOption(f, "", compiler.compilerFlags, inPlace, true, true);
2516                f.Puts("\n");
2517             }
2518             if(compiler.linkerFlags && compiler.linkerFlags.count)
2519             {
2520                f.Puts("\nLDFLAGS +=");
2521                OutputListOption(f, "Wl,", compiler.linkerFlags, inPlace, true, false);
2522                f.Puts("\n");
2523             }
2524             f.Puts("\n");
2525             f.Puts("\nOFLAGS += $(LDFLAGS)");
2526             f.Puts("\n");
2527             f.Puts("ifdef ARCH_FLAGS\n");
2528             f.Puts("CFLAGS += $(ARCH_FLAGS)\n");
2529             f.Puts("OFLAGS += $(ARCH_FLAGS)\n");
2530             f.Puts("endif\n");
2531
2532             delete f;
2533
2534             result = true;
2535          }
2536       }
2537       delete name;
2538       delete compilerName;
2539       return result;
2540    }
2541
2542    bool GenerateMakefile(char * altMakefilePath, bool noResources, char * includemkPath, ProjectConfig config)
2543    {
2544       bool result = false;
2545       char filePath[MAX_LOCATION];
2546       char makeFile[MAX_LOCATION];
2547       // PathBackup pathBackup { };
2548       // char oldDirectory[MAX_LOCATION];
2549       File f = null;
2550
2551       if(!altMakefilePath)
2552       {
2553          strcpy(filePath, topNode.path);
2554          CatMakeFileName(makeFile, config);
2555          PathCatSlash(filePath, makeFile);
2556       }
2557
2558       f = FileOpen(altMakefilePath ? altMakefilePath : filePath, write);
2559
2560       /*SetPath(false, compiler, config);
2561       GetWorkingDir(oldDirectory, MAX_LOCATION);
2562       ChangeWorkingDir(topNode.path);*/
2563
2564       if(f)
2565       {
2566          bool test;
2567          int ifCount;
2568          Platform platform;
2569          char targetDir[MAX_LOCATION];
2570          char objDirExpNoSpaces[MAX_LOCATION];
2571          char objDirNoSpaces[MAX_LOCATION];
2572          char resDirNoSpaces[MAX_LOCATION];
2573          char targetDirExpNoSpaces[MAX_LOCATION];
2574          char fixedModuleName[MAX_FILENAME];
2575          char fixedConfigName[MAX_FILENAME];
2576          int c, len;
2577          int lenObjDirExpNoSpaces, lenTargetDirExpNoSpaces;
2578          // Non-zero if we're building eC code
2579          // We'll have to be careful with this when merging configs where eC files can be excluded in some configs and included in others
2580          int numCObjects = 0;
2581          int numObjects = 0;
2582          int numRCObjects = 0;
2583          bool containsCXX = false; // True if the project contains a C++ file
2584          bool relObjDir, sameOrRelObjTargetDirs;
2585          String objDirExp = GetObjDirExpression(config);
2586          TargetTypes targetType = GetTargetType(config);
2587
2588          char cfDir[MAX_LOCATION];
2589          int objectsParts = 0;
2590          int eCsourcesParts = 0;
2591          int rcSourcesParts = 0;
2592          Array<String> listItems { };
2593          Map<String, int> varStringLenDiffs { };
2594          Map<String, NameCollisionInfo> namesInfo { };
2595
2596          Map<String, int> cflagsVariations { };
2597          Map<intptr, int> nodeCFlagsMapping { };
2598
2599          Map<String, int> ecflagsVariations { };
2600          Map<intptr, int> nodeECFlagsMapping { };
2601
2602          ReplaceSpaces(objDirNoSpaces, objDirExp);
2603          strcpy(targetDir, GetTargetDirExpression(config));
2604          ReplaceSpaces(targetDirExpNoSpaces, targetDir);
2605
2606          strcpy(objDirExpNoSpaces, GetObjDirExpression(config));
2607          ChangeCh(objDirExpNoSpaces, '\\', '/'); // TODO: this is a hack, paths should never include win32 path seperators - fix this in ProjectSettings and ProjectLoad instead
2608          {
2609             char temp[MAX_LOCATION];
2610             ReplaceSpaces(temp, objDirExpNoSpaces);
2611             strcpy(objDirExpNoSpaces, temp);
2612          }
2613          ReplaceSpaces(resDirNoSpaces, resNode.path ? resNode.path : "");
2614          ReplaceSpaces(fixedModuleName, moduleName);
2615          ReplaceSpaces(fixedConfigName, GetConfigName(config));
2616          CamelCase(fixedConfigName);
2617
2618          lenObjDirExpNoSpaces = strlen(objDirExpNoSpaces);
2619          relObjDir = lenObjDirExpNoSpaces == 0 ||
2620                (objDirExpNoSpaces[0] == '.' && (lenObjDirExpNoSpaces == 1 || objDirExpNoSpaces[1] == '.'));
2621          lenTargetDirExpNoSpaces = strlen(targetDirExpNoSpaces);
2622          sameOrRelObjTargetDirs = lenTargetDirExpNoSpaces == 0 ||
2623                (targetDirExpNoSpaces[0] == '.' && (lenTargetDirExpNoSpaces == 1 || targetDirExpNoSpaces[1] == '.')) ||
2624                !fstrcmp(objDirExpNoSpaces, targetDirExpNoSpaces);
2625
2626          f.Printf(".PHONY: all objdir%s cleantarget clean realclean distclean\n\n", sameOrRelObjTargetDirs ? "" : " targetdir");
2627
2628          f.Puts("# CORE VARIABLES\n\n");
2629
2630          f.Printf("MODULE := %s\n", fixedModuleName);
2631          f.Printf("VERSION := %s\n", property::moduleVersion);
2632          f.Printf("CONFIG := %s\n", fixedConfigName);
2633          f.Puts("ifndef COMPILER\n" "COMPILER := default\n" "endif\n");
2634          f.Puts("\n");
2635
2636          test = GetTargetTypeIsSetByPlatform(config);
2637          if(test)
2638          {
2639             ifCount = 0;
2640             for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2641             {
2642                TargetTypes targetType;
2643                PlatformOptions projectPOs, configPOs;
2644                MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
2645                targetType = platformTargetType;
2646                if(targetType)
2647                {
2648                   if(ifCount)
2649                      f.Puts("else\n");
2650                   ifCount++;
2651                   f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2652                   f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2653                }
2654             }
2655             f.Puts("else\n");
2656          }
2657          f.Printf("TARGET_TYPE = %s\n", TargetTypeToMakefileVariable(targetType));
2658          if(test)
2659          {
2660             if(ifCount)
2661             {
2662                for(c = 0; c < ifCount; c++)
2663                   f.Puts("endif\n");
2664             }
2665          }
2666          f.Puts("\n");
2667
2668          f.Puts("# FLAGS\n\n");
2669
2670          f.Puts("ECFLAGS =\n");
2671          f.Puts("ifndef DEBIAN_PACKAGE\n" "CFLAGS =\n" "LDFLAGS =\n" "endif\n");
2672          f.Puts("PRJ_CFLAGS =\n");
2673          f.Puts("CECFLAGS =\n");
2674          f.Puts("OFLAGS =\n");
2675          f.Puts("LIBS =\n");
2676          f.Puts("\n");
2677
2678          f.Puts("ifdef DEBUG\n" "NOSTRIP := y\n" "endif\n");
2679          f.Puts("\n");
2680
2681          // Important: We cannot use this ifdef anymore, EXECUTABLE_TARGET is not yet defined. It's embedded in the crossplatform.mk EXECUTABLE
2682          //f.Puts("ifdef EXECUTABLE_TARGET\n");
2683          f.Printf("CONSOLE = %s\n", GetConsole(config) ? "-mconsole" : "-mwindows");
2684          //f.Puts("endif\n");
2685          f.Puts("\n");
2686
2687          f.Puts("# INCLUDES\n\n");
2688
2689          if(compilerConfigsDir && compilerConfigsDir[0])
2690          {
2691             strcpy(cfDir, compilerConfigsDir);
2692             if(cfDir && cfDir[0] && cfDir[strlen(cfDir)-1] != '/')
2693                strcat(cfDir, "/");
2694          }
2695          else
2696          {
2697             GetIDECompilerConfigsDir(cfDir, true, true);
2698             // Use CF_DIR environment variable for absolute paths only
2699             if(cfDir[0] == '/' || (cfDir[0] && cfDir[1] == ':'))
2700                strcpy(cfDir, "$(CF_DIR)");
2701          }
2702
2703          f.Printf("_CF_DIR = %s\n", cfDir);
2704          f.Puts("\n");
2705
2706          f.Printf("include %s\n", includemkPath ? includemkPath : "$(_CF_DIR)crossplatform.mk");
2707          f.Puts("include $(_CF_DIR)$(TARGET_PLATFORM)-$(COMPILER).cf\n");
2708          f.Puts("\n");
2709
2710          f.Puts("# POST-INCLUDES VARIABLES\n\n");
2711
2712          f.Printf("OBJ = %s%s\n", objDirExpNoSpaces, objDirExpNoSpaces[0] ? "/" : "");
2713          f.Puts("\n");
2714
2715          f.Printf("RES = %s%s\n", resDirNoSpaces, resDirNoSpaces[0] ? "/" : "");
2716          f.Puts("\n");
2717
2718          // test = GetTargetTypeIsSetByPlatform(config);
2719          {
2720             char target[MAX_LOCATION];
2721             char temp[MAX_LOCATION];
2722             if(test)
2723             {
2724                TargetTypes type;
2725                ifCount = 0;
2726                for(type = (TargetTypes)1; type < TargetTypes::enumSize; type++)
2727                {
2728                   if(type != targetType)
2729                   {
2730                      if(ifCount)
2731                         f.Puts("else\n");
2732                      ifCount++;
2733                      f.Printf("ifeq \"$(TARGET_TYPE)\" \"%s\"\n", TargetTypeToMakefileVariable(type));
2734
2735                      GetMakefileTargetFileName(type, target, config);
2736                      strcpy(temp, targetDir);
2737                      PathCatSlash(temp, target);
2738                      ReplaceSpaces(target, temp);
2739                      f.Printf("TARGET = %s\n", target);
2740                   }
2741                }
2742                f.Puts("else\n");
2743             }
2744             GetMakefileTargetFileName(targetType, target, config);
2745             strcpy(temp, targetDir);
2746             PathCatSlash(temp, target);
2747             ReplaceSpaces(target, temp);
2748             f.Printf("TARGET = %s\n", target);
2749
2750             if(test)
2751             {
2752                if(ifCount)
2753                {
2754                   for(c = 0; c < ifCount; c++)
2755                      f.Puts("endif\n");
2756                }
2757             }
2758          }
2759          f.Puts("\n");
2760
2761          // Use something fixed here, to not cause Makefile differences across compilers...
2762          varStringLenDiffs["$(OBJ)"] = 30; // strlen("obj/memoryGuard.android.gcc-4.6.2") - 6;
2763          // varStringLenDiffs["$(OBJ)"] = strlen(objDirNoSpaces) - 6;
2764
2765          topNode.GenMakefileGetNameCollisionInfo(namesInfo, config);
2766
2767          {
2768             int c;
2769             char * map[5][2] = { { "COBJECTS", "C" }, { "SYMBOLS", "S" }, { "IMPORTS", "I" }, { "ECOBJECTS", "O" }, { "BOWLS", "B" } };
2770
2771             numCObjects = topNode.GenMakefilePrintNode(f, this, eCsources, namesInfo, listItems, config, null);
2772             if(numCObjects)
2773             {
2774                eCsourcesParts = OutputFileList(f, "_ECSOURCES", listItems, varStringLenDiffs, null);
2775
2776                f.Puts("ECSOURCES = $(call shwspace,$(_ECSOURCES))\n");
2777                if(eCsourcesParts > 1)
2778                {
2779                   for(c = 1; c <= eCsourcesParts; c++)
2780                      f.Printf("ECSOURCES%d = $(call shwspace,$(_ECSOURCES%d))\n", c, c);
2781                }
2782                f.Puts("\n");
2783
2784                for(c = 0; c < 5; c++)
2785                {
2786                   if(eCsourcesParts > 1)
2787                   {
2788                      int n;
2789                      f.Printf("%s =", map[c][0]);
2790                      for(n = 1; n <= eCsourcesParts; n++)
2791                         f.Printf(" $(%s%d)", map[c][0], n);
2792                      f.Puts("\n");
2793                      for(n = 1; n <= eCsourcesParts; n++)
2794                         f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES%d)))))\n", map[c][0], n, map[c][1], n);
2795                   }
2796                   else if(eCsourcesParts == 1)
2797                      f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.ec,%%$(%s),$(notdir $(_ECSOURCES)))))\n", map[c][0], map[c][1]);
2798                   f.Puts("\n");
2799                }
2800             }
2801          }
2802
2803          numRCObjects = topNode.GenMakefilePrintNode(f, this, rcSources, namesInfo, listItems, config, null);
2804          if(numRCObjects)
2805          {
2806             f.Puts("ifdef WINDOWS_TARGET\n\n");
2807
2808             rcSourcesParts = OutputFileList(f, "_RCSOURCES", listItems, varStringLenDiffs, null);
2809
2810             f.Puts("RCSOURCES = $(call shwspace,$(_RCSOURCES))\n");
2811             if(rcSourcesParts > 1)
2812             {
2813                for(c = 1; c <= rcSourcesParts; c++)
2814                   f.Printf("RCSOURCES%d = $(call shwspace,$(_RCSOURCES%d))\n", c, c);
2815             }
2816             f.Puts("\n");
2817             if(rcSourcesParts > 1)
2818             {
2819                int n;
2820                f.Printf("%s =", "RCOBJECTS");
2821                for(n = 1; n <= rcSourcesParts; n++)
2822                   f.Printf(" $(%s%d)", "RCOBJECTS", n);
2823                f.Puts("\n");
2824                for(n = 1; n <= rcSourcesParts; n++)
2825                   f.Printf("%s%d = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES%d)))))\n", "RCOBJECTS", n, "O", n);
2826             }
2827             else if(rcSourcesParts == 1)
2828                f.Printf("%s = $(call shwspace,$(addprefix $(OBJ),$(patsubst %%.rc,%%$(%s),$(notdir $(_RCSOURCES)))))\n", "RCOBJECTS", "O");
2829             f.Puts("\n");
2830
2831             f.Puts("else\n");
2832             f.Puts("RCSOURCES =\n");
2833             f.Puts("RCOBJECTS =\n");
2834             f.Puts("endif\n\n");
2835          }
2836
2837          numObjects = topNode.GenMakefilePrintNode(f, this, objects, namesInfo, listItems, config, &containsCXX);
2838          if(numObjects)
2839             objectsParts = OutputFileList(f, "_OBJECTS", listItems, varStringLenDiffs, null);
2840          f.Printf("OBJECTS =%s%s%s%s\n",
2841                numObjects ? " $(_OBJECTS)" : "", numCObjects ? " $(ECOBJECTS)" : "",
2842                numCObjects ? " $(OBJ)$(MODULE).main$(O)" : "",
2843                numRCObjects ? " $(RCOBJECTS)" : "");
2844          f.Puts("\n");
2845
2846          topNode.GenMakefilePrintNode(f, this, sources, null, listItems, config, null);
2847          {
2848             char * prefix;
2849             if(numCObjects && numRCObjects)
2850                prefix = "$(ECSOURCES) $(RCSOURCES)";
2851             else if(numCObjects)
2852                prefix = "$(ECSOURCES)";
2853             else
2854                prefix = null;
2855             OutputFileList(f, "SOURCES", listItems, varStringLenDiffs, prefix);
2856          }
2857
2858          if(!noResources)
2859             resNode.GenMakefilePrintNode(f, this, resources, null, listItems, config, null);
2860          OutputFileList(f, "RESOURCES", listItems, varStringLenDiffs, null);
2861
2862          f.Puts("LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)\n");
2863          f.Puts("\n");
2864          if((config && config.options && config.options.libraries) ||
2865                (options && options.libraries))
2866          {
2867             f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2868             f.Puts("LIBS +=");
2869             if(config && config.options && config.options.libraries)
2870                OutputLibraries(f, config.options.libraries);
2871             else if(options && options.libraries)
2872                OutputLibraries(f, options.libraries);
2873             f.Puts("\n");
2874             f.Puts("endif\n");
2875             f.Puts("\n");
2876          }
2877
2878          topNode.GenMakeCollectAssignNodeFlags(config, numCObjects,
2879                cflagsVariations, nodeCFlagsMapping,
2880                ecflagsVariations, nodeECFlagsMapping, null);
2881
2882          GenMakePrintCustomFlags(f, "PRJ_CFLAGS", false, cflagsVariations);
2883          GenMakePrintCustomFlags(f, "ECFLAGS", true, ecflagsVariations);
2884
2885          if(platforms || (config && config.platforms))
2886          {
2887             ifCount = 0;
2888             //for(platform = firstPlatform; platform <= lastPlatform; platform++)
2889             //for(platform = win32; platform <= apple; platform++)
2890
2891             f.Puts("# PLATFORM-SPECIFIC OPTIONS\n\n");
2892             for(platform = (Platform)1; platform < Platform::enumSize; platform++)
2893             {
2894                PlatformOptions projectPlatformOptions, configPlatformOptions;
2895                MatchProjectAndConfigPlatformOptions(config, platform, &projectPlatformOptions, &configPlatformOptions);
2896
2897                if(projectPlatformOptions || configPlatformOptions)
2898                {
2899                   if(ifCount)
2900                      f.Puts("else\n");
2901                   ifCount++;
2902                   f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
2903                   f.Puts("\n");
2904
2905                   if((projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count) ||
2906                      (configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count))
2907                   {
2908                      f.Puts("CFLAGS +=");
2909                      if(projectPlatformOptions && projectPlatformOptions.options.compilerOptions && projectPlatformOptions.options.compilerOptions.count)
2910                      {
2911                         f.Puts(" \\\n\t ");
2912                         for(s : projectPlatformOptions.options.compilerOptions)
2913                            f.Printf(" %s", s);
2914                      }
2915                      if(configPlatformOptions && configPlatformOptions.options.compilerOptions && configPlatformOptions.options.compilerOptions.count)
2916                      {
2917                         f.Puts(" \\\n\t ");
2918                         for(s : configPlatformOptions.options.compilerOptions)
2919                            f.Printf(" %s", s);
2920                      }
2921                      f.Puts("\n");
2922                      f.Puts("\n");
2923                   }
2924
2925                   if((projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count) ||
2926                      (configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count))
2927                   {
2928                      f.Puts("OFLAGS +=");
2929                      if(projectPlatformOptions && projectPlatformOptions.options.linkerOptions && projectPlatformOptions.options.linkerOptions.count)
2930                      {
2931                         bool needWl = false;
2932                         f.Puts(" \\\n\t ");
2933                         for(s : projectPlatformOptions.options.linkerOptions)
2934                         {
2935                            if(!IsLinkerOption(s))
2936                               f.Printf(" %s", s);
2937                            else
2938                               needWl = true;
2939                         }
2940                         if(needWl)
2941                         {
2942                            f.Puts(" -Wl");
2943                            for(s : projectPlatformOptions.options.linkerOptions)
2944                               if(IsLinkerOption(s))
2945                                  f.Printf(",%s", s);
2946                         }
2947                      }
2948                      if(configPlatformOptions && configPlatformOptions.options.linkerOptions && configPlatformOptions.options.linkerOptions.count)
2949                      {
2950                         bool needWl = false;
2951                         f.Puts(" \\\n\t ");
2952                         for(s : configPlatformOptions.options.linkerOptions)
2953                         {
2954                            if(IsLinkerOption(s))
2955                               f.Printf(" %s", s);
2956                            else
2957                               needWl = true;
2958                         }
2959                         if(needWl)
2960                         {
2961                            f.Puts(" -Wl");
2962                            for(s : configPlatformOptions.options.linkerOptions)
2963                               if(!IsLinkerOption(s))
2964                                  f.Printf(",%s", s);
2965                         }
2966                      }
2967                      f.Puts("\n");
2968                      f.Puts("\n");
2969                   }
2970
2971                   if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2972                         (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count) ||
2973                         (projectPlatformOptions && projectPlatformOptions.options.libraries && projectPlatformOptions.options.libraries.count) ||
2974                         (configPlatformOptions && configPlatformOptions.options.libraries && configPlatformOptions.options.libraries.count))
2975                   {
2976                      f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
2977                      if((projectPlatformOptions && projectPlatformOptions.options.libraryDirs && projectPlatformOptions.options.libraryDirs.count) ||
2978                         (configPlatformOptions && configPlatformOptions.options.libraryDirs && configPlatformOptions.options.libraryDirs.count))
2979                      {
2980                         f.Puts("OFLAGS +=");
2981                         if(configPlatformOptions && configPlatformOptions.options.libraryDirs)
2982                            OutputListOption(f, "L", configPlatformOptions.options.libraryDirs, lineEach, true, false);
2983                         if(projectPlatformOptions && projectPlatformOptions.options.libraryDirs)
2984                            OutputListOption(f, "L", projectPlatformOptions.options.libraryDirs, lineEach, true, false);
2985                         f.Puts("\n");
2986                      }
2987
2988                      if((configPlatformOptions && configPlatformOptions.options.libraries))
2989                      {
2990                         if(configPlatformOptions.options.libraries.count)
2991                         {
2992                            f.Puts("LIBS +=");
2993                            OutputLibraries(f, configPlatformOptions.options.libraries);
2994                            f.Puts("\n");
2995                         }
2996                      }
2997                      else if(projectPlatformOptions && projectPlatformOptions.options.libraries)
2998                      {
2999                         if(projectPlatformOptions.options.libraries.count)
3000                         {
3001                            f.Puts("LIBS +=");
3002                            OutputLibraries(f, projectPlatformOptions.options.libraries);
3003                            f.Puts("\n");
3004                         }
3005                      }
3006                      f.Puts("endif\n");
3007                      f.Puts("\n");
3008                   }
3009                }
3010             }
3011             if(ifCount)
3012             {
3013                for(c = 0; c < ifCount; c++)
3014                   f.Puts("endif\n");
3015             }
3016             f.Puts("\n");
3017          }
3018
3019          if((config && config.options && config.options.compilerOptions && config.options.compilerOptions.count) ||
3020                (options && options.compilerOptions && options.compilerOptions.count))
3021          {
3022             f.Puts("CFLAGS +=");
3023             f.Puts(" \\\n\t");
3024
3025             if(config && config.options && config.options.compilerOptions && config.options.compilerOptions.count)
3026             {
3027                for(s : config.options.compilerOptions)
3028                   f.Printf(" %s", s);
3029             }
3030             if(options && options.compilerOptions && options.compilerOptions.count)
3031             {
3032                for(s : options.compilerOptions)
3033                   f.Printf(" %s", s);
3034             }
3035             f.Puts("\n");
3036             f.Puts("\n");
3037          }
3038
3039          if((config && config.options && config.options.linkerOptions && config.options.linkerOptions.count) ||
3040                (options && options.linkerOptions && options.linkerOptions.count))
3041          {
3042             f.Puts("OFLAGS +=");
3043             f.Puts(" \\\n\t");
3044
3045             if(config && config.options && config.options.linkerOptions && config.options.linkerOptions.count)
3046             {
3047                bool needWl = false;
3048                for(s : config.options.linkerOptions)
3049                {
3050                   if(!IsLinkerOption(s))
3051                      f.Printf(" %s", s);
3052                   else
3053                      needWl = true;
3054                }
3055                if(needWl)
3056                {
3057                   f.Puts(" -Wl");
3058                   for(s : config.options.linkerOptions)
3059                      if(IsLinkerOption(s))
3060                         f.Printf(",%s", s);
3061                }
3062             }
3063             if(options && options.linkerOptions && options.linkerOptions.count)
3064             {
3065                bool needWl = false;
3066                for(s : options.linkerOptions)
3067                {
3068                   if(!IsLinkerOption(s))
3069                      f.Printf(" %s", s);
3070                   else
3071                      needWl = true;
3072                }
3073                if(needWl)
3074                {
3075                   f.Puts(" -Wl");
3076                   for(s : options.linkerOptions)
3077                      if(IsLinkerOption(s))
3078                         f.Printf(",%s", s);
3079                }
3080             }
3081             f.Puts("\n");
3082             f.Puts("\n");
3083          }
3084
3085          f.Puts("CECFLAGS += -cpp $(_CPP)");
3086          f.Puts("\n");
3087          f.Puts("\n");
3088
3089          if(GetProfile(config))
3090             f.Puts("OFLAGS += -pg\n\n");
3091
3092          if((config && config.options && config.options.libraryDirs) || (options && options.libraryDirs))
3093          {
3094             f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3095             f.Puts("OFLAGS +=");
3096             if(config && config.options && config.options.libraryDirs)
3097                OutputListOption(f, "L", config.options.libraryDirs, lineEach, true, false);
3098             if(options && options.libraryDirs)
3099                OutputListOption(f, "L", options.libraryDirs, lineEach, true, false);
3100             f.Puts("\n");
3101             f.Puts("endif\n");
3102             f.Puts("\n");
3103          }
3104
3105          f.Puts("# TARGETS\n");
3106          f.Puts("\n");
3107
3108          f.Printf("all: objdir%s $(TARGET)\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3109          f.Puts("\n");
3110
3111          f.Puts("objdir:\n");
3112          if(!relObjDir)
3113             f.Puts("\t$(if $(wildcard $(OBJ)),,$(call mkdirq,$(OBJ)))\n");
3114
3115             f.Puts("\t$(if $(ECERE_SDK_SRC),$(if $(wildcard $(call escspace,$(ECERE_SDK_SRC)/crossplatform.mk)),,@$(call echo,Ecere SDK Source Warning: The value of ECERE_SDK_SRC is pointing to an incorrect ($(ECERE_SDK_SRC)/crossplatform.mk) location.)),)\n");
3116             f.Puts("\t$(if $(ECERE_SDK_SRC),,$(if $(ECP_DEBUG)$(ECC_DEBUG)$(ECS_DEBUG),@$(call echo,ECC Debug Warning: Please define ECERE_SDK_SRC before using ECP_DEBUG, ECC_DEBUG or ECS_DEBUG),))\n");
3117          //f.Puts("# PRE-BUILD COMMANDS\n");
3118          if(options && options.prebuildCommands)
3119          {
3120             for(s : options.prebuildCommands)
3121                if(s && s[0]) f.Printf("\t%s\n", s);
3122          }
3123          if(config && config.options && config.options.prebuildCommands)
3124          {
3125             for(s : config.options.prebuildCommands)
3126                if(s && s[0]) f.Printf("\t%s\n", s);
3127          }
3128          if(platforms || (config && config.platforms))
3129          {
3130             ifCount = 0;
3131             //f.Puts("# TARGET_PLATFORM-SPECIFIC PRE-BUILD COMMANDS\n");
3132             for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3133             {
3134                PlatformOptions projectPOs, configPOs;
3135                MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3136
3137                if((projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count) ||
3138                      (configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count))
3139                {
3140                   if(ifCount)
3141                      f.Puts("else\n");
3142                   ifCount++;
3143                   f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3144
3145                   if(projectPOs && projectPOs.options.prebuildCommands && projectPOs.options.prebuildCommands.count)
3146                   {
3147                      for(s : projectPOs.options.prebuildCommands)
3148                         if(s && s[0]) f.Printf("\t%s\n", s);
3149                   }
3150                   if(configPOs && configPOs.options.prebuildCommands && configPOs.options.prebuildCommands.count)
3151                   {
3152                      for(s : configPOs.options.prebuildCommands)
3153                         if(s && s[0]) f.Printf("\t%s\n", s);
3154                   }
3155                }
3156             }
3157             if(ifCount)
3158             {
3159                int c;
3160                for(c = 0; c < ifCount; c++)
3161                   f.Puts("endif\n");
3162             }
3163          }
3164          f.Puts("\n");
3165
3166          if(!sameOrRelObjTargetDirs)
3167          {
3168             f.Puts("targetdir:\n");
3169                f.Printf("\t$(if $(wildcard %s),,$(call mkdirq,%s))\n", targetDirExpNoSpaces, targetDirExpNoSpaces);
3170             f.Puts("\n");
3171          }
3172
3173          if(numCObjects)
3174          {
3175             // Main Module (Linking) for ECERE C modules
3176             f.Puts("$(OBJ)$(MODULE).main.ec: $(SYMBOLS) $(COBJECTS)\n");
3177             // use of objDirExpNoSpaces used instead of $(OBJ) to prevent problematic joining of arguments in ecs
3178             f.Printf("\t$(ECS)%s $(ARCH_FLAGS) $(ECSLIBOPT) $(SYMBOLS) $(IMPORTS) -symbols %s -o $@\n",
3179                GetConsole(config) ? " -console" : "", objDirExpNoSpaces);
3180             f.Puts("\n");
3181             // Main Module (Linking) for ECERE C modules
3182             f.Puts("$(OBJ)$(MODULE).main.c: $(OBJ)$(MODULE).main.ec\n");
3183             f.Puts("\t$(ECP) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS)"
3184                   " -c $(OBJ)$(MODULE).main.ec -o $(OBJ)$(MODULE).main.sym -symbols $(OBJ)\n");
3185             f.Puts("\t$(ECC) $(CFLAGS) $(CECFLAGS) $(ECFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY)"
3186                   " -c $(OBJ)$(MODULE).main.ec -o $@ -symbols $(OBJ)\n");
3187             f.Puts("\n");
3188          }
3189
3190          // *** Target ***
3191
3192          // This would not rebuild the target on updated objects
3193          // f.Printf("$(TARGET): $(SOURCES) $(RESOURCES) | objdir $(SYMBOLS) $(OBJECTS)%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3194
3195          // This should fix it for good!
3196          f.Puts("$(SYMBOLS): | objdir\n");
3197          f.Puts("$(OBJECTS): | objdir\n");
3198
3199          // This alone was breaking the tarball, object directory does not get created first (order-only rules happen last it seems!)
3200          f.Printf("$(TARGET): $(SOURCES)%s $(RESOURCES) $(SYMBOLS) $(OBJECTS) | objdir%s\n",
3201                rcSourcesParts ? " $(RCSOURCES)" : "", sameOrRelObjTargetDirs ? "" : " targetdir");
3202
3203          f.Printf("\t@$(call rmq,$(OBJ)linkobjects.lst)\n");
3204          f.Printf("\t@$(call touch,$(OBJ)linkobjects.lst)\n");
3205          OutputLinkObjectActions(f, "_OBJECTS", objectsParts);
3206          if(rcSourcesParts)
3207          {
3208             f.Puts("ifdef WINDOWS_TARGET\n");
3209             OutputLinkObjectActions(f, "RCOBJECTS", rcSourcesParts);
3210             f.Puts("endif\n");
3211          }
3212          if(numCObjects)
3213          {
3214             f.Printf("\t@$(call echo,$(OBJ)$(MODULE).main$(O)) >> $(OBJ)linkobjects.lst\n");
3215             OutputLinkObjectActions(f, "ECOBJECTS", eCsourcesParts);
3216          }
3217
3218          f.Puts("ifndef STATIC_LIBRARY_TARGET\n");
3219
3220          f.Printf("\t$(%s) $(OFLAGS) @$(OBJ)linkobjects.lst $(LIBS) %s-o $(TARGET) $(INSTALLNAME)\n", containsCXX ? "CXX" : "CC", containsCXX ? "-lstdc++ " : "");
3221          if(!GetDebug(config))
3222          {
3223             f.Puts("ifndef NOSTRIP\n");
3224             f.Puts("\t$(STRIP) $(STRIPOPT) $(TARGET)\n");
3225             f.Puts("endif\n");
3226
3227             if(GetCompress(config))
3228             {
3229                f.Printf("ifndef %s\n", PlatformToMakefileTargetVariable(win32));
3230                f.Puts("ifdef EXECUTABLE_TARGET\n");
3231                   f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3232                f.Puts("endif\n");
3233                f.Puts("else\n");
3234                   f.Puts("\t$(UPX) $(UPXFLAGS) $(TARGET)\n");
3235                f.Puts("endif\n");
3236             }
3237          }
3238          if(resNode.files && resNode.files.count && !noResources)
3239             resNode.GenMakefileAddResources(f, resNode.path, config);
3240          f.Puts("else\n");
3241          f.Puts("\t$(AR) rcs $(TARGET) @$(OBJ)linkobjects.lst $(LIBS)\n");
3242          f.Puts("endif\n");
3243          f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3244          f.Puts("ifdef LINUX_TARGET\n");
3245          f.Puts("ifdef LINUX_HOST\n");
3246          // TODO?: support symlinks for longer version numbers
3247          f.Puts("\t$(if $(basename $(VER)),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)),)\n");
3248          f.Puts("\t$(if $(VER),ln -sf $(LP)$(MODULE)$(SO)$(VER) $(OBJ)$(LP)$(MODULE)$(SO),)\n");
3249          f.Puts("endif\n");
3250          f.Puts("endif\n");
3251          f.Puts("endif\n");
3252
3253          //f.Puts("# POST-BUILD COMMANDS\n");
3254          if(options && options.postbuildCommands)
3255          {
3256             for(s : options.postbuildCommands)
3257                if(s && s[0]) f.Printf("\t%s\n", s);
3258          }
3259          if(config && config.options && config.options.postbuildCommands)
3260          {
3261             for(s : config.options.postbuildCommands)
3262                if(s && s[0]) f.Printf("\t%s\n", s);
3263          }
3264          if(platforms || (config && config.platforms))
3265          {
3266             ifCount = 0;
3267             //f.Puts("# TARGET_PLATFORM-SPECIFIC POST-BUILD COMMANDS\n");
3268             for(platform = (Platform)1; platform < Platform::enumSize; platform++)
3269             {
3270                PlatformOptions projectPOs, configPOs;
3271                MatchProjectAndConfigPlatformOptions(config, platform, &projectPOs, &configPOs);
3272
3273                if((projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count) ||
3274                      (configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count))
3275                {
3276                   if(ifCount)
3277                      f.Puts("else\n");
3278                   ifCount++;
3279                   f.Printf("ifdef %s\n", PlatformToMakefileTargetVariable(platform));
3280
3281                   if(projectPOs && projectPOs.options.postbuildCommands && projectPOs.options.postbuildCommands.count)
3282                   {
3283                      for(s : projectPOs.options.postbuildCommands)
3284                         if(s && s[0]) f.Printf("\t%s\n", s);
3285                   }
3286                   if(configPOs && configPOs.options.postbuildCommands && configPOs.options.postbuildCommands.count)
3287                   {
3288                      for(s : configPOs.options.postbuildCommands)
3289                         if(s && s[0]) f.Printf("\t%s\n", s);
3290                   }
3291                }
3292             }
3293             if(ifCount)
3294             {
3295                int c;
3296                for(c = 0; c < ifCount; c++)
3297                   f.Puts("endif\n");
3298             }
3299          }
3300          f.Puts("\n");
3301
3302          f.Puts("# SYMBOL RULES\n");
3303          f.Puts("\n");
3304
3305          topNode.GenMakefilePrintSymbolRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3306
3307          f.Puts("# C OBJECT RULES\n");
3308          f.Puts("\n");
3309
3310          topNode.GenMakefilePrintCObjectRules(f, this, config, nodeCFlagsMapping, nodeECFlagsMapping);
3311
3312          f.Puts("# OBJECT RULES\n");
3313          f.Puts("\n");
3314          // todo call this still but only generate rules whith specific options
3315          // see we-have-file-specific-options in ProjectNode.ec
3316          topNode.GenMakefilePrintObjectRules(f, this, namesInfo, config, nodeCFlagsMapping, nodeECFlagsMapping);
3317
3318          if(numCObjects)
3319             GenMakefilePrintMainObjectRule(f, config);
3320
3321          f.Printf("cleantarget: objdir%s\n", sameOrRelObjTargetDirs ? "" : " targetdir");
3322          f.Puts("\t$(call rmq,$(TARGET))\n");
3323          f.Puts("ifdef SHARED_LIBRARY_TARGET\n");
3324          f.Puts("ifdef LINUX_TARGET\n");
3325          f.Puts("ifdef LINUX_HOST\n");
3326          // TODO?: support symlinks for longer version numbers
3327          f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO)$(basename $(VER)))\n");
3328          f.Puts("\t$(call rmq,$(OBJ)$(LP)$(MODULE)$(SO))\n");
3329          f.Puts("endif\n");
3330          f.Puts("endif\n");
3331          f.Puts("endif\n");
3332          f.Puts("\n");
3333
3334          f.Puts("clean: cleantarget\n");
3335          f.Printf("\t$(call rmq,$(OBJ)linkobjects.lst)\n");
3336          OutputCleanActions(f, "_OBJECTS", objectsParts);
3337          if(rcSourcesParts)
3338          {
3339             f.Puts("ifdef WINDOWS_TARGET\n");
3340             OutputCleanActions(f, "RCOBJECTS", rcSourcesParts);
3341             f.Puts("endif\n");
3342          }
3343          if(numCObjects)
3344          {
3345             f.Printf("\t$(call rmq,%s)\n", "$(OBJ)$(MODULE).main.o $(OBJ)$(MODULE).main.c $(OBJ)$(MODULE).main.ec $(OBJ)$(MODULE).main$(I) $(OBJ)$(MODULE).main$(S)");
3346             OutputCleanActions(f, "ECOBJECTS", eCsourcesParts);
3347             OutputCleanActions(f, "COBJECTS", eCsourcesParts);
3348             OutputCleanActions(f, "BOWLS", eCsourcesParts);
3349             OutputCleanActions(f, "IMPORTS", eCsourcesParts);
3350             OutputCleanActions(f, "SYMBOLS", eCsourcesParts);
3351          }
3352          f.Puts("\n");
3353
3354          f.Puts("realclean: cleantarget\n");
3355          f.Puts("\t$(call rmrq,$(OBJ))\n");
3356          if(!sameOrRelObjTargetDirs)
3357             f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3358          f.Puts("\n");
3359
3360          f.Puts("distclean: cleantarget\n");
3361          if(!sameOrRelObjTargetDirs)
3362             f.Printf("\t$(call rmdirq,%s)\n", targetDirExpNoSpaces);
3363          if(!relObjDir)
3364             f.Puts("\t$(call rmrq,obj/)\n");
3365
3366          delete f;
3367
3368          listItems.Free();
3369          delete listItems;
3370          varStringLenDiffs.Free();
3371          delete varStringLenDiffs;
3372          namesInfo.Free();
3373          delete namesInfo;
3374
3375          delete cflagsVariations;
3376          delete nodeCFlagsMapping;
3377          delete ecflagsVariations;
3378          delete nodeECFlagsMapping;
3379
3380          result = true;
3381       }
3382
3383       // ChangeWorkingDir(oldDirectory);
3384       // delete pathBackup;
3385
3386       if(config)
3387          config.makingModified = false;
3388       return result;
3389    }
3390
3391    void GenMakefilePrintMainObjectRule(File f, ProjectConfig config)
3392    {
3393       char extension[MAX_EXTENSION] = "c";
3394       char modulePath[MAX_LOCATION];
3395       char fixedModuleName[MAX_FILENAME];
3396       DualPipe dep;
3397       char command[2048];
3398       char objDirNoSpaces[MAX_LOCATION];
3399       String objDirExp = GetObjDirExpression(config);
3400
3401       ReplaceSpaces(objDirNoSpaces, objDirExp);
3402       ReplaceSpaces(fixedModuleName, moduleName);
3403       
3404       //sprintf(fixedModuleName, "%s.main", fixedPrjName);
3405       //strcat(fixedModuleName, ".main");
3406
3407 #if 0       // TODO: Fix nospaces stuff
3408       // *** Dependency command ***
3409       sprintf(command, "gcc -MT $(OBJ)%s$(O) -MM $(OBJ)%s.c", fixedModuleName, fixedModuleName);
3410
3411       // System Includes (from global settings)
3412       for(item : compiler.dirs[Includes])
3413       {
3414          strcat(command, " -isystem ");
3415          if(strchr(item.name, ' '))
3416          {
3417             strcat(command, "\"");
3418             strcat(command, item);
3419             strcat(command, "\"");
3420          }
3421          else
3422             strcat(command, item);
3423       }
3424
3425       for(item = includeDirs.first; item; item = item.next)
3426       {
3427          strcat(command, " -I");
3428          if(strchr(item.name, ' '))
3429          {
3430             strcat(command, "\"");
3431             strcat(command, item.name);
3432             strcat(command, "\"");
3433          }
3434          else
3435             strcat(command, item.name);
3436       }
3437       for(item = preprocessorDefs.first; item; item = item.next)
3438       {
3439          strcat(command, " -D");
3440          strcat(command, item.name);
3441       }
3442
3443       // Execute it
3444       if((dep = DualPipeOpen(PipeOpenMode { output = 1, error = 1, input = 2 }, command)))
3445       {
3446          char line[1024];
3447          bool result = true;
3448          bool firstLine = true;
3449
3450          // To do some time: auto save external dependencies?
3451          while(!dep.Eof())
3452          {
3453             if(dep.GetLine(line, sizeof(line)-1))
3454             {
3455                if(firstLine)
3456                {
3457                   char * colon = strstr(line, ":");
3458                   if(strstr(line, "No such file") || strstr(line, ",") || (colon && strstr(colon+1, ":")))
3459                   {
3460                      result = false;
3461                      break;
3462                   }
3463                   firstLine = false;
3464                }
3465                f.Puts(line);
3466                f.Puts("\n");
3467             }
3468             if(!result) break;
3469          }
3470          delete dep;
3471
3472          // If we failed to generate dependencies...
3473          if(!result)
3474          {
3475 #endif
3476             f.Puts("$(OBJ)$(MODULE).main$(O): $(OBJ)$(MODULE).main.c\n");
3477             f.Printf("\t$(CC) $(CFLAGS) $(PRJ_CFLAGS) $(FVISIBILITY) -c $(OBJ)$(MODULE).main.%s -o $@\n", extension);
3478             f.Puts("\n");
3479 #if 0
3480          }
3481       }
3482 #endif
3483    }
3484
3485    void GenMakePrintCustomFlags(File f, String variableName, bool printNonCustom, Map<String, int> cflagsVariations)
3486    {
3487       int c;
3488       for(c = printNonCustom ? 0 : 1; c <= cflagsVariations.count; c++)
3489       {
3490          for(v : cflagsVariations)
3491          {
3492             if(v == c)
3493             {
3494                if(v == 1)
3495                   f.Printf("%s +=", variableName);
3496                else
3497                   f.Printf("CUSTOM%d_%s =", v-1, variableName);
3498                f.Puts(&v ? &v : "");
3499                f.Puts("\n\n");
3500                break;
3501             }
3502          }
3503       }
3504    }
3505
3506    void MatchProjectAndConfigPlatformOptions(ProjectConfig config, Platform platform,
3507          PlatformOptions * projectPlatformOptions, PlatformOptions * configPlatformOptions)
3508    {
3509       *projectPlatformOptions = null;
3510       *configPlatformOptions = null;
3511       if(platforms)
3512       {
3513          for(p : platforms)
3514          {
3515             if(!strcmpi(p.name, platform))
3516             {
3517                *projectPlatformOptions = p;
3518                break;
3519             }
3520          }
3521       }
3522       if(config && config.platforms)
3523       {
3524          for(p : config.platforms)
3525          {
3526             if(!strcmpi(p.name, platform))
3527             {
3528                *configPlatformOptions = p;
3529                break;
3530             }
3531          }
3532       }
3533    }
3534 }
3535
3536 static inline void ProjectLoadLastBuildNamesInfo(Project prj, ProjectConfig cfg)
3537 {
3538    if(prj.lastBuildNamesInfo)
3539    {
3540       prj.lastBuildNamesInfo.Free();
3541       delete prj.lastBuildNamesInfo;
3542    }
3543    prj.lastBuildNamesInfo = { };
3544    prj.topNode.GenMakefileGetNameCollisionInfo(prj.lastBuildNamesInfo, cfg);
3545 }
3546
3547 Project LegacyBinaryLoadProject(File f, char * filePath)
3548 {
3549    Project project = null;
3550    char signature[sizeof(epjSignature)];
3551
3552    f.Read(signature, sizeof(signature), 1);
3553    if(!strncmp(signature, (char *)epjSignature, sizeof(epjSignature)))
3554    {
3555       char topNodePath[MAX_LOCATION];
3556       /*ProjectConfig newConfig
3557       {
3558          name = CopyString("Default");
3559          makingModified = true;
3560          compilingModified = true;
3561          linkingModified = true;
3562          options = { };
3563       };*/
3564
3565       project = Project { options = { } };
3566       LegacyBinaryLoadNode(project.topNode, f);
3567       delete project.topNode.path;
3568       GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3569       MakeSlashPath(topNodePath);
3570
3571       PathCatSlash(topNodePath, filePath);
3572       project.filePath = topNodePath;
3573       
3574       /* THIS IS ALREADY DONE BY filePath property
3575       StripLastDirectory(topNodePath, topNodePath);
3576       project.topNode.path = CopyString(topNodePath);
3577       */
3578       // Shouldn't this be done BEFORE the StripLastDirectory? project.filePath = topNodePath;
3579       
3580       // newConfig.options.defaultNameSpace = "";
3581       /*newConfig.objDir.dir = "obj";
3582       newConfig.targetDir.dir = "";*/
3583
3584       //project.configurations = { [ newConfig ] };
3585       //project.config = newConfig;
3586
3587       // Project Settings
3588       if(!f.Eof())
3589       {
3590          int temp;
3591          int len,c, count;
3592          String targetFileName, targetDirectory, objectsDirectory;
3593
3594          // { executable = 0, sharedLibrary = 1, staticLibrary = 2 };
3595          f.Read(&temp, sizeof(int),1);
3596          switch(temp)
3597          {
3598             case 0: project.options.targetType = executable; break;
3599             case 1: project.options.targetType = sharedLibrary; break;
3600             case 2: project.options.targetType = staticLibrary; break;
3601          }
3602
3603          f.Read(&len, sizeof(int),1);
3604          targetFileName = new char[len+1];
3605          f.Read(targetFileName, sizeof(char), len+1);
3606          project.options.targetFileName = targetFileName;
3607          delete targetFileName;
3608
3609          f.Read(&len, sizeof(int),1);
3610          targetDirectory = new char[len+1];
3611          f.Read(targetDirectory, sizeof(char), len+1);
3612          project.options.targetDirectory = targetDirectory;
3613          delete targetDirectory;
3614
3615          f.Read(&len, sizeof(int),1);
3616          objectsDirectory = new byte[len+1];
3617          f.Read(objectsDirectory, sizeof(char), len+1);
3618          project.options.objectsDirectory = objectsDirectory;
3619          delete objectsDirectory;
3620
3621          f.Read(&temp, sizeof(int),1);
3622          project./*config.*/options.debug = temp ? true : false;
3623          f.Read(&temp, sizeof(int),1);         
3624          project./*config.*/options.optimization = temp ? speed : none;
3625          f.Read(&temp, sizeof(int),1);
3626          project./*config.*/options.profile = temp ? true : false;
3627          f.Read(&temp, sizeof(int),1);
3628          project.options.warnings = temp ? all : unset;
3629
3630          f.Read(&count, sizeof(int),1);
3631          if(count)
3632          {
3633             project.options.includeDirs = { };
3634             for(c = 0; c < count; c++)
3635             {
3636                char * name;
3637                f.Read(&len, sizeof(int),1);
3638                name = new char[len+1];
3639                f.Read(name, sizeof(char), len+1);
3640                project.options.includeDirs.Add(name);
3641             }
3642          }
3643
3644          f.Read(&count, sizeof(int),1);
3645          if(count)
3646          {
3647             project.options.libraryDirs = { };
3648             for(c = 0; c < count; c++)
3649             {
3650                char * name;            
3651                f.Read(&len, sizeof(int),1);
3652                name = new char[len+1];
3653                f.Read(name, sizeof(char), len+1);
3654                project.options.libraryDirs.Add(name);
3655             }
3656          }
3657
3658          f.Read(&count, sizeof(int),1);
3659          if(count)
3660          {
3661             project.options.libraries = { };
3662             for(c = 0; c < count; c++)
3663             {
3664                char * name;
3665                f.Read(&len, sizeof(int),1);
3666                name = new char[len+1];
3667                f.Read(name, sizeof(char), len+1);
3668                project.options.libraries.Add(name);
3669             }
3670          }
3671
3672          f.Read(&count, sizeof(int),1);
3673          if(count)
3674          {
3675             project.options.preprocessorDefinitions = { };
3676             for(c = 0; c < count; c++)
3677             {
3678                char * name;
3679                f.Read(&len, sizeof(int),1);
3680                name = new char[len+1];
3681                f.Read(name, sizeof(char), len+1);
3682                project.options.preprocessorDefinitions.Add(name);
3683             }
3684          }
3685
3686          f.Read(&temp, sizeof(int),1);
3687          project.options.console = temp ? true : false;
3688       }
3689
3690       for(node : project.topNode.files)
3691       {
3692          if(node.type == resources)
3693          {
3694             project.resNode = node;
3695             break;
3696          }
3697       }
3698    }
3699    else
3700       f.Seek(0, start);
3701    return project;
3702 }
3703
3704 void ProjectConfig::LegacyProjectConfigLoad(File f)
3705 {  
3706    delete options;
3707    options = { };
3708    while(!f.Eof())
3709    {
3710       char buffer[65536];
3711       char section[128];
3712       char subSection[128];
3713       char * equal;
3714       int len;
3715       uint pos;
3716       
3717       pos = f.Tell();
3718       f.GetLine(buffer, 65536 - 1);
3719       TrimLSpaces(buffer, buffer);
3720       TrimRSpaces(buffer, buffer);
3721       if(strlen(buffer))
3722       {
3723          if(buffer[0] == '-')
3724          {
3725             equal = &buffer[0];
3726             equal[0] = ' ';
3727             TrimLSpaces(equal, equal);
3728             if(!strcmpi(subSection, "LibraryDirs"))
3729             {
3730                if(!options.libraryDirs)
3731                   options.libraryDirs = { [ CopyString(equal) ] };
3732                else
3733                   options.libraryDirs.Add(CopyString(equal));
3734             }
3735             else if(!strcmpi(subSection, "IncludeDirs"))
3736             {
3737                if(!options.includeDirs)
3738                   options.includeDirs = { [ CopyString(equal) ] };
3739                else
3740                   options.includeDirs.Add(CopyString(equal));
3741             }
3742          }
3743          else if(buffer[0] == '+')
3744          {
3745             if(name)
3746             {
3747                f.Seek(pos, start);
3748                break;
3749             }
3750             else
3751             {
3752                equal = &buffer[0];
3753                equal[0] = ' ';
3754                TrimLSpaces(equal, equal);
3755                delete name; name = CopyString(equal); // property::name = equal;
3756             }
3757          }
3758          else if(!strcmpi(buffer, "Compiler Options"))
3759             strcpy(section, buffer);
3760          else if(!strcmpi(buffer, "IncludeDirs"))
3761             strcpy(subSection, buffer);
3762          else if(!strcmpi(buffer, "Linker Options"))
3763             strcpy(section, buffer);
3764          else if(!strcmpi(buffer, "LibraryDirs"))
3765             strcpy(subSection, buffer);
3766          else if(!strcmpi(buffer, "Files") || !strcmpi(buffer, "Resources"))
3767          {
3768             f.Seek(pos, start);
3769             break;
3770          }
3771          else
3772          {
3773             equal = strstr(buffer, "=");
3774             if(equal)
3775             {
3776                equal[0] = '\0';
3777                TrimRSpaces(buffer, buffer);
3778                equal++;
3779                TrimLSpaces(equal, equal);
3780                if(!strcmpi(buffer, "Target Name"))
3781                   options.targetFileName = /*CopyString(*/equal/*)*/;
3782                else if(!strcmpi(buffer, "Target Type"))
3783                {
3784                   if(!strcmpi(equal, "Executable"))
3785                      options.targetType = executable;
3786                   else if(!strcmpi(equal, "Shared"))
3787                      options.targetType = sharedLibrary;
3788                   else if(!strcmpi(equal, "Static"))
3789                      options.targetType = staticLibrary;
3790                   else
3791                      options.targetType = executable;
3792                }
3793                else if(!strcmpi(buffer, "Target Directory"))
3794                   options.targetDirectory = /*CopyString(*/equal/*)*/;
3795                else if(!strcmpi(buffer, "Console"))
3796                   options.console = ParseTrueFalseValue(equal);
3797                else if(!strcmpi(buffer, "Libraries"))
3798                {
3799                   if(!options.libraries) options.libraries = { };
3800                   ParseArrayValue(options.libraries, equal);
3801                }
3802                else if(!strcmpi(buffer, "Intermediate Directory"))
3803                   options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
3804                else if(!strcmpi(buffer, "Debug"))
3805                   options.debug = ParseTrueFalseValue(equal);
3806                else if(!strcmpi(buffer, "Optimize"))
3807                {
3808                   if(!strcmpi(equal, "None"))
3809                      options.optimization = none;
3810                   else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
3811                      options.optimization = speed;
3812                   else if(!strcmpi(equal, "Size"))
3813                      options.optimization = size;
3814                   else
3815                      options.optimization = none;
3816                }
3817                else if(!strcmpi(buffer, "Compress"))
3818                   options.compress = ParseTrueFalseValue(equal);
3819                else if(!strcmpi(buffer, "Profile"))
3820                   options.profile = ParseTrueFalseValue(equal);
3821                else if(!strcmpi(buffer, "AllWarnings"))
3822                   options.warnings = ParseTrueFalseValue(equal) ? all : unset;
3823                else if(!strcmpi(buffer, "MemoryGuard"))
3824                   options.memoryGuard = ParseTrueFalseValue(equal);
3825                else if(!strcmpi(buffer, "Default Name Space"))
3826                   options.defaultNameSpace = CopyString(equal);
3827                else if(!strcmpi(buffer, "Strict Name Spaces"))
3828                   options.strictNameSpaces = ParseTrueFalseValue(equal);
3829                else if(!strcmpi(buffer, "Preprocessor Definitions"))
3830                {
3831                   if(!options.preprocessorDefinitions) options.preprocessorDefinitions = { };
3832                   ParseArrayValue(options.preprocessorDefinitions, equal);
3833                }
3834             }
3835          }
3836       }
3837    }
3838    if(!options.targetDirectory && options.objectsDirectory)
3839       options.targetDirectory = /*CopyString(*/options.objectsDirectory/*)*/;
3840    //if(!objDir.dir) objDir.dir = "obj";
3841    //if(!targetDir.dir) targetDir.dir = "";
3842    // if(!targetName) property::targetName = "";   // How can a targetFileName be nothing???
3843    // if(!defaultNameSpace) property::defaultNameSpace = "";
3844    makingModified = true;
3845 }
3846
3847 Project LegacyAsciiLoadProject(File f, char * filePath)
3848 {
3849    Project project = null;
3850    ProjectNode node = null;
3851    int pos;
3852    char parentPath[MAX_LOCATION];
3853    char section[128] = "";
3854    char subSection[128] = "";
3855    ProjectNode parent;
3856    bool configurationsPresent = false;
3857
3858    f.Seek(0, start);
3859    while(!f.Eof())
3860    {
3861       char buffer[65536];
3862       //char version[16];
3863       char * equal;
3864       int len;
3865       pos = f.Tell();
3866       f.GetLine(buffer, 65536 - 1);
3867       TrimLSpaces(buffer, buffer);
3868       TrimRSpaces(buffer, buffer);
3869       if(strlen(buffer))
3870       {
3871          if(buffer[0] == '-' || buffer[0] == '=')
3872          {
3873             bool simple = buffer[0] == '-';
3874             equal = &buffer[0];
3875             equal[0] = ' ';
3876             TrimLSpaces(equal, equal);
3877             if(!strcmpi(section, "Target") && !strcmpi(subSection, "LibraryDirs"))
3878             {
3879                if(!project.config.options.libraryDirs)
3880                   project.config.options.libraryDirs = { [ CopyString(equal) ] };
3881                else
3882                   project.config.options.libraryDirs.Add(CopyString(equal));
3883             }
3884             else if(!strcmpi(section, "Target") && !strcmpi(subSection, "IncludeDirs"))
3885             {
3886                if(!project.config.options.includeDirs)
3887                   project.config.options.includeDirs = { [ CopyString(equal) ] };
3888                else
3889                   project.config.options.includeDirs.Add(CopyString(equal));
3890             }
3891             else if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3892             {
3893                len = strlen(equal);
3894                if(len)
3895                {
3896                   char temp[MAX_LOCATION];
3897                   ProjectNode child { };
3898                   // We don't need to do this anymore, fileName is just a property that sets name & path
3899                   // child.fileName = CopyString(equal);
3900                   if(simple)
3901                   {
3902                      child.name = CopyString(equal);
3903                      child.path = CopyString(parentPath);
3904                   }
3905                   else
3906                   {
3907                      GetLastDirectory(equal, temp);
3908                      child.name = CopyString(temp);
3909                      StripLastDirectory(equal, temp);
3910                      child.path = CopyString(temp);
3911                   }
3912                   child.nodeType = file;
3913                   child.parent = parent;
3914                   child.indent = parent.indent + 1;
3915                   child.type = file;
3916                   child.icon = NodeIcons::SelectFileIcon(child.name);
3917                   parent.files.Add(child);
3918                   node = child;
3919                   //child = null;
3920                }
3921                else
3922                {
3923                   StripLastDirectory(parentPath, parentPath);
3924                   parent = parent.parent;
3925                }
3926             }
3927          }
3928          else if(buffer[0] == '+')
3929          {
3930             equal = &buffer[0];
3931             equal[0] = ' ';
3932             TrimLSpaces(equal, equal);
3933             if(!strcmpi(section, "Target") && (!strcmpi(subSection, "Files") || !strcmpi(subSection, "Resources")))
3934             {
3935                char temp[MAX_LOCATION];
3936                ProjectNode child { };
3937                // NEW: Folders now have a path set like files
3938                child.name = CopyString(equal);
3939                strcpy(temp, parentPath);
3940                PathCatSlash(temp, child.name);
3941                child.path = CopyString(temp);
3942
3943                child.parent = parent;
3944                child.indent = parent.indent + 1;
3945                child.type = folder;
3946                child.nodeType = folder;
3947                child.files = { };
3948                child.icon = folder;
3949                PathCatSlash(parentPath, child.name);
3950                parent.files.Add(child);
3951                parent = child;
3952                node = child;
3953                //child = null;
3954             }
3955             else if(!strcmpi(section, "Configurations"))
3956             {
3957                ProjectConfig newConfig
3958                {
3959                   makingModified = true;
3960                   options = { };
3961                };
3962                f.Seek(pos, start);
3963                LegacyProjectConfigLoad(newConfig, f);
3964                project.configurations.Add(newConfig);
3965             }
3966          }
3967          else if(!strcmpi(buffer, "ECERE Project File"));
3968          else if(!strcmpi(buffer, "Version 0a"))
3969             ; //strcpy(version, "0a");
3970          else if(!strcmpi(buffer, "Version 0.1a"))
3971             ; //strcpy(version, "0.1a");
3972          else if(!strcmpi(buffer, "Configurations"))
3973          {
3974             project.configurations.Free();
3975             project.config = null;
3976             strcpy(section, buffer);
3977             configurationsPresent = true;
3978          }
3979          else if(!strcmpi(buffer, "Target") || !strnicmp(buffer, "Target \"", strlen("Target \"")))
3980          {
3981             ProjectConfig newConfig { name = CopyString("Default"), options = { } };
3982             char topNodePath[MAX_LOCATION];
3983             // newConfig.defaultNameSpace = "";
3984             //newConfig.objDir.dir = "obj";
3985             //newConfig.targetDir.dir = "";
3986             project = Project { /*options = { }*/ };
3987             project.configurations = { [ newConfig ] };
3988             project.config = newConfig;
3989             // if(project.topNode.path) delete project.topNode.path;
3990             GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
3991             MakeSlashPath(topNodePath);
3992             PathCatSlash(topNodePath, filePath);
3993             project.filePath = topNodePath;
3994             parentPath[0] = '\0';
3995             parent = project.topNode;
3996             node = parent;
3997             strcpy(section, "Target");
3998             equal = &buffer[6];
3999             if(equal[0] == ' ')
4000             {
4001                equal++;
4002                if(equal[0] == '\"')
4003                {
4004                   StripQuotes(equal, equal);
4005                   delete project.moduleName; project.moduleName = CopyString(equal);
4006                }
4007             }
4008          }
4009          else if(!strcmpi(buffer, "Compiler Options"));
4010          else if(!strcmpi(buffer, "IncludeDirs"))
4011             strcpy(subSection, buffer);
4012          else if(!strcmpi(buffer, "Linker Options"));
4013          else if(!strcmpi(buffer, "LibraryDirs"))
4014             strcpy(subSection, buffer);
4015          else if(!strcmpi(buffer, "Files"))
4016          {
4017             strcpy(section, "Target");
4018             strcpy(subSection, buffer);
4019          }
4020          else if(!strcmpi(buffer, "Resources"))
4021          {
4022             ProjectNode child { };
4023             parent.files.Add(child);
4024             child.parent = parent;
4025             child.indent = parent.indent + 1;
4026             child.name = CopyString(buffer);
4027             child.path = CopyString("");
4028             child.type = resources;
4029             child.files = { };
4030             child.icon = archiveFile;
4031             project.resNode = child;
4032             parent = child;
4033             node = child;
4034             strcpy(subSection, buffer);
4035          }
4036          else
4037          {
4038             equal = strstr(buffer, "=");
4039             if(equal)
4040             {
4041                equal[0] = '\0';
4042                TrimRSpaces(buffer, buffer);
4043                equal++;
4044                TrimLSpaces(equal, equal);
4045
4046                if(!strcmpi(section, "Target"))
4047                {
4048                   if(!strcmpi(buffer, "Build Exclusions"))
4049                   {
4050                      if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4051                      {
4052                         /*if(node && node.type != NodeTypes::project)
4053                            ParseListValue(node.buildExclusions, equal);*/
4054                      }
4055                   }
4056                   else if(!strcmpi(buffer, "Path") && !strcmpi(subSection, "Resources"))
4057                   {
4058                      delete project.resNode.path;
4059                      project.resNode.path = CopyString(equal);
4060                      PathCatSlash(parentPath, equal);
4061                   }
4062
4063                   // Config Settings
4064                   else if(!strcmpi(buffer, "Intermediate Directory"))
4065                      project.config.options.objectsDirectory = /*CopyString(*/equal/*)*/; //objDir.expression = equal;
4066                   else if(!strcmpi(buffer, "Debug"))
4067                      project.config.options.debug = ParseTrueFalseValue(equal);
4068                   else if(!strcmpi(buffer, "Optimize"))
4069                   {
4070                      if(!strcmpi(equal, "None"))
4071                         project.config.options.optimization = none;
4072                      else if(!strcmpi(equal, "Speed") || !strcmpi(equal, "True"))
4073                         project.config.options.optimization = speed;
4074                      else if(!strcmpi(equal, "Size"))
4075                         project.config.options.optimization = size;
4076                      else
4077                         project.config.options.optimization = none;
4078                   }
4079                   else if(!strcmpi(buffer, "Profile"))
4080                      project.config.options.profile = ParseTrueFalseValue(equal);
4081                   else if(!strcmpi(buffer, "MemoryGuard"))
4082                      project.config.options.memoryGuard = ParseTrueFalseValue(equal);
4083                   else
4084                   {
4085                      if(!project.options) project.options = { };
4086
4087                      // Project Wide Settings (All configs)
4088                      if(!strcmpi(buffer, "Target Name"))
4089                         project.options.targetFileName = /*CopyString(*/equal/*)*/;
4090                      else if(!strcmpi(buffer, "Target Type"))
4091                      {
4092                         if(!strcmpi(equal, "Executable"))
4093                            project.options.targetType = executable;
4094                         else if(!strcmpi(equal, "Shared"))
4095                            project.options.targetType = sharedLibrary;
4096                         else if(!strcmpi(equal, "Static"))
4097                            project.options.targetType = staticLibrary;
4098                         else
4099                            project.options.targetType = executable;
4100                      }
4101                      else if(!strcmpi(buffer, "Target Directory"))
4102                         project.options.targetDirectory = /*CopyString(*/equal/*)*/;
4103                      else if(!strcmpi(buffer, "Console"))
4104                         project.options.console = ParseTrueFalseValue(equal);
4105                      else if(!strcmpi(buffer, "Libraries"))
4106                      {
4107                         if(!project.options.libraries) project.options.libraries = { };
4108                         ParseArrayValue(project.options.libraries, equal);
4109                      }
4110                      else if(!strcmpi(buffer, "AllWarnings"))
4111                         project.options.warnings = ParseTrueFalseValue(equal) ? all : unset;
4112                      else if(!strcmpi(buffer, "Preprocessor Definitions"))
4113                      {
4114                         if(!strcmpi(section, "Target") && !strcmpi(subSection, "Files"))
4115                         {
4116                            /*if(node && (node.type == NodeTypes::project || (node.type == file && !node.isInResources) || node.type == folder))
4117                               ParseListValue(node.preprocessorDefs, equal);*/
4118                         }
4119                         else
4120                         {
4121                            if(!project.options.preprocessorDefinitions) project.options.preprocessorDefinitions = { };
4122                            ParseArrayValue(project.options.preprocessorDefinitions, equal);
4123                         }
4124                      }
4125                   }
4126                }
4127             }
4128          }
4129       }
4130    }
4131    parent = null;
4132
4133    SplitPlatformLibraries(project);
4134
4135    if(configurationsPresent)
4136       CombineIdenticalConfigOptions(project);
4137    return project;
4138 }
4139
4140 void SplitPlatformLibraries(Project project)
4141 {
4142    if(project && project.configurations)
4143    {
4144       for(cfg : project.configurations)
4145       {
4146          if(cfg.options.libraries && cfg.options.libraries.count)
4147          {
4148             Iterator<String> it { cfg.options.libraries };
4149             while(it.Next())
4150             {
4151                String l = it.data;
4152                char * platformName = strstr(l, ":");
4153                if(platformName)
4154                {
4155                   PlatformOptions platform = null;
4156                   platformName++;
4157                   if(!cfg.platforms) cfg.platforms = { };
4158                   for(p : cfg.platforms)
4159                   {
4160                      if(!strcmpi(platformName, p.name))
4161                      {
4162                         platform = p;
4163                         break;
4164                      }
4165                   }
4166                   if(!platform)
4167                   {
4168                      platform = { name = CopyString(platformName), options = { libraries = { } } };
4169                      cfg.platforms.Add(platform);
4170                   }
4171                   *(platformName-1) = 0;
4172                   platform.options.libraries.Add(CopyString(l));
4173
4174                   cfg.options.libraries.Delete(it.pointer);
4175                   it.pointer = null;
4176                }
4177             }
4178          }
4179       }      
4180    }
4181 }
4182
4183 void CombineIdenticalConfigOptions(Project project)
4184 {
4185    if(project && project.configurations && project.configurations.count)
4186    {
4187       DataMember member;
4188       ProjectOptions nullOptions { };
4189       ProjectConfig firstConfig = null;
4190       for(cfg : project.configurations)
4191       {
4192          if(cfg.options.targetType != staticLibrary)
4193          {
4194             firstConfig = cfg;
4195             break;
4196          }
4197       }
4198       if(!firstConfig)
4199          firstConfig = project.configurations.firstIterator.data;
4200
4201       for(member = class(ProjectOptions).membersAndProperties.first; member; member = member.next)
4202       {
4203          if(!member.isProperty)
4204          {
4205             Class type = eSystem_FindClass(__thisModule, member.dataTypeString);
4206             if(type)
4207             {
4208                bool same = true;
4209
4210                for(cfg : project.configurations)
4211                {
4212                   if(cfg != firstConfig)
4213                   {
4214                      if(cfg.options.targetType != staticLibrary)
4215                      {
4216                         int result;
4217                         
4218                         if(type.type == noHeadClass || type.type == normalClass)
4219                         {
4220                            result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
4221                               *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4222                               *(void **)((byte *)cfg.options         + member.offset + member._class.offset));
4223                         }
4224                         else
4225                         {
4226                            result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
4227                               (byte *)firstConfig.options + member.offset + member._class.offset,
4228                               (byte *)cfg.options         + member.offset + member._class.offset);
4229                         }
4230                         if(result)
4231                         {
4232                            same = false;
4233                            break;
4234                         }
4235                      }
4236                   }                  
4237                }
4238                if(same)
4239                {
4240                   if(type.type == noHeadClass || type.type == normalClass)
4241                   {
4242                      if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
4243                         *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4244                         *(void **)((byte *)nullOptions         + member.offset + member._class.offset)))
4245                         continue;
4246                   }
4247                   else
4248                   {
4249                      if(!((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
4250                         (byte *)firstConfig.options + member.offset + member._class.offset,
4251                         (byte *)nullOptions         + member.offset + member._class.offset))
4252                         continue;
4253                   }
4254
4255                   if(!project.options) project.options = { };
4256                   
4257                   /*if(type.type == noHeadClass || type.type == normalClass)
4258                   {
4259                      ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type, 
4260                         (byte *)project.options + member.offset + member._class.offset,
4261                         *(void **)((byte *)firstConfig.options + member.offset + member._class.offset));
4262                   }
4263                   else
4264                   {
4265                      void * address = (byte *)firstConfig.options + member.offset + member._class.offset;
4266                      // TOFIX: ListBox::SetData / OnCopy mess
4267                      ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCopy])(type, 
4268                         (byte *)project.options + member.offset + member._class.offset,
4269                         (type.typeSize > 4) ? address : 
4270                            ((type.typeSize == 4) ? (void *)*(uint32 *)address : 
4271                               ((type.typeSize == 2) ? (void *)*(uint16*)address : 
4272                                  (void *)*(byte *)address )));                              
4273                   }*/
4274                   memcpy(
4275                      (byte *)project.options + member.offset + member._class.offset,
4276                      (byte *)firstConfig.options + member.offset + member._class.offset, type.typeSize);
4277
4278                   for(cfg : project.configurations)
4279                   {
4280                      if(cfg.options.targetType == staticLibrary)
4281                      {
4282                         int result;
4283                         
4284                         if(type.type == noHeadClass || type.type == normalClass)
4285                         {
4286                            result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
4287                               *(void **)((byte *)firstConfig.options + member.offset + member._class.offset),
4288                               *(void **)((byte *)cfg.options         + member.offset + member._class.offset));
4289                         }
4290                         else
4291                         {
4292                            result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, 
4293                               (byte *)firstConfig.options + member.offset + member._class.offset,
4294                               (byte *)cfg.options         + member.offset + member._class.offset);
4295                         }
4296                         if(result)
4297                            continue;
4298                      }
4299                      if(cfg != firstConfig)
4300                      {
4301                         if(type.type == noHeadClass || type.type == normalClass)
4302                         {
4303                            ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, 
4304                               *(void **)((byte *)cfg.options + member.offset + member._class.offset));
4305                         }
4306                         else
4307                         {
4308                            ((void (*)(void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnFree])(type, 
4309                               (byte *)cfg.options + member.offset + member._class.offset);
4310                         }
4311                         memset((byte *)cfg.options + member.offset + member._class.offset, 0, type.typeSize);
4312                      }                     
4313                   }
4314                   memset((byte *)firstConfig.options + member.offset + member._class.offset, 0, type.typeSize);
4315                }
4316             }
4317          }
4318       }
4319       delete nullOptions;
4320
4321       // Compare Platform Specific Settings
4322       {
4323          bool same = true;
4324          for(cfg : project.configurations)
4325          {
4326             if(cfg != firstConfig && cfg.options.targetType != staticLibrary && (firstConfig.platforms || cfg.platforms) &&
4327                ((!firstConfig.platforms && cfg.platforms) || firstConfig.platforms.OnCompare(cfg.platforms)))
4328             {
4329                same = false;
4330                break;
4331             }
4332          }
4333          if(same && firstConfig.platforms)
4334          {
4335             for(cfg : project.configurations)
4336             {
4337                if(cfg.options.targetType == staticLibrary && firstConfig.platforms.OnCompare(cfg.platforms))
4338                   continue;
4339                if(cfg != firstConfig)
4340                {
4341                   cfg.platforms.Free();
4342                   delete cfg.platforms;
4343                }
4344             }
4345             project.platforms = firstConfig.platforms;
4346             firstConfig.platforms = null;
4347          }
4348       }
4349
4350       // Static libraries can't contain libraries
4351       for(cfg : project.configurations)
4352       {
4353          if(cfg.options.targetType == staticLibrary)
4354          {
4355             if(!cfg.options.libraries) cfg.options.libraries = { };
4356             cfg.options.libraries.Free();
4357          }
4358       }
4359    }
4360 }
4361
4362 Project LoadProject(char * filePath, char * activeConfigName)
4363 {
4364    Project project = null;
4365    File f = FileOpen(filePath, read);
4366    if(f)
4367    {
4368       project = LegacyBinaryLoadProject(f, filePath);
4369       if(!project)
4370       {
4371          JSONParser parser { f = f };
4372          JSONResult result = parser.GetObject(class(Project), &project);
4373          if(project)
4374          {
4375             char insidePath[MAX_LOCATION];
4376
4377             delete project.topNode.files;
4378             if(!project.files) project.files = { };
4379             project.topNode.files = project.files;
4380
4381             {
4382                char topNodePath[MAX_LOCATION];
4383                GetWorkingDir(topNodePath, sizeof(topNodePath)-1);
4384                MakeSlashPath(topNodePath);
4385                PathCatSlash(topNodePath, filePath);
4386                project.filePath = topNodePath;//filePath;
4387             }
4388
4389             project.topNode.FixupNode(insidePath);
4390
4391             project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4392             delete project.resNode.path;
4393             project.resNode.path = project.resourcesPath;
4394             project.resourcesPath = null;
4395             project.resNode.nodeType = (ProjectNodeType)-1;
4396             delete project.resNode.files;
4397             project.resNode.files = project.resources;
4398             project.files = null;
4399             project.resources = null;
4400             if(!project.configurations) project.configurations = { };
4401
4402             project.resNode.FixupNode(insidePath);
4403          }
4404          delete parser;
4405       }
4406       if(!project)
4407          project = LegacyAsciiLoadProject(f, filePath);
4408
4409       delete f;
4410
4411       if(project)
4412       {
4413          if(!project.options) project.options = { };
4414          if(activeConfigName && activeConfigName[0] && project.configurations)
4415             project.config = project.GetConfig(activeConfigName);
4416          if(!project.config && project.configurations)
4417             project.config = project.configurations.firstIterator.data;
4418
4419          if(!project.resNode)
4420          {
4421             project.resNode = project.topNode.Add(project, "Resources", project.topNode.files.last, resources, archiveFile, false);
4422          }
4423          
4424          if(!project.moduleName)
4425             project.moduleName = CopyString(project.name);
4426          if(project.config && 
4427             (!project.options || !project.options.targetFileName || !project.options.targetFileName[0]) &&
4428             (!project.config.options.targetFileName || !project.config.options.targetFileName[0]))
4429          {
4430             //delete project.config.options.targetFileName;
4431             
4432             project.options.targetFileName = /*CopyString(*/project.moduleName/*)*/;
4433             project.config.options.optimization = none;
4434             project.config.options.debug = true;
4435             //project.config.options.warnings = unset;
4436             project.config.options.memoryGuard = false;
4437             project.config.compilingModified = true;
4438             project.config.linkingModified = true;
4439          }
4440          else if(!project.topNode.name && project.config)
4441          {
4442             project.topNode.name = CopyString(project.config.options.targetFileName);
4443          }
4444
4445          /* // THIS IS NOW AUTOMATED WITH A project CHECK IN ProjectNode
4446          project.topNode.configurations = project.configurations;
4447          project.topNode.platforms = project.platforms;
4448          project.topNode.options = project.options;*/
4449       }
4450    }
4451    return project;
4452 }