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