Add support for mc files and remove hardcoded WMC instructions from Makefile . Thanks...
[reactos.git] / reactos / tools / rbuild / backend / mingw / modulehandler.h
1 /*
2 * Copyright (C) 2005 Casper S. Hornstrup
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18 #ifndef MINGW_MODULEHANDLER_H
19 #define MINGW_MODULEHANDLER_H
20
21 #include "../backend.h"
22 #include "mingw.h"
23
24 class MingwBackend;
25
26 extern std::string
27 GetTargetMacro ( const Module&, bool with_dollar = true );
28
29 extern std::string
30 PrefixFilename (
31 const std::string& filename,
32 const std::string& prefix );
33
34 class MingwModuleHandler
35 {
36 public:
37 MingwModuleHandler ( const Module& module_ );
38 virtual ~MingwModuleHandler();
39
40 static void SetBackend ( MingwBackend* backend_ );
41 static void SetMakefile ( FILE* f );
42 void EnablePreCompiledHeaderSupport ();
43
44 static const FileLocation* PassThruCacheDirectory (const FileLocation* fileLocation );
45
46 static const FileLocation* GetTargetFilename (
47 const Module& module,
48 string_list* pclean_files );
49
50 static const FileLocation* GetImportLibraryFilename (
51 const Module& module,
52 string_list* pclean_files );
53
54 static std::string GenerateGccDefineParametersFromVector ( const std::vector<Define*>& defines, std::set<std::string> &used_defs );
55 static std::string GenerateGccIncludeParametersFromVector ( const std::vector<Include*>& includes );
56
57 std::string GetModuleTargets ( const Module& module );
58 void GetObjectsVector ( const IfableData& data,
59 std::vector<FileLocation>& objectFiles ) const;
60 void GenerateSourceMacro();
61 void GenerateObjectMacro();
62 void GenerateTargetMacro();
63 void GenerateOtherMacros();
64
65 static MingwModuleHandler* InstanciateHandler ( const Module& module_,
66 MingwBackend* backend_ );
67 virtual HostType DefaultHost() = 0;
68 void GeneratePreconditionDependencies ();
69 virtual void Process () = 0;
70 virtual std::string TypeSpecificCFlags() { return ""; }
71 virtual std::string TypeSpecificNasmFlags() { return ""; }
72 virtual std::string TypeSpecificLinkerFlags() { return ""; }
73 void GenerateInvocations () const;
74 void GenerateCleanTarget () const;
75 void GenerateInstallTarget () const;
76 void GenerateDependsTarget () const;
77 static bool ReferenceObjects ( const Module& module );
78 virtual void AddImplicitLibraries ( Module& module ) { return; }
79
80 void OutputCopyCommand ( const FileLocation& source,
81 const FileLocation& destination );
82 protected:
83 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
84 std::string GetWorkingDirectory () const;
85 std::string GetBasename ( const std::string& filename ) const;
86 const FileLocation* GetActualSourceFilename ( const FileLocation* file ) const;
87 std::string GetExtraDependencies ( const FileLocation *file ) const;
88 std::string GetCompilationUnitDependencies ( const CompilationUnit& compilationUnit ) const;
89 const FileLocation* GetModuleArchiveFilename () const;
90 bool IsGeneratedFile ( const File& file ) const;
91 std::string GetImportLibraryDependency ( const Module& importedModule );
92 void GetTargets ( const Module& dependencyModule,
93 string_list& targets );
94 void GetModuleDependencies ( string_list& dependencies );
95 std::string GetAllDependencies () const;
96 void GetSourceFilenames ( std::vector<FileLocation>& list,
97 bool includeGeneratedFiles ) const;
98 void GetSourceFilenamesWithoutGeneratedFiles ( std::vector<FileLocation>& list ) const;
99 const FileLocation* GetObjectFilename ( const FileLocation* sourceFile,
100 const Module& module,
101 string_list* pclean_files ) const;
102
103 std::string GetObjectFilenames ();
104
105 std::string GetPreconditionDependenciesName () const;
106 std::string GetCFlagsMacro () const;
107 static std::string GetObjectsMacro ( const Module& );
108 std::string GetLinkingDependenciesMacro () const;
109 std::string GetLibsMacro () const;
110 std::string GetLinkerMacro () const;
111 void GenerateCleanObjectsAsYouGoCode () const;
112 void GenerateRunRsymCode () const;
113 void GenerateRunStripCode () const;
114 void GenerateLinkerCommand ( const std::string& dependencies,
115 const std::string& linker,
116 const std::string& linkerParameters,
117 const std::string& objectsMacro,
118 const std::string& libsMacro,
119 const std::string& pefixupParameters );
120 void GeneratePhonyTarget() const;
121 void GenerateBuildMapCode ( const FileLocation *mapTarget = NULL );
122 void GenerateRules ();
123 void GenerateImportLibraryTargetIfNeeded ();
124 void GetDefinitionDependencies ( std::vector<FileLocation>& dependencies ) const;
125 std::string GetLinkingDependencies () const;
126 static MingwBackend* backend;
127 static FILE* fMakefile;
128 bool use_pch;
129 private:
130 std::string ConcatenatePaths ( const std::string& path1,
131 const std::string& path2 ) const;
132 std::string GenerateGccDefineParameters () const;
133 std::string GenerateCompilerParametersFromVector ( const std::vector<CompilerFlag*>& compilerFlags ) const;
134 std::string GenerateLinkerParametersFromVector ( const std::vector<LinkerFlag*>& linkerFlags ) const;
135 std::string GenerateImportLibraryDependenciesFromVector ( const std::vector<Library*>& libraries );
136 std::string GenerateLinkerParameters () const;
137 void GenerateMacro ( const char* assignmentOperation,
138 const std::string& macro,
139 const IfableData& data,
140 std::set<const Define *>* used_defs,
141 bool generatingCompilerMacro );
142 void GenerateMacros ( const char* op,
143 const IfableData& data,
144 const std::vector<LinkerFlag*>* linkerFlags,
145 std::set<const Define *>& used_defs );
146 void GenerateSourceMacros ( const char* assignmentOperation,
147 const IfableData& data );
148 void GenerateObjectMacros ( const char* assignmentOperation,
149 const IfableData& data );
150 std::string GenerateGccIncludeParameters () const;
151 std::string GenerateGccParameters () const;
152 std::string GenerateNasmParameters () const;
153 const FileLocation* GetPrecompiledHeaderFilename () const;
154 void GenerateGccCommand ( const FileLocation* sourceFile,
155 const std::string& extraDependencies,
156 const std::string& cc,
157 const std::string& cflagsMacro );
158 void GenerateGccAssemblerCommand ( const FileLocation* sourceFile,
159 const std::string& cc,
160 const std::string& cflagsMacro );
161 void GenerateNasmCommand ( const FileLocation* sourceFile,
162 const std::string& nasmflagsMacro );
163 void GenerateWindresCommand ( const FileLocation* sourceFile,
164 const std::string& windresflagsMacro );
165 void GenerateWinebuildCommands ( const FileLocation* sourceFile );
166 void GenerateWmcCommands ( const FileLocation* sourceFile);
167 std::string GetWidlFlags ( const CompilationUnit& compilationUnit );
168 void GenerateWidlCommandsServer (
169 const CompilationUnit& compilationUnit,
170 const std::string& widlflagsMacro );
171 void GenerateWidlCommandsClient (
172 const CompilationUnit& compilationUnit,
173 const std::string& widlflagsMacro );
174 void GenerateWidlCommandsIdlHeader (
175 const CompilationUnit& compilationUnit,
176 const std::string& widlflagsMacro );
177 void GenerateWidlCommandsEmbeddedTypeLib (
178 const CompilationUnit& compilationUnit,
179 const std::string& widlflagsMacro );
180 void GenerateWidlCommands ( const CompilationUnit& compilationUnit,
181 const std::string& widlflagsMacro );
182 void GenerateCommands ( const CompilationUnit& compilationUnit,
183 const std::string& extraDependencies,
184 const std::string& cc,
185 const std::string& cppc,
186 const std::string& cflagsMacro,
187 const std::string& nasmflagsMacro,
188 const std::string& windresflagsMacro,
189 const std::string& widlflagsMacro );
190 void GenerateObjectFileTargets ( const IfableData& data,
191 const std::string& cc,
192 const std::string& cppc,
193 const std::string& cflagsMacro,
194 const std::string& nasmflagsMacro,
195 const std::string& windresflagsMacro,
196 const std::string& widlflagsMacro );
197 void GenerateObjectFileTargets ( const std::string& cc,
198 const std::string& cppc,
199 const std::string& cflagsMacro,
200 const std::string& nasmflagsMacro,
201 const std::string& windresflagsMacro,
202 const std::string& widlflagsMacro );
203 const FileLocation* GenerateArchiveTarget ( const std::string& ar,
204 const std::string& objs_macro ) const;
205 void GetMcObjectDependencies ( std::vector<FileLocation>& dependencies,
206 const FileLocation *file ) const;
207 void GetSpecObjectDependencies ( std::vector<FileLocation>& dependencies,
208 const FileLocation *file ) const;
209 void GetWidlObjectDependencies ( std::vector<FileLocation>& dependencies,
210 const FileLocation *file ) const;
211 void GetDefaultDependencies ( string_list& dependencies ) const;
212 void GetInvocationDependencies ( const Module& module, string_list& dependencies );
213 bool IsWineModule () const;
214 const FileLocation* GetDefinitionFilename () const;
215 void GenerateBuildNonSymbolStrippedCode ();
216 void CleanupCompilationUnitVector ( std::vector<CompilationUnit*>& compilationUnits );
217 void GetRpcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
218 void GetMcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
219 static std::string GetPropertyValue ( const Module& module, const std::string& name );
220 const FileLocation* GetRpcServerHeaderFilename ( const FileLocation *base ) const;
221 const FileLocation* GetRpcClientHeaderFilename ( const FileLocation *base ) const;
222 const FileLocation* GetIdlHeaderFilename ( const FileLocation *base ) const;
223 const FileLocation* GetMcHeaderFilename ( const FileLocation *base ) const;
224 std::string GetModuleCleanTarget ( const Module& module ) const;
225 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector<std::string>& moduleNames ) const;
226 public:
227 const Module& module;
228 string_list clean_files;
229 std::string cflagsMacro;
230 std::string nasmflagsMacro;
231 std::string windresflagsMacro;
232 std::string widlflagsMacro;
233 std::string linkerflagsMacro;
234 std::string sourcesMacro;
235 std::string objectsMacro;
236 std::string libsMacro;
237 std::string linkDepsMacro;
238 };
239
240
241 class MingwBuildToolModuleHandler : public MingwModuleHandler
242 {
243 public:
244 MingwBuildToolModuleHandler ( const Module& module );
245 virtual HostType DefaultHost() { return HostTrue; }
246 virtual void Process ();
247 private:
248 void GenerateBuildToolModuleTarget ();
249 };
250
251
252 class MingwKernelModuleHandler : public MingwModuleHandler
253 {
254 public:
255 MingwKernelModuleHandler ( const Module& module );
256 virtual HostType DefaultHost() { return HostFalse; }
257 virtual void Process ();
258 private:
259 void GenerateKernelModuleTarget ();
260 };
261
262
263 class MingwStaticLibraryModuleHandler : public MingwModuleHandler
264 {
265 public:
266 MingwStaticLibraryModuleHandler ( const Module& module );
267 virtual HostType DefaultHost() { return HostFalse; }
268 virtual void Process ();
269 private:
270 void GenerateStaticLibraryModuleTarget ();
271 };
272
273
274 class MingwObjectLibraryModuleHandler : public MingwModuleHandler
275 {
276 public:
277 MingwObjectLibraryModuleHandler ( const Module& module );
278 virtual HostType DefaultHost() { return HostFalse; }
279 virtual void Process ();
280 private:
281 void GenerateObjectLibraryModuleTarget ();
282 };
283
284
285 class MingwKernelModeDLLModuleHandler : public MingwModuleHandler
286 {
287 public:
288 MingwKernelModeDLLModuleHandler ( const Module& module );
289 virtual HostType DefaultHost() { return HostFalse; }
290 virtual void Process ();
291 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
292 void AddImplicitLibraries ( Module& module );
293 private:
294 void GenerateKernelModeDLLModuleTarget ();
295 };
296
297
298 class MingwKernelModeDriverModuleHandler : public MingwModuleHandler
299 {
300 public:
301 MingwKernelModeDriverModuleHandler ( const Module& module );
302 virtual HostType DefaultHost() { return HostFalse; }
303 virtual void Process ();
304 std::string TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
305 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
306 void AddImplicitLibraries ( Module& module );
307 private:
308 void GenerateKernelModeDriverModuleTarget ();
309 };
310
311
312 class MingwNativeDLLModuleHandler : public MingwModuleHandler
313 {
314 public:
315 MingwNativeDLLModuleHandler ( const Module& module );
316 virtual HostType DefaultHost() { return HostFalse; }
317 virtual void Process ();
318 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
319 void AddImplicitLibraries ( Module& module );
320 private:
321 void GenerateNativeDLLModuleTarget ();
322 };
323
324
325 class MingwNativeCUIModuleHandler : public MingwModuleHandler
326 {
327 public:
328 MingwNativeCUIModuleHandler ( const Module& module );
329 virtual HostType DefaultHost() { return HostFalse; }
330 virtual void Process ();
331 std::string TypeSpecificCFlags() { return "-D__NTAPP__"; }
332 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
333 void AddImplicitLibraries ( Module& module );
334 private:
335 void GenerateNativeCUIModuleTarget ();
336 };
337
338
339 class MingwWin32DLLModuleHandler : public MingwModuleHandler
340 {
341 public:
342 MingwWin32DLLModuleHandler ( const Module& module );
343 virtual HostType DefaultHost() { return HostFalse; }
344 virtual void Process ();
345 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
346 void AddImplicitLibraries ( Module& module );
347 private:
348 void GenerateWin32DLLModuleTarget ();
349 };
350
351
352 class MingwWin32OCXModuleHandler : public MingwModuleHandler
353 {
354 public:
355 MingwWin32OCXModuleHandler ( const Module& module );
356 virtual HostType DefaultHost() { return HostFalse; }
357 virtual void Process ();
358 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
359 void AddImplicitLibraries ( Module& module );
360 private:
361 void GenerateWin32OCXModuleTarget ();
362 };
363
364
365 class MingwWin32CUIModuleHandler : public MingwModuleHandler
366 {
367 public:
368 MingwWin32CUIModuleHandler ( const Module& module );
369 virtual HostType DefaultHost() { return HostFalse; }
370 virtual void Process ();
371 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
372 void AddImplicitLibraries ( Module& module );
373 private:
374 void GenerateWin32CUIModuleTarget ();
375 };
376
377
378 class MingwWin32GUIModuleHandler : public MingwModuleHandler
379 {
380 public:
381 MingwWin32GUIModuleHandler ( const Module& module );
382 virtual HostType DefaultHost() { return HostFalse; }
383 virtual void Process ();
384 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
385 void AddImplicitLibraries ( Module& module );
386 private:
387 void GenerateWin32GUIModuleTarget ();
388 };
389
390
391 class MingwBootLoaderModuleHandler : public MingwModuleHandler
392 {
393 public:
394 MingwBootLoaderModuleHandler ( const Module& module );
395 virtual HostType DefaultHost() { return HostFalse; }
396 virtual void Process ();
397 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
398 private:
399 void GenerateBootLoaderModuleTarget ();
400 };
401
402
403 class MingwBootSectorModuleHandler : public MingwModuleHandler
404 {
405 public:
406 MingwBootSectorModuleHandler ( const Module& module );
407 virtual HostType DefaultHost() { return HostFalse; }
408 virtual void Process ();
409 std::string TypeSpecificNasmFlags() { return "-f bin"; }
410 private:
411 void GenerateBootSectorModuleTarget ();
412 };
413
414
415 class MingwBootProgramModuleHandler : public MingwModuleHandler
416 {
417 public:
418 MingwBootProgramModuleHandler ( const Module& module );
419 virtual HostType DefaultHost() { return HostFalse; }
420 virtual void Process ();
421 std::string GetProgTextAddrMacro ();
422 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
423 private:
424 void GenerateBootProgramModuleTarget ();
425 };
426
427
428 class MingwIsoModuleHandler : public MingwModuleHandler
429 {
430 public:
431 MingwIsoModuleHandler ( const Module& module );
432 virtual HostType DefaultHost() { return HostFalse; }
433 virtual void Process ();
434 private:
435 void GenerateIsoModuleTarget ();
436 void GetBootstrapCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
437 void GetNonModuleCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
438 void GetCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
439 void GetBootstrapCdFiles ( std::vector<FileLocation>& out ) const;
440 void GetNonModuleCdFiles ( std::vector<FileLocation>& out ) const;
441 void GetCdFiles ( std::vector<FileLocation>& out ) const;
442 void OutputBootstrapfileCopyCommands ( const std::string& bootcdDirectory );
443 void OutputCdfileCopyCommands ( const std::string& bootcdDirectory );
444 };
445
446
447 class MingwLiveIsoModuleHandler : public MingwModuleHandler
448 {
449 public:
450 MingwLiveIsoModuleHandler ( const Module& module );
451 virtual HostType DefaultHost() { return HostFalse; }
452 virtual void Process ();
453 private:
454 void GenerateLiveIsoModuleTarget ();
455 void CreateDirectory ( const std::string& directory );
456 void OutputModuleCopyCommands ( std::string& livecdDirectory,
457 std::string& livecdReactos );
458 void OutputNonModuleCopyCommands ( std::string& livecdDirectory,
459 std::string& livecdReactos );
460 void OutputProfilesDirectoryCommands ( std::string& livecdDirectory );
461 void OutputLoaderCommands ( std::string& livecdDirectory );
462 void OutputRegistryCommands ( std::string& livecdDirectory );
463 };
464
465
466 class MingwTestModuleHandler : public MingwModuleHandler
467 {
468 public:
469 MingwTestModuleHandler ( const Module& module );
470 virtual HostType DefaultHost() { return HostFalse; }
471 virtual void Process ();
472 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
473 protected:
474 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
475 private:
476 void GenerateTestModuleTarget ();
477 };
478
479
480 class MingwRpcServerModuleHandler : public MingwModuleHandler
481 {
482 public:
483 MingwRpcServerModuleHandler ( const Module& module );
484 virtual HostType DefaultHost() { return HostFalse; }
485 virtual void Process ();
486 };
487
488
489 class MingwRpcClientModuleHandler : public MingwModuleHandler
490 {
491 public:
492 MingwRpcClientModuleHandler ( const Module& module );
493 virtual HostType DefaultHost() { return HostFalse; }
494 virtual void Process ();
495 };
496
497 class MingwAliasModuleHandler : public MingwModuleHandler
498 {
499 public:
500 MingwAliasModuleHandler ( const Module& module );
501 virtual HostType DefaultHost() { return HostFalse; }
502 virtual void Process ();
503 };
504
505 class MingwIdlHeaderModuleHandler : public MingwModuleHandler
506 {
507 public:
508 MingwIdlHeaderModuleHandler ( const Module& module );
509 virtual HostType DefaultHost() { return HostFalse; }
510 virtual void Process ();
511 };
512
513 class MingwEmbeddedTypeLibModuleHandler : public MingwModuleHandler
514 {
515 public:
516 MingwEmbeddedTypeLibModuleHandler ( const Module& module );
517 virtual HostType DefaultHost() { return HostFalse; }
518 virtual void Process ();
519 };
520
521 class MingwElfExecutableModuleHandler : public MingwModuleHandler
522 {
523 public:
524 MingwElfExecutableModuleHandler ( const Module& module );
525 virtual HostType DefaultHost() { return HostFalse; }
526 virtual void Process ();
527 };
528
529 #endif /* MINGW_MODULEHANDLER_H */