GetObjectFilename() shouldn't be able to modify the list of generated files
[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 ) const;
101
102 std::string GetObjectFilenames ();
103
104 std::string GetPreconditionDependenciesName () const;
105 std::string GetCFlagsMacro () const;
106 static std::string GetObjectsMacro ( const Module& );
107 std::string GetLinkingDependenciesMacro () const;
108 std::string GetLibsMacro () const;
109 std::string GetLinkerMacro () const;
110 void GenerateCleanObjectsAsYouGoCode () const;
111 void GenerateRunRsymCode () const;
112 void GenerateRunStripCode () const;
113 void GenerateLinkerCommand ( const std::string& dependencies,
114 const std::string& linker,
115 const std::string& linkerParameters,
116 const std::string& objectsMacro,
117 const std::string& libsMacro,
118 const std::string& pefixupParameters );
119 void GeneratePhonyTarget() const;
120 void GenerateBuildMapCode ( const FileLocation *mapTarget = NULL );
121 void GenerateRules ();
122 void GenerateImportLibraryTargetIfNeeded ();
123 void GetDefinitionDependencies ( std::vector<FileLocation>& dependencies ) const;
124 std::string GetLinkingDependencies () const;
125 static MingwBackend* backend;
126 static FILE* fMakefile;
127 bool use_pch;
128 private:
129 std::string ConcatenatePaths ( const std::string& path1,
130 const std::string& path2 ) const;
131 std::string GenerateGccDefineParameters () const;
132 std::string GenerateCompilerParametersFromVector ( const std::vector<CompilerFlag*>& compilerFlags, const CompilerType type ) const;
133 std::string GenerateLinkerParametersFromVector ( const std::vector<LinkerFlag*>& linkerFlags ) const;
134 std::string GenerateImportLibraryDependenciesFromVector ( const std::vector<Library*>& libraries );
135 std::string GenerateLinkerParameters () const;
136 void GenerateMacro ( const char* assignmentOperation,
137 const std::string& macro,
138 const IfableData& data,
139 std::set<const Define *>* used_defs,
140 bool generatingCompilerMacro );
141 void GenerateMacros ( const char* op,
142 const IfableData& data,
143 const std::vector<LinkerFlag*>* linkerFlags,
144 std::set<const Define *>& used_defs );
145 void GenerateSourceMacros ( const char* assignmentOperation,
146 const IfableData& data );
147 void GenerateObjectMacros ( const char* assignmentOperation,
148 const IfableData& data );
149 std::string GenerateGccIncludeParameters () const;
150 std::string GenerateGccParameters () const;
151 std::string GenerateNasmParameters () const;
152 const FileLocation* GetPrecompiledHeaderFilename () const;
153 void GenerateGccCommand ( const FileLocation* sourceFile,
154 const std::string& extraDependencies );
155 void GenerateCommands ( const CompilationUnit& compilationUnit,
156 const std::string& extraDependencies );
157 void GenerateObjectFileTargets ( const IfableData& data );
158 void GenerateObjectFileTargets ();
159 const FileLocation* GenerateArchiveTarget ();
160 void GetMcObjectDependencies ( std::vector<FileLocation>& dependencies,
161 const FileLocation *file ) const;
162 void GetSpecObjectDependencies ( std::vector<FileLocation>& dependencies,
163 const FileLocation *file ) const;
164 void GetWidlObjectDependencies ( std::vector<FileLocation>& dependencies,
165 const FileLocation *file ) const;
166 void GetDefaultDependencies ( string_list& dependencies ) const;
167 void GetInvocationDependencies ( const Module& module, string_list& dependencies );
168 bool IsWineModule () const;
169 const FileLocation* GetDefinitionFilename () const;
170 void GenerateBuildNonSymbolStrippedCode ();
171 void CleanupCompilationUnitVector ( std::vector<CompilationUnit*>& compilationUnits );
172 void GetRpcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
173 void GetMcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
174 static std::string GetPropertyValue ( const Module& module, const std::string& name );
175 const FileLocation* GetRpcServerHeaderFilename ( const FileLocation *base ) const;
176 const FileLocation* GetRpcClientHeaderFilename ( const FileLocation *base ) const;
177 const FileLocation* GetRpcProxyHeaderFilename ( const FileLocation *base ) const;
178 const FileLocation* GetIdlHeaderFilename ( const FileLocation *base ) const;
179 const FileLocation* GetMcHeaderFilename ( const FileLocation *base ) const;
180 std::string GetModuleCleanTarget ( const Module& module ) const;
181 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector<std::string>& moduleNames ) const;
182 public:
183 const Module& module;
184 string_list clean_files;
185 std::string cflagsMacro;
186 std::string nasmflagsMacro;
187 std::string windresflagsMacro;
188 std::string widlflagsMacro;
189 std::string linkerflagsMacro;
190 std::string sourcesMacro;
191 std::string objectsMacro;
192 std::string libsMacro;
193 std::string linkDepsMacro;
194 };
195
196
197 class MingwBuildToolModuleHandler : public MingwModuleHandler
198 {
199 public:
200 MingwBuildToolModuleHandler ( const Module& module );
201 virtual HostType DefaultHost() { return HostTrue; }
202 virtual void Process ();
203 private:
204 void GenerateBuildToolModuleTarget ();
205 };
206
207
208 class MingwKernelModuleHandler : public MingwModuleHandler
209 {
210 public:
211 MingwKernelModuleHandler ( const Module& module );
212 virtual HostType DefaultHost() { return HostFalse; }
213 virtual void Process ();
214 private:
215 void GenerateKernelModuleTarget ();
216 };
217
218
219 class MingwStaticLibraryModuleHandler : public MingwModuleHandler
220 {
221 public:
222 MingwStaticLibraryModuleHandler ( const Module& module );
223 virtual HostType DefaultHost() { return HostFalse; }
224 virtual void Process ();
225 private:
226 void GenerateStaticLibraryModuleTarget ();
227 };
228
229
230 class MingwObjectLibraryModuleHandler : public MingwModuleHandler
231 {
232 public:
233 MingwObjectLibraryModuleHandler ( const Module& module );
234 virtual HostType DefaultHost() { return HostFalse; }
235 virtual void Process ();
236 private:
237 void GenerateObjectLibraryModuleTarget ();
238 };
239
240
241 class MingwKernelModeDLLModuleHandler : public MingwModuleHandler
242 {
243 public:
244 MingwKernelModeDLLModuleHandler ( const Module& module );
245 virtual HostType DefaultHost() { return HostFalse; }
246 virtual void Process ();
247 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
248 void AddImplicitLibraries ( Module& module );
249 private:
250 void GenerateKernelModeDLLModuleTarget ();
251 };
252
253
254 class MingwKernelModeDriverModuleHandler : public MingwModuleHandler
255 {
256 public:
257 MingwKernelModeDriverModuleHandler ( const Module& module );
258 virtual HostType DefaultHost() { return HostFalse; }
259 virtual void Process ();
260 std::string TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
261 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
262 void AddImplicitLibraries ( Module& module );
263 private:
264 void GenerateKernelModeDriverModuleTarget ();
265 };
266
267
268 class MingwNativeDLLModuleHandler : public MingwModuleHandler
269 {
270 public:
271 MingwNativeDLLModuleHandler ( const Module& module );
272 virtual HostType DefaultHost() { return HostFalse; }
273 virtual void Process ();
274 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
275 void AddImplicitLibraries ( Module& module );
276 private:
277 void GenerateNativeDLLModuleTarget ();
278 };
279
280
281 class MingwNativeCUIModuleHandler : public MingwModuleHandler
282 {
283 public:
284 MingwNativeCUIModuleHandler ( const Module& module );
285 virtual HostType DefaultHost() { return HostFalse; }
286 virtual void Process ();
287 std::string TypeSpecificCFlags() { return "-D__NTAPP__"; }
288 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
289 void AddImplicitLibraries ( Module& module );
290 private:
291 void GenerateNativeCUIModuleTarget ();
292 };
293
294
295 class MingwWin32DLLModuleHandler : public MingwModuleHandler
296 {
297 public:
298 MingwWin32DLLModuleHandler ( const Module& module );
299 virtual HostType DefaultHost() { return HostFalse; }
300 virtual void Process ();
301 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
302 void AddImplicitLibraries ( Module& module );
303 private:
304 void GenerateWin32DLLModuleTarget ();
305 };
306
307
308 class MingwWin32OCXModuleHandler : public MingwModuleHandler
309 {
310 public:
311 MingwWin32OCXModuleHandler ( const Module& module );
312 virtual HostType DefaultHost() { return HostFalse; }
313 virtual void Process ();
314 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
315 void AddImplicitLibraries ( Module& module );
316 private:
317 void GenerateWin32OCXModuleTarget ();
318 };
319
320
321 class MingwWin32CUIModuleHandler : public MingwModuleHandler
322 {
323 public:
324 MingwWin32CUIModuleHandler ( const Module& module );
325 virtual HostType DefaultHost() { return HostFalse; }
326 virtual void Process ();
327 std::string TypeSpecificLinkerFlags() { return module.cplusplus ? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
328 void AddImplicitLibraries ( Module& module );
329 private:
330 void GenerateWin32CUIModuleTarget ();
331 };
332
333
334 class MingwWin32GUIModuleHandler : public MingwModuleHandler
335 {
336 public:
337 MingwWin32GUIModuleHandler ( 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 GenerateWin32GUIModuleTarget ();
344 };
345
346
347 class MingwBootLoaderModuleHandler : public MingwModuleHandler
348 {
349 public:
350 MingwBootLoaderModuleHandler ( const Module& module );
351 virtual HostType DefaultHost() { return HostFalse; }
352 virtual void Process ();
353 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
354 private:
355 void GenerateBootLoaderModuleTarget ();
356 };
357
358
359 class MingwBootSectorModuleHandler : public MingwModuleHandler
360 {
361 public:
362 MingwBootSectorModuleHandler ( const Module& module );
363 virtual HostType DefaultHost() { return HostFalse; }
364 virtual void Process ();
365 std::string TypeSpecificNasmFlags() { return "-f bin"; }
366 private:
367 void GenerateBootSectorModuleTarget ();
368 };
369
370
371 class MingwBootProgramModuleHandler : public MingwModuleHandler
372 {
373 public:
374 MingwBootProgramModuleHandler ( const Module& module );
375 virtual HostType DefaultHost() { return HostFalse; }
376 virtual void Process ();
377 std::string GetProgTextAddrMacro ();
378 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
379 private:
380 void GenerateBootProgramModuleTarget ();
381 };
382
383
384 class MingwIsoModuleHandler : public MingwModuleHandler
385 {
386 public:
387 MingwIsoModuleHandler ( const Module& module );
388 virtual HostType DefaultHost() { return HostFalse; }
389 virtual void Process ();
390 private:
391 void GenerateIsoModuleTarget ();
392 void GetBootstrapCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
393 void GetNonModuleCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
394 void GetCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
395 void GetBootstrapCdFiles ( std::vector<FileLocation>& out ) const;
396 void GetNonModuleCdFiles ( std::vector<FileLocation>& out ) const;
397 void GetCdFiles ( std::vector<FileLocation>& out ) const;
398 void OutputBootstrapfileCopyCommands ( const std::string& bootcdDirectory );
399 void OutputCdfileCopyCommands ( const std::string& bootcdDirectory );
400 };
401
402
403 class MingwLiveIsoModuleHandler : public MingwModuleHandler
404 {
405 public:
406 MingwLiveIsoModuleHandler ( const Module& module );
407 virtual HostType DefaultHost() { return HostFalse; }
408 virtual void Process ();
409 private:
410 void GenerateLiveIsoModuleTarget ();
411 void CreateDirectory ( const std::string& directory );
412 void OutputModuleCopyCommands ( std::string& livecdDirectory,
413 std::string& livecdReactos );
414 void OutputNonModuleCopyCommands ( std::string& livecdDirectory,
415 std::string& livecdReactos );
416 void OutputProfilesDirectoryCommands ( std::string& livecdDirectory );
417 void OutputLoaderCommands ( std::string& livecdDirectory );
418 void OutputRegistryCommands ( std::string& livecdDirectory );
419 };
420
421
422 class MingwTestModuleHandler : public MingwModuleHandler
423 {
424 public:
425 MingwTestModuleHandler ( const Module& module );
426 virtual HostType DefaultHost() { return HostFalse; }
427 virtual void Process ();
428 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
429 protected:
430 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
431 private:
432 void GenerateTestModuleTarget ();
433 };
434
435
436 class MingwRpcServerModuleHandler : public MingwModuleHandler
437 {
438 public:
439 MingwRpcServerModuleHandler ( const Module& module );
440 virtual HostType DefaultHost() { return HostFalse; }
441 virtual void Process ();
442 };
443
444
445 class MingwRpcClientModuleHandler : public MingwModuleHandler
446 {
447 public:
448 MingwRpcClientModuleHandler ( const Module& module );
449 virtual HostType DefaultHost() { return HostFalse; }
450 virtual void Process ();
451 };
452
453
454 class MingwRpcProxyModuleHandler : public MingwModuleHandler
455 {
456 public:
457 MingwRpcProxyModuleHandler ( const Module& module );
458 virtual HostType DefaultHost() { return HostFalse; }
459 virtual void Process ();
460 };
461
462
463 class MingwAliasModuleHandler : public MingwModuleHandler
464 {
465 public:
466 MingwAliasModuleHandler ( const Module& module );
467 virtual HostType DefaultHost() { return HostFalse; }
468 virtual void Process ();
469 };
470
471 class MingwIdlHeaderModuleHandler : public MingwModuleHandler
472 {
473 public:
474 MingwIdlHeaderModuleHandler ( const Module& module );
475 virtual HostType DefaultHost() { return HostFalse; }
476 virtual void Process ();
477 };
478
479 class MingwEmbeddedTypeLibModuleHandler : public MingwModuleHandler
480 {
481 public:
482 MingwEmbeddedTypeLibModuleHandler ( const Module& module );
483 virtual HostType DefaultHost() { return HostFalse; }
484 virtual void Process ();
485 };
486
487 class MingwElfExecutableModuleHandler : public MingwModuleHandler
488 {
489 public:
490 MingwElfExecutableModuleHandler ( const Module& module );
491 virtual HostType DefaultHost() { return HostFalse; }
492 virtual void Process ();
493 };
494
495 #endif /* MINGW_MODULEHANDLER_H */