1 #ifndef MAKEFILE_GENERATOR
7 enum DirExpressionType { unknown, targetDir, intermediateObjectsDir }; // "type" is not right
9 class DirExpression : struct
12 DirExpressionType type;
23 return dir ? dir : "";
29 dir = CopyString(value);
35 void Evaluate(char * expression, Project project, CompilerConfig compiler, ProjectConfig config, int bitDepth)
38 char * expr = expression;
41 char buffer[MAX_LOCATION];
45 expr = ideSettings.projectDefaultTargetDir;
46 else if(type == intermediateObjectsDir)
47 expr = ideSettings.projectDefaultIntermediateObjDir;
50 expr = defaultObjDirExpression;
52 if((len = strlen(expr)))
55 char * configName = config && config.name && config.name[0] ? config.name : "Common";
56 char * projectName = project.name ? project.name : "";
57 char * moduleName = project.moduleName ? project.moduleName : "";
58 char * compilerName = (compiler && compiler.name) ? compiler.name : defaultCompilerName;
59 char * targetPlatformName = compiler && compiler.targetPlatform ? compiler.targetPlatform : "";
60 char buffer[MAX_LOCATION];
61 for(c = 0, d = 0; c < len; c++)
63 if(expr[c] == '$' && c < len - 1 && expr[c + 1] == '(')
66 for(i = c + 2; i < len; i++)
73 if(!strnicmp(&expr[c + 2], "Config", n) || !strnicmp(&expr[c + 2], "Config", n))
76 strcat(buffer, configName);
77 CamelCase(&buffer[d]);
78 d += strlen(configName);
81 else if(!strnicmp(&expr[c + 2], "Module", n) || !strnicmp(&expr[c + 2], "Project", n))
84 strcat(buffer, moduleName);
85 //CamelCase(&buffer[d]);
86 d += strlen(moduleName);
89 else if(!strnicmp(&expr[c + 2], "Platform", n))
92 strcat(buffer, targetPlatformName);
93 CamelCase(&buffer[d]);
94 d += strlen(targetPlatformName);
97 else if(!strnicmp(&expr[c + 2], "Compiler", n))
100 strcat(buffer, compilerName);
101 CamelCase(&buffer[d]);
102 d += strlen(compilerName);
105 else if(!strnicmp(&expr[c + 2], "Debug_Suffix", n))
107 // We don't support .debug from the IDE yet...
110 else if(!strnicmp(&expr[c + 2], "Compiler_Suffix", n))
112 if(bitDepth || (compilerName[0] && strcmpi(compilerName, "default")))
114 if(compilerName[0] && strcmpi(compilerName, "default"))
118 strcat(buffer, compilerName);
119 CamelCase(&buffer[d]);
120 d += strlen(compilerName)+1;
124 strcat(buffer, ".x32");
127 else if(bitDepth == 64)
129 strcat(buffer, ".x64");
137 buffer[d++] = expr[c];
142 buffer[d++] = expr[c];
147 else if(expr[i] == '\\' || expr[i] == '/')
150 strncat(buffer, &expr[i], i - c);
158 buffer[d++] = expr[c];
162 buffer[d++] = expr[c];
166 if(dir && strcmp(buffer, dir))
169 dir = CopyString(buffer);
174 dir = CopyString("");
179 public enum TargetTypes { unset, executable, sharedLibrary, staticLibrary };
180 public enum OptimizationStrategy { unset, none, speed, size };
181 public enum WarningsOption { unset, normal, none, all }; // TOCHECK: More options?
182 public enum BuildBitDepth { all, bits32, bits64 };
184 Array<String> CopyArrayString(Array<String> array)
186 Array<String> copy = null;
190 for(s : array) copy.Add(CopyString(s));
195 public class ProjectOptions
199 property SetBool allWarnings
207 WarningsOption warnings;
211 SetBool noLineNumbers;
212 OptimizationStrategy optimization;
213 Array<String> preprocessorDefinitions;
214 property Array<String> includeDirs
220 if(value && value.count)
225 includeDirs.Add(CopyValidateMakefilePath(s));
232 get { return includeDirs; }
233 isset { return includeDirs && includeDirs.count; }
235 String defaultNameSpace;
236 SetBool strictNameSpaces;
239 TargetTypes targetType;
240 // NOTE: The JSON Parser deletes strings after setting a String property, so we do a copy here.
241 // (This behavior is different from Objects (class instances) values which are not deleted)
242 // Code calling these properties should *NOT* use CopyString().
243 property char * targetFileName
245 set { delete targetFileName; if(value && value[0]) targetFileName = CopyValidateMakefilePath(value); }
246 get { return targetFileName; }
247 isset { return targetFileName && targetFileName[0]; }
249 property char * targetDirectory
251 set { delete targetDirectory; if(value /*&& value[0]*/) targetDirectory = CopyValidateMakefilePath(value); }
252 get { return targetDirectory; }
253 isset { return targetDirectory != null/*&& targetDirectory[0]*/; }
255 property char * objectsDirectory
257 set { delete objectsDirectory; if(value /*&& value[0]*/) objectsDirectory = CopyValidateMakefilePath(value); }
258 get { return objectsDirectory; }
259 isset { return objectsDirectory != null/*&& objectsDirectory[0]*/; }
261 Array<String> libraries;
262 Array<String> linkerOptions;
263 property Array<String> libraryDirs
269 if(value && value.count)
274 libraryDirs.Add(CopyValidateMakefilePath(s));
275 value.Free(); // why do I have to do this here? it's a property, shouldn't json deal with this?
281 get { return libraryDirs; }
282 isset { return libraryDirs && libraryDirs.count; }
287 // todo; move those to compiler/linker sections
288 SetBool excludeFromBuild;
289 BuildBitDepth buildBitDepth;
292 property Array<String> prebuildCommands
297 prebuildCommands.Free();
298 if(value && value.count)
300 if(!prebuildCommands)
301 prebuildCommands = { };
303 prebuildCommands.Add(CopyValidateMakefilePath(s));
308 delete prebuildCommands;
310 get { return prebuildCommands; }
311 isset { return prebuildCommands && prebuildCommands.count; }
313 property Array<String> postbuildCommands
317 if(postbuildCommands)
318 postbuildCommands.Free();
319 if(value && value.count)
321 if(!postbuildCommands)
322 postbuildCommands = { };
324 postbuildCommands.Add(CopyValidateMakefilePath(s));
329 delete postbuildCommands;
331 get { return postbuildCommands; }
332 isset { return postbuildCommands && postbuildCommands.count; }
335 ProjectOptions Copy()
337 // TODO: We'll want some solution so that we can use OnCopy for copying containers (Array<String>)
342 memoryGuard = memoryGuard,
344 noLineNumbers = noLineNumbers;
345 optimization = optimization,
346 defaultNameSpace = CopyString(defaultNameSpace),
347 strictNameSpaces = strictNameSpaces,
348 targetType = targetType,
349 targetFileName = /*CopyString(*/targetFileName/*)*/,
350 targetDirectory = /*CopyString(*/targetDirectory/*)*/,
351 objectsDirectory = /*CopyString(*/objectsDirectory/*)*/,
354 excludeFromBuild = excludeFromBuild,
356 preprocessorDefinitions = CopyArrayString(preprocessorDefinitions),
357 includeDirs = CopyArrayString(includeDirs),
358 libraries = CopyArrayString(libraries),
359 linkerOptions = CopyArrayString(linkerOptions),
360 libraryDirs = CopyArrayString(libraryDirs),
361 prebuildCommands = CopyArrayString(prebuildCommands),
362 postbuildCommands = CopyArrayString(postbuildCommands)
369 PrintLn("warnings:", warnings);
370 PrintLn("debug:", debug);
371 PrintLn("memoryGuard:", memoryGuard);
372 PrintLn("profile:", profile);
373 //PrintLn("noLineNumbers:", noLineNumbers);
374 PrintLn("optimization:", optimization);
377 //PrintLn("dddddddd:", dddddddd);
379 PrintLn("fastMath:", fastMath);
381 PrintLn("preprocessorDefinitions:", preprocessorDefinitions);
382 PrintLn("includeDirs:", includeDirs);
385 //PrintLn("dddddddd:", dddddddd);
393 if(preprocessorDefinitions) { preprocessorDefinitions.Free(); delete preprocessorDefinitions; }
394 if(includeDirs) { includeDirs.Free(); delete includeDirs; }
395 delete defaultNameSpace;
396 delete targetFileName;
397 delete targetDirectory;
398 delete objectsDirectory;
399 if(libraries) { libraries.Free(); delete libraries; }
400 if(linkerOptions) { linkerOptions.Free(); delete linkerOptions; }
401 if(libraryDirs) { libraryDirs.Free(); delete libraryDirs; }
402 if(prebuildCommands) { prebuildCommands.Free(); delete prebuildCommands; }
403 if(postbuildCommands) { postbuildCommands.Free(); delete postbuildCommands; }
406 Array<String> includeDirs;
407 String targetFileName;
408 String targetDirectory;
409 String objectsDirectory;
410 Array<String> libraryDirs;
411 Array<String> prebuildCommands;
412 Array<String> postbuildCommands;
414 property bool isEmpty
418 if(warnings == unset &&
420 memoryGuard == unset &&
422 noLineNumbers == unset &&
423 optimization == unset &&
424 !preprocessorDefinitions &&
425 (!includeDirs || !includeDirs.count) &&
427 strictNameSpaces == unset &&
428 targetType == unset &&
434 (!libraryDirs || !libraryDirs.count) &&
437 excludeFromBuild == unset &&
439 (!prebuildCommands || !prebuildCommands.count) &&
440 (!postbuildCommands || !postbuildCommands.count) )
447 public class PlatformOptions
451 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
459 PlatformOptions Copy()
464 options ? options.Copy() : null
468 ProjectOptions options;
471 class ProjectConfig : struct
475 property ProjectOptions options { get { return options; } set { options = value; } isset { return options && !options.isEmpty; } }
476 property Array<PlatformOptions> platforms
478 get { return platforms; }
481 if(platforms) { platforms.Free(); delete platforms; }
484 List<PlatformOptions> empty { };
485 Iterator<PlatformOptions> it { value };
487 for(p : platforms; !p.options || p.options.isEmpty) empty.Add(p);
488 for(p : empty; it.Find(p)) platforms.Delete(it.pointer);
498 if(p.options && !p.options.isEmpty)
507 ProjectOptions options;
509 bool compilingModified, linkingModified, symbolGenModified;
510 Array<PlatformOptions> platforms;
517 if(platforms) { platforms.Free(); delete platforms; }
522 Array<PlatformOptions> platforms = null;
526 for(p : this.platforms)
528 platforms.Add(p.Copy());
534 options ? options.Copy() : null,