2 * Copyright (C) 2005 Casper S. Hornstrup
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.
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.
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.
18 #ifndef MINGW_MODULEHANDLER_H
19 #define MINGW_MODULEHANDLER_H
21 #include "../backend.h"
27 GetTargetMacro ( const Module
&, bool with_dollar
= true );
31 const std::string
& filename
,
32 const std::string
& prefix
);
34 class MingwModuleHandler
37 MingwModuleHandler ( const Module
& module_
);
38 virtual ~MingwModuleHandler();
40 static void SetBackend ( MingwBackend
* backend_
);
41 static void SetMakefile ( FILE* f
);
42 void EnablePreCompiledHeaderSupport ();
44 static const FileLocation
* PassThruCacheDirectory (const FileLocation
* fileLocation
);
46 static const FileLocation
* GetTargetFilename (
48 string_list
* pclean_files
);
50 static const FileLocation
* GetImportLibraryFilename (
52 string_list
* pclean_files
);
54 static std::string
GenerateGccDefineParametersFromVector ( const std::vector
<Define
*>& defines
, std::set
<std::string
> &used_defs
);
55 static std::string
GenerateGccIncludeParametersFromVector ( const std::vector
<Include
*>& includes
);
57 std::string
GetModuleTargets ( const Module
& module
);
58 void GetObjectsVector ( const IfableData
& data
,
59 std::vector
<FileLocation
>& objectFiles
) const;
60 void GenerateSourceMacro();
61 void GenerateObjectMacro();
62 void GenerateTargetMacro();
63 void GenerateOtherMacros();
65 static MingwModuleHandler
* InstanciateHandler ( const Module
& module_
,
66 MingwBackend
* backend_
);
67 virtual HostType
DefaultHost() = 0;
68 void GeneratePreconditionDependencies ();
69 virtual void Process () = 0;
70 virtual std::string
TypeSpecificCFlags() { return ""; }
71 virtual std::string
TypeSpecificNasmFlags() { return ""; }
72 virtual std::string
TypeSpecificLinkerFlags() { return ""; }
73 void GenerateInvocations () const;
74 void GenerateCleanTarget () const;
75 void GenerateInstallTarget () const;
76 void GenerateDependsTarget () const;
77 static bool ReferenceObjects ( const Module
& module
);
78 virtual void AddImplicitLibraries ( Module
& module
) { return; }
80 void OutputCopyCommand ( const FileLocation
& source
,
81 const FileLocation
& destination
);
83 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
84 std::string
GetWorkingDirectory () const;
85 std::string
GetBasename ( const std::string
& filename
) const;
86 const FileLocation
* GetActualSourceFilename ( const FileLocation
* file
) const;
87 std::string
GetExtraDependencies ( const FileLocation
*file
) const;
88 std::string
GetCompilationUnitDependencies ( const CompilationUnit
& compilationUnit
) const;
89 const FileLocation
* GetModuleArchiveFilename () const;
90 bool IsGeneratedFile ( const File
& file
) const;
91 std::string
GetImportLibraryDependency ( const Module
& importedModule
);
92 void GetTargets ( const Module
& dependencyModule
,
93 string_list
& targets
);
94 void GetModuleDependencies ( string_list
& dependencies
);
95 std::string
GetAllDependencies () const;
96 void GetSourceFilenames ( std::vector
<FileLocation
>& list
,
97 bool includeGeneratedFiles
) const;
98 void GetSourceFilenamesWithoutGeneratedFiles ( std::vector
<FileLocation
>& list
) const;
99 const FileLocation
* GetObjectFilename ( const FileLocation
* sourceFile
,
100 const Module
& module
,
101 string_list
* pclean_files
) const;
103 std::string
GetObjectFilenames ();
105 std::string
GetPreconditionDependenciesName () const;
106 std::string
GetCFlagsMacro () const;
107 static std::string
GetObjectsMacro ( const Module
& );
108 std::string
GetLinkingDependenciesMacro () const;
109 std::string
GetLibsMacro () const;
110 std::string
GetLinkerMacro () const;
111 void GenerateCleanObjectsAsYouGoCode () const;
112 void GenerateRunRsymCode () const;
113 void GenerateRunStripCode () const;
114 void GenerateLinkerCommand ( const std::string
& dependencies
,
115 const std::string
& linker
,
116 const std::string
& linkerParameters
,
117 const std::string
& objectsMacro
,
118 const std::string
& libsMacro
,
119 const std::string
& pefixupParameters
);
120 void GeneratePhonyTarget() const;
121 void GenerateBuildMapCode ( const FileLocation
*mapTarget
= NULL
);
122 void GenerateRules ();
123 void GenerateImportLibraryTargetIfNeeded ();
124 void GetDefinitionDependencies ( std::vector
<FileLocation
>& dependencies
) const;
125 std::string
GetLinkingDependencies () const;
126 static MingwBackend
* backend
;
127 static FILE* fMakefile
;
130 std::string
ConcatenatePaths ( const std::string
& path1
,
131 const std::string
& path2
) const;
132 std::string
GenerateGccDefineParameters () const;
133 std::string
GenerateCompilerParametersFromVector ( const std::vector
<CompilerFlag
*>& compilerFlags
) 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 GenerateMacro ( const char* assignmentOperation
,
138 const std::string
& macro
,
139 const IfableData
& data
,
140 std::set
<const Define
*>* used_defs
,
141 bool generatingCompilerMacro
);
142 void GenerateMacros ( const char* op
,
143 const IfableData
& data
,
144 const std::vector
<LinkerFlag
*>* linkerFlags
,
145 std::set
<const Define
*>& used_defs
);
146 void GenerateSourceMacros ( const char* assignmentOperation
,
147 const IfableData
& data
);
148 void GenerateObjectMacros ( const char* assignmentOperation
,
149 const IfableData
& data
);
150 std::string
GenerateGccIncludeParameters () const;
151 std::string
GenerateGccParameters () const;
152 std::string
GenerateNasmParameters () const;
153 const FileLocation
* GetPrecompiledHeaderFilename () const;
154 void GenerateGccCommand ( const FileLocation
* sourceFile
,
155 const std::string
& extraDependencies
,
156 const std::string
& cc
,
157 const std::string
& cflagsMacro
);
158 void GenerateGccAssemblerCommand ( const FileLocation
* sourceFile
,
159 const std::string
& cc
,
160 const std::string
& cflagsMacro
);
161 void GenerateNasmCommand ( const FileLocation
* sourceFile
,
162 const std::string
& nasmflagsMacro
);
163 void GenerateWindresCommand ( const FileLocation
* sourceFile
,
164 const std::string
& windresflagsMacro
);
165 void GenerateWinebuildCommands ( const FileLocation
* sourceFile
);
166 void GenerateWmcCommands ( const FileLocation
* sourceFile
);
167 std::string
GetWidlFlags ( const CompilationUnit
& compilationUnit
);
168 void GenerateWidlCommandsServer (
169 const CompilationUnit
& compilationUnit
,
170 const std::string
& widlflagsMacro
);
171 void GenerateWidlCommandsClient (
172 const CompilationUnit
& compilationUnit
,
173 const std::string
& widlflagsMacro
);
174 void GenerateWidlCommandsIdlHeader (
175 const CompilationUnit
& compilationUnit
,
176 const std::string
& widlflagsMacro
);
177 void GenerateWidlCommandsEmbeddedTypeLib (
178 const CompilationUnit
& compilationUnit
,
179 const std::string
& widlflagsMacro
);
180 void GenerateWidlCommands ( const CompilationUnit
& compilationUnit
,
181 const std::string
& widlflagsMacro
);
182 void GenerateCommands ( const CompilationUnit
& compilationUnit
,
183 const std::string
& extraDependencies
,
184 const std::string
& cc
,
185 const std::string
& cppc
,
186 const std::string
& cflagsMacro
,
187 const std::string
& nasmflagsMacro
,
188 const std::string
& windresflagsMacro
,
189 const std::string
& widlflagsMacro
);
190 void GenerateObjectFileTargets ( const IfableData
& data
,
191 const std::string
& cc
,
192 const std::string
& cppc
,
193 const std::string
& cflagsMacro
,
194 const std::string
& nasmflagsMacro
,
195 const std::string
& windresflagsMacro
,
196 const std::string
& widlflagsMacro
);
197 void GenerateObjectFileTargets ( const std::string
& cc
,
198 const std::string
& cppc
,
199 const std::string
& cflagsMacro
,
200 const std::string
& nasmflagsMacro
,
201 const std::string
& windresflagsMacro
,
202 const std::string
& widlflagsMacro
);
203 const FileLocation
* GenerateArchiveTarget ( const std::string
& ar
,
204 const std::string
& objs_macro
) const;
205 void GetMcObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
206 const FileLocation
*file
) const;
207 void GetSpecObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
208 const FileLocation
*file
) const;
209 void GetWidlObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
210 const FileLocation
*file
) const;
211 void GetDefaultDependencies ( string_list
& dependencies
) const;
212 void GetInvocationDependencies ( const Module
& module
, string_list
& dependencies
);
213 bool IsWineModule () const;
214 const FileLocation
* GetDefinitionFilename () const;
215 void GenerateBuildNonSymbolStrippedCode ();
216 void CleanupCompilationUnitVector ( std::vector
<CompilationUnit
*>& compilationUnits
);
217 void GetRpcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
218 void GetMcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
219 static std::string
GetPropertyValue ( const Module
& module
, const std::string
& name
);
220 const FileLocation
* GetRpcServerHeaderFilename ( const FileLocation
*base
) const;
221 const FileLocation
* GetRpcClientHeaderFilename ( const FileLocation
*base
) const;
222 const FileLocation
* GetIdlHeaderFilename ( const FileLocation
*base
) const;
223 const FileLocation
* GetMcHeaderFilename ( const FileLocation
*base
) const;
224 std::string
GetModuleCleanTarget ( const Module
& module
) const;
225 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector
<std::string
>& moduleNames
) const;
227 const Module
& module
;
228 string_list clean_files
;
229 std::string cflagsMacro
;
230 std::string nasmflagsMacro
;
231 std::string windresflagsMacro
;
232 std::string widlflagsMacro
;
233 std::string linkerflagsMacro
;
234 std::string sourcesMacro
;
235 std::string objectsMacro
;
236 std::string libsMacro
;
237 std::string linkDepsMacro
;
241 class MingwBuildToolModuleHandler
: public MingwModuleHandler
244 MingwBuildToolModuleHandler ( const Module
& module
);
245 virtual HostType
DefaultHost() { return HostTrue
; }
246 virtual void Process ();
248 void GenerateBuildToolModuleTarget ();
252 class MingwKernelModuleHandler
: public MingwModuleHandler
255 MingwKernelModuleHandler ( const Module
& module
);
256 virtual HostType
DefaultHost() { return HostFalse
; }
257 virtual void Process ();
259 void GenerateKernelModuleTarget ();
263 class MingwStaticLibraryModuleHandler
: public MingwModuleHandler
266 MingwStaticLibraryModuleHandler ( const Module
& module
);
267 virtual HostType
DefaultHost() { return HostFalse
; }
268 virtual void Process ();
270 void GenerateStaticLibraryModuleTarget ();
274 class MingwObjectLibraryModuleHandler
: public MingwModuleHandler
277 MingwObjectLibraryModuleHandler ( const Module
& module
);
278 virtual HostType
DefaultHost() { return HostFalse
; }
279 virtual void Process ();
281 void GenerateObjectLibraryModuleTarget ();
285 class MingwKernelModeDLLModuleHandler
: public MingwModuleHandler
288 MingwKernelModeDLLModuleHandler ( const Module
& module
);
289 virtual HostType
DefaultHost() { return HostFalse
; }
290 virtual void Process ();
291 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
292 void AddImplicitLibraries ( Module
& module
);
294 void GenerateKernelModeDLLModuleTarget ();
298 class MingwKernelModeDriverModuleHandler
: public MingwModuleHandler
301 MingwKernelModeDriverModuleHandler ( const Module
& module
);
302 virtual HostType
DefaultHost() { return HostFalse
; }
303 virtual void Process ();
304 std::string
TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
305 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
306 void AddImplicitLibraries ( Module
& module
);
308 void GenerateKernelModeDriverModuleTarget ();
312 class MingwNativeDLLModuleHandler
: public MingwModuleHandler
315 MingwNativeDLLModuleHandler ( const Module
& module
);
316 virtual HostType
DefaultHost() { return HostFalse
; }
317 virtual void Process ();
318 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
319 void AddImplicitLibraries ( Module
& module
);
321 void GenerateNativeDLLModuleTarget ();
325 class MingwNativeCUIModuleHandler
: public MingwModuleHandler
328 MingwNativeCUIModuleHandler ( const Module
& module
);
329 virtual HostType
DefaultHost() { return HostFalse
; }
330 virtual void Process ();
331 std::string
TypeSpecificCFlags() { return "-D__NTAPP__"; }
332 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
333 void AddImplicitLibraries ( Module
& module
);
335 void GenerateNativeCUIModuleTarget ();
339 class MingwWin32DLLModuleHandler
: public MingwModuleHandler
342 MingwWin32DLLModuleHandler ( const Module
& module
);
343 virtual HostType
DefaultHost() { return HostFalse
; }
344 virtual void Process ();
345 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
346 void AddImplicitLibraries ( Module
& module
);
348 void GenerateWin32DLLModuleTarget ();
352 class MingwWin32OCXModuleHandler
: public MingwModuleHandler
355 MingwWin32OCXModuleHandler ( const Module
& module
);
356 virtual HostType
DefaultHost() { return HostFalse
; }
357 virtual void Process ();
358 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
359 void AddImplicitLibraries ( Module
& module
);
361 void GenerateWin32OCXModuleTarget ();
365 class MingwWin32CUIModuleHandler
: public MingwModuleHandler
368 MingwWin32CUIModuleHandler ( const Module
& module
);
369 virtual HostType
DefaultHost() { return HostFalse
; }
370 virtual void Process ();
371 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
372 void AddImplicitLibraries ( Module
& module
);
374 void GenerateWin32CUIModuleTarget ();
378 class MingwWin32GUIModuleHandler
: public MingwModuleHandler
381 MingwWin32GUIModuleHandler ( const Module
& module
);
382 virtual HostType
DefaultHost() { return HostFalse
; }
383 virtual void Process ();
384 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
385 void AddImplicitLibraries ( Module
& module
);
387 void GenerateWin32GUIModuleTarget ();
391 class MingwBootLoaderModuleHandler
: public MingwModuleHandler
394 MingwBootLoaderModuleHandler ( const Module
& module
);
395 virtual HostType
DefaultHost() { return HostFalse
; }
396 virtual void Process ();
397 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
399 void GenerateBootLoaderModuleTarget ();
403 class MingwBootSectorModuleHandler
: public MingwModuleHandler
406 MingwBootSectorModuleHandler ( const Module
& module
);
407 virtual HostType
DefaultHost() { return HostFalse
; }
408 virtual void Process ();
409 std::string
TypeSpecificNasmFlags() { return "-f bin"; }
411 void GenerateBootSectorModuleTarget ();
415 class MingwBootProgramModuleHandler
: public MingwModuleHandler
418 MingwBootProgramModuleHandler ( const Module
& module
);
419 virtual HostType
DefaultHost() { return HostFalse
; }
420 virtual void Process ();
421 std::string
GetProgTextAddrMacro ();
422 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
424 void GenerateBootProgramModuleTarget ();
428 class MingwIsoModuleHandler
: public MingwModuleHandler
431 MingwIsoModuleHandler ( const Module
& module
);
432 virtual HostType
DefaultHost() { return HostFalse
; }
433 virtual void Process ();
435 void GenerateIsoModuleTarget ();
436 void GetBootstrapCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
437 void GetNonModuleCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
438 void GetCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
439 void GetBootstrapCdFiles ( std::vector
<FileLocation
>& out
) const;
440 void GetNonModuleCdFiles ( std::vector
<FileLocation
>& out
) const;
441 void GetCdFiles ( std::vector
<FileLocation
>& out
) const;
442 void OutputBootstrapfileCopyCommands ( const std::string
& bootcdDirectory
);
443 void OutputCdfileCopyCommands ( const std::string
& bootcdDirectory
);
447 class MingwLiveIsoModuleHandler
: public MingwModuleHandler
450 MingwLiveIsoModuleHandler ( const Module
& module
);
451 virtual HostType
DefaultHost() { return HostFalse
; }
452 virtual void Process ();
454 void GenerateLiveIsoModuleTarget ();
455 void CreateDirectory ( const std::string
& directory
);
456 void OutputModuleCopyCommands ( std::string
& livecdDirectory
,
457 std::string
& livecdReactos
);
458 void OutputNonModuleCopyCommands ( std::string
& livecdDirectory
,
459 std::string
& livecdReactos
);
460 void OutputProfilesDirectoryCommands ( std::string
& livecdDirectory
);
461 void OutputLoaderCommands ( std::string
& livecdDirectory
);
462 void OutputRegistryCommands ( std::string
& livecdDirectory
);
466 class MingwTestModuleHandler
: public MingwModuleHandler
469 MingwTestModuleHandler ( const Module
& module
);
470 virtual HostType
DefaultHost() { return HostFalse
; }
471 virtual void Process ();
472 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
474 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
476 void GenerateTestModuleTarget ();
480 class MingwRpcServerModuleHandler
: public MingwModuleHandler
483 MingwRpcServerModuleHandler ( const Module
& module
);
484 virtual HostType
DefaultHost() { return HostFalse
; }
485 virtual void Process ();
489 class MingwRpcClientModuleHandler
: public MingwModuleHandler
492 MingwRpcClientModuleHandler ( const Module
& module
);
493 virtual HostType
DefaultHost() { return HostFalse
; }
494 virtual void Process ();
497 class MingwAliasModuleHandler
: public MingwModuleHandler
500 MingwAliasModuleHandler ( const Module
& module
);
501 virtual HostType
DefaultHost() { return HostFalse
; }
502 virtual void Process ();
505 class MingwIdlHeaderModuleHandler
: public MingwModuleHandler
508 MingwIdlHeaderModuleHandler ( const Module
& module
);
509 virtual HostType
DefaultHost() { return HostFalse
; }
510 virtual void Process ();
513 class MingwEmbeddedTypeLibModuleHandler
: public MingwModuleHandler
516 MingwEmbeddedTypeLibModuleHandler ( const Module
& module
);
517 virtual HostType
DefaultHost() { return HostFalse
; }
518 virtual void Process ();
521 class MingwElfExecutableModuleHandler
: public MingwModuleHandler
524 MingwElfExecutableModuleHandler ( const Module
& module
);
525 virtual HostType
DefaultHost() { return HostFalse
; }
526 virtual void Process ();
529 #endif /* MINGW_MODULEHANDLER_H */