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