2 public import static "ecere"
10 define pathListSep = ";";
12 define pathListSep = ":";
15 #if defined(_DEBUG) && defined(__WIN32__)
16 extern int getch(void);
19 void ParseDirList(char * string, Container<String> list)
23 int numTokens = TokenizeWith(string, sizeof(tokens) / sizeof(byte *), tokens, ";", false);
25 for(c = 0; c < numTokens; c++)
26 list.Add(CopyString(tokens[c]));
29 // NOTE: FileMonitors are not to be used by an Application class. globalSystem is not set up properly otherwise.
30 // Mantis ticket #545 was filed regarding this.
31 class epj2makeApp : GuiApplication
37 char * configName = null;
38 char * epjPath = null;
39 char * makePath = null;
45 Project project = null;
47 CompilerConfig optionsCompiler { };
49 bool noGlobalSettings = false;
50 bool noResources = false;
51 bool noWarnings = false;
52 const char * overrideObjDir = null;
53 const char * includemkPath = null;
56 for(c = 0; c < this.argc; c++)
58 char * arg = this.argv[c];
59 int argLen = strlen(arg);
61 argv = renew argv char *[argc + 1];
62 argv[argc] = new char[argLen + 1];
63 strcpy(argv[argc], arg);
65 while(argv[argc][argLen - 1] == '\\' && c < this.argc-1)
72 argv[argc] = renew argv[argc] char[argLen + len + 1];
74 argv[argc][argLen - 1] = ' ';
75 strcpy(argv[argc] + argLen, arg);
82 for(c = 1; c < argc; c++)
84 const char * arg = argv[c];
87 if(!strcmpi(arg+1, "make"))
90 optionsCompiler.makeCommand = argv[c];
94 else if(!strcmpi(arg+1, "cpp"))
97 optionsCompiler.cppCommand = argv[c];
101 else if(!strcmpi(arg+1, "cc"))
104 optionsCompiler.ccCommand = argv[c];
108 else if(!strcmpi(arg+1, "ecp"))
111 optionsCompiler.ecpCommand = argv[c];
115 else if(!strcmpi(arg+1, "ecc"))
118 optionsCompiler.eccCommand = argv[c];
122 else if(!strcmpi(arg+1, "ecs"))
125 optionsCompiler.ecsCommand = argv[c];
129 else if(!strcmpi(arg+1, "ear"))
132 optionsCompiler.earCommand = argv[c];
136 else if(!strcmpi(arg+1, "noglobalsettings"))
138 noGlobalSettings = true;
140 else if(!strcmpi(arg+1, "noresources"))
144 else if(!strcmpi(arg+1, "includemk"))
147 includemkPath = argv[c];
151 else if(arg[1] == 'w' && !arg[2])
155 else if(arg[1] == 'c' && !arg[2])
159 int argLen = strlen(argv[c]);
160 configName = new char[argLen + 1];
161 strcpy(configName, argv[c]);
166 else if(arg[1] == 't' && !arg[2])
168 // Obsolete target platform option
173 else if(arg[1] == 'o')
177 int argLen = strlen(argv[c]);
178 makePath = new char[argLen + 1];
179 strcpy(makePath, argv[c]);
184 else if(arg[1] == 'i')
187 ParseDirList((char *)argv[c], optionsCompiler.includeDirs);
191 else if(arg[1] == 'l')
194 ParseDirList((char *)argv[c], optionsCompiler.libraryDirs);
198 else if(arg[1] == 'd' && !arg[2])
201 overrideObjDir = argv[c];
208 printf($"invalid option: %s\n", arg);
215 int argLen = strlen(arg);
216 epjPath = new char[argLen + 1];
217 strcpy(epjPath, arg);
229 printf("%s", $"Syntax:\n");
230 printf("%s", $" epj2make [-t <target platform>] [-c <configuration>] [toolchain] [directories] [options] [-o <output>] <input>\n");
231 printf("%s", $" toolchain:\n");
232 printf("%s", $" [-make <make tool>]\n");
233 printf("%s", $" [-cpp <c preprocessor>]\n");
234 printf("%s", $" [-cc <c compiler>]\n");
235 printf("%s", $" [-ecp <eC preprocessor>]\n");
236 printf("%s", $" [-ecc <eC compiler>]\n");
237 printf("%s", $" [-ecs <eC symbol generator>]\n");
238 printf("%s", $" [-ear <Ecere Archiver>]\n");
239 printf("%s", $" directories:\n");
240 printf("%s", $" [-i <include dir[;inc dir[...]]>]\n");
241 printf("%s", $" [-l <library dir[;lib dir[...]]>]\n");
242 printf("%s", $" options:\n");
243 printf("%s", $" [-noglobalsettings]\n");
244 printf("%s", $" [-noresources]\n");
245 printf("%s", $" [-d <intermediate objects directory>]\n");
246 printf("%s", $" [-includemk <crossplatform.mk path>]\n");
250 if(FileExists(epjPath).isFile)
252 char extension[MAX_EXTENSION] = "";
253 GetExtension(epjPath, extension);
255 if(!strcmp(extension, ProjectExtension))
259 defaultCompiler = MakeDefaultCompiler("Default", true);
264 const char * compiler = getenv("COMPILER");
265 if(!compiler) compiler = "Default";
266 settingsContainer.Load();
267 //incref ideSettings;
268 delete settingsContainer;
270 // TODO: Command line option to choose between the two
271 // or a command line option to not use global settings
272 //defaultCompiler = MakeDefaultCompiler();
273 defaultCompiler = ideSettings.GetCompilerConfig(compiler);
274 // possible TODO: use the workspace to select the active compiler
275 // TODO: option to specify compiler name when using global settings
278 if(optionsCompiler.makeCommand)
279 defaultCompiler.makeCommand = optionsCompiler.makeCommand;
280 if(optionsCompiler.cppCommand)
281 defaultCompiler.cppCommand = optionsCompiler.cppCommand;
282 if(optionsCompiler.ccCommand)
283 defaultCompiler.ccCommand = optionsCompiler.ccCommand;
284 if(optionsCompiler.ecpCommand)
285 defaultCompiler.ecpCommand = optionsCompiler.ecpCommand;
286 if(optionsCompiler.eccCommand)
287 defaultCompiler.eccCommand = optionsCompiler.eccCommand;
288 if(optionsCompiler.ecsCommand)
289 defaultCompiler.ecsCommand = optionsCompiler.ecsCommand;
290 if(optionsCompiler.earCommand)
291 defaultCompiler.earCommand = optionsCompiler.earCommand;
292 // TODO: Pass/combine/override the include and library dirs
293 for(dir : optionsCompiler.includeDirs)
294 defaultCompiler.includeDirs.Add(dir);
295 for(dir : optionsCompiler.libraryDirs)
296 defaultCompiler.libraryDirs.Add(dir);
297 delete optionsCompiler;
299 project = LoadProject(epjPath, null);
302 ProjectConfig defaultConfig = null;
306 for(config : project.configurations)
308 if(!strcmpi(configName, config.name))
310 project.config = config;
316 printf($"Error: Project configuration (%s) was not found.\n", configName);
320 ProjectConfig releaseConfig = null;
321 for(config : project.configurations)
323 if(!strcmpi(config.name, "Release"))
325 releaseConfig = config;
329 if(!releaseConfig && project.configurations.count)
331 releaseConfig = project.configurations[0];
332 printf($"Notice: Project configuration (%s) will be used.\n", releaseConfig.name);
337 project.config = releaseConfig;
340 delete releaseConfig.options.targetDirectory;
341 releaseConfig.options.targetDirectory = CopyString(overrideObjDir);
342 delete releaseConfig.options.objectsDirectory;
343 releaseConfig.options.objectsDirectory = CopyString(overrideObjDir);
346 releaseConfig.options.warnings = none;
348 else if(overrideObjDir)
350 delete project.options.targetDirectory;
351 project.options.targetDirectory = CopyString(overrideObjDir);
352 delete project.options.objectsDirectory;
353 project.options.objectsDirectory = CopyString(overrideObjDir);
356 project.options.warnings = none;
360 project.GenerateCompilerCf(defaultCompiler, project.topNode.ContainsFilesWithExtension("ec", project.config));
361 project.GenerateCrossPlatformMk(null);
362 if(project.GenerateMakefile(makePath, noResources, includemkPath, project.config))
365 printf("%s\n", makePath);
370 delete defaultCompiler;
372 delete defaultConfig;
376 printf($"Error: Unable to open project file (%s) due to unknown error.\n", epjPath);
380 printf($"Error: Input file (%s) does not exist.\n", epjPath);
383 //if(optionsCompiler) // how to fix those leaks?
384 delete optionsCompiler;
390 // Why do we need to free this here?
391 delete defaultCompiler;
394 for(c = 0; c<argc; c++)
401 #if defined(_DEBUG) && defined(__WIN32__)