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;
126 std::string
GetLinkingDependencies () const;
127 static MingwBackend
* backend
;
128 static FILE* fMakefile
;
131 std::string
ConcatenatePaths ( const std::string
& path1
,
132 const std::string
& path2
) const;
133 std::string
GenerateGccDefineParameters () const;
134 std::string
GenerateCompilerParametersFromVector ( const std::vector
<CompilerFlag
*>& compilerFlags
) const;
135 std::string
GenerateLinkerParametersFromVector ( const std::vector
<LinkerFlag
*>& linkerFlags
) const;
136 std::string
GenerateImportLibraryDependenciesFromVector ( const std::vector
<Library
*>& libraries
);
137 std::string
GenerateLinkerParameters () const;
138 void GenerateMacro ( const char* assignmentOperation
,
139 const std::string
& macro
,
140 const IfableData
& data
,
141 std::set
<const Define
*>* used_defs
,
142 bool generatingCompilerMacro
);
143 void GenerateMacros ( const char* op
,
144 const IfableData
& data
,
145 const std::vector
<LinkerFlag
*>* linkerFlags
,
146 std::set
<const Define
*>& used_defs
);
147 void GenerateSourceMacros ( const char* assignmentOperation
,
148 const IfableData
& data
);
149 void GenerateObjectMacros ( const char* assignmentOperation
,
150 const IfableData
& data
);
151 std::string
GenerateGccIncludeParameters () const;
152 std::string
GenerateGccParameters () const;
153 std::string
GenerateNasmParameters () const;
154 const FileLocation
* GetPrecompiledHeaderFilename () const;
155 void GenerateGccCommand ( const FileLocation
* sourceFile
,
156 const std::string
& extraDependencies
,
157 const std::string
& cc
,
158 const std::string
& cflagsMacro
);
159 void GenerateGccAssemblerCommand ( const FileLocation
* sourceFile
,
160 const std::string
& cc
,
161 const std::string
& cflagsMacro
);
162 void GenerateNasmCommand ( const FileLocation
* sourceFile
,
163 const std::string
& nasmflagsMacro
);
164 void GenerateWindresCommand ( const FileLocation
* sourceFile
,
165 const std::string
& windresflagsMacro
);
166 void GenerateWinebuildCommands ( 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 GetSpecObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
206 const FileLocation
*file
) const;
207 void GetWidlObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
208 const FileLocation
*file
) const;
209 void GetDefaultDependencies ( string_list
& dependencies
) const;
210 void GetInvocationDependencies ( const Module
& module
, string_list
& dependencies
);
211 bool IsWineModule () const;
212 const FileLocation
* GetDefinitionFilename () const;
213 void GenerateBuildNonSymbolStrippedCode ();
214 void CleanupCompilationUnitVector ( std::vector
<CompilationUnit
*>& compilationUnits
);
215 void GetRpcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
216 static std::string
GetPropertyValue ( const Module
& module
, const std::string
& name
);
217 const FileLocation
* GetRpcServerHeaderFilename ( const FileLocation
*base
) const;
218 const FileLocation
* GetRpcClientHeaderFilename ( const FileLocation
*base
) const;
219 const FileLocation
* GetIdlHeaderFilename ( const FileLocation
*base
) const;
220 std::string
GetModuleCleanTarget ( const Module
& module
) const;
221 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector
<std::string
>& moduleNames
) const;
223 const Module
& module
;
224 string_list clean_files
;
225 std::string cflagsMacro
;
226 std::string nasmflagsMacro
;
227 std::string windresflagsMacro
;
228 std::string widlflagsMacro
;
229 std::string linkerflagsMacro
;
230 std::string sourcesMacro
;
231 std::string objectsMacro
;
232 std::string libsMacro
;
233 std::string linkDepsMacro
;
237 class MingwBuildToolModuleHandler
: public MingwModuleHandler
240 MingwBuildToolModuleHandler ( const Module
& module
);
241 virtual HostType
DefaultHost() { return HostTrue
; }
242 virtual void Process ();
244 void GenerateBuildToolModuleTarget ();
248 class MingwKernelModuleHandler
: public MingwModuleHandler
251 MingwKernelModuleHandler ( const Module
& module
);
252 virtual HostType
DefaultHost() { return HostFalse
; }
253 virtual void Process ();
255 void GenerateKernelModuleTarget ();
259 class MingwStaticLibraryModuleHandler
: public MingwModuleHandler
262 MingwStaticLibraryModuleHandler ( const Module
& module
);
263 virtual HostType
DefaultHost() { return HostFalse
; }
264 virtual void Process ();
266 void GenerateStaticLibraryModuleTarget ();
270 class MingwObjectLibraryModuleHandler
: public MingwModuleHandler
273 MingwObjectLibraryModuleHandler ( const Module
& module
);
274 virtual HostType
DefaultHost() { return HostFalse
; }
275 virtual void Process ();
277 void GenerateObjectLibraryModuleTarget ();
281 class MingwKernelModeDLLModuleHandler
: public MingwModuleHandler
284 MingwKernelModeDLLModuleHandler ( const Module
& module
);
285 virtual HostType
DefaultHost() { return HostFalse
; }
286 virtual void Process ();
287 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
288 void AddImplicitLibraries ( Module
& module
);
290 void GenerateKernelModeDLLModuleTarget ();
294 class MingwKernelModeDriverModuleHandler
: public MingwModuleHandler
297 MingwKernelModeDriverModuleHandler ( const Module
& module
);
298 virtual HostType
DefaultHost() { return HostFalse
; }
299 virtual void Process ();
300 std::string
TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
301 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
302 void AddImplicitLibraries ( Module
& module
);
304 void GenerateKernelModeDriverModuleTarget ();
308 class MingwNativeDLLModuleHandler
: public MingwModuleHandler
311 MingwNativeDLLModuleHandler ( const Module
& module
);
312 virtual HostType
DefaultHost() { return HostFalse
; }
313 virtual void Process ();
314 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
315 void AddImplicitLibraries ( Module
& module
);
317 void GenerateNativeDLLModuleTarget ();
321 class MingwNativeCUIModuleHandler
: public MingwModuleHandler
324 MingwNativeCUIModuleHandler ( const Module
& module
);
325 virtual HostType
DefaultHost() { return HostFalse
; }
326 virtual void Process ();
327 std::string
TypeSpecificCFlags() { return "-D__NTAPP__"; }
328 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
329 void AddImplicitLibraries ( Module
& module
);
331 void GenerateNativeCUIModuleTarget ();
335 class MingwWin32DLLModuleHandler
: public MingwModuleHandler
338 MingwWin32DLLModuleHandler ( const Module
& module
);
339 virtual HostType
DefaultHost() { return HostFalse
; }
340 virtual void Process ();
341 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
342 void AddImplicitLibraries ( Module
& module
);
344 void GenerateWin32DLLModuleTarget ();
348 class MingwWin32OCXModuleHandler
: public MingwModuleHandler
351 MingwWin32OCXModuleHandler ( const Module
& module
);
352 virtual HostType
DefaultHost() { return HostFalse
; }
353 virtual void Process ();
354 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
355 void AddImplicitLibraries ( Module
& module
);
357 void GenerateWin32OCXModuleTarget ();
361 class MingwWin32CUIModuleHandler
: public MingwModuleHandler
364 MingwWin32CUIModuleHandler ( const Module
& module
);
365 virtual HostType
DefaultHost() { return HostFalse
; }
366 virtual void Process ();
367 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
368 void AddImplicitLibraries ( Module
& module
);
370 void GenerateWin32CUIModuleTarget ();
374 class MingwWin32GUIModuleHandler
: public MingwModuleHandler
377 MingwWin32GUIModuleHandler ( const Module
& module
);
378 virtual HostType
DefaultHost() { return HostFalse
; }
379 virtual void Process ();
380 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
381 void AddImplicitLibraries ( Module
& module
);
383 void GenerateWin32GUIModuleTarget ();
387 class MingwBootLoaderModuleHandler
: public MingwModuleHandler
390 MingwBootLoaderModuleHandler ( const Module
& module
);
391 virtual HostType
DefaultHost() { return HostFalse
; }
392 virtual void Process ();
393 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
395 void GenerateBootLoaderModuleTarget ();
399 class MingwBootSectorModuleHandler
: public MingwModuleHandler
402 MingwBootSectorModuleHandler ( const Module
& module
);
403 virtual HostType
DefaultHost() { return HostFalse
; }
404 virtual void Process ();
405 std::string
TypeSpecificNasmFlags() { return "-f bin"; }
407 void GenerateBootSectorModuleTarget ();
411 class MingwBootProgramModuleHandler
: public MingwModuleHandler
414 MingwBootProgramModuleHandler ( const Module
& module
);
415 virtual HostType
DefaultHost() { return HostFalse
; }
416 virtual void Process ();
417 std::string
GetProgTextAddrMacro ();
418 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
420 void GenerateBootProgramModuleTarget ();
424 class MingwIsoModuleHandler
: public MingwModuleHandler
427 MingwIsoModuleHandler ( const Module
& module
);
428 virtual HostType
DefaultHost() { return HostFalse
; }
429 virtual void Process ();
431 void GenerateIsoModuleTarget ();
432 void GetBootstrapCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
433 void GetNonModuleCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
434 void GetCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
435 void GetBootstrapCdFiles ( std::vector
<FileLocation
>& out
) const;
436 void GetNonModuleCdFiles ( std::vector
<FileLocation
>& out
) const;
437 void GetCdFiles ( std::vector
<FileLocation
>& out
) const;
438 void OutputBootstrapfileCopyCommands ( const std::string
& bootcdDirectory
);
439 void OutputCdfileCopyCommands ( const std::string
& bootcdDirectory
);
443 class MingwLiveIsoModuleHandler
: public MingwModuleHandler
446 MingwLiveIsoModuleHandler ( const Module
& module
);
447 virtual HostType
DefaultHost() { return HostFalse
; }
448 virtual void Process ();
450 void GenerateLiveIsoModuleTarget ();
451 void CreateDirectory ( const std::string
& directory
);
452 void OutputModuleCopyCommands ( std::string
& livecdDirectory
,
453 std::string
& livecdReactos
);
454 void OutputNonModuleCopyCommands ( std::string
& livecdDirectory
,
455 std::string
& livecdReactos
);
456 void OutputProfilesDirectoryCommands ( std::string
& livecdDirectory
);
457 void OutputLoaderCommands ( std::string
& livecdDirectory
);
458 void OutputRegistryCommands ( std::string
& livecdDirectory
);
462 class MingwTestModuleHandler
: public MingwModuleHandler
465 MingwTestModuleHandler ( const Module
& module
);
466 virtual HostType
DefaultHost() { return HostFalse
; }
467 virtual void Process ();
468 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
470 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
472 void GenerateTestModuleTarget ();
476 class MingwRpcServerModuleHandler
: public MingwModuleHandler
479 MingwRpcServerModuleHandler ( const Module
& module
);
480 virtual HostType
DefaultHost() { return HostFalse
; }
481 virtual void Process ();
485 class MingwRpcClientModuleHandler
: public MingwModuleHandler
488 MingwRpcClientModuleHandler ( const Module
& module
);
489 virtual HostType
DefaultHost() { return HostFalse
; }
490 virtual void Process ();
493 class MingwAliasModuleHandler
: public MingwModuleHandler
496 MingwAliasModuleHandler ( const Module
& module
);
497 virtual HostType
DefaultHost() { return HostFalse
; }
498 virtual void Process ();
501 class MingwIdlHeaderModuleHandler
: public MingwModuleHandler
504 MingwIdlHeaderModuleHandler ( const Module
& module
);
505 virtual HostType
DefaultHost() { return HostFalse
; }
506 virtual void Process ();
509 class MingwEmbeddedTypeLibModuleHandler
: public MingwModuleHandler
512 MingwEmbeddedTypeLibModuleHandler ( const Module
& module
);
513 virtual HostType
DefaultHost() { return HostFalse
; }
514 virtual void Process ();
517 class MingwElfExecutableModuleHandler
: public MingwModuleHandler
520 MingwElfExecutableModuleHandler ( const Module
& module
);
521 virtual HostType
DefaultHost() { return HostFalse
; }
522 virtual void Process ();
525 #endif /* MINGW_MODULEHANDLER_H */