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 Platform targetPlatform = GetRuntimePlatform();
47 Project project = null;
49 CompilerConfig optionsCompiler { };
51 bool noGlobalSettings = false;
52 bool noResources = false;
53 bool noWarnings = false;
54 const char * overrideObjDir = null;
55 const char * includemkPath = null;
58 for(c = 0; c < this.argc; c++)
60 char * arg = this.argv[c];
61 int argLen = strlen(arg);
63 argv = renew argv char *[argc + 1];
64 argv[argc] = new char[argLen + 1];
65 strcpy(argv[argc], arg);
67 while(argv[argc][argLen - 1] == '\\' && c < this.argc-1)
74 argv[argc] = renew argv[argc] char[argLen + len + 1];
76 argv[argc][argLen - 1] = ' ';
77 strcpy(argv[argc] + argLen, arg);
84 for(c = 1; c < argc; c++)
86 const char * arg = argv[c];
89 if(!strcmpi(arg+1, "make"))
92 optionsCompiler.makeCommand = argv[c];
96 else if(!strcmpi(arg+1, "cpp"))
99 optionsCompiler.cppCommand = argv[c];
103 else if(!strcmpi(arg+1, "cc"))
106 optionsCompiler.ccCommand = argv[c];
110 else if(!strcmpi(arg+1, "ecp"))
113 optionsCompiler.ecpCommand = argv[c];
117 else if(!strcmpi(arg+1, "ecc"))
120 optionsCompiler.eccCommand = argv[c];
124 else if(!strcmpi(arg+1, "ecs"))
127 optionsCompiler.ecsCommand = argv[c];
131 else if(!strcmpi(arg+1, "ear"))
134 optionsCompiler.earCommand = argv[c];
138 else if(!strcmpi(arg+1, "noglobalsettings"))
140 noGlobalSettings = true;
142 else if(!strcmpi(arg+1, "noresources"))
146 else if(!strcmpi(arg+1, "includemk"))
149 includemkPath = argv[c];
153 else if(arg[1] == 'w' && !arg[2])
157 else if(arg[1] == 'c' && !arg[2])
161 int argLen = strlen(argv[c]);
162 configName = new char[argLen + 1];
163 strcpy(configName, argv[c]);
168 else if(arg[1] == 't' && !arg[2])
171 targetPlatform = argv[c];
175 else if(arg[1] == 'o')
179 int argLen = strlen(argv[c]);
180 makePath = new char[argLen + 1];
181 strcpy(makePath, argv[c]);
186 else if(arg[1] == 'i')
189 ParseDirList((char *)argv[c], optionsCompiler.includeDirs);
193 else if(arg[1] == 'l')
196 ParseDirList((char *)argv[c], optionsCompiler.libraryDirs);
200 else if(arg[1] == 'd' && !arg[2])
203 overrideObjDir = argv[c];
210 printf($"invalid option: %s\n", arg);
217 int argLen = strlen(arg);
218 epjPath = new char[argLen + 1];
219 strcpy(epjPath, arg);
231 printf($"Syntax:\n");
232 printf($" epj2make [-t <target platform>] [-c <configuration>] [toolchain] [directories] [options] [-o <output>] <input>\n");
233 printf($" toolchain:\n");
234 printf($" [-make <make tool>]\n");
235 printf($" [-cpp <c preprocessor>]\n");
236 printf($" [-cc <c compiler>]\n");
237 printf($" [-ecp <eC preprocessor>]\n");
238 printf($" [-ecc <eC compiler>]\n");
239 printf($" [-ecs <eC symbol generator>]\n");
240 printf($" [-ear <Ecere Archiver>]\n");
241 printf($" directories:\n");
242 printf($" [-i <include dir[;inc dir[...]]>]\n");
243 printf($" [-l <library dir[;lib dir[...]]>]\n");
244 printf($" options:\n");
245 printf($" [-noglobalsettings]\n");
246 printf($" [-noresources]\n");
247 printf($" [-d <intermediate objects directory>]\n");
248 printf($" [-includemk <crossplatform.mk path>]\n");
252 if(FileExists(epjPath).isFile)
254 char extension[MAX_EXTENSION] = "";
255 GetExtension(epjPath, extension);
257 if(!strcmp(extension, ProjectExtension))
261 defaultCompiler = MakeDefaultCompiler("Default", true);
266 const char * compiler = getenv("COMPILER");
267 if(!compiler) compiler = "Default";
268 settingsContainer.Load();
269 //incref ideSettings;
270 delete settingsContainer;
272 // TODO: Command line option to choose between the two
273 // or a command line option to not use global settings
274 //defaultCompiler = MakeDefaultCompiler();
275 defaultCompiler = ideSettings.GetCompilerConfig(compiler);
276 // possible TODO: use the workspace to select the active compiler
277 // TODO: option to specify compiler name when using global settings
280 if(optionsCompiler.makeCommand)
281 defaultCompiler.makeCommand = optionsCompiler.makeCommand;
282 if(optionsCompiler.cppCommand)
283 defaultCompiler.cppCommand = optionsCompiler.cppCommand;
284 if(optionsCompiler.ccCommand)
285 defaultCompiler.ccCommand = optionsCompiler.ccCommand;
286 if(optionsCompiler.ecpCommand)
287 defaultCompiler.ecpCommand = optionsCompiler.ecpCommand;
288 if(optionsCompiler.eccCommand)
289 defaultCompiler.eccCommand = optionsCompiler.eccCommand;
290 if(optionsCompiler.ecsCommand)
291 defaultCompiler.ecsCommand = optionsCompiler.ecsCommand;
292 if(optionsCompiler.earCommand)
293 defaultCompiler.earCommand = optionsCompiler.earCommand;
294 // TODO: Pass/combine/override the include and library dirs
295 for(dir : optionsCompiler.includeDirs)
296 defaultCompiler.includeDirs.Add(dir);
297 for(dir : optionsCompiler.libraryDirs)
298 defaultCompiler.libraryDirs.Add(dir);
299 delete optionsCompiler;
301 project = LoadProject(epjPath, null);
304 ProjectConfig defaultConfig = null;
308 for(config : project.configurations)
310 if(!strcmpi(configName, config.name))
312 project.config = config;
318 printf($"Error: Project configuration (%s) was not found.\n", configName);
322 ProjectConfig releaseConfig = null;
323 for(config : project.configurations)
325 if(!strcmpi(config.name, "Release"))
327 releaseConfig = config;
331 if(!releaseConfig && project.configurations.count)
333 releaseConfig = project.configurations[0];
334 printf($"Notice: Project configuration (%s) will be used.\n", releaseConfig.name);
339 project.config = releaseConfig;
342 delete releaseConfig.options.targetDirectory;
343 releaseConfig.options.targetDirectory = CopyString(overrideObjDir);
344 delete releaseConfig.options.objectsDirectory;
345 releaseConfig.options.objectsDirectory = CopyString(overrideObjDir);
348 releaseConfig.options.warnings = none;
350 else if(overrideObjDir)
352 delete project.options.targetDirectory;
353 project.options.targetDirectory = CopyString(overrideObjDir);
354 delete project.options.objectsDirectory;
355 project.options.objectsDirectory = CopyString(overrideObjDir);
358 project.options.warnings = none;
362 project.GenerateCompilerCf(defaultCompiler, project.topNode.ContainsFilesWithExtension("ec", project.config));
363 project.GenerateCrossPlatformMk(null);
364 if(project.GenerateMakefile(makePath, noResources, includemkPath, project.config))
367 printf("%s\n", makePath);
372 delete defaultCompiler;
374 delete defaultConfig;
378 printf($"Error: Unable to open project file (%s) due to unknown error.\n", epjPath);
382 printf($"Error: Input file (%s) does not exist.\n", epjPath);
385 //if(optionsCompiler) // how to fix those leaks?
386 delete optionsCompiler;
392 // Why do we need to free this here?
393 delete defaultCompiler;
396 for(c = 0; c<argc; c++)
403 #if defined(_DEBUG) && defined(__WIN32__)