Search a property by its name
[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 std::string PassThruCacheDirectory (
45 const std::string &f,
46 Directory* directoryTree );
47
48 static std::string PassThruCacheDirectory (const FileLocation* fileLocation );
49
50 static Directory* GetTargetDirectoryTree (
51 const Module& module );
52
53 static std::string GetTargetFilename (
54 const Module& module,
55 string_list* pclean_files );
56
57 static std::string
58 GetImportLibraryFilename (
59 const Module& module,
60 string_list* pclean_files );
61
62 static std::string GenerateGccDefineParametersFromVector ( const std::vector<Define*>& defines );
63 static std::string GenerateGccIncludeParametersFromVector ( const std::vector<Include*>& includes );
64
65 std::string GetModuleTargets ( const Module& module );
66 void GetObjectsVector ( const IfableData& data,
67 std::vector<std::string>& objectFiles ) const;
68 void GenerateObjectMacro();
69 void GenerateTargetMacro();
70 void GenerateOtherMacros();
71
72 static MingwModuleHandler* InstanciateHandler ( const Module& module_,
73 MingwBackend* backend_ );
74 virtual HostType DefaultHost() = 0;
75 void GeneratePreconditionDependencies ();
76 virtual void Process () = 0;
77 virtual std::string TypeSpecificCFlags() { return ""; }
78 virtual std::string TypeSpecificNasmFlags() { return ""; }
79 virtual std::string TypeSpecificLinkerFlags() { return ""; }
80 void GenerateInvocations () const;
81 void GenerateCleanTarget () const;
82 void GenerateInstallTarget () const;
83 void GenerateDependsTarget () const;
84 static bool ReferenceObjects ( const Module& module );
85 virtual void AddImplicitLibraries ( Module& module ) { return; }
86 protected:
87 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
88 std::string GetWorkingDirectory () const;
89 std::string GetBasename ( const std::string& filename ) const;
90 FileLocation* GetActualSourceFilename ( const FileLocation* fileLocation ) const;
91 std::string GetExtraDependencies ( const std::string& filename ) const;
92 std::string GetCompilationUnitDependencies ( const CompilationUnit& compilationUnit ) const;
93 std::string GetModuleArchiveFilename () const;
94 bool IsGeneratedFile ( const File& file ) const;
95 std::string GetImportLibraryDependency ( const Module& importedModule );
96 void GetTargets ( const Module& dependencyModule,
97 string_list& targets );
98 void GetModuleDependencies ( string_list& dependencies );
99 std::string GetAllDependencies () const;
100 void GetSourceFilenames ( string_list& list,
101 bool includeGeneratedFiles ) const;
102 void GetSourceFilenamesWithoutGeneratedFiles ( string_list& list ) const;
103 std::string GetObjectFilename ( const FileLocation* sourceFileLocation,
104 string_list* pclean_files ) const;
105
106 std::string GetObjectFilenames ();
107
108 std::string GetPreconditionDependenciesName () const;
109 std::string GetCFlagsMacro () const;
110 static std::string GetObjectsMacro ( const Module& );
111 std::string GetLinkingDependenciesMacro () const;
112 std::string GetLibsMacro () const;
113 std::string GetLinkerMacro () const;
114 void GenerateCleanObjectsAsYouGoCode () const;
115 void GenerateRunRsymCode () const;
116 void GenerateRunStripCode () const;
117 void GenerateLinkerCommand ( const std::string& dependencies,
118 const std::string& linker,
119 const std::string& linkerParameters,
120 const std::string& objectsMacro,
121 const std::string& libsMacro,
122 const std::string& pefixupParameters );
123 void GeneratePhonyTarget() const;
124 void GenerateBuildMapCode ( const char *mapTarget = NULL );
125 void GenerateRules ();
126 void GenerateImportLibraryTargetIfNeeded ();
127 void GetDefinitionDependencies ( string_list& dependencies ) const;
128 std::string GetLinkingDependencies () const;
129 static MingwBackend* backend;
130 static FILE* fMakefile;
131 bool use_pch;
132 private:
133 std::string ConcatenatePaths ( const std::string& path1,
134 const std::string& path2 ) const;
135 std::string GenerateGccDefineParameters () const;
136 std::string GenerateCompilerParametersFromVector ( const std::vector<CompilerFlag*>& compilerFlags ) const;
137 std::string GenerateLinkerParametersFromVector ( const std::vector<LinkerFlag*>& linkerFlags ) const;
138 std::string GenerateImportLibraryDependenciesFromVector ( const std::vector<Library*>& libraries );
139 std::string GenerateLinkerParameters () const;
140 void GenerateMacro ( const char* assignmentOperation,
141 const std::string& macro,
142 const IfableData& data );
143 void GenerateMacros ( const char* op,
144 const IfableData& data,
145 const std::vector<LinkerFlag*>* linkerFlags );
146 void GenerateObjectMacros ( const char* assignmentOperation,
147 const IfableData& data,
148 const std::vector<LinkerFlag*>* linkerFlags );
149 std::string GenerateGccIncludeParameters () const;
150 std::string GenerateGccParameters () const;
151 std::string GenerateNasmParameters () const;
152 std::string GetPrecompiledHeaderFilename () const;
153 void GenerateGccCommand ( const FileLocation* sourceFileLocation,
154 const std::string& extraDependencies,
155 const std::string& cc,
156 const std::string& cflagsMacro );
157 void GenerateGccAssemblerCommand ( const FileLocation* sourceFileLocation,
158 const std::string& cc,
159 const std::string& cflagsMacro );
160 void GenerateNasmCommand ( const FileLocation* sourceFileLocation,
161 const std::string& nasmflagsMacro );
162 void GenerateWindresCommand ( const FileLocation* sourceFileLocation,
163 const std::string& windresflagsMacro );
164 void GenerateWinebuildCommands ( const FileLocation* sourceFileLocation );
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& cc,
182 const std::string& cppc,
183 const std::string& cflagsMacro,
184 const std::string& nasmflagsMacro,
185 const std::string& windresflagsMacro,
186 const std::string& widlflagsMacro );
187 void GenerateObjectFileTargets ( const IfableData& data,
188 const std::string& cc,
189 const std::string& cppc,
190 const std::string& cflagsMacro,
191 const std::string& nasmflagsMacro,
192 const std::string& windresflagsMacro,
193 const std::string& widlflagsMacro );
194 void GenerateObjectFileTargets ( const std::string& cc,
195 const std::string& cppc,
196 const std::string& cflagsMacro,
197 const std::string& nasmflagsMacro,
198 const std::string& windresflagsMacro,
199 const std::string& widlflagsMacro );
200 std::string GenerateArchiveTarget ( const std::string& ar,
201 const std::string& objs_macro ) const;
202 void GetSpecObjectDependencies ( string_list& dependencies,
203 const std::string& filename ) const;
204 void GetWidlObjectDependencies ( string_list& dependencies,
205 const std::string& filename ) const;
206 void GetDefaultDependencies ( string_list& dependencies ) const;
207 void GetInvocationDependencies ( const Module& module, string_list& dependencies );
208 bool IsWineModule () const;
209 std::string GetDefinitionFilename () const;
210 static std::string RemoveVariables ( std::string path);
211 void GenerateBuildNonSymbolStrippedCode ();
212 void CleanupCompilationUnitVector ( std::vector<CompilationUnit*>& compilationUnits );
213 void GetRpcHeaderDependencies ( std::vector<std::string>& dependencies ) const;
214 static std::string GetPropertyValue ( const Module& module, const std::string& name );
215 std::string GetRpcServerHeaderFilename ( std::string basename ) const;
216 std::string GetRpcClientHeaderFilename ( std::string basename ) const;
217 std::string GetIdlHeaderFilename ( std::string basename ) 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 objectsMacro;
229 std::string libsMacro;
230 std::string linkDepsMacro;
231 };
232
233
234 class MingwBuildToolModuleHandler : public MingwModuleHandler
235 {
236 public:
237 MingwBuildToolModuleHandler ( const Module& module );
238 virtual HostType DefaultHost() { return HostTrue; }
239 virtual void Process ();
240 private:
241 void GenerateBuildToolModuleTarget ();
242 };
243
244
245 class MingwKernelModuleHandler : public MingwModuleHandler
246 {
247 public:
248 MingwKernelModuleHandler ( const Module& module );
249 virtual HostType DefaultHost() { return HostFalse; }
250 virtual void Process ();
251 private:
252 void GenerateKernelModuleTarget ();
253 };
254
255
256 class MingwStaticLibraryModuleHandler : public MingwModuleHandler
257 {
258 public:
259 MingwStaticLibraryModuleHandler ( const Module& module );
260 virtual HostType DefaultHost() { return HostFalse; }
261 virtual void Process ();
262 private:
263 void GenerateStaticLibraryModuleTarget ();
264 };
265
266
267 class MingwObjectLibraryModuleHandler : public MingwModuleHandler
268 {
269 public:
270 MingwObjectLibraryModuleHandler ( const Module& module );
271 virtual HostType DefaultHost() { return HostFalse; }
272 virtual void Process ();
273 private:
274 void GenerateObjectLibraryModuleTarget ();
275 };
276
277
278 class MingwKernelModeDLLModuleHandler : public MingwModuleHandler
279 {
280 public:
281 MingwKernelModeDLLModuleHandler ( const Module& module );
282 virtual HostType DefaultHost() { return HostFalse; }
283 virtual void Process ();
284 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
285 void AddImplicitLibraries ( Module& module );
286 private:
287 void GenerateKernelModeDLLModuleTarget ();
288 };
289
290
291 class MingwKernelModeDriverModuleHandler : public MingwModuleHandler
292 {
293 public:
294 MingwKernelModeDriverModuleHandler ( const Module& module );
295 virtual HostType DefaultHost() { return HostFalse; }
296 virtual void Process ();
297 std::string TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
298 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
299 void AddImplicitLibraries ( Module& module );
300 private:
301 void GenerateKernelModeDriverModuleTarget ();
302 };
303
304
305 class MingwNativeDLLModuleHandler : public MingwModuleHandler
306 {
307 public:
308 MingwNativeDLLModuleHandler ( const Module& module );
309 virtual HostType DefaultHost() { return HostFalse; }
310 virtual void Process ();
311 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
312 void AddImplicitLibraries ( Module& module );
313 private:
314 void GenerateNativeDLLModuleTarget ();
315 };
316
317
318 class MingwNativeCUIModuleHandler : public MingwModuleHandler
319 {
320 public:
321 MingwNativeCUIModuleHandler ( const Module& module );
322 virtual HostType DefaultHost() { return HostFalse; }
323 virtual void Process ();
324 std::string TypeSpecificCFlags() { return "-D__NTAPP__"; }
325 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
326 void AddImplicitLibraries ( Module& module );
327 private:
328 void GenerateNativeCUIModuleTarget ();
329 };
330
331
332 class MingwWin32DLLModuleHandler : public MingwModuleHandler
333 {
334 public:
335 MingwWin32DLLModuleHandler ( const Module& module );
336 virtual HostType DefaultHost() { return HostFalse; }
337 virtual void Process ();
338 std::string TypeSpecificLinkerFlags() { return module.useHostStdlib ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
339 void AddImplicitLibraries ( Module& module );
340 private:
341 void GenerateWin32DLLModuleTarget ();
342 };
343
344
345 class MingwWin32OCXModuleHandler : public MingwModuleHandler
346 {
347 public:
348 MingwWin32OCXModuleHandler ( const Module& module );
349 virtual HostType DefaultHost() { return HostFalse; }
350 virtual void Process ();
351 std::string TypeSpecificLinkerFlags() { return module.useHostStdlib ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
352 void AddImplicitLibraries ( Module& module );
353 private:
354 void GenerateWin32OCXModuleTarget ();
355 };
356
357
358 class MingwWin32CUIModuleHandler : public MingwModuleHandler
359 {
360 public:
361 MingwWin32CUIModuleHandler ( const Module& module );
362 virtual HostType DefaultHost() { return HostFalse; }
363 virtual void Process ();
364 std::string TypeSpecificLinkerFlags() { return module.useHostStdlib ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
365 void AddImplicitLibraries ( Module& module );
366 private:
367 void GenerateWin32CUIModuleTarget ();
368 };
369
370
371 class MingwWin32GUIModuleHandler : public MingwModuleHandler
372 {
373 public:
374 MingwWin32GUIModuleHandler ( const Module& module );
375 virtual HostType DefaultHost() { return HostFalse; }
376 virtual void Process ();
377 std::string TypeSpecificLinkerFlags() { return module.useHostStdlib ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
378 void AddImplicitLibraries ( Module& module );
379 private:
380 void GenerateWin32GUIModuleTarget ();
381 };
382
383
384 class MingwBootLoaderModuleHandler : public MingwModuleHandler
385 {
386 public:
387 MingwBootLoaderModuleHandler ( const Module& module );
388 virtual HostType DefaultHost() { return HostFalse; }
389 virtual void Process ();
390 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
391 private:
392 void GenerateBootLoaderModuleTarget ();
393 };
394
395
396 class MingwBootSectorModuleHandler : public MingwModuleHandler
397 {
398 public:
399 MingwBootSectorModuleHandler ( const Module& module );
400 virtual HostType DefaultHost() { return HostFalse; }
401 virtual void Process ();
402 std::string TypeSpecificNasmFlags() { return "-f bin"; }
403 private:
404 void GenerateBootSectorModuleTarget ();
405 };
406
407
408 class MingwBootProgramModuleHandler : public MingwModuleHandler
409 {
410 public:
411 MingwBootProgramModuleHandler ( const Module& module );
412 virtual HostType DefaultHost() { return HostFalse; }
413 virtual void Process ();
414 std::string GetProgTextAddrMacro ();
415 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
416 private:
417 void GenerateBootProgramModuleTarget ();
418 };
419
420
421 class MingwIsoModuleHandler : public MingwModuleHandler
422 {
423 public:
424 MingwIsoModuleHandler ( const Module& module );
425 virtual HostType DefaultHost() { return HostFalse; }
426 virtual void Process ();
427 private:
428 void GenerateIsoModuleTarget ();
429 std::string GetBootstrapCdDirectories ( const std::string& bootcdDirectory );
430 std::string GetNonModuleCdDirectories ( const std::string& bootcdDirectory );
431 std::string GetCdDirectories ( const std::string& bootcdDirectory );
432 void GetBootstrapCdFiles ( std::vector<std::string>& out ) const;
433 void GetNonModuleCdFiles ( std::vector<std::string>& out ) const;
434 void GetCdFiles ( std::vector<std::string>& out ) const;
435 void OutputBootstrapfileCopyCommands ( const std::string& bootcdDirectory );
436 void OutputCdfileCopyCommands ( const std::string& bootcdDirectory );
437 };
438
439
440 class MingwLiveIsoModuleHandler : public MingwModuleHandler
441 {
442 public:
443 MingwLiveIsoModuleHandler ( const Module& module );
444 virtual HostType DefaultHost() { return HostFalse; }
445 virtual void Process ();
446 private:
447 void GenerateLiveIsoModuleTarget ();
448 void CreateDirectory ( const std::string& directory );
449 void OutputCopyCommand ( const std::string& sourceFilename,
450 const std::string& targetFilename,
451 const std::string& targetDirectory );
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 #endif /* MINGW_MODULEHANDLER_H */