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);
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 IDESettingsContainer settingsContainer;
267 dataOwner = &ideSettings;
269 settingsContainer.Load();
270 //incref ideSettings;
271 delete settingsContainer;
273 // TODO: Command line option to choose between the two
274 // or a command line option to not use global settings
275 //defaultCompiler = MakeDefaultCompiler();
276 defaultCompiler = ideSettings.GetCompilerConfig("Default");
277 // possible TODO: use the workspace to select the active compiler
278 // TODO: option to specify compiler name when using global settings
281 if(optionsCompiler.makeCommand)
282 defaultCompiler.makeCommand = optionsCompiler.makeCommand;
283 if(optionsCompiler.cppCommand)
284 defaultCompiler.cppCommand = optionsCompiler.cppCommand;
285 if(optionsCompiler.ccCommand)
286 defaultCompiler.ccCommand = optionsCompiler.ccCommand;
287 if(optionsCompiler.ecpCommand)
288 defaultCompiler.ecpCommand = optionsCompiler.ecpCommand;
289 if(optionsCompiler.eccCommand)
290 defaultCompiler.eccCommand = optionsCompiler.eccCommand;
291 if(optionsCompiler.ecsCommand)
292 defaultCompiler.ecsCommand = optionsCompiler.ecsCommand;
293 if(optionsCompiler.earCommand)
294 defaultCompiler.earCommand = optionsCompiler.earCommand;
295 // TODO: Pass/combine/override the include and library dirs
296 for(dir : optionsCompiler.includeDirs)
297 defaultCompiler.includeDirs.Add(dir);
298 for(dir : optionsCompiler.libraryDirs)
299 defaultCompiler.libraryDirs.Add(dir);
300 delete optionsCompiler;
302 project = LoadProject(epjPath);
305 ProjectConfig defaultConfig = null;
309 for(config : project.configurations)
311 if(!strcmpi(configName, config.name))
313 project.config = config;
319 printf("Error: Project configuration (%s) was not found.\n", configName);
323 ProjectConfig releaseConfig = null;
324 for(config : project.configurations)
326 if(!strcmpi(config.name, "Release"))
328 releaseConfig = config;
332 if(!releaseConfig && project.configurations.count)
334 releaseConfig = project.configurations[0];
335 printf("Notice: Project configuration (%s) will be used.\n", releaseConfig.name);
340 project.config = releaseConfig;
343 delete releaseConfig.options.targetDirectory;
344 releaseConfig.options.targetDirectory = CopyString(overrideObjDir);
345 delete releaseConfig.options.objectsDirectory;
346 releaseConfig.options.objectsDirectory = CopyString(overrideObjDir);
349 releaseConfig.options.warnings = none;
351 else if(overrideObjDir)
353 delete project.options.targetDirectory;
354 project.options.targetDirectory = CopyString(overrideObjDir);
355 delete project.options.objectsDirectory;
356 project.options.objectsDirectory = CopyString(overrideObjDir);
359 project.options.warnings = none;
363 if(project.GenerateMakefile(makePath, noResources, includemkPath))
366 printf("%s\n", makePath);
371 delete defaultCompiler;
373 delete defaultConfig;
377 printf("Error: Unable to open project file (%s) due to unknown error.\n", epjPath);
381 printf("Error: Input file (%s) does not exist.\n", epjPath);
384 //if(optionsCompiler) // how to fix those leaks?
385 delete optionsCompiler;
391 // Why do we need to free this here?
392 delete defaultCompiler;
395 for(c = 0; c<argc; c++)