2 public import static "ecere"
10 define pathListSep = ";";
12 define pathListSep = ":";
15 #if defined(_DEBUG) && defined(__WIN32__)
16 extern int getch(void);
19 IDESettings ideSettings;
21 IDESettingsContainer settingsContainer
23 dataOwner = &ideSettings;
24 dataClass = class(IDESettings);
27 IDEConfigHolder ideConfig { };
29 void ParseDirList(char * string, Container<String> list)
33 int numTokens = TokenizeWith(string, sizeof(tokens) / sizeof(byte *), tokens, ";", false);
35 for(c = 0; c < numTokens; c++)
36 list.Add(CopyString(tokens[c]));
39 // NOTE: FileMonitors are not to be used by an Application class. globalSystem is not set up properly otherwise.
40 // Mantis ticket #545 was filed regarding this.
41 class epj2makeApp : GuiApplication
47 char * configName = null;
48 char * epjPath = null;
49 char * makePath = null;
55 Project project = null;
57 CompilerConfig optionsCompiler { };
59 bool noGlobalSettings = false;
60 bool noResources = false;
61 bool noWarnings = false;
62 const char * overrideObjDir = null;
63 const char * includemkPath = null;
66 for(c = 0; c < this.argc; c++)
68 char * arg = this.argv[c];
69 int argLen = strlen(arg);
71 argv = renew argv char *[argc + 1];
72 argv[argc] = new char[argLen + 1];
73 strcpy(argv[argc], arg);
75 while(argv[argc][argLen - 1] == '\\' && c < this.argc-1)
82 argv[argc] = renew argv[argc] char[argLen + len + 1];
84 argv[argc][argLen - 1] = ' ';
85 strcpy(argv[argc] + argLen, arg);
92 for(c = 1; c < argc; c++)
94 const char * arg = argv[c];
97 if(!strcmpi(arg+1, "make"))
100 optionsCompiler.makeCommand = argv[c];
104 else if(!strcmpi(arg+1, "cpp"))
107 optionsCompiler.cppCommand = argv[c];
111 else if(!strcmpi(arg+1, "cc"))
114 optionsCompiler.ccCommand = argv[c];
118 else if(!strcmpi(arg+1, "ecp"))
121 optionsCompiler.ecpCommand = argv[c];
125 else if(!strcmpi(arg+1, "ecc"))
128 optionsCompiler.eccCommand = argv[c];
132 else if(!strcmpi(arg+1, "ecs"))
135 optionsCompiler.ecsCommand = argv[c];
139 else if(!strcmpi(arg+1, "ear"))
142 optionsCompiler.earCommand = argv[c];
146 else if(!strcmpi(arg+1, "noglobalsettings"))
148 noGlobalSettings = true;
150 else if(!strcmpi(arg+1, "noresources"))
154 else if(!strcmpi(arg+1, "includemk"))
157 includemkPath = argv[c];
161 else if(arg[1] == 'w' && !arg[2])
165 else if(arg[1] == 'c' && !arg[2])
169 int argLen = strlen(argv[c]);
170 configName = new char[argLen + 1];
171 strcpy(configName, argv[c]);
176 else if(arg[1] == 't' && !arg[2])
178 // Obsolete target platform option
183 else if(arg[1] == 'o')
187 int argLen = strlen(argv[c]);
188 makePath = new char[argLen + 1];
189 strcpy(makePath, argv[c]);
194 else if(arg[1] == 'i')
197 ParseDirList((char *)argv[c], optionsCompiler.includeDirs);
201 else if(arg[1] == 'l')
204 ParseDirList((char *)argv[c], optionsCompiler.libraryDirs);
208 else if(arg[1] == 'd' && !arg[2])
211 overrideObjDir = argv[c];
218 printf($"invalid option: %s\n", arg);
225 int argLen = strlen(arg);
226 epjPath = new char[argLen + 1];
227 strcpy(epjPath, arg);
239 printf("%s", $"Syntax:\n");
240 printf("%s", $" epj2make [-t <target platform>] [-c <configuration>] [toolchain] [directories] [options] [-o <output>] <input>\n");
241 printf("%s", $" toolchain:\n");
242 printf("%s", $" [-make <make tool>]\n");
243 printf("%s", $" [-cpp <c preprocessor>]\n");
244 printf("%s", $" [-cc <c compiler>]\n");
245 printf("%s", $" [-ecp <eC preprocessor>]\n");
246 printf("%s", $" [-ecc <eC compiler>]\n");
247 printf("%s", $" [-ecs <eC symbol generator>]\n");
248 printf("%s", $" [-ear <Ecere Archiver>]\n");
249 printf("%s", $" directories:\n");
250 printf("%s", $" [-i <include dir[;inc dir[...]]>]\n");
251 printf("%s", $" [-l <library dir[;lib dir[...]]>]\n");
252 printf("%s", $" options:\n");
253 printf("%s", $" [-noglobalsettings]\n");
254 printf("%s", $" [-noresources]\n");
255 printf("%s", $" [-d <intermediate objects directory>]\n");
256 printf("%s", $" [-includemk <crossplatform.mk path>]\n");
260 if(FileExists(epjPath).isFile)
262 char extension[MAX_EXTENSION] = "";
263 GetExtension(epjPath, extension);
265 if(!strcmp(extension, ProjectExtension))
269 defaultCompiler = MakeDefaultCompiler("Default", true);
274 const char * compiler = getenv("COMPILER");
275 if(!compiler) compiler = "Default";
276 settingsContainer.Load();
277 ideConfig.compilers.read(settingsContainer);
279 //incref ideSettings;
280 delete settingsContainer;
282 // TODO: Command line option to choose between the two
283 // or a command line option to not use global settings
284 //defaultCompiler = MakeDefaultCompiler();
285 defaultCompiler = ideConfig.compilers.GetCompilerConfig(compiler);
286 // possible TODO: use the workspace to select the active compiler
287 // TODO: option to specify compiler name when using global settings
290 if(optionsCompiler.makeCommand)
291 defaultCompiler.makeCommand = optionsCompiler.makeCommand;
292 if(optionsCompiler.cppCommand)
293 defaultCompiler.cppCommand = optionsCompiler.cppCommand;
294 if(optionsCompiler.ccCommand)
295 defaultCompiler.ccCommand = optionsCompiler.ccCommand;
296 if(optionsCompiler.ecpCommand)
297 defaultCompiler.ecpCommand = optionsCompiler.ecpCommand;
298 if(optionsCompiler.eccCommand)
299 defaultCompiler.eccCommand = optionsCompiler.eccCommand;
300 if(optionsCompiler.ecsCommand)
301 defaultCompiler.ecsCommand = optionsCompiler.ecsCommand;
302 if(optionsCompiler.earCommand)
303 defaultCompiler.earCommand = optionsCompiler.earCommand;
304 // TODO: Pass/combine/override the include and library dirs
305 for(dir : optionsCompiler.includeDirs)
306 defaultCompiler.includeDirs.Add(dir);
307 for(dir : optionsCompiler.libraryDirs)
308 defaultCompiler.libraryDirs.Add(dir);
309 delete optionsCompiler;
311 project = LoadProject(epjPath, null);
314 ProjectConfig defaultConfig = null;
318 for(config : project.configurations)
320 if(!strcmpi(configName, config.name))
322 project.config = config;
328 printf($"Error: Project configuration (%s) was not found.\n", configName);
332 ProjectConfig releaseConfig = null;
333 for(config : project.configurations)
335 if(!strcmpi(config.name, "Release"))
337 releaseConfig = config;
341 if(!releaseConfig && project.configurations.count)
343 releaseConfig = project.configurations[0];
344 printf($"Notice: Project configuration (%s) will be used.\n", releaseConfig.name);
349 project.config = releaseConfig;
352 delete releaseConfig.options.targetDirectory;
353 releaseConfig.options.targetDirectory = CopyString(overrideObjDir);
354 delete releaseConfig.options.objectsDirectory;
355 releaseConfig.options.objectsDirectory = CopyString(overrideObjDir);
358 releaseConfig.options.warnings = none;
360 else if(overrideObjDir)
362 delete project.options.targetDirectory;
363 project.options.targetDirectory = CopyString(overrideObjDir);
364 delete project.options.objectsDirectory;
365 project.options.objectsDirectory = CopyString(overrideObjDir);
368 project.options.warnings = none;
372 project.GenerateCompilerCf(defaultCompiler, project.topNode.ContainsFilesWithExtension("ec", project.config));
373 project.GenerateCrossPlatformMk(null);
374 if(project.GenerateMakefile(makePath, noResources, includemkPath, project.config))
377 printf("%s\n", makePath);
382 delete defaultCompiler;
384 delete defaultConfig;
388 printf($"Error: Unable to open project file (%s) due to unknown error.\n", epjPath);
392 printf($"Error: Input file (%s) does not exist.\n", epjPath);
395 //if(optionsCompiler) // how to fix those leaks?
396 delete optionsCompiler;
402 // Why do we need to free this here?
403 delete defaultCompiler;
406 for(c = 0; c<argc; c++)
413 #if defined(_DEBUG) && defined(__WIN32__)