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