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 CompilerType type
) 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 const std::string
& GetWidlFlags ( const CompilationUnit
& compilationUnit
);
159 void GenerateWidlCommandsServer (
160 const CompilationUnit
& compilationUnit
,
161 const std::string
& widlflagsMacro
);
162 void GenerateWidlCommandsClient (
163 const CompilationUnit
& compilationUnit
,
164 const std::string
& widlflagsMacro
);
165 void GenerateWidlCommandsProxy (
166 const CompilationUnit
& compilationUnit
,
167 const std::string
& widlflagsMacro
);
168 void GenerateWidlCommandsIdlHeader (
169 const CompilationUnit
& compilationUnit
,
170 const std::string
& widlflagsMacro
);
171 void GenerateWidlCommandsEmbeddedTypeLib (
172 const CompilationUnit
& compilationUnit
,
173 const std::string
& widlflagsMacro
);
174 void GenerateWidlCommands ( const CompilationUnit
& compilationUnit
,
175 const std::string
& widlflagsMacro
);
176 void GenerateCommands ( const CompilationUnit
& compilationUnit
,
177 const std::string
& extraDependencies
,
178 const std::string
& cc
,
179 const std::string
& cppc
,
180 const std::string
& cflagsMacro
,
181 const std::string
& nasmflagsMacro
,
182 const std::string
& windresflagsMacro
,
183 const std::string
& widlflagsMacro
);
184 void GenerateObjectFileTargets ( const IfableData
& data
,
185 const std::string
& cc
,
186 const std::string
& cppc
,
187 const std::string
& cflagsMacro
,
188 const std::string
& nasmflagsMacro
,
189 const std::string
& windresflagsMacro
,
190 const std::string
& widlflagsMacro
);
191 void GenerateObjectFileTargets ( 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 const FileLocation
* GenerateArchiveTarget ( const std::string
& ar
,
198 const std::string
& objs_macro
) const;
199 void GetMcObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
200 const FileLocation
*file
) const;
201 void GetSpecObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
202 const FileLocation
*file
) const;
203 void GetWidlObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
204 const FileLocation
*file
) const;
205 void GetDefaultDependencies ( string_list
& dependencies
) const;
206 void GetInvocationDependencies ( const Module
& module
, string_list
& dependencies
);
207 bool IsWineModule () const;
208 const FileLocation
* GetDefinitionFilename () const;
209 void GenerateBuildNonSymbolStrippedCode ();
210 void CleanupCompilationUnitVector ( std::vector
<CompilationUnit
*>& compilationUnits
);
211 void GetRpcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
212 void GetMcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
213 static std::string
GetPropertyValue ( const Module
& module
, const std::string
& name
);
214 const FileLocation
* GetRpcServerHeaderFilename ( const FileLocation
*base
) const;
215 const FileLocation
* GetRpcClientHeaderFilename ( const FileLocation
*base
) const;
216 const FileLocation
* GetRpcProxyHeaderFilename ( const FileLocation
*base
) const;
217 const FileLocation
* GetIdlHeaderFilename ( const FileLocation
*base
) const;
218 const FileLocation
* GetMcHeaderFilename ( const FileLocation
*base
) const;
219 std::string
GetModuleCleanTarget ( const Module
& module
) const;
220 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector
<std::string
>& moduleNames
) const;
222 const Module
& module
;
223 string_list clean_files
;
224 std::string cflagsMacro
;
225 std::string nasmflagsMacro
;
226 std::string windresflagsMacro
;
227 std::string widlflagsMacro
;
228 std::string linkerflagsMacro
;
229 std::string sourcesMacro
;
230 std::string objectsMacro
;
231 std::string libsMacro
;
232 std::string linkDepsMacro
;
236 class MingwBuildToolModuleHandler
: public MingwModuleHandler
239 MingwBuildToolModuleHandler ( const Module
& module
);
240 virtual HostType
DefaultHost() { return HostTrue
; }
241 virtual void Process ();
243 void GenerateBuildToolModuleTarget ();
247 class MingwKernelModuleHandler
: public MingwModuleHandler
250 MingwKernelModuleHandler ( const Module
& module
);
251 virtual HostType
DefaultHost() { return HostFalse
; }
252 virtual void Process ();
254 void GenerateKernelModuleTarget ();
258 class MingwStaticLibraryModuleHandler
: public MingwModuleHandler
261 MingwStaticLibraryModuleHandler ( const Module
& module
);
262 virtual HostType
DefaultHost() { return HostFalse
; }
263 virtual void Process ();
265 void GenerateStaticLibraryModuleTarget ();
269 class MingwObjectLibraryModuleHandler
: public MingwModuleHandler
272 MingwObjectLibraryModuleHandler ( const Module
& module
);
273 virtual HostType
DefaultHost() { return HostFalse
; }
274 virtual void Process ();
276 void GenerateObjectLibraryModuleTarget ();
280 class MingwKernelModeDLLModuleHandler
: public MingwModuleHandler
283 MingwKernelModeDLLModuleHandler ( const Module
& module
);
284 virtual HostType
DefaultHost() { return HostFalse
; }
285 virtual void Process ();
286 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
287 void AddImplicitLibraries ( Module
& module
);
289 void GenerateKernelModeDLLModuleTarget ();
293 class MingwKernelModeDriverModuleHandler
: public MingwModuleHandler
296 MingwKernelModeDriverModuleHandler ( const Module
& module
);
297 virtual HostType
DefaultHost() { return HostFalse
; }
298 virtual void Process ();
299 std::string
TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
300 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
301 void AddImplicitLibraries ( Module
& module
);
303 void GenerateKernelModeDriverModuleTarget ();
307 class MingwNativeDLLModuleHandler
: public MingwModuleHandler
310 MingwNativeDLLModuleHandler ( const Module
& module
);
311 virtual HostType
DefaultHost() { return HostFalse
; }
312 virtual void Process ();
313 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
314 void AddImplicitLibraries ( Module
& module
);
316 void GenerateNativeDLLModuleTarget ();
320 class MingwNativeCUIModuleHandler
: public MingwModuleHandler
323 MingwNativeCUIModuleHandler ( const Module
& module
);
324 virtual HostType
DefaultHost() { return HostFalse
; }
325 virtual void Process ();
326 std::string
TypeSpecificCFlags() { return "-D__NTAPP__"; }
327 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
328 void AddImplicitLibraries ( Module
& module
);
330 void GenerateNativeCUIModuleTarget ();
334 class MingwWin32DLLModuleHandler
: public MingwModuleHandler
337 MingwWin32DLLModuleHandler ( const Module
& module
);
338 virtual HostType
DefaultHost() { return HostFalse
; }
339 virtual void Process ();
340 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
341 void AddImplicitLibraries ( Module
& module
);
343 void GenerateWin32DLLModuleTarget ();
347 class MingwWin32OCXModuleHandler
: public MingwModuleHandler
350 MingwWin32OCXModuleHandler ( const Module
& module
);
351 virtual HostType
DefaultHost() { return HostFalse
; }
352 virtual void Process ();
353 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
354 void AddImplicitLibraries ( Module
& module
);
356 void GenerateWin32OCXModuleTarget ();
360 class MingwWin32CUIModuleHandler
: public MingwModuleHandler
363 MingwWin32CUIModuleHandler ( const Module
& module
);
364 virtual HostType
DefaultHost() { return HostFalse
; }
365 virtual void Process ();
366 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
367 void AddImplicitLibraries ( Module
& module
);
369 void GenerateWin32CUIModuleTarget ();
373 class MingwWin32GUIModuleHandler
: public MingwModuleHandler
376 MingwWin32GUIModuleHandler ( const Module
& module
);
377 virtual HostType
DefaultHost() { return HostFalse
; }
378 virtual void Process ();
379 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
380 void AddImplicitLibraries ( Module
& module
);
382 void GenerateWin32GUIModuleTarget ();
386 class MingwBootLoaderModuleHandler
: public MingwModuleHandler
389 MingwBootLoaderModuleHandler ( const Module
& module
);
390 virtual HostType
DefaultHost() { return HostFalse
; }
391 virtual void Process ();
392 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
394 void GenerateBootLoaderModuleTarget ();
398 class MingwBootSectorModuleHandler
: public MingwModuleHandler
401 MingwBootSectorModuleHandler ( const Module
& module
);
402 virtual HostType
DefaultHost() { return HostFalse
; }
403 virtual void Process ();
404 std::string
TypeSpecificNasmFlags() { return "-f bin"; }
406 void GenerateBootSectorModuleTarget ();
410 class MingwBootProgramModuleHandler
: public MingwModuleHandler
413 MingwBootProgramModuleHandler ( const Module
& module
);
414 virtual HostType
DefaultHost() { return HostFalse
; }
415 virtual void Process ();
416 std::string
GetProgTextAddrMacro ();
417 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
419 void GenerateBootProgramModuleTarget ();
423 class MingwIsoModuleHandler
: public MingwModuleHandler
426 MingwIsoModuleHandler ( const Module
& module
);
427 virtual HostType
DefaultHost() { return HostFalse
; }
428 virtual void Process ();
430 void GenerateIsoModuleTarget ();
431 void GetBootstrapCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
432 void GetNonModuleCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
433 void GetCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
434 void GetBootstrapCdFiles ( std::vector
<FileLocation
>& out
) const;
435 void GetNonModuleCdFiles ( std::vector
<FileLocation
>& out
) const;
436 void GetCdFiles ( std::vector
<FileLocation
>& out
) const;
437 void OutputBootstrapfileCopyCommands ( const std::string
& bootcdDirectory
);
438 void OutputCdfileCopyCommands ( const std::string
& bootcdDirectory
);
442 class MingwLiveIsoModuleHandler
: public MingwModuleHandler
445 MingwLiveIsoModuleHandler ( const Module
& module
);
446 virtual HostType
DefaultHost() { return HostFalse
; }
447 virtual void Process ();
449 void GenerateLiveIsoModuleTarget ();
450 void CreateDirectory ( const std::string
& directory
);
451 void OutputModuleCopyCommands ( std::string
& livecdDirectory
,
452 std::string
& livecdReactos
);
453 void OutputNonModuleCopyCommands ( std::string
& livecdDirectory
,
454 std::string
& livecdReactos
);
455 void OutputProfilesDirectoryCommands ( std::string
& livecdDirectory
);
456 void OutputLoaderCommands ( std::string
& livecdDirectory
);
457 void OutputRegistryCommands ( std::string
& livecdDirectory
);
461 class MingwTestModuleHandler
: public MingwModuleHandler
464 MingwTestModuleHandler ( const Module
& module
);
465 virtual HostType
DefaultHost() { return HostFalse
; }
466 virtual void Process ();
467 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
469 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
471 void GenerateTestModuleTarget ();
475 class MingwRpcServerModuleHandler
: public MingwModuleHandler
478 MingwRpcServerModuleHandler ( const Module
& module
);
479 virtual HostType
DefaultHost() { return HostFalse
; }
480 virtual void Process ();
484 class MingwRpcClientModuleHandler
: public MingwModuleHandler
487 MingwRpcClientModuleHandler ( const Module
& module
);
488 virtual HostType
DefaultHost() { return HostFalse
; }
489 virtual void Process ();
493 class MingwRpcProxyModuleHandler
: public MingwModuleHandler
496 MingwRpcProxyModuleHandler ( const Module
& module
);
497 virtual HostType
DefaultHost() { return HostFalse
; }
498 virtual void Process ();
502 class MingwAliasModuleHandler
: public MingwModuleHandler
505 MingwAliasModuleHandler ( const Module
& module
);
506 virtual HostType
DefaultHost() { return HostFalse
; }
507 virtual void Process ();
510 class MingwIdlHeaderModuleHandler
: public MingwModuleHandler
513 MingwIdlHeaderModuleHandler ( const Module
& module
);
514 virtual HostType
DefaultHost() { return HostFalse
; }
515 virtual void Process ();
518 class MingwEmbeddedTypeLibModuleHandler
: public MingwModuleHandler
521 MingwEmbeddedTypeLibModuleHandler ( const Module
& module
);
522 virtual HostType
DefaultHost() { return HostFalse
; }
523 virtual void Process ();
526 class MingwElfExecutableModuleHandler
: public MingwModuleHandler
529 MingwElfExecutableModuleHandler ( const Module
& module
);
530 virtual HostType
DefaultHost() { return HostFalse
; }
531 virtual void Process ();
534 #endif /* MINGW_MODULEHANDLER_H */