Merge 15329:15546 from trunk
[reactos.git] / reactos / tools / rbuild / backend / mingw / modulehandler.h
1 #ifndef MINGW_MODULEHANDLER_H
2 #define MINGW_MODULEHANDLER_H
3
4 #include "../backend.h"
5 #include "mingw.h"
6
7 class MingwBackend;
8
9 extern std::string
10 GetTargetMacro ( const Module&, bool with_dollar = true );
11
12 extern std::string
13 PrefixFilename (
14 const std::string& filename,
15 const std::string& prefix );
16
17 class MingwModuleHandler
18 {
19 public:
20 MingwModuleHandler ( const Module& module_ );
21 virtual ~MingwModuleHandler();
22
23 static void SetBackend ( MingwBackend* backend_ );
24 static void SetMakefile ( FILE* f );
25 static void SetUsePch ( bool use_pch );
26
27 static std::string PassThruCacheDirectory (
28 const std::string &f,
29 Directory* directoryTree );
30
31 static Directory* GetTargetDirectoryTree (
32 const Module& module );
33
34 static std::string GetTargetFilename (
35 const Module& module,
36 string_list* pclean_files );
37
38 static std::string
39 GetImportLibraryFilename (
40 const Module& module,
41 string_list* pclean_files );
42
43 static std::string GenerateGccDefineParametersFromVector ( const std::vector<Define*>& defines );
44 static std::string GenerateGccIncludeParametersFromVector ( const std::vector<Include*>& includes );
45
46 std::string GetModuleTargets ( const Module& module );
47 void GetObjectsVector ( const IfableData& data,
48 std::vector<std::string>& objectFiles ) const;
49 void GenerateObjectMacro();
50 void GenerateTargetMacro();
51 void GenerateOtherMacros();
52
53 static MingwModuleHandler* InstanciateHandler ( const Module& module_,
54 MingwBackend* backend_ );
55 virtual HostType DefaultHost() = 0;
56 void GeneratePreconditionDependencies ();
57 virtual void Process () = 0;
58 virtual std::string TypeSpecificCFlags() { return ""; }
59 virtual std::string TypeSpecificNasmFlags() { return ""; }
60 virtual std::string TypeSpecificLinkerFlags() { return ""; }
61 void GenerateInvocations () const;
62 void GenerateCleanTarget () const;
63 void GenerateInstallTarget () const;
64 static bool ReferenceObjects ( const Module& module );
65 protected:
66 virtual void GetModuleSpecificSourceFiles ( std::vector<File*>& sourceFiles );
67 std::string GetWorkingDirectory () const;
68 std::string GetBasename ( const std::string& filename ) const;
69 std::string GetActualSourceFilename ( const std::string& filename ) const;
70 std::string GetModuleArchiveFilename () const;
71 bool IsGeneratedFile ( const File& file ) const;
72 std::string GetImportLibraryDependency ( const Module& importedModule );
73 void GetTargets ( const Module& dependencyModule,
74 string_list& targets );
75 void GetModuleDependencies ( string_list& dependencies );
76 std::string GetAllDependencies () const;
77 void GetSourceFilenames ( string_list& list,
78 bool includeGeneratedFiles ) const;
79 void GetSourceFilenamesWithoutGeneratedFiles ( string_list& list ) const;
80 std::string GetObjectFilename ( const std::string& sourceFilename,
81 string_list* pclean_files ) const;
82
83 std::string GetObjectFilenames ();
84
85 std::string GetPreconditionDependenciesName () const;
86 std::string GetCFlagsMacro () const;
87 static std::string GetObjectsMacro ( const Module& );
88 std::string GetLinkingDependenciesMacro () const;
89 std::string GetLibsMacro () const;
90 std::string GetLinkerMacro () const;
91 void GenerateCleanObjectsAsYouGoCode () const;
92 void GenerateRunRsymCode () const;
93 void GenerateLinkerCommand ( const std::string& dependencies,
94 const std::string& linker,
95 const std::string& linkerParameters,
96 const std::string& objectsMacro,
97 const std::string& libsMacro );
98 void GeneratePhonyTarget() const;
99 void GenerateRules ();
100 void GenerateImportLibraryTargetIfNeeded ();
101 void GetDefinitionDependencies ( string_list& dependencies ) const;
102 std::string GetLinkingDependencies () const;
103 static MingwBackend* backend;
104 static FILE* fMakefile;
105 static bool use_pch;
106 private:
107 std::string ConcatenatePaths ( const std::string& path1,
108 const std::string& path2 ) const;
109 std::string GenerateGccDefineParameters () const;
110 std::string GenerateCompilerParametersFromVector ( const std::vector<CompilerFlag*>& compilerFlags ) const;
111 std::string GenerateLinkerParametersFromVector ( const std::vector<LinkerFlag*>& linkerFlags ) const;
112 std::string GenerateImportLibraryDependenciesFromVector ( const std::vector<Library*>& libraries );
113 std::string GenerateLinkerParameters () const;
114 void GenerateMacro ( const char* assignmentOperation,
115 const std::string& macro,
116 const IfableData& data );
117 void GenerateMacros ( const char* op,
118 const IfableData& data,
119 const std::vector<LinkerFlag*>* linkerFlags );
120 void GenerateObjectMacros ( const char* assignmentOperation,
121 const IfableData& data,
122 const std::vector<LinkerFlag*>* linkerFlags );
123 std::string GenerateGccIncludeParameters () const;
124 std::string GenerateGccParameters () const;
125 std::string GenerateNasmParameters () const;
126 void GenerateGccCommand ( const std::string& sourceFilename,
127 const std::string& cc,
128 const std::string& cflagsMacro );
129 void GenerateGccAssemblerCommand ( const std::string& sourceFilename,
130 const std::string& cc,
131 const std::string& cflagsMacro );
132 void GenerateNasmCommand ( const std::string& sourceFilename,
133 const std::string& nasmflagsMacro );
134 void GenerateWindresCommand ( const std::string& sourceFilename,
135 const std::string& windresflagsMacro );
136 void GenerateWinebuildCommands ( const std::string& sourceFilename );
137 std::string GetWidlFlags ( const File& file );
138 void GenerateWidlCommandsServer (
139 const File& file,
140 const std::string& widlflagsMacro );
141 void GenerateWidlCommandsClient (
142 const File& file,
143 const std::string& widlflagsMacro );
144 void GenerateWidlCommands ( const File& file,
145 const std::string& widlflagsMacro );
146 void GenerateCommands ( const File& file,
147 const std::string& cc,
148 const std::string& cppc,
149 const std::string& cflagsMacro,
150 const std::string& nasmflagsMacro,
151 const std::string& windresflagsMacro,
152 const std::string& widlflagsMacro );
153 void GenerateObjectFileTargets ( const IfableData& data,
154 const std::string& cc,
155 const std::string& cppc,
156 const std::string& cflagsMacro,
157 const std::string& nasmflagsMacro,
158 const std::string& windresflagsMacro,
159 const std::string& widlflagsMacro );
160 void GenerateObjectFileTargets ( const std::string& cc,
161 const std::string& cppc,
162 const std::string& cflagsMacro,
163 const std::string& nasmflagsMacro,
164 const std::string& windresflagsMacro,
165 const std::string& widlflagsMacro );
166 std::string GenerateArchiveTarget ( const std::string& ar,
167 const std::string& objs_macro ) const;
168 void GetSpecObjectDependencies ( string_list& dependencies,
169 const std::string& filename ) const;
170 void GetWidlObjectDependencies ( string_list& dependencies,
171 const std::string& filename ) const;
172 void GetDefaultDependencies ( string_list& dependencies ) const;
173 void GetInvocationDependencies ( const Module& module, string_list& dependencies );
174 bool IsWineModule () const;
175 std::string GetDefinitionFilename () const;
176 static std::string RemoveVariables ( std::string path);
177 void GenerateBuildMapCode ();
178 void GenerateBuildNonSymbolStrippedCode ();
179 void CleanupFileVector ( std::vector<File*>& sourceFiles );
180 void GetRpcHeaderDependencies ( string_list& dependencies ) const;
181 std::string GetRpcServerHeaderFilename ( std::string basename ) const;
182 std::string GetRpcClientHeaderFilename ( std::string basename ) 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 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 std::string TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
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 TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
249 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
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__ -D_SEH_NO_NATIVE_NLG"; }
262 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
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 TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
275 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
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__ -D_SEH_NO_NATIVE_NLG"; }
288 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
289 private:
290 void GenerateNativeCUIModuleTarget ();
291 };
292
293
294 class MingwWin32DLLModuleHandler : public MingwModuleHandler
295 {
296 public:
297 MingwWin32DLLModuleHandler ( const Module& module );
298 virtual HostType DefaultHost() { return HostFalse; }
299 virtual void Process ();
300 private:
301 void GenerateWin32DLLModuleTarget ();
302 };
303
304
305 class MingwWin32CUIModuleHandler : public MingwModuleHandler
306 {
307 public:
308 MingwWin32CUIModuleHandler ( const Module& module );
309 virtual HostType DefaultHost() { return HostFalse; }
310 virtual void Process ();
311 private:
312 void GenerateWin32CUIModuleTarget ();
313 };
314
315
316 class MingwWin32GUIModuleHandler : public MingwModuleHandler
317 {
318 public:
319 MingwWin32GUIModuleHandler ( const Module& module );
320 virtual HostType DefaultHost() { return HostFalse; }
321 virtual void Process ();
322 private:
323 void GenerateWin32GUIModuleTarget ();
324 };
325
326
327 class MingwBootLoaderModuleHandler : public MingwModuleHandler
328 {
329 public:
330 MingwBootLoaderModuleHandler ( const Module& module );
331 virtual HostType DefaultHost() { return HostFalse; }
332 virtual void Process ();
333 std::string TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
334 private:
335 void GenerateBootLoaderModuleTarget ();
336 };
337
338
339 class MingwBootSectorModuleHandler : public MingwModuleHandler
340 {
341 public:
342 MingwBootSectorModuleHandler ( const Module& module );
343 virtual HostType DefaultHost() { return HostFalse; }
344 virtual void Process ();
345 std::string TypeSpecificNasmFlags() { return "-f bin"; }
346 private:
347 void GenerateBootSectorModuleTarget ();
348 };
349
350
351 class MingwIsoModuleHandler : public MingwModuleHandler
352 {
353 public:
354 MingwIsoModuleHandler ( const Module& module );
355 virtual HostType DefaultHost() { return HostFalse; }
356 virtual void Process ();
357 private:
358 void GenerateIsoModuleTarget ();
359 std::string GetBootstrapCdDirectories ( const std::string& bootcdDirectory );
360 std::string GetNonModuleCdDirectories ( const std::string& bootcdDirectory );
361 std::string GetCdDirectories ( const std::string& bootcdDirectory );
362 void GetBootstrapCdFiles ( std::vector<std::string>& out ) const;
363 void GetNonModuleCdFiles ( std::vector<std::string>& out ) const;
364 void GetCdFiles ( std::vector<std::string>& out ) const;
365 void OutputBootstrapfileCopyCommands ( const std::string& bootcdDirectory );
366 void OutputCdfileCopyCommands ( const std::string& bootcdDirectory );
367 };
368
369
370 class MingwLiveIsoModuleHandler : public MingwModuleHandler
371 {
372 public:
373 MingwLiveIsoModuleHandler ( const Module& module );
374 virtual HostType DefaultHost() { return HostFalse; }
375 virtual void Process ();
376 private:
377 void GenerateLiveIsoModuleTarget ();
378 void CreateDirectory ( const std::string& directory );
379 void OutputCopyCommand ( const std::string& sourceFilename,
380 const std::string& targetFilename,
381 const std::string& targetDirectory );
382 void OutputModuleCopyCommands ( std::string& livecdDirectory,
383 std::string& livecdReactos );
384 void OutputNonModuleCopyCommands ( std::string& livecdDirectory,
385 std::string& livecdReactos );
386 void OutputProfilesDirectoryCommands ( std::string& livecdDirectory );
387 void OutputLoaderCommands ( std::string& livecdDirectory );
388 void OutputRegistryCommands ( std::string& livecdDirectory );
389 };
390
391
392 class MingwTestModuleHandler : public MingwModuleHandler
393 {
394 public:
395 MingwTestModuleHandler ( const Module& module );
396 virtual HostType DefaultHost() { return HostFalse; }
397 virtual void Process ();
398 protected:
399 virtual void GetModuleSpecificSourceFiles ( std::vector<File*>& sourceFiles );
400 private:
401 void GenerateTestModuleTarget ();
402 };
403
404
405 class MingwRpcServerModuleHandler : public MingwModuleHandler
406 {
407 public:
408 MingwRpcServerModuleHandler ( const Module& module );
409 virtual HostType DefaultHost() { return HostFalse; }
410 virtual void Process ();
411 };
412
413
414 class MingwRpcClientModuleHandler : public MingwModuleHandler
415 {
416 public:
417 MingwRpcClientModuleHandler ( const Module& module );
418 virtual HostType DefaultHost() { return HostFalse; }
419 virtual void Process ();
420 };
421
422 #endif /* MINGW_MODULEHANDLER_H */