102cf80ae584f056b858307b490ffd962836dc52
[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 class Rule;
26
27 extern std::string
28 GetTargetMacro ( const Module&, bool with_dollar = true );
29
30 extern std::string
31 PrefixFilename (
32 const std::string& filename,
33 const std::string& prefix );
34
35 class MingwModuleHandler
36 {
37 public:
38 MingwModuleHandler ( const Module& module_ );
39 virtual ~MingwModuleHandler();
40
41 static void SetBackend ( MingwBackend* backend_ );
42 static void SetMakefile ( FILE* f );
43 void EnablePreCompiledHeaderSupport ();
44
45 static const FileLocation* PassThruCacheDirectory (const FileLocation* fileLocation );
46
47 static const FileLocation* GetTargetFilename (
48 const Module& module,
49 string_list* pclean_files );
50
51 static const FileLocation* GetImportLibraryFilename (
52 const Module& module,
53 string_list* pclean_files );
54
55 static std::string GenerateGccDefineParametersFromVector ( const std::vector<Define*>& defines, std::set<std::string> &used_defs );
56 static std::string GenerateGccIncludeParametersFromVector ( const std::vector<Include*>& includes );
57
58 std::string GetModuleTargets ( const Module& module );
59 void GetObjectsVector ( const IfableData& data,
60 std::vector<FileLocation>& objectFiles ) const;
61 void GenerateSourceMacro();
62 void GenerateObjectMacro();
63 void GenerateTargetMacro();
64 void GenerateOtherMacros();
65
66 static MingwModuleHandler* InstanciateHandler ( const Module& module_,
67 MingwBackend* backend_ );
68 virtual HostType DefaultHost() = 0;
69 void GeneratePreconditionDependencies ();
70 virtual void Process () = 0;
71 virtual std::string TypeSpecificCFlags() { return ""; }
72 virtual std::string TypeSpecificNasmFlags() { return ""; }
73 virtual std::string TypeSpecificLinkerFlags() { return ""; }
74 void GenerateInvocations () const;
75 void GenerateCleanTarget () const;
76 void GenerateInstallTarget () const;
77 void GenerateDependsTarget () const;
78 static bool ReferenceObjects ( const Module& module );
79 virtual void AddImplicitLibraries ( Module& module ) { return; }
80
81 void OutputCopyCommand ( const FileLocation& source,
82 const FileLocation& destination );
83 protected:
84 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
85 std::string GetWorkingDirectory () const;
86 std::string GetBasename ( const std::string& filename ) const;
87 const FileLocation* GetActualSourceFilename ( const FileLocation* file ) const;
88 std::string GetExtraDependencies ( const FileLocation *file ) const;
89 std::string GetCompilationUnitDependencies ( const CompilationUnit& compilationUnit ) const;
90 const FileLocation* GetModuleArchiveFilename () const;
91 bool IsGeneratedFile ( const File& file ) const;
92 std::string GetImportLibraryDependency ( const Module& importedModule );
93 void GetTargets ( const Module& dependencyModule,
94 string_list& targets );
95 void GetModuleDependencies ( string_list& dependencies );
96 std::string GetAllDependencies () const;
97 void GetSourceFilenames ( std::vector<FileLocation>& list,
98 bool includeGeneratedFiles ) const;
99 void GetSourceFilenamesWithoutGeneratedFiles ( std::vector<FileLocation>& list ) const;
100 const FileLocation* GetObjectFilename ( const FileLocation* sourceFile,
101 const Module& module ) 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& linkerParameters,
116 const std::string& pefixupParameters );
117 void GeneratePhonyTarget() const;
118 void GenerateBuildMapCode ( const FileLocation *mapTarget = NULL );
119 void GenerateRules ();
120 void GenerateImportLibraryTargetIfNeeded ();
121 void GetDefinitionDependencies ( std::vector<FileLocation>& dependencies ) const;
122 std::string GetLinkingDependencies () const;
123 static MingwBackend* backend;
124 static FILE* fMakefile;
125 bool use_pch;
126 private:
127 std::string ConcatenatePaths ( const std::string& path1,
128 const std::string& path2 ) const;
129 std::string GenerateGccDefineParameters () const;
130 std::string GenerateCompilerParametersFromVector ( const std::vector<CompilerFlag*>& compilerFlags, const CompilerType type ) const;
131 std::string GenerateLinkerParametersFromVector ( const std::vector<LinkerFlag*>& linkerFlags ) const;
132 std::string GenerateImportLibraryDependenciesFromVector ( const std::vector<Library*>& libraries );
133 std::string GenerateLinkerParameters () const;
134 void GenerateMacro ( const char* assignmentOperation,
135 const std::string& macro,
136 const IfableData& data,
137 std::set<const Define *>* used_defs,
138 bool generatingCompilerMacro );
139 void GenerateMacros ( const char* op,
140 const IfableData& data,
141 const std::vector<LinkerFlag*>* linkerFlags,
142 std::set<const Define *>& used_defs );
143 void GenerateSourceMacros ( const char* assignmentOperation,
144 const IfableData& data );
145 void GenerateObjectMacros ( const char* assignmentOperation,
146 const IfableData& data );
147 std::string GenerateGccIncludeParameters () const;
148 std::string GenerateGccParameters () const;
149 std::string GenerateNasmParameters () const;
150 const FileLocation* GetPrecompiledHeaderFilename () const;
151 void GenerateGccCommand ( const FileLocation* sourceFile,
152 const Rule *rule,
153 const std::string& extraDependencies );
154 void GenerateCommands ( const CompilationUnit& compilationUnit,
155 const std::string& extraDependencies );
156 void GenerateObjectFileTargets ( const IfableData& data );
157 void GenerateObjectFileTargets ();
158 const FileLocation* GenerateArchiveTarget ();
159 void GetMcObjectDependencies ( std::vector<FileLocation>& dependencies,
160 const FileLocation *file ) const;
161 void GetSpecObjectDependencies ( std::vector<FileLocation>& dependencies,
162 const FileLocation *file ) const;
163 void GetWidlObjectDependencies ( std::vector<FileLocation>& dependencies,
164 const FileLocation *file ) const;
165 void GetDefaultDependencies ( string_list& dependencies ) const;
166 void GetInvocationDependencies ( const Module& module, string_list& dependencies );
167 bool IsWineModule () const;
168 const FileLocation* GetDefinitionFilename () const;
169 void GenerateBuildNonSymbolStrippedCode ();
170 void CleanupCompilationUnitVector ( std::vector<CompilationUnit*>& compilationUnits );
171 void GetRpcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
172 void GetMcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
173 static std::string GetPropertyValue ( const Module& module, const std::string& name );
174 const FileLocation* GetRpcServerHeaderFilename ( const FileLocation *base ) const;
175 const FileLocation* GetRpcClientHeaderFilename ( const FileLocation *base ) const;
176 const FileLocation* GetRpcProxyHeaderFilename ( const FileLocation *base ) const;
177 const FileLocation* GetIdlHeaderFilename ( const FileLocation *base ) const;
178 const FileLocation* GetMcHeaderFilename ( const FileLocation *base ) const;
179 std::string GetModuleCleanTarget ( const Module& module ) const;
180 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector<std::string>& moduleNames ) const;
181 public:
182 const Module& module;
183 string_list clean_files;
184 std::string cflagsMacro;
185 std::string nasmflagsMacro;
186 std::string windresflagsMacro;
187 std::string widlflagsMacro;
188 std::string linkerflagsMacro;
189 std::string sourcesMacro;
190 std::string objectsMacro;
191 std::string libsMacro;
192 std::string linkDepsMacro;
193 };
194
195
196 class MingwBuildToolModuleHandler : public MingwModuleHandler
197 {
198 public:
199 MingwBuildToolModuleHandler ( const Module& module );
200 virtual HostType DefaultHost() { return HostTrue; }
201 virtual void Process ();
202 private:
203 void GenerateBuildToolModuleTarget ();
204 };
205
206
207 class MingwKernelModuleHandler : public MingwModuleHandler
208 {
209 public:
210 MingwKernelModuleHandler ( const Module& module );
211 virtual HostType DefaultHost() { return HostFalse; }
212 virtual void Process ();
213 private:
214 void GenerateKernelModuleTarget ();
215 };
216
217
218 class MingwStaticLibraryModuleHandler : public MingwModuleHandler
219 {
220 public:
221 MingwStaticLibraryModuleHandler ( const Module& module );
222 virtual HostType DefaultHost() { return HostFalse; }
223 virtual void Process ();
224 private:
225 void GenerateStaticLibraryModuleTarget ();
226 };
227
228
229 class MingwHostStaticLibraryModuleHandler : public MingwModuleHandler
230 {
231 public:
232 MingwHostStaticLibraryModuleHandler ( const Module& module );
233 virtual HostType DefaultHost() { return HostTrue; }
234 virtual void Process ();
235 private:
236 void GenerateHostStaticLibraryModuleTarget ();
237 };
238
239
240 class MingwObjectLibraryModuleHandler : public MingwModuleHandler
241 {
242 public:
243 MingwObjectLibraryModuleHandler ( const Module& module );
244 virtual HostType DefaultHost() { return HostFalse; }
245 virtual void Process ();
246 private:
247 void GenerateObjectLibraryModuleTarget ();
248 };
249
250
251 class MingwKernelModeDLLModuleHandler : public MingwModuleHandler
252 {
253 public:
254 MingwKernelModeDLLModuleHandler ( const Module& module );
255 virtual HostType DefaultHost() { return HostFalse; }
256 virtual void Process ();
257 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
258 void AddImplicitLibraries ( Module& module );
259 private:
260 void GenerateKernelModeDLLModuleTarget ();
261 };
262
263
264 class MingwKernelModeDriverModuleHandler : public MingwModuleHandler
265 {
266 public:
267 MingwKernelModeDriverModuleHandler ( const Module& module );
268 virtual HostType DefaultHost() { return HostFalse; }
269 virtual void Process ();
270 std::string TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
271 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
272 void AddImplicitLibraries ( Module& module );
273 private:
274 void GenerateKernelModeDriverModuleTarget ();
275 };
276
277
278 class MingwNativeDLLModuleHandler : public MingwModuleHandler
279 {
280 public:
281 MingwNativeDLLModuleHandler ( 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 GenerateNativeDLLModuleTarget ();
288 };
289
290
291 class MingwNativeCUIModuleHandler : public MingwModuleHandler
292 {
293 public:
294 MingwNativeCUIModuleHandler ( const Module& module );
295 virtual HostType DefaultHost() { return HostFalse; }
296 virtual void Process ();
297 std::string TypeSpecificCFlags() { return "-D__NTAPP__"; }
298 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
299 void AddImplicitLibraries ( Module& module );
300 private:
301 void GenerateNativeCUIModuleTarget ();
302 };
303
304
305 class MingwWin32DLLModuleHandler : public MingwModuleHandler
306 {
307 public:
308 MingwWin32DLLModuleHandler ( const Module& module );
309 virtual HostType DefaultHost() { return HostFalse; }
310 virtual void Process ();
311 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
312 void AddImplicitLibraries ( Module& module );
313 private:
314 void GenerateWin32DLLModuleTarget ();
315 };
316
317
318 class MingwWin32OCXModuleHandler : public MingwModuleHandler
319 {
320 public:
321 MingwWin32OCXModuleHandler ( const Module& module );
322 virtual HostType DefaultHost() { return HostFalse; }
323 virtual void Process ();
324 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
325 void AddImplicitLibraries ( Module& module );
326 private:
327 void GenerateWin32OCXModuleTarget ();
328 };
329
330
331 class MingwWin32CUIModuleHandler : public MingwModuleHandler
332 {
333 public:
334 MingwWin32CUIModuleHandler ( const Module& module );
335 virtual HostType DefaultHost() { return HostFalse; }
336 virtual void Process ();
337 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
338 void AddImplicitLibraries ( Module& module );
339 private:
340 void GenerateWin32CUIModuleTarget ();
341 };
342
343
344 class MingwWin32GUIModuleHandler : public MingwModuleHandler
345 {
346 public:
347 MingwWin32GUIModuleHandler ( const Module& module );
348 virtual HostType DefaultHost() { return HostFalse; }
349 virtual void Process ();
350 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
351 void AddImplicitLibraries ( Module& module );
352 private:
353 void GenerateWin32GUIModuleTarget ();
354 };
355
356
357 class MingwBootLoaderModuleHandler : public MingwModuleHandler
358 {
359 public:
360 MingwBootLoaderModuleHandler ( const Module& module );
361 virtual HostType DefaultHost() { return HostFalse; }
362 virtual void Process ();
363 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
364 private:
365 void GenerateBootLoaderModuleTarget ();
366 };
367
368
369 class MingwBootSectorModuleHandler : public MingwModuleHandler
370 {
371 public:
372 MingwBootSectorModuleHandler ( const Module& module );
373 virtual HostType DefaultHost() { return HostFalse; }
374 virtual void Process ();
375 std::string TypeSpecificNasmFlags() { return "-f bin"; }
376 private:
377 void GenerateBootSectorModuleTarget ();
378 };
379
380
381 class MingwBootProgramModuleHandler : public MingwModuleHandler
382 {
383 public:
384 MingwBootProgramModuleHandler ( const Module& module );
385 virtual HostType DefaultHost() { return HostFalse; }
386 virtual void Process ();
387 std::string GetProgTextAddrMacro ();
388 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
389 private:
390 void GenerateBootProgramModuleTarget ();
391 };
392
393
394 class MingwIsoModuleHandler : public MingwModuleHandler
395 {
396 public:
397 MingwIsoModuleHandler ( const Module& module );
398 virtual HostType DefaultHost() { return HostFalse; }
399 virtual void Process ();
400 private:
401 void GenerateIsoModuleTarget ();
402 void GetBootstrapCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
403 void GetNonModuleCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
404 void GetCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
405 void GetBootstrapCdFiles ( std::vector<FileLocation>& out ) const;
406 void GetNonModuleCdFiles ( std::vector<FileLocation>& out ) const;
407 void GetCdFiles ( std::vector<FileLocation>& out ) const;
408 void OutputBootstrapfileCopyCommands ( const std::string& bootcdDirectory );
409 void OutputCdfileCopyCommands ( const std::string& bootcdDirectory );
410 };
411
412
413 class MingwLiveIsoModuleHandler : public MingwModuleHandler
414 {
415 public:
416 MingwLiveIsoModuleHandler ( const Module& module );
417 virtual HostType DefaultHost() { return HostFalse; }
418 virtual void Process ();
419 private:
420 void GenerateLiveIsoModuleTarget ();
421 void CreateDirectory ( const std::string& directory );
422 void OutputModuleCopyCommands ( std::string& livecdDirectory,
423 std::string& livecdReactos );
424 void OutputNonModuleCopyCommands ( std::string& livecdDirectory,
425 std::string& livecdReactos );
426 void OutputProfilesDirectoryCommands ( std::string& livecdDirectory );
427 void OutputLoaderCommands ( std::string& livecdDirectory );
428 void OutputRegistryCommands ( std::string& livecdDirectory );
429 };
430
431
432 class MingwTestModuleHandler : public MingwModuleHandler
433 {
434 public:
435 MingwTestModuleHandler ( const Module& module );
436 virtual HostType DefaultHost() { return HostFalse; }
437 virtual void Process ();
438 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
439 protected:
440 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
441 private:
442 void GenerateTestModuleTarget ();
443 };
444
445
446 class MingwRpcServerModuleHandler : public MingwModuleHandler
447 {
448 public:
449 MingwRpcServerModuleHandler ( const Module& module );
450 virtual HostType DefaultHost() { return HostFalse; }
451 virtual void Process ();
452 };
453
454
455 class MingwRpcClientModuleHandler : public MingwModuleHandler
456 {
457 public:
458 MingwRpcClientModuleHandler ( const Module& module );
459 virtual HostType DefaultHost() { return HostFalse; }
460 virtual void Process ();
461 };
462
463
464 class MingwRpcProxyModuleHandler : public MingwModuleHandler
465 {
466 public:
467 MingwRpcProxyModuleHandler ( const Module& module );
468 virtual HostType DefaultHost() { return HostFalse; }
469 virtual void Process ();
470 };
471
472
473 class MingwAliasModuleHandler : public MingwModuleHandler
474 {
475 public:
476 MingwAliasModuleHandler ( const Module& module );
477 virtual HostType DefaultHost() { return HostFalse; }
478 virtual void Process ();
479 };
480
481 class MingwIdlHeaderModuleHandler : public MingwModuleHandler
482 {
483 public:
484 MingwIdlHeaderModuleHandler ( const Module& module );
485 virtual HostType DefaultHost() { return HostFalse; }
486 virtual void Process ();
487 };
488
489 class MingwEmbeddedTypeLibModuleHandler : public MingwModuleHandler
490 {
491 public:
492 MingwEmbeddedTypeLibModuleHandler ( const Module& module );
493 virtual HostType DefaultHost() { return HostFalse; }
494 virtual void Process ();
495 };
496
497 class MingwElfExecutableModuleHandler : public MingwModuleHandler
498 {
499 public:
500 MingwElfExecutableModuleHandler ( const Module& module );
501 virtual HostType DefaultHost() { return HostFalse; }
502 virtual void Process ();
503 };
504
505 #endif /* MINGW_MODULEHANDLER_H */