2 public import static "ecere"
10 define pathListSep = ";";
12 define pathListSep = ":";
15 void ParseDirList(char * string, Container<String> list)
19 int numTokens = TokenizeWith(string, sizeof(tokens) / sizeof(byte *), tokens, ";", false);
21 for(c = 0; c < numTokens; c++)
22 list.Add(CopyString(tokens[c]));
25 // NOTE: FileMonitors are not to be used by an Application class. globalSystem is not set up properly otherwise.
26 // Mantis ticket #545 was filed regarding this.
27 class epj2makeApp : GuiApplication
33 char * configName = null;
34 char * epjPath = null;
35 char * makePath = null;
41 Platform targetPlatform = GetRuntimePlatform();
43 Project project = null;
45 CompilerConfig optionsCompiler { };
47 bool noGlobalSettings = false;
48 bool noResources = false;
49 bool noWarnings = false;
50 char * overrideObjDir = null;
51 char * includemkPath = null;
54 for(c = 0; c < this.argc; c++)
56 char * arg = this.argv[c];
57 int argLen = strlen(arg);
59 argv = renew argv char *[argc + 1];
60 argv[argc] = new char[argLen + 1];
61 strcpy(argv[argc], arg);
63 while(argv[argc][argLen - 1] == '\\' && c < this.argc-1)
70 argv[argc] = renew argv[argc] char[argLen + len + 1];
72 argv[argc][argLen - 1] = ' ';
73 strcpy(argv[argc] + argLen, arg);
80 for(c = 1; c < argc; c++)
85 if(!strcmpi(arg+1, "make"))
88 optionsCompiler.makeCommand = argv[c];
92 else if(!strcmpi(arg+1, "cpp"))
95 optionsCompiler.cppCommand = argv[c];
99 else if(!strcmpi(arg+1, "cc"))
102 optionsCompiler.ccCommand = argv[c];
106 else if(!strcmpi(arg+1, "ecp"))
109 optionsCompiler.ecpCommand = argv[c];
113 else if(!strcmpi(arg+1, "ecc"))
116 optionsCompiler.eccCommand = argv[c];
120 else if(!strcmpi(arg+1, "ecs"))
123 optionsCompiler.ecsCommand = argv[c];
127 else if(!strcmpi(arg+1, "ear"))
130 optionsCompiler.earCommand = argv[c];
134 else if(!strcmpi(arg+1, "noglobalsettings"))
136 noGlobalSettings = true;
138 else if(!strcmpi(arg+1, "noresources"))
142 else if(!strcmpi(arg+1, "includemk"))
145 includemkPath = argv[c];
149 else if(arg[1] == 'w' && !arg[2])
153 else if(arg[1] == 'c' && !arg[2])
157 int argLen = strlen(argv[c]);
158 configName = new char[argLen + 1];
159 strcpy(configName, argv[c]);
164 else if(arg[1] == 't' && !arg[2])
167 targetPlatform = argv[c];
171 else if(arg[1] == 'o')
175 int argLen = strlen(argv[c]);
176 makePath = new char[argLen + 1];
177 strcpy(makePath, argv[c]);
182 else if(arg[1] == 'i')
185 ParseDirList(argv[c], optionsCompiler.includeDirs);
189 else if(arg[1] == 'l')
192 ParseDirList(argv[c], optionsCompiler.libraryDirs);
196 else if(arg[1] == 'd' && !arg[2])
199 overrideObjDir = argv[c];
206 printf($"invalid option: %s\n", arg);
213 int argLen = strlen(arg);
214 epjPath = new char[argLen + 1];
215 strcpy(epjPath, arg);
227 printf($"Syntax:\n");
228 printf($" epj2make [-t <target platform>] [-c <configuration>] [toolchain] [directories] [options] [-o <output>] <input>\n");
229 printf($" toolchain:\n");
230 printf($" [-make <make tool>]\n");
231 printf($" [-cpp <c preprocessor>]\n");
232 printf($" [-cc <c compiler>]\n");
233 printf($" [-ecp <eC preprocessor>]\n");
234 printf($" [-ecc <eC compiler>]\n");
235 printf($" [-ecs <eC symbol generator>]\n");
236 printf($" [-ear <Ecere Archiver>]\n");
237 printf($" directories:\n");
238 printf($" [-i <include dir[;inc dir[...]]>]\n");
239 printf($" [-l <library dir[;lib dir[...]]>]\n");
240 printf($" options:\n");
241 printf($" [-noglobalsettings]\n");
242 printf($" [-noresources]\n");
243 printf($" [-d <intermediate objects directory>]\n");
244 printf($" [-includemk <crossplatform.mk path>]\n");
248 if(FileExists(epjPath).isFile)
250 char extension[MAX_EXTENSION] = "";
251 GetExtension(epjPath, extension);
253 if(!strcmp(extension, ProjectExtension))
257 defaultCompiler = MakeDefaultCompiler("Default", true);
262 char * compiler = getenv("COMPILER");
263 if(!compiler) compiler = "Default";
264 settingsContainer.Load();
265 //incref ideSettings;
266 delete settingsContainer;
268 // TODO: Command line option to choose between the two
269 // or a command line option to not use global settings
270 //defaultCompiler = MakeDefaultCompiler();
271 defaultCompiler = ideSettings.GetCompilerConfig(compiler);
272 // possible TODO: use the workspace to select the active compiler
273 // TODO: option to specify compiler name when using global settings
276 if(optionsCompiler.makeCommand)
277 defaultCompiler.makeCommand = optionsCompiler.makeCommand;
278 if(optionsCompiler.cppCommand)
279 defaultCompiler.cppCommand = optionsCompiler.cppCommand;
280 if(optionsCompiler.ccCommand)
281 defaultCompiler.ccCommand = optionsCompiler.ccCommand;
282 if(optionsCompiler.ecpCommand)
283 defaultCompiler.ecpCommand = optionsCompiler.ecpCommand;
284 if(optionsCompiler.eccCommand)
285 defaultCompiler.eccCommand = optionsCompiler.eccCommand;
286 if(optionsCompiler.ecsCommand)
287 defaultCompiler.ecsCommand = optionsCompiler.ecsCommand;
288 if(optionsCompiler.earCommand)
289 defaultCompiler.earCommand = optionsCompiler.earCommand;
290 // TODO: Pass/combine/override the include and library dirs
291 for(dir : optionsCompiler.includeDirs)
292 defaultCompiler.includeDirs.Add(dir);
293 for(dir : optionsCompiler.libraryDirs)
294 defaultCompiler.libraryDirs.Add(dir);
295 delete optionsCompiler;
297 project = LoadProject(epjPath);
300 ProjectConfig defaultConfig = null;
304 for(config : project.configurations)
306 if(!strcmpi(configName, config.name))
308 project.config = config;
314 printf($"Error: Project configuration (%s) was not found.\n", configName);
318 ProjectConfig releaseConfig = null;
319 for(config : project.configurations)
321 if(!strcmpi(config.name, "Release"))
323 releaseConfig = config;
327 if(!releaseConfig && project.configurations.count)
329 releaseConfig = project.configurations[0];
330 printf($"Notice: Project configuration (%s) will be used.\n", releaseConfig.name);
335 project.config = releaseConfig;
338 delete releaseConfig.options.targetDirectory;
339 releaseConfig.options.targetDirectory = CopyString(overrideObjDir);
340 delete releaseConfig.options.objectsDirectory;
341 releaseConfig.options.objectsDirectory = CopyString(overrideObjDir);
344 releaseConfig.options.warnings = none;
346 else if(overrideObjDir)
348 delete project.options.targetDirectory;
349 project.options.targetDirectory = CopyString(overrideObjDir);
350 delete project.options.objectsDirectory;
351 project.options.objectsDirectory = CopyString(overrideObjDir);
354 project.options.warnings = none;
358 project.GenerateCompilerCf(defaultCompiler);
359 project.GenerateCrossPlatformMk();
360 if(project.GenerateMakefile(makePath, noResources, includemkPath, project.config))
363 printf("%s\n", makePath);
368 delete defaultCompiler;
370 delete defaultConfig;
374 printf($"Error: Unable to open project file (%s) due to unknown error.\n", epjPath);
378 printf($"Error: Input file (%s) does not exist.\n", epjPath);
381 //if(optionsCompiler) // how to fix those leaks?
382 delete optionsCompiler;
388 // Why do we need to free this here?
389 delete defaultCompiler;
392 for(c = 0; c<argc; c++)