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 <include.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 settingsContainer.Load();
263 //incref ideSettings;
264 delete settingsContainer;
266 // TODO: Command line option to choose between the two
267 // or a command line option to not use global settings
268 //defaultCompiler = MakeDefaultCompiler();
269 defaultCompiler = ideSettings.GetCompilerConfig("Default");
270 // possible TODO: use the workspace to select the active compiler
271 // TODO: option to specify compiler name when using global settings
274 if(optionsCompiler.makeCommand)
275 defaultCompiler.makeCommand = optionsCompiler.makeCommand;
276 if(optionsCompiler.cppCommand)
277 defaultCompiler.cppCommand = optionsCompiler.cppCommand;
278 if(optionsCompiler.ccCommand)
279 defaultCompiler.ccCommand = optionsCompiler.ccCommand;
280 if(optionsCompiler.ecpCommand)
281 defaultCompiler.ecpCommand = optionsCompiler.ecpCommand;
282 if(optionsCompiler.eccCommand)
283 defaultCompiler.eccCommand = optionsCompiler.eccCommand;
284 if(optionsCompiler.ecsCommand)
285 defaultCompiler.ecsCommand = optionsCompiler.ecsCommand;
286 if(optionsCompiler.earCommand)
287 defaultCompiler.earCommand = optionsCompiler.earCommand;
288 // TODO: Pass/combine/override the include and library dirs
289 for(dir : optionsCompiler.includeDirs)
290 defaultCompiler.includeDirs.Add(dir);
291 for(dir : optionsCompiler.libraryDirs)
292 defaultCompiler.libraryDirs.Add(dir);
293 delete optionsCompiler;
295 project = LoadProject(epjPath);
298 ProjectConfig defaultConfig = null;
302 for(config : project.configurations)
304 if(!strcmpi(configName, config.name))
306 project.config = config;
312 printf($"Error: Project configuration (%s) was not found.\n", configName);
316 ProjectConfig releaseConfig = null;
317 for(config : project.configurations)
319 if(!strcmpi(config.name, "Release"))
321 releaseConfig = config;
325 if(!releaseConfig && project.configurations.count)
327 releaseConfig = project.configurations[0];
328 printf($"Notice: Project configuration (%s) will be used.\n", releaseConfig.name);
333 project.config = releaseConfig;
336 delete releaseConfig.options.targetDirectory;
337 releaseConfig.options.targetDirectory = CopyString(overrideObjDir);
338 delete releaseConfig.options.objectsDirectory;
339 releaseConfig.options.objectsDirectory = CopyString(overrideObjDir);
342 releaseConfig.options.warnings = none;
344 else if(overrideObjDir)
346 delete project.options.targetDirectory;
347 project.options.targetDirectory = CopyString(overrideObjDir);
348 delete project.options.objectsDirectory;
349 project.options.objectsDirectory = CopyString(overrideObjDir);
352 project.options.warnings = none;
356 if(project.GenerateMakefile(makePath, noResources, includemkPath, defaultCompiler, project.config))
359 printf("%s\n", makePath);
364 delete defaultCompiler;
366 delete defaultConfig;
370 printf($"Error: Unable to open project file (%s) due to unknown error.\n", epjPath);
374 printf($"Error: Input file (%s) does not exist.\n", epjPath);
377 //if(optionsCompiler) // how to fix those leaks?
378 delete optionsCompiler;
384 // Why do we need to free this here?
385 delete defaultCompiler;
388 for(c = 0; c<argc; c++)