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)
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 CompilerConfig compiler = GetCompilerConfig();
56 ProjectConfig config = project.config;
57 char * configName = config && config.name && config.name[0] ? config.name : "Common";
58 char * projectName = project.name ? project.name : "";
59 char * moduleName = project.moduleName ? project.moduleName : "";
60 char * compilingPlatformName = GetRuntimePlatform();
61 char * compilerName = (compiler && compiler.name) ? compiler.name : defaultCompilerName;
62 char * targetPlatformName = compiler && compiler.targetPlatform ? compiler.targetPlatform : "";
63 char buffer[MAX_LOCATION];
64 for(c = 0, d = 0; c < len; c++)
66 if(expr[c] == '$' && c < len - 1 && expr[c + 1] == '(')
69 for(i = c + 2; i < len; i++)
76 if(!strnicmp(&expr[c + 2], "Config", n) || !strnicmp(&expr[c + 2], "Config", n))
79 strcat(buffer, configName);
80 CamelCase(&buffer[d]);
81 d += strlen(configName);
84 else if(!strnicmp(&expr[c + 2], "Module", n) || !strnicmp(&expr[c + 2], "Project", n))
87 strcat(buffer, moduleName);
88 //CamelCase(&buffer[d]);
89 d += strlen(moduleName);
92 else if(!strnicmp(&expr[c + 2], "Platform", n))
95 strcat(buffer, targetPlatformName);
96 CamelCase(&buffer[d]);
97 d += strlen(targetPlatformName);
98 /*if(strcmpi(targetPlatformName, compilingPlatformName))
102 strcat(buffer, compilingPlatformName);
103 d += strlen(compilingPlatformName);
107 else if(!strnicmp(&expr[c + 2], "Compiler", n))
110 strcat(buffer, compilerName);
111 CamelCase(&buffer[d]);
112 d += strlen(compilerName);
117 buffer[d++] = expr[c];
122 buffer[d++] = expr[c];
127 else if(expr[i] == '\\' || expr[i] == '/')
130 strncat(buffer, &expr[i], i - c);
138 buffer[d++] = expr[c];
142 buffer[d++] = expr[c];
146 if(dir && strcmp(buffer, dir))
149 dir = CopyString(buffer);
155 dir = CopyString("");
160 public enum TargetTypes { unset, executable, sharedLibrary, staticLibrary };
161 public enum OptimizationStrategy { unset, none, speed, size };
162 public enum WarningsOption { unset, normal, none, all }; // TOCHECK: More options?
164 Array<String> CopyArrayString(Array<String> array)
166 Array<String> copy = null;
170 for(s : array) copy.Add(CopyString(s));
175 public class ProjectOptions
179 property SetBool allWarnings
187 WarningsOption warnings;
191 SetBool noLineNumbers;
192 OptimizationStrategy optimization;
193 Array<String> preprocessorDefinitions;
194 property Array<String> includeDirs
200 if(value && value.count)
205 includeDirs.Add(CopyValidateMakefilePath(s));
212 get { return includeDirs; }
213 isset { return includeDirs && includeDirs.count; }
215 String defaultNameSpace;
216 SetBool strictNameSpaces;
219 TargetTypes targetType;
220 property char * targetFileName
222 set { delete targetFileName; if(value && value[0]) targetFileName = CopyValidateMakefilePath(value); }
223 get { return targetFileName; }
224 isset { return targetFileName && targetFileName[0]; }
226 property char * targetDirectory
228 set { delete targetDirectory; if(value /*&& value[0]*/) targetDirectory = CopyValidateMakefilePath(value); }
229 get { return targetDirectory; }
230 isset { return targetDirectory != null/*&& targetDirectory[0]*/; }
232 property char * objectsDirectory
234 set { delete objectsDirectory; if(value /*&& value[0]*/) objectsDirectory = CopyValidateMakefilePath(value); }
235 get { return objectsDirectory; }
236 isset { return objectsDirectory != null/*&& objectsDirectory[0]*/; }
238 Array<String> libraries;
239 Array<String> linkerOptions;
240 property Array<String> libraryDirs
246 if(value && value.count)
251 libraryDirs.Add(CopyValidateMakefilePath(s));
252 value.Free(); // why do I have to do this here? it's a property, shouldn't json deal with this?
258 get { return libraryDirs; }
259 isset { return libraryDirs && libraryDirs.count; }
264 SetBool excludeFromBuild;
266 property Array<String> prebuildCommands
271 prebuildCommands.Free();
272 if(value && value.count)
274 if(!prebuildCommands)
275 prebuildCommands = { };
277 prebuildCommands.Add(CopyValidateMakefilePath(s));
282 delete prebuildCommands;
284 get { return prebuildCommands; }
285 isset { return prebuildCommands && prebuildCommands.count; }
287 property Array<String> postbuildCommands
291 if(postbuildCommands)
292 postbuildCommands.Free();
293 if(value && value.count)
295 if(!postbuildCommands)
296 postbuildCommands = { };
298 postbuildCommands.Add(CopyValidateMakefilePath(s));
303 delete postbuildCommands;
305 get { return postbuildCommands; }
306 isset { return postbuildCommands && postbuildCommands.count; }
309 ProjectOptions Copy()
311 // TODO: We'll want some solution so that we can use OnCopy for copying containers (Array<String>)
316 memoryGuard = memoryGuard,
318 noLineNumbers = noLineNumbers;
319 optimization = optimization,
320 defaultNameSpace = CopyString(defaultNameSpace),
321 strictNameSpaces = strictNameSpaces,
322 targetType = targetType,
323 targetFileName = CopyString(targetFileName),
324 targetDirectory = CopyString(targetDirectory),
325 objectsDirectory = CopyString(objectsDirectory),
328 excludeFromBuild = excludeFromBuild,
329 preprocessorDefinitions = CopyArrayString(preprocessorDefinitions),
330 includeDirs = CopyArrayString(includeDirs),
331 libraries = CopyArrayString(libraries),
332 linkerOptions = CopyArrayString(linkerOptions),
333 libraryDirs = CopyArrayString(libraryDirs),
334 prebuildCommands = CopyArrayString(prebuildCommands),
335 postbuildCommands = CopyArrayString(postbuildCommands)
341 if(preprocessorDefinitions) { preprocessorDefinitions.Free(); delete preprocessorDefinitions; }
342 if(includeDirs) { includeDirs.Free(); delete includeDirs; }
343 delete defaultNameSpace;
344 delete targetFileName;
345 delete targetDirectory;
346 delete objectsDirectory;
347 if(libraries) { libraries.Free(); delete libraries; }
348 if(linkerOptions) { linkerOptions.Free(); delete linkerOptions; }
349 if(libraryDirs) { libraryDirs.Free(); delete libraryDirs; }
350 if(prebuildCommands) { prebuildCommands.Free(); delete prebuildCommands; }
351 if(postbuildCommands) { postbuildCommands.Free(); delete postbuildCommands; }
354 Array<String> includeDirs;
355 String targetFileName;
356 String targetDirectory;
357 String objectsDirectory;
358 Array<String> libraryDirs;
359 Array<String> prebuildCommands;
360 Array<String> postbuildCommands;
362 property bool isEmpty
366 if(warnings == unset &&
368 memoryGuard == unset &&
370 noLineNumbers == unset &&
371 optimization == unset &&
372 !preprocessorDefinitions &&
375 strictNameSpaces == unset &&
376 targetType == unset &&
385 excludeFromBuild == unset &&
394 public class PlatformOptions
398 ProjectOptions options;
406 PlatformOptions Copy()
411 options ? options.Copy() : null
416 class ProjectConfig : struct
420 ProjectOptions options;
421 Array<PlatformOptions> platforms;
426 bool compilingModified, linkingModified, symbolGenModified;
433 if(platforms) { platforms.Free(); delete platforms; }
438 Array<PlatformOptions> platforms = null;
442 for(p : this.platforms)
444 platforms.Add(p.Copy());
450 options ? options.Copy() : null,