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