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