Merge from branch ReactX to Trunk,
[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
126 std::string GetLinkingDependencies () const;
127 static MingwBackend* backend;
128 static FILE* fMakefile;
129 bool use_pch;
130 private:
131 std::string ConcatenatePaths ( const std::string& path1,
132 const std::string& path2 ) const;
133 std::string GenerateGccDefineParameters () const;
134 std::string GenerateCompilerParametersFromVector ( const std::vector<CompilerFlag*>& compilerFlags ) const;
135 std::string GenerateLinkerParametersFromVector ( const std::vector<LinkerFlag*>& linkerFlags ) const;
136 std::string GenerateImportLibraryDependenciesFromVector ( const std::vector<Library*>& libraries );
137 std::string GenerateLinkerParameters () const;
138 void GenerateMacro ( const char* assignmentOperation,
139 const std::string& macro,
140 const IfableData& data,
141 std::set<const Define *>* used_defs,
142 bool generatingCompilerMacro );
143 void GenerateMacros ( const char* op,
144 const IfableData& data,
145 const std::vector<LinkerFlag*>* linkerFlags,
146 std::set<const Define *>& used_defs );
147 void GenerateSourceMacros ( const char* assignmentOperation,
148 const IfableData& data );
149 void GenerateObjectMacros ( const char* assignmentOperation,
150 const IfableData& data );
151 std::string GenerateGccIncludeParameters () const;
152 std::string GenerateGccParameters () const;
153 std::string GenerateNasmParameters () const;
154 const FileLocation* GetPrecompiledHeaderFilename () const;
155 void GenerateGccCommand ( const FileLocation* sourceFile,
156 const std::string& extraDependencies,
157 const std::string& cc,
158 const std::string& cflagsMacro );
159 void GenerateGccAssemblerCommand ( const FileLocation* sourceFile,
160 const std::string& cc,
161 const std::string& cflagsMacro );
162 void GenerateNasmCommand ( const FileLocation* sourceFile,
163 const std::string& nasmflagsMacro );
164 void GenerateWindresCommand ( const FileLocation* sourceFile,
165 const std::string& windresflagsMacro );
166 void GenerateWinebuildCommands ( 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 GetSpecObjectDependencies ( std::vector<FileLocation>& dependencies,
206 const FileLocation *file ) const;
207 void GetWidlObjectDependencies ( std::vector<FileLocation>& dependencies,
208 const FileLocation *file ) const;
209 void GetDefaultDependencies ( string_list& dependencies ) const;
210 void GetInvocationDependencies ( const Module& module, string_list& dependencies );
211 bool IsWineModule () const;
212 const FileLocation* GetDefinitionFilename () const;
213 void GenerateBuildNonSymbolStrippedCode ();
214 void CleanupCompilationUnitVector ( std::vector<CompilationUnit*>& compilationUnits );
215 void GetRpcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
216 static std::string GetPropertyValue ( const Module& module, const std::string& name );
217 const FileLocation* GetRpcServerHeaderFilename ( const FileLocation *base ) const;
218 const FileLocation* GetRpcClientHeaderFilename ( const FileLocation *base ) const;
219 const FileLocation* GetIdlHeaderFilename ( const FileLocation *base ) const;
220 std::string GetModuleCleanTarget ( const Module& module ) const;
221 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector<std::string>& moduleNames ) const;
222 public:
223 const Module& module;
224 string_list clean_files;
225 std::string cflagsMacro;
226 std::string nasmflagsMacro;
227 std::string windresflagsMacro;
228 std::string widlflagsMacro;
229 std::string linkerflagsMacro;
230 std::string sourcesMacro;
231 std::string objectsMacro;
232 std::string libsMacro;
233 std::string linkDepsMacro;
234 };
235
236
237 class MingwBuildToolModuleHandler : public MingwModuleHandler
238 {
239 public:
240 MingwBuildToolModuleHandler ( const Module& module );
241 virtual HostType DefaultHost() { return HostTrue; }
242 virtual void Process ();
243 private:
244 void GenerateBuildToolModuleTarget ();
245 };
246
247
248 class MingwKernelModuleHandler : public MingwModuleHandler
249 {
250 public:
251 MingwKernelModuleHandler ( const Module& module );
252 virtual HostType DefaultHost() { return HostFalse; }
253 virtual void Process ();
254 private:
255 void GenerateKernelModuleTarget ();
256 };
257
258
259 class MingwStaticLibraryModuleHandler : public MingwModuleHandler
260 {
261 public:
262 MingwStaticLibraryModuleHandler ( const Module& module );
263 virtual HostType DefaultHost() { return HostFalse; }
264 virtual void Process ();
265 private:
266 void GenerateStaticLibraryModuleTarget ();
267 };
268
269
270 class MingwObjectLibraryModuleHandler : public MingwModuleHandler
271 {
272 public:
273 MingwObjectLibraryModuleHandler ( const Module& module );
274 virtual HostType DefaultHost() { return HostFalse; }
275 virtual void Process ();
276 private:
277 void GenerateObjectLibraryModuleTarget ();
278 };
279
280
281 class MingwKernelModeDLLModuleHandler : public MingwModuleHandler
282 {
283 public:
284 MingwKernelModeDLLModuleHandler ( const Module& module );
285 virtual HostType DefaultHost() { return HostFalse; }
286 virtual void Process ();
287 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
288 void AddImplicitLibraries ( Module& module );
289 private:
290 void GenerateKernelModeDLLModuleTarget ();
291 };
292
293
294 class MingwKernelModeDriverModuleHandler : public MingwModuleHandler
295 {
296 public:
297 MingwKernelModeDriverModuleHandler ( const Module& module );
298 virtual HostType DefaultHost() { return HostFalse; }
299 virtual void Process ();
300 std::string TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
301 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
302 void AddImplicitLibraries ( Module& module );
303 private:
304 void GenerateKernelModeDriverModuleTarget ();
305 };
306
307
308 class MingwNativeDLLModuleHandler : public MingwModuleHandler
309 {
310 public:
311 MingwNativeDLLModuleHandler ( const Module& module );
312 virtual HostType DefaultHost() { return HostFalse; }
313 virtual void Process ();
314 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
315 void AddImplicitLibraries ( Module& module );
316 private:
317 void GenerateNativeDLLModuleTarget ();
318 };
319
320
321 class MingwNativeCUIModuleHandler : public MingwModuleHandler
322 {
323 public:
324 MingwNativeCUIModuleHandler ( const Module& module );
325 virtual HostType DefaultHost() { return HostFalse; }
326 virtual void Process ();
327 std::string TypeSpecificCFlags() { return "-D__NTAPP__"; }
328 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
329 void AddImplicitLibraries ( Module& module );
330 private:
331 void GenerateNativeCUIModuleTarget ();
332 };
333
334
335 class MingwWin32DLLModuleHandler : public MingwModuleHandler
336 {
337 public:
338 MingwWin32DLLModuleHandler ( const Module& module );
339 virtual HostType DefaultHost() { return HostFalse; }
340 virtual void Process ();
341 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
342 void AddImplicitLibraries ( Module& module );
343 private:
344 void GenerateWin32DLLModuleTarget ();
345 };
346
347
348 class MingwWin32OCXModuleHandler : public MingwModuleHandler
349 {
350 public:
351 MingwWin32OCXModuleHandler ( const Module& module );
352 virtual HostType DefaultHost() { return HostFalse; }
353 virtual void Process ();
354 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
355 void AddImplicitLibraries ( Module& module );
356 private:
357 void GenerateWin32OCXModuleTarget ();
358 };
359
360
361 class MingwWin32CUIModuleHandler : public MingwModuleHandler
362 {
363 public:
364 MingwWin32CUIModuleHandler ( const Module& module );
365 virtual HostType DefaultHost() { return HostFalse; }
366 virtual void Process ();
367 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
368 void AddImplicitLibraries ( Module& module );
369 private:
370 void GenerateWin32CUIModuleTarget ();
371 };
372
373
374 class MingwWin32GUIModuleHandler : public MingwModuleHandler
375 {
376 public:
377 MingwWin32GUIModuleHandler ( const Module& module );
378 virtual HostType DefaultHost() { return HostFalse; }
379 virtual void Process ();
380 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
381 void AddImplicitLibraries ( Module& module );
382 private:
383 void GenerateWin32GUIModuleTarget ();
384 };
385
386
387 class MingwBootLoaderModuleHandler : public MingwModuleHandler
388 {
389 public:
390 MingwBootLoaderModuleHandler ( const Module& module );
391 virtual HostType DefaultHost() { return HostFalse; }
392 virtual void Process ();
393 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
394 private:
395 void GenerateBootLoaderModuleTarget ();
396 };
397
398
399 class MingwBootSectorModuleHandler : public MingwModuleHandler
400 {
401 public:
402 MingwBootSectorModuleHandler ( const Module& module );
403 virtual HostType DefaultHost() { return HostFalse; }
404 virtual void Process ();
405 std::string TypeSpecificNasmFlags() { return "-f bin"; }
406 private:
407 void GenerateBootSectorModuleTarget ();
408 };
409
410
411 class MingwBootProgramModuleHandler : public MingwModuleHandler
412 {
413 public:
414 MingwBootProgramModuleHandler ( const Module& module );
415 virtual HostType DefaultHost() { return HostFalse; }
416 virtual void Process ();
417 std::string GetProgTextAddrMacro ();
418 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
419 private:
420 void GenerateBootProgramModuleTarget ();
421 };
422
423
424 class MingwIsoModuleHandler : public MingwModuleHandler
425 {
426 public:
427 MingwIsoModuleHandler ( const Module& module );
428 virtual HostType DefaultHost() { return HostFalse; }
429 virtual void Process ();
430 private:
431 void GenerateIsoModuleTarget ();
432 void GetBootstrapCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
433 void GetNonModuleCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
434 void GetCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
435 void GetBootstrapCdFiles ( std::vector<FileLocation>& out ) const;
436 void GetNonModuleCdFiles ( std::vector<FileLocation>& out ) const;
437 void GetCdFiles ( std::vector<FileLocation>& out ) const;
438 void OutputBootstrapfileCopyCommands ( const std::string& bootcdDirectory );
439 void OutputCdfileCopyCommands ( const std::string& bootcdDirectory );
440 };
441
442
443 class MingwLiveIsoModuleHandler : public MingwModuleHandler
444 {
445 public:
446 MingwLiveIsoModuleHandler ( const Module& module );
447 virtual HostType DefaultHost() { return HostFalse; }
448 virtual void Process ();
449 private:
450 void GenerateLiveIsoModuleTarget ();
451 void CreateDirectory ( const std::string& directory );
452 void OutputModuleCopyCommands ( std::string& livecdDirectory,
453 std::string& livecdReactos );
454 void OutputNonModuleCopyCommands ( std::string& livecdDirectory,
455 std::string& livecdReactos );
456 void OutputProfilesDirectoryCommands ( std::string& livecdDirectory );
457 void OutputLoaderCommands ( std::string& livecdDirectory );
458 void OutputRegistryCommands ( std::string& livecdDirectory );
459 };
460
461
462 class MingwTestModuleHandler : public MingwModuleHandler
463 {
464 public:
465 MingwTestModuleHandler ( const Module& module );
466 virtual HostType DefaultHost() { return HostFalse; }
467 virtual void Process ();
468 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
469 protected:
470 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
471 private:
472 void GenerateTestModuleTarget ();
473 };
474
475
476 class MingwRpcServerModuleHandler : public MingwModuleHandler
477 {
478 public:
479 MingwRpcServerModuleHandler ( const Module& module );
480 virtual HostType DefaultHost() { return HostFalse; }
481 virtual void Process ();
482 };
483
484
485 class MingwRpcClientModuleHandler : public MingwModuleHandler
486 {
487 public:
488 MingwRpcClientModuleHandler ( const Module& module );
489 virtual HostType DefaultHost() { return HostFalse; }
490 virtual void Process ();
491 };
492
493 class MingwAliasModuleHandler : public MingwModuleHandler
494 {
495 public:
496 MingwAliasModuleHandler ( const Module& module );
497 virtual HostType DefaultHost() { return HostFalse; }
498 virtual void Process ();
499 };
500
501 class MingwIdlHeaderModuleHandler : public MingwModuleHandler
502 {
503 public:
504 MingwIdlHeaderModuleHandler ( const Module& module );
505 virtual HostType DefaultHost() { return HostFalse; }
506 virtual void Process ();
507 };
508
509 class MingwEmbeddedTypeLibModuleHandler : public MingwModuleHandler
510 {
511 public:
512 MingwEmbeddedTypeLibModuleHandler ( const Module& module );
513 virtual HostType DefaultHost() { return HostFalse; }
514 virtual void Process ();
515 };
516
517 class MingwElfExecutableModuleHandler : public MingwModuleHandler
518 {
519 public:
520 MingwElfExecutableModuleHandler ( const Module& module );
521 virtual HostType DefaultHost() { return HostFalse; }
522 virtual void Process ();
523 };
524
525 #endif /* MINGW_MODULEHANDLER_H */