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