Support define overriding in child .rbuild files
[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 string_list* pclean_files ) const;
101
102 std::string GetObjectFilenames ();
103
104 std::string GetPreconditionDependenciesName () const;
105 std::string GetCFlagsMacro () const;
106 static std::string GetObjectsMacro ( const Module& );
107 std::string GetLinkingDependenciesMacro () const;
108 std::string GetLibsMacro () const;
109 std::string GetLinkerMacro () const;
110 void GenerateCleanObjectsAsYouGoCode () const;
111 void GenerateRunRsymCode () const;
112 void GenerateRunStripCode () const;
113 void GenerateLinkerCommand ( const std::string& dependencies,
114 const std::string& linker,
115 const std::string& linkerParameters,
116 const std::string& objectsMacro,
117 const std::string& libsMacro,
118 const std::string& pefixupParameters );
119 void GeneratePhonyTarget() const;
120 void GenerateBuildMapCode ( const FileLocation *mapTarget = NULL );
121 void GenerateRules ();
122 void GenerateImportLibraryTargetIfNeeded ();
123 void GetDefinitionDependencies ( std::vector<FileLocation>& dependencies ) const;
124
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<std::string>* used_defs );
141 void GenerateMacros ( const char* op,
142 const IfableData& data,
143 const std::vector<LinkerFlag*>* linkerFlags,
144 std::set<std::string>& used_defs );
145 void GenerateSourceMacros ( const char* assignmentOperation,
146 const IfableData& data );
147 void GenerateObjectMacros ( const char* assignmentOperation,
148 const IfableData& data );
149 std::string GenerateGccIncludeParameters () const;
150 std::string GenerateGccParameters () const;
151 std::string GenerateNasmParameters () const;
152 const FileLocation* GetPrecompiledHeaderFilename () const;
153 void GenerateGccCommand ( const FileLocation* sourceFile,
154 const std::string& extraDependencies,
155 const std::string& cc,
156 const std::string& cflagsMacro );
157 void GenerateGccAssemblerCommand ( const FileLocation* sourceFile,
158 const std::string& cc,
159 const std::string& cflagsMacro );
160 void GenerateNasmCommand ( const FileLocation* sourceFile,
161 const std::string& nasmflagsMacro );
162 void GenerateWindresCommand ( const FileLocation* sourceFile,
163 const std::string& windresflagsMacro );
164 void GenerateWinebuildCommands ( const FileLocation* sourceFile );
165 std::string GetWidlFlags ( const CompilationUnit& compilationUnit );
166 void GenerateWidlCommandsServer (
167 const CompilationUnit& compilationUnit,
168 const std::string& widlflagsMacro );
169 void GenerateWidlCommandsClient (
170 const CompilationUnit& compilationUnit,
171 const std::string& widlflagsMacro );
172 void GenerateWidlCommandsIdlHeader (
173 const CompilationUnit& compilationUnit,
174 const std::string& widlflagsMacro );
175 void GenerateWidlCommandsEmbeddedTypeLib (
176 const CompilationUnit& compilationUnit,
177 const std::string& widlflagsMacro );
178 void GenerateWidlCommands ( const CompilationUnit& compilationUnit,
179 const std::string& widlflagsMacro );
180 void GenerateCommands ( const CompilationUnit& compilationUnit,
181 const std::string& extraDependencies,
182 const std::string& cc,
183 const std::string& cppc,
184 const std::string& cflagsMacro,
185 const std::string& nasmflagsMacro,
186 const std::string& windresflagsMacro,
187 const std::string& widlflagsMacro );
188 void GenerateObjectFileTargets ( const IfableData& data,
189 const std::string& cc,
190 const std::string& cppc,
191 const std::string& cflagsMacro,
192 const std::string& nasmflagsMacro,
193 const std::string& windresflagsMacro,
194 const std::string& widlflagsMacro );
195 void GenerateObjectFileTargets ( const std::string& cc,
196 const std::string& cppc,
197 const std::string& cflagsMacro,
198 const std::string& nasmflagsMacro,
199 const std::string& windresflagsMacro,
200 const std::string& widlflagsMacro );
201 const FileLocation* GenerateArchiveTarget ( const std::string& ar,
202 const std::string& objs_macro ) const;
203 void GetSpecObjectDependencies ( std::vector<FileLocation>& dependencies,
204 const FileLocation *file ) const;
205 void GetWidlObjectDependencies ( std::vector<FileLocation>& dependencies,
206 const FileLocation *file ) const;
207 void GetDefaultDependencies ( string_list& dependencies ) const;
208 void GetInvocationDependencies ( const Module& module, string_list& dependencies );
209 bool IsWineModule () const;
210 const FileLocation* GetDefinitionFilename () const;
211 void GenerateBuildNonSymbolStrippedCode ();
212 void CleanupCompilationUnitVector ( std::vector<CompilationUnit*>& compilationUnits );
213 void GetRpcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
214 static std::string GetPropertyValue ( const Module& module, const std::string& name );
215 const FileLocation* GetRpcServerHeaderFilename ( const FileLocation *base ) const;
216 const FileLocation* GetRpcClientHeaderFilename ( const FileLocation *base ) const;
217 const FileLocation* GetIdlHeaderFilename ( const FileLocation *base ) const;
218 std::string GetModuleCleanTarget ( const Module& module ) const;
219 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector<std::string>& moduleNames ) const;
220 public:
221 const Module& module;
222 string_list clean_files;
223 std::string cflagsMacro;
224 std::string nasmflagsMacro;
225 std::string windresflagsMacro;
226 std::string widlflagsMacro;
227 std::string linkerflagsMacro;
228 std::string sourcesMacro;
229 std::string objectsMacro;
230 std::string libsMacro;
231 std::string linkDepsMacro;
232 };
233
234
235 class MingwBuildToolModuleHandler : public MingwModuleHandler
236 {
237 public:
238 MingwBuildToolModuleHandler ( const Module& module );
239 virtual HostType DefaultHost() { return HostTrue; }
240 virtual void Process ();
241 private:
242 void GenerateBuildToolModuleTarget ();
243 };
244
245
246 class MingwKernelModuleHandler : public MingwModuleHandler
247 {
248 public:
249 MingwKernelModuleHandler ( const Module& module );
250 virtual HostType DefaultHost() { return HostFalse; }
251 virtual void Process ();
252 private:
253 void GenerateKernelModuleTarget ();
254 };
255
256
257 class MingwStaticLibraryModuleHandler : public MingwModuleHandler
258 {
259 public:
260 MingwStaticLibraryModuleHandler ( const Module& module );
261 virtual HostType DefaultHost() { return HostFalse; }
262 virtual void Process ();
263 private:
264 void GenerateStaticLibraryModuleTarget ();
265 };
266
267
268 class MingwObjectLibraryModuleHandler : public MingwModuleHandler
269 {
270 public:
271 MingwObjectLibraryModuleHandler ( const Module& module );
272 virtual HostType DefaultHost() { return HostFalse; }
273 virtual void Process ();
274 private:
275 void GenerateObjectLibraryModuleTarget ();
276 };
277
278
279 class MingwKernelModeDLLModuleHandler : public MingwModuleHandler
280 {
281 public:
282 MingwKernelModeDLLModuleHandler ( const Module& module );
283 virtual HostType DefaultHost() { return HostFalse; }
284 virtual void Process ();
285 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
286 void AddImplicitLibraries ( Module& module );
287 private:
288 void GenerateKernelModeDLLModuleTarget ();
289 };
290
291
292 class MingwKernelModeDriverModuleHandler : public MingwModuleHandler
293 {
294 public:
295 MingwKernelModeDriverModuleHandler ( const Module& module );
296 virtual HostType DefaultHost() { return HostFalse; }
297 virtual void Process ();
298 std::string TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
299 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
300 void AddImplicitLibraries ( Module& module );
301 private:
302 void GenerateKernelModeDriverModuleTarget ();
303 };
304
305
306 class MingwNativeDLLModuleHandler : public MingwModuleHandler
307 {
308 public:
309 MingwNativeDLLModuleHandler ( const Module& module );
310 virtual HostType DefaultHost() { return HostFalse; }
311 virtual void Process ();
312 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
313 void AddImplicitLibraries ( Module& module );
314 private:
315 void GenerateNativeDLLModuleTarget ();
316 };
317
318
319 class MingwNativeCUIModuleHandler : public MingwModuleHandler
320 {
321 public:
322 MingwNativeCUIModuleHandler ( const Module& module );
323 virtual HostType DefaultHost() { return HostFalse; }
324 virtual void Process ();
325 std::string TypeSpecificCFlags() { return "-D__NTAPP__"; }
326 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
327 void AddImplicitLibraries ( Module& module );
328 private:
329 void GenerateNativeCUIModuleTarget ();
330 };
331
332
333 class MingwWin32DLLModuleHandler : public MingwModuleHandler
334 {
335 public:
336 MingwWin32DLLModuleHandler ( const Module& module );
337 virtual HostType DefaultHost() { return HostFalse; }
338 virtual void Process ();
339 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
340 void AddImplicitLibraries ( Module& module );
341 private:
342 void GenerateWin32DLLModuleTarget ();
343 };
344
345
346 class MingwWin32OCXModuleHandler : public MingwModuleHandler
347 {
348 public:
349 MingwWin32OCXModuleHandler ( const Module& module );
350 virtual HostType DefaultHost() { return HostFalse; }
351 virtual void Process ();
352 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
353 void AddImplicitLibraries ( Module& module );
354 private:
355 void GenerateWin32OCXModuleTarget ();
356 };
357
358
359 class MingwWin32CUIModuleHandler : public MingwModuleHandler
360 {
361 public:
362 MingwWin32CUIModuleHandler ( const Module& module );
363 virtual HostType DefaultHost() { return HostFalse; }
364 virtual void Process ();
365 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
366 void AddImplicitLibraries ( Module& module );
367 private:
368 void GenerateWin32CUIModuleTarget ();
369 };
370
371
372 class MingwWin32GUIModuleHandler : public MingwModuleHandler
373 {
374 public:
375 MingwWin32GUIModuleHandler ( const Module& module );
376 virtual HostType DefaultHost() { return HostFalse; }
377 virtual void Process ();
378 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
379 void AddImplicitLibraries ( Module& module );
380 private:
381 void GenerateWin32GUIModuleTarget ();
382 };
383
384
385 class MingwBootLoaderModuleHandler : public MingwModuleHandler
386 {
387 public:
388 MingwBootLoaderModuleHandler ( const Module& module );
389 virtual HostType DefaultHost() { return HostFalse; }
390 virtual void Process ();
391 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
392 private:
393 void GenerateBootLoaderModuleTarget ();
394 };
395
396
397 class MingwBootSectorModuleHandler : public MingwModuleHandler
398 {
399 public:
400 MingwBootSectorModuleHandler ( const Module& module );
401 virtual HostType DefaultHost() { return HostFalse; }
402 virtual void Process ();
403 std::string TypeSpecificNasmFlags() { return "-f bin"; }
404 private:
405 void GenerateBootSectorModuleTarget ();
406 };
407
408
409 class MingwBootProgramModuleHandler : public MingwModuleHandler
410 {
411 public:
412 MingwBootProgramModuleHandler ( const Module& module );
413 virtual HostType DefaultHost() { return HostFalse; }
414 virtual void Process ();
415 std::string GetProgTextAddrMacro ();
416 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
417 private:
418 void GenerateBootProgramModuleTarget ();
419 };
420
421
422 class MingwIsoModuleHandler : public MingwModuleHandler
423 {
424 public:
425 MingwIsoModuleHandler ( const Module& module );
426 virtual HostType DefaultHost() { return HostFalse; }
427 virtual void Process ();
428 private:
429 void GenerateIsoModuleTarget ();
430 void GetBootstrapCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
431 void GetNonModuleCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
432 void GetCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
433 void GetBootstrapCdFiles ( std::vector<FileLocation>& out ) const;
434 void GetNonModuleCdFiles ( std::vector<FileLocation>& out ) const;
435 void GetCdFiles ( std::vector<FileLocation>& out ) const;
436 void OutputBootstrapfileCopyCommands ( const std::string& bootcdDirectory );
437 void OutputCdfileCopyCommands ( const std::string& bootcdDirectory );
438 };
439
440
441 class MingwLiveIsoModuleHandler : public MingwModuleHandler
442 {
443 public:
444 MingwLiveIsoModuleHandler ( const Module& module );
445 virtual HostType DefaultHost() { return HostFalse; }
446 virtual void Process ();
447 private:
448 void GenerateLiveIsoModuleTarget ();
449 void CreateDirectory ( const std::string& directory );
450 void OutputModuleCopyCommands ( std::string& livecdDirectory,
451 std::string& livecdReactos );
452 void OutputNonModuleCopyCommands ( std::string& livecdDirectory,
453 std::string& livecdReactos );
454 void OutputProfilesDirectoryCommands ( std::string& livecdDirectory );
455 void OutputLoaderCommands ( std::string& livecdDirectory );
456 void OutputRegistryCommands ( std::string& livecdDirectory );
457 };
458
459
460 class MingwTestModuleHandler : public MingwModuleHandler
461 {
462 public:
463 MingwTestModuleHandler ( const Module& module );
464 virtual HostType DefaultHost() { return HostFalse; }
465 virtual void Process ();
466 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
467 protected:
468 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
469 private:
470 void GenerateTestModuleTarget ();
471 };
472
473
474 class MingwRpcServerModuleHandler : public MingwModuleHandler
475 {
476 public:
477 MingwRpcServerModuleHandler ( const Module& module );
478 virtual HostType DefaultHost() { return HostFalse; }
479 virtual void Process ();
480 };
481
482
483 class MingwRpcClientModuleHandler : public MingwModuleHandler
484 {
485 public:
486 MingwRpcClientModuleHandler ( const Module& module );
487 virtual HostType DefaultHost() { return HostFalse; }
488 virtual void Process ();
489 };
490
491 class MingwAliasModuleHandler : public MingwModuleHandler
492 {
493 public:
494 MingwAliasModuleHandler ( const Module& module );
495 virtual HostType DefaultHost() { return HostFalse; }
496 virtual void Process ();
497 };
498
499 class MingwIdlHeaderModuleHandler : public MingwModuleHandler
500 {
501 public:
502 MingwIdlHeaderModuleHandler ( const Module& module );
503 virtual HostType DefaultHost() { return HostFalse; }
504 virtual void Process ();
505 };
506
507 class MingwEmbeddedTypeLibModuleHandler : public MingwModuleHandler
508 {
509 public:
510 MingwEmbeddedTypeLibModuleHandler ( const Module& module );
511 virtual HostType DefaultHost() { return HostFalse; }
512 virtual void Process ();
513 };
514
515 class MingwElfExecutableModuleHandler : public MingwModuleHandler
516 {
517 public:
518 MingwElfExecutableModuleHandler ( const Module& module );
519 virtual HostType DefaultHost() { return HostFalse; }
520 virtual void Process ();
521 };
522
523 #endif /* MINGW_MODULEHANDLER_H */