627c796a2f3cc1c590fbe7dd0669d9205647e60d
[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 protected:
86 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
87 std::string GetWorkingDirectory () const;
88 std::string GetBasename ( const std::string& filename ) const;
89 FileLocation* GetActualSourceFilename ( const FileLocation* fileLocation ) const;
90 std::string GetExtraDependencies ( const std::string& filename ) const;
91 std::string MingwModuleHandler::GetCompilationUnitDependencies ( const CompilationUnit& compilationUnit ) const;
92 std::string GetModuleArchiveFilename () const;
93 bool IsGeneratedFile ( const File& file ) const;
94 std::string GetImportLibraryDependency ( const Module& importedModule );
95 void GetTargets ( const Module& dependencyModule,
96 string_list& targets );
97 void GetModuleDependencies ( string_list& dependencies );
98 std::string GetAllDependencies () const;
99 void GetSourceFilenames ( string_list& list,
100 bool includeGeneratedFiles ) const;
101 void GetSourceFilenamesWithoutGeneratedFiles ( string_list& list ) const;
102 std::string GetObjectFilename ( const FileLocation* sourceFileLocation,
103 string_list* pclean_files ) const;
104
105 std::string GetObjectFilenames ();
106
107 std::string GetPreconditionDependenciesName () const;
108 std::string GetCFlagsMacro () const;
109 static std::string GetObjectsMacro ( const Module& );
110 std::string GetLinkingDependenciesMacro () const;
111 std::string GetLibsMacro () const;
112 std::string GetLinkerMacro () const;
113 void GenerateCleanObjectsAsYouGoCode () const;
114 void GenerateRunRsymCode () const;
115 void GenerateLinkerCommand ( const std::string& dependencies,
116 const std::string& linker,
117 const std::string& linkerParameters,
118 const std::string& objectsMacro,
119 const std::string& libsMacro,
120 const std::string& pefixupParameters );
121 void GeneratePhonyTarget() const;
122 void GenerateBuildMapCode ( const char *mapTarget = NULL );
123 void GenerateRules ();
124 void GenerateImportLibraryTargetIfNeeded ();
125 void GetDefinitionDependencies ( string_list& dependencies ) const;
126 std::string GetLinkingDependencies () const;
127 static MingwBackend* backend;
128 static FILE* fMakefile;
129 bool use_pch;
130 private:
131 std::string ConcatenatePaths ( const std::string& path1,
132 const std::string& path2 ) const;
133 std::string GenerateGccDefineParameters () const;
134 std::string GenerateCompilerParametersFromVector ( const std::vector<CompilerFlag*>& compilerFlags ) const;
135 std::string GenerateLinkerParametersFromVector ( const std::vector<LinkerFlag*>& linkerFlags ) const;
136 std::string GenerateImportLibraryDependenciesFromVector ( const std::vector<Library*>& libraries );
137 std::string GenerateLinkerParameters () const;
138 void GenerateMacro ( const char* assignmentOperation,
139 const std::string& macro,
140 const IfableData& data );
141 void GenerateMacros ( const char* op,
142 const IfableData& data,
143 const std::vector<LinkerFlag*>* linkerFlags );
144 void GenerateObjectMacros ( const char* assignmentOperation,
145 const IfableData& data,
146 const std::vector<LinkerFlag*>* linkerFlags );
147 std::string GenerateGccIncludeParameters () const;
148 std::string GenerateGccParameters () const;
149 std::string GenerateNasmParameters () const;
150 std::string MingwModuleHandler::GetPrecompiledHeaderFilename () const;
151 void GenerateGccCommand ( const FileLocation* sourceFileLocation,
152 const std::string& extraDependencies,
153 const std::string& cc,
154 const std::string& cflagsMacro );
155 void GenerateGccAssemblerCommand ( const FileLocation* sourceFileLocation,
156 const std::string& cc,
157 const std::string& cflagsMacro );
158 void GenerateNasmCommand ( const FileLocation* sourceFileLocation,
159 const std::string& nasmflagsMacro );
160 void GenerateWindresCommand ( const FileLocation* sourceFileLocation,
161 const std::string& windresflagsMacro );
162 void GenerateWinebuildCommands ( const FileLocation* sourceFileLocation );
163 std::string GetWidlFlags ( const CompilationUnit& compilationUnit );
164 void GenerateWidlCommandsServer (
165 const CompilationUnit& compilationUnit,
166 const std::string& widlflagsMacro );
167 void GenerateWidlCommandsClient (
168 const CompilationUnit& compilationUnit,
169 const std::string& widlflagsMacro );
170 void GenerateWidlCommands ( const CompilationUnit& compilationUnit,
171 const std::string& widlflagsMacro );
172 void GenerateCommands ( const CompilationUnit& compilationUnit,
173 const std::string& cc,
174 const std::string& cppc,
175 const std::string& cflagsMacro,
176 const std::string& nasmflagsMacro,
177 const std::string& windresflagsMacro,
178 const std::string& widlflagsMacro );
179 void GenerateObjectFileTargets ( const IfableData& data,
180 const std::string& cc,
181 const std::string& cppc,
182 const std::string& cflagsMacro,
183 const std::string& nasmflagsMacro,
184 const std::string& windresflagsMacro,
185 const std::string& widlflagsMacro );
186 void GenerateObjectFileTargets ( const std::string& cc,
187 const std::string& cppc,
188 const std::string& cflagsMacro,
189 const std::string& nasmflagsMacro,
190 const std::string& windresflagsMacro,
191 const std::string& widlflagsMacro );
192 std::string GenerateArchiveTarget ( const std::string& ar,
193 const std::string& objs_macro ) const;
194 void GetSpecObjectDependencies ( string_list& dependencies,
195 const std::string& filename ) const;
196 void GetWidlObjectDependencies ( string_list& dependencies,
197 const std::string& filename ) const;
198 void GetDefaultDependencies ( string_list& dependencies ) const;
199 void GetInvocationDependencies ( const Module& module, string_list& dependencies );
200 bool IsWineModule () const;
201 std::string GetDefinitionFilename () const;
202 static std::string RemoveVariables ( std::string path);
203 void GenerateBuildNonSymbolStrippedCode ();
204 void CleanupCompilationUnitVector ( std::vector<CompilationUnit*>& compilationUnits );
205 void GetRpcHeaderDependencies ( std::vector<std::string>& dependencies ) const;
206 std::string GetRpcServerHeaderFilename ( std::string basename ) const;
207 std::string GetRpcClientHeaderFilename ( std::string basename ) const;
208 std::string GetModuleCleanTarget ( const Module& module ) const;
209 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector<std::string>& moduleNames ) const;
210 public:
211 const Module& module;
212 string_list clean_files;
213 std::string cflagsMacro;
214 std::string nasmflagsMacro;
215 std::string windresflagsMacro;
216 std::string widlflagsMacro;
217 std::string linkerflagsMacro;
218 std::string objectsMacro;
219 std::string libsMacro;
220 std::string linkDepsMacro;
221 };
222
223
224 class MingwBuildToolModuleHandler : public MingwModuleHandler
225 {
226 public:
227 MingwBuildToolModuleHandler ( const Module& module );
228 virtual HostType DefaultHost() { return HostTrue; }
229 virtual void Process ();
230 private:
231 void GenerateBuildToolModuleTarget ();
232 };
233
234
235 class MingwKernelModuleHandler : public MingwModuleHandler
236 {
237 public:
238 MingwKernelModuleHandler ( const Module& module );
239 virtual HostType DefaultHost() { return HostFalse; }
240 virtual void Process ();
241 std::string TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
242 private:
243 void GenerateKernelModuleTarget ();
244 };
245
246
247 class MingwStaticLibraryModuleHandler : public MingwModuleHandler
248 {
249 public:
250 MingwStaticLibraryModuleHandler ( const Module& module );
251 virtual HostType DefaultHost() { return HostFalse; }
252 virtual void Process ();
253 private:
254 void GenerateStaticLibraryModuleTarget ();
255 };
256
257
258 class MingwObjectLibraryModuleHandler : public MingwModuleHandler
259 {
260 public:
261 MingwObjectLibraryModuleHandler ( const Module& module );
262 virtual HostType DefaultHost() { return HostFalse; }
263 virtual void Process ();
264 private:
265 void GenerateObjectLibraryModuleTarget ();
266 };
267
268
269 class MingwKernelModeDLLModuleHandler : public MingwModuleHandler
270 {
271 public:
272 MingwKernelModeDLLModuleHandler ( const Module& module );
273 virtual HostType DefaultHost() { return HostFalse; }
274 virtual void Process ();
275 std::string TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
276 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
277 private:
278 void GenerateKernelModeDLLModuleTarget ();
279 };
280
281
282 class MingwKernelModeDriverModuleHandler : public MingwModuleHandler
283 {
284 public:
285 MingwKernelModeDriverModuleHandler ( const Module& module );
286 virtual HostType DefaultHost() { return HostFalse; }
287 virtual void Process ();
288 std::string TypeSpecificCFlags() { return "-D__NTDRIVER__ -D_SEH_NO_NATIVE_NLG"; }
289 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
290 private:
291 void GenerateKernelModeDriverModuleTarget ();
292 };
293
294
295 class MingwNativeDLLModuleHandler : public MingwModuleHandler
296 {
297 public:
298 MingwNativeDLLModuleHandler ( const Module& module );
299 virtual HostType DefaultHost() { return HostFalse; }
300 virtual void Process ();
301 std::string TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
302 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
303 private:
304 void GenerateNativeDLLModuleTarget ();
305 };
306
307
308 class MingwNativeCUIModuleHandler : public MingwModuleHandler
309 {
310 public:
311 MingwNativeCUIModuleHandler ( const Module& module );
312 virtual HostType DefaultHost() { return HostFalse; }
313 virtual void Process ();
314 std::string TypeSpecificCFlags() { return "-D__NTAPP__ -D_SEH_NO_NATIVE_NLG"; }
315 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
316 private:
317 void GenerateNativeCUIModuleTarget ();
318 };
319
320
321 class MingwWin32DLLModuleHandler : public MingwModuleHandler
322 {
323 public:
324 MingwWin32DLLModuleHandler ( const Module& module );
325 virtual HostType DefaultHost() { return HostFalse; }
326 virtual void Process ();
327 private:
328 void GenerateWin32DLLModuleTarget ();
329 };
330
331
332 class MingwWin32CUIModuleHandler : public MingwModuleHandler
333 {
334 public:
335 MingwWin32CUIModuleHandler ( const Module& module );
336 virtual HostType DefaultHost() { return HostFalse; }
337 virtual void Process ();
338 private:
339 void GenerateWin32CUIModuleTarget ();
340 };
341
342
343 class MingwWin32GUIModuleHandler : public MingwModuleHandler
344 {
345 public:
346 MingwWin32GUIModuleHandler ( const Module& module );
347 virtual HostType DefaultHost() { return HostFalse; }
348 virtual void Process ();
349 private:
350 void GenerateWin32GUIModuleTarget ();
351 };
352
353
354 class MingwBootLoaderModuleHandler : public MingwModuleHandler
355 {
356 public:
357 MingwBootLoaderModuleHandler ( const Module& module );
358 virtual HostType DefaultHost() { return HostFalse; }
359 virtual void Process ();
360 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
361 private:
362 void GenerateBootLoaderModuleTarget ();
363 };
364
365
366 class MingwBootSectorModuleHandler : public MingwModuleHandler
367 {
368 public:
369 MingwBootSectorModuleHandler ( const Module& module );
370 virtual HostType DefaultHost() { return HostFalse; }
371 virtual void Process ();
372 std::string TypeSpecificNasmFlags() { return "-f bin"; }
373 private:
374 void GenerateBootSectorModuleTarget ();
375 };
376
377
378 class MingwBootProgramModuleHandler : public MingwModuleHandler
379 {
380 public:
381 MingwBootProgramModuleHandler ( const Module& module );
382 virtual HostType DefaultHost() { return HostFalse; }
383 virtual void Process ();
384 std::string GetProgTextAddrMacro ();
385 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
386 private:
387 void GenerateBootProgramModuleTarget ();
388 };
389
390
391 class MingwIsoModuleHandler : public MingwModuleHandler
392 {
393 public:
394 MingwIsoModuleHandler ( const Module& module );
395 virtual HostType DefaultHost() { return HostFalse; }
396 virtual void Process ();
397 private:
398 void GenerateIsoModuleTarget ();
399 std::string GetBootstrapCdDirectories ( const std::string& bootcdDirectory );
400 std::string GetNonModuleCdDirectories ( const std::string& bootcdDirectory );
401 std::string GetCdDirectories ( const std::string& bootcdDirectory );
402 void GetBootstrapCdFiles ( std::vector<std::string>& out ) const;
403 void GetNonModuleCdFiles ( std::vector<std::string>& out ) const;
404 void GetCdFiles ( std::vector<std::string>& out ) const;
405 void OutputBootstrapfileCopyCommands ( const std::string& bootcdDirectory );
406 void OutputCdfileCopyCommands ( const std::string& bootcdDirectory );
407 };
408
409
410 class MingwLiveIsoModuleHandler : public MingwModuleHandler
411 {
412 public:
413 MingwLiveIsoModuleHandler ( const Module& module );
414 virtual HostType DefaultHost() { return HostFalse; }
415 virtual void Process ();
416 private:
417 void GenerateLiveIsoModuleTarget ();
418 void CreateDirectory ( const std::string& directory );
419 void OutputCopyCommand ( const std::string& sourceFilename,
420 const std::string& targetFilename,
421 const std::string& targetDirectory );
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 protected:
439 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
440 private:
441 void GenerateTestModuleTarget ();
442 };
443
444
445 class MingwRpcServerModuleHandler : public MingwModuleHandler
446 {
447 public:
448 MingwRpcServerModuleHandler ( const Module& module );
449 virtual HostType DefaultHost() { return HostFalse; }
450 virtual void Process ();
451 };
452
453
454 class MingwRpcClientModuleHandler : public MingwModuleHandler
455 {
456 public:
457 MingwRpcClientModuleHandler ( const Module& module );
458 virtual HostType DefaultHost() { return HostFalse; }
459 virtual void Process ();
460 };
461
462 class MingwAliasModuleHandler : public MingwModuleHandler
463 {
464 public:
465 MingwAliasModuleHandler ( const Module& module );
466 virtual HostType DefaultHost() { return HostFalse; }
467 virtual void Process ();
468 };
469
470 #endif /* MINGW_MODULEHANDLER_H */