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