Merge amd64 NDK from amd64 branch:
[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 enum SpecFileType
36 {
37 None,
38 Spec = 1,
39 PSpec = 2
40 };
41
42 class MingwModuleHandler
43 {
44 public:
45 MingwModuleHandler ( const Module& module_ );
46 virtual ~MingwModuleHandler();
47
48 static void SetBackend ( MingwBackend* backend_ );
49 static void SetMakefile ( FILE* f );
50 void EnablePreCompiledHeaderSupport ();
51
52 static const FileLocation* PassThruCacheDirectory (const FileLocation* fileLocation );
53
54 static const FileLocation* GetTargetFilename (
55 const Module& module,
56 string_list* pclean_files );
57
58 static const FileLocation* GetImportLibraryFilename (
59 const Module& module,
60 string_list* pclean_files,
61 bool delayimp );
62
63 static std::string GenerateGccDefineParametersFromVector ( const std::vector<Define*>& defines, std::set<std::string> &used_defs );
64 static std::string GenerateDefineParametersFromVector ( const std::vector<Define*>& defines, CompilerType compiler );
65 static std::string GenerateCompilerParametersFromVector ( const std::vector<CompilerFlag*>& compilerFlags, const CompilerType type );
66 static std::string GenerateIncludeParametersFromVector ( const std::vector<Include*>& includes, CompilerType compiler );
67
68 static void GenerateParameters ( const char* prefix,
69 const char* assignmentOperation,
70 const IfableData& data );
71
72 std::string GetModuleTargets ( const Module& module );
73 void GetObjectsVector ( const IfableData& data,
74 std::vector<FileLocation>& objectFiles ) const;
75 void GenerateSourceMacro();
76 void GenerateObjectMacro();
77 void GenerateTargetMacro();
78 void GenerateOtherMacros();
79
80 static MingwModuleHandler* InstanciateHandler ( const Module& module_,
81 MingwBackend* backend_ );
82 void GeneratePreconditionDependencies ();
83 virtual void Process () { GenerateRules (); }
84 void GenerateInvocations () const;
85 void GenerateCleanTarget () const;
86 void GenerateInstallTarget () const;
87 void GenerateDependsTarget () const;
88 static bool ReferenceObjects ( const Module& module );
89 virtual void AddImplicitLibraries ( Module& module ) { return; }
90
91 void OutputCopyCommand ( const FileLocation& source,
92 const FileLocation& destination );
93 void OutputCopyCommandSingle ( const FileLocation& source,
94 const FileLocation& destination );
95 protected:
96 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
97 std::string GetWorkingDirectory () const;
98 std::string GetBasename ( const std::string& filename ) const;
99 std::string GetCompilationUnitDependencies ( const CompilationUnit& compilationUnit ) const;
100 const FileLocation* GetModuleArchiveFilename () const;
101 std::string GetImportLibraryDependency ( const Module& importedModule, bool delayimp );
102 void GetTargets ( const Module& dependencyModule,
103 string_list& targets );
104 void GetModuleDependencies ( string_list& dependencies );
105 std::string GetAllDependencies () const;
106 const FileLocation* GetObjectFilename ( const FileLocation* sourceFile,
107 const Module& module ) const;
108
109 std::string GetPreconditionDependenciesName () const;
110 static std::string GetObjectsMacro ( const Module& );
111 std::string GetLinkingDependenciesMacro () const;
112 std::string GetLibsMacro () const;
113 std::string GetLinkerMacro () const;
114 static std::string GetDebugFormat ();
115 void GenerateCleanObjectsAsYouGoCode () const;
116 void GenerateRunRsymCode () const;
117 void GenerateRunStripCode () const;
118 void GenerateLinkerCommand ( const std::string& dependencies,
119 const std::string& linkerParameters,
120 const std::string& pefixupParameters );
121 void GeneratePhonyTarget() const;
122 void GenerateBuildMapCode ( const FileLocation *mapTarget = NULL );
123 void GenerateRules ();
124 void GenerateImportLibraryTarget (const FileLocation *defFilename, const FileLocation *library_target, bool delayimp);
125 void GenerateImportLibraryTargetIfNeeded ();
126 void GetDefinitionDependencies ( std::vector<FileLocation>& dependencies ) const;
127 std::string GetLinkingDependencies () const;
128 static MingwBackend* backend;
129 static FILE* fMakefile;
130 bool use_pch;
131 private:
132 std::string ConcatenatePaths ( const std::string& path1,
133 const std::string& path2 ) const;
134 std::string GenerateLinkerParametersFromVector ( const std::vector<LinkerFlag*>& linkerFlags ) const;
135 std::string GenerateImportLibraryDependenciesFromVector ( const std::vector<Library*>& libraries );
136 std::string GenerateLinkerParameters () const;
137 void GenerateMacros ( const char* op,
138 const IfableData& data,
139 const std::vector<LinkerFlag*>* linkerFlags,
140 std::set<const Define *>& used_defs );
141 void GenerateSourceMacros ( const IfableData& data );
142 void GenerateObjectMacros ( const IfableData& data );
143 const FileLocation* GetPrecompiledHeaderFilename () const;
144 const FileLocation* GetPrecompiledHeaderPath () const;
145 const FileLocation* GetDlldataFilename () const;
146 void GenerateGccCommand ( const FileLocation* sourceFile,
147 const Rule *rule,
148 const std::string& extraDependencies );
149 void GenerateCommands ( const CompilationUnit& compilationUnit,
150 const std::string& extraDependencies );
151 void GenerateObjectFileTargets ( const IfableData& data );
152 void GenerateObjectFileTargets ();
153 const FileLocation* GenerateArchiveTarget ();
154 void GetMcObjectDependencies ( std::vector<FileLocation>& dependencies,
155 const FileLocation *file ) const;
156 void GetSpecObjectDependencies ( std::vector<FileLocation>& dependencies,
157 const FileLocation *file ) const;
158 void GetSpecImplibDependencies ( std::vector<FileLocation>& dependencies,
159 const FileLocation *file ) const;
160 void GetWidlObjectDependencies ( std::vector<FileLocation>& dependencies,
161 const FileLocation *file ) const;
162 void GetDefaultDependencies ( string_list& dependencies ) const;
163 void GetInvocationDependencies ( const Module& module, string_list& dependencies );
164 SpecFileType IsSpecDefinitionFile () const;
165 const FileLocation* GetDefinitionFilename () const;
166 void GenerateBuildNonSymbolStrippedCode ();
167 void CleanupCompilationUnitVector ( std::vector<CompilationUnit*>& compilationUnits );
168 void GetRpcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
169 void GetMcHeaderDependencies ( std::vector<FileLocation>& dependencies ) const;
170 static std::string GetPropertyValue ( const Module& module, const std::string& name );
171 const FileLocation* GetRpcServerHeaderFilename ( const FileLocation *base ) const;
172 const FileLocation* GetRpcClientHeaderFilename ( const FileLocation *base ) const;
173 const FileLocation* GetRpcProxyHeaderFilename ( const FileLocation *base ) const;
174 const FileLocation* GetIdlHeaderFilename ( const FileLocation *base ) const;
175 const FileLocation* GetMcHeaderFilename ( const FileLocation *base ) const;
176 std::string GetModuleCleanTarget ( const Module& module ) const;
177 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector<std::string>& moduleNames ) const;
178 public:
179 const Module& module;
180 string_list clean_files;
181 std::string commonflagsMacro;
182 std::string cflagsMacro;
183 std::string cxxflagsMacro;
184 std::string nasmflagsMacro;
185 std::string windresflagsMacro;
186 std::string widlflagsMacro;
187 std::string linkerflagsMacro;
188 std::string sourcesMacro;
189 std::string objectsMacro;
190 std::string libsMacro;
191 std::string linkDepsMacro;
192 };
193
194
195 class MingwBuildToolModuleHandler : public MingwModuleHandler
196 {
197 public:
198 MingwBuildToolModuleHandler ( const Module& module );
199 virtual void Process ();
200 private:
201 void GenerateBuildToolModuleTarget ();
202 };
203
204
205 class MingwKernelModuleHandler : public MingwModuleHandler
206 {
207 public:
208 MingwKernelModuleHandler ( const Module& module );
209 virtual void Process ();
210 private:
211 void GenerateKernelModuleTarget ();
212 };
213
214
215 class MingwKernelModeDLLModuleHandler : public MingwModuleHandler
216 {
217 public:
218 MingwKernelModeDLLModuleHandler ( const Module& module );
219 virtual void Process ();
220 void AddImplicitLibraries ( Module& module );
221 private:
222 void GenerateKernelModeDLLModuleTarget ();
223 };
224
225
226 class MingwNativeDLLModuleHandler : public MingwModuleHandler
227 {
228 public:
229 MingwNativeDLLModuleHandler ( const Module& module );
230 virtual void Process ();
231 void AddImplicitLibraries ( Module& module );
232 private:
233 void GenerateNativeDLLModuleTarget ();
234 };
235
236
237 class MingwNativeCUIModuleHandler : public MingwModuleHandler
238 {
239 public:
240 MingwNativeCUIModuleHandler ( const Module& module );
241 virtual void Process ();
242 void AddImplicitLibraries ( Module& module );
243 private:
244 void GenerateNativeCUIModuleTarget ();
245 };
246
247
248 class MingwWin32DLLModuleHandler : public MingwModuleHandler
249 {
250 public:
251 MingwWin32DLLModuleHandler ( const Module& module );
252 virtual void Process ();
253 void AddImplicitLibraries ( Module& module );
254 private:
255 void GenerateWin32DLLModuleTarget ();
256 };
257
258
259 class MingwWin32OCXModuleHandler : public MingwModuleHandler
260 {
261 public:
262 MingwWin32OCXModuleHandler ( const Module& module );
263 virtual void Process ();
264 void AddImplicitLibraries ( Module& module );
265 private:
266 void GenerateWin32OCXModuleTarget ();
267 };
268
269
270 class MingwWin32CUIModuleHandler : public MingwModuleHandler
271 {
272 public:
273 MingwWin32CUIModuleHandler ( const Module& module );
274 virtual void Process ();
275 void AddImplicitLibraries ( Module& module );
276 private:
277 void GenerateWin32CUIModuleTarget ();
278 };
279
280
281 class MingwWin32GUIModuleHandler : public MingwModuleHandler
282 {
283 public:
284 MingwWin32GUIModuleHandler ( const Module& module );
285 virtual void Process ();
286 void AddImplicitLibraries ( Module& module );
287 private:
288 void GenerateWin32GUIModuleTarget ();
289 };
290
291
292 class MingwBootLoaderModuleHandler : public MingwModuleHandler
293 {
294 public:
295 MingwBootLoaderModuleHandler ( const Module& module );
296 virtual void Process ();
297 private:
298 void GenerateBootLoaderModuleTarget ();
299 };
300
301
302 class MingwBootProgramModuleHandler : public MingwModuleHandler
303 {
304 public:
305 MingwBootProgramModuleHandler ( const Module& module );
306 virtual void Process ();
307 std::string GetProgTextAddrMacro ();
308 private:
309 void GenerateBootProgramModuleTarget ();
310 };
311
312
313 class MingwIsoModuleHandler : public MingwModuleHandler
314 {
315 public:
316 MingwIsoModuleHandler ( const Module& module );
317 virtual void Process ();
318 private:
319 void GenerateIsoModuleTarget ();
320 void GetBootstrapCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
321 void GetNonModuleCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
322 void GetCdDirectories ( std::vector<FileLocation>& out, const std::string& bootcdDirectory );
323 void GetBootstrapCdFiles ( std::vector<FileLocation>& out ) const;
324 void GetNonModuleCdFiles ( std::vector<FileLocation>& out ) const;
325 void GetCdFiles ( std::vector<FileLocation>& out ) const;
326 void OutputBootstrapfileCopyCommands ( const std::string& bootcdDirectory,
327 std::vector<FileLocation>& destinations );
328 void OutputCdfileCopyCommands ( const std::string& bootcdDirectory,
329 std::vector<FileLocation>& destinations );
330 };
331
332
333 class MingwLiveIsoModuleHandler : public MingwModuleHandler
334 {
335 public:
336 MingwLiveIsoModuleHandler ( const Module& module );
337 virtual void Process ();
338 private:
339 void GenerateLiveIsoModuleTarget ();
340 void CreateDirectory ( const std::string& directory );
341 void OutputModuleCopyCommands ( std::string& livecdDirectory,
342 std::string& livecdReactos,
343 std::vector<FileLocation>& destinations );
344 void OutputNonModuleCopyCommands ( std::string& livecdDirectory,
345 std::string& livecdReactos,
346 std::vector<FileLocation>& destinations );
347 void OutputProfilesDirectoryCommands ( std::string& livecdDirectory,
348 std::vector<FileLocation>& destinations );
349 void OutputLoaderCommands ( std::string& livecdDirectory,
350 std::vector<FileLocation>& destinations );
351 void OutputRegistryCommands ( std::string& livecdDirectory );
352 };
353
354
355 class MingwTestModuleHandler : public MingwModuleHandler
356 {
357 public:
358 MingwTestModuleHandler ( const Module& module );
359 virtual void Process ();
360 protected:
361 virtual void GetModuleSpecificCompilationUnits ( std::vector<CompilationUnit*>& compilationUnits );
362 private:
363 void GenerateTestModuleTarget ();
364 };
365
366 class MingwAliasModuleHandler : public MingwModuleHandler
367 {
368 public:
369 MingwAliasModuleHandler ( const Module& module );
370 virtual void Process ();
371 };
372
373 class MingwCabinetModuleHandler : public MingwModuleHandler
374 {
375 public:
376 MingwCabinetModuleHandler ( const Module& module );
377 virtual void Process ();
378 };
379
380 class MingwElfExecutableModuleHandler : public MingwModuleHandler
381 {
382 public:
383 MingwElfExecutableModuleHandler ( const Module& module );
384 virtual void Process ();
385 };
386
387 #endif /* MINGW_MODULEHANDLER_H */