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