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