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 string_list
* pclean_files
) const;
102 std::string
GetObjectFilenames ();
104 std::string
GetPreconditionDependenciesName () const;
105 std::string
GetCFlagsMacro () const;
106 static std::string
GetObjectsMacro ( const Module
& );
107 std::string
GetLinkingDependenciesMacro () const;
108 std::string
GetLibsMacro () const;
109 std::string
GetLinkerMacro () const;
110 void GenerateCleanObjectsAsYouGoCode () const;
111 void GenerateRunRsymCode () const;
112 void GenerateRunStripCode () const;
113 void GenerateLinkerCommand ( const std::string
& dependencies
,
114 const std::string
& linker
,
115 const std::string
& linkerParameters
,
116 const std::string
& objectsMacro
,
117 const std::string
& libsMacro
,
118 const std::string
& pefixupParameters
);
119 void GeneratePhonyTarget() const;
120 void GenerateBuildMapCode ( const FileLocation
*mapTarget
= NULL
);
121 void GenerateRules ();
122 void GenerateImportLibraryTargetIfNeeded ();
123 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
<std::string
>* used_defs
);
141 void GenerateMacros ( const char* op
,
142 const IfableData
& data
,
143 const std::vector
<LinkerFlag
*>* linkerFlags
,
144 std::set
<std::string
>& used_defs
);
145 void GenerateSourceMacros ( const char* assignmentOperation
,
146 const IfableData
& data
);
147 void GenerateObjectMacros ( const char* assignmentOperation
,
148 const IfableData
& data
);
149 std::string
GenerateGccIncludeParameters () const;
150 std::string
GenerateGccParameters () const;
151 std::string
GenerateNasmParameters () const;
152 const FileLocation
* GetPrecompiledHeaderFilename () const;
153 void GenerateGccCommand ( const FileLocation
* sourceFile
,
154 const std::string
& extraDependencies
,
155 const std::string
& cc
,
156 const std::string
& cflagsMacro
);
157 void GenerateGccAssemblerCommand ( const FileLocation
* sourceFile
,
158 const std::string
& cc
,
159 const std::string
& cflagsMacro
);
160 void GenerateNasmCommand ( const FileLocation
* sourceFile
,
161 const std::string
& nasmflagsMacro
);
162 void GenerateWindresCommand ( const FileLocation
* sourceFile
,
163 const std::string
& windresflagsMacro
);
164 void GenerateWinebuildCommands ( const FileLocation
* sourceFile
);
165 std::string
GetWidlFlags ( const CompilationUnit
& compilationUnit
);
166 void GenerateWidlCommandsServer (
167 const CompilationUnit
& compilationUnit
,
168 const std::string
& widlflagsMacro
);
169 void GenerateWidlCommandsClient (
170 const CompilationUnit
& compilationUnit
,
171 const std::string
& widlflagsMacro
);
172 void GenerateWidlCommandsIdlHeader (
173 const CompilationUnit
& compilationUnit
,
174 const std::string
& widlflagsMacro
);
175 void GenerateWidlCommandsEmbeddedTypeLib (
176 const CompilationUnit
& compilationUnit
,
177 const std::string
& widlflagsMacro
);
178 void GenerateWidlCommands ( const CompilationUnit
& compilationUnit
,
179 const std::string
& widlflagsMacro
);
180 void GenerateCommands ( const CompilationUnit
& compilationUnit
,
181 const std::string
& extraDependencies
,
182 const std::string
& cc
,
183 const std::string
& cppc
,
184 const std::string
& cflagsMacro
,
185 const std::string
& nasmflagsMacro
,
186 const std::string
& windresflagsMacro
,
187 const std::string
& widlflagsMacro
);
188 void GenerateObjectFileTargets ( const IfableData
& data
,
189 const std::string
& cc
,
190 const std::string
& cppc
,
191 const std::string
& cflagsMacro
,
192 const std::string
& nasmflagsMacro
,
193 const std::string
& windresflagsMacro
,
194 const std::string
& widlflagsMacro
);
195 void GenerateObjectFileTargets ( const std::string
& cc
,
196 const std::string
& cppc
,
197 const std::string
& cflagsMacro
,
198 const std::string
& nasmflagsMacro
,
199 const std::string
& windresflagsMacro
,
200 const std::string
& widlflagsMacro
);
201 const FileLocation
* GenerateArchiveTarget ( const std::string
& ar
,
202 const std::string
& objs_macro
) const;
203 void GetSpecObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
204 const FileLocation
*file
) const;
205 void GetWidlObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
206 const FileLocation
*file
) const;
207 void GetDefaultDependencies ( string_list
& dependencies
) const;
208 void GetInvocationDependencies ( const Module
& module
, string_list
& dependencies
);
209 bool IsWineModule () const;
210 const FileLocation
* GetDefinitionFilename () const;
211 void GenerateBuildNonSymbolStrippedCode ();
212 void CleanupCompilationUnitVector ( std::vector
<CompilationUnit
*>& compilationUnits
);
213 void GetRpcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
214 static std::string
GetPropertyValue ( const Module
& module
, const std::string
& name
);
215 const FileLocation
* GetRpcServerHeaderFilename ( const FileLocation
*base
) const;
216 const FileLocation
* GetRpcClientHeaderFilename ( const FileLocation
*base
) const;
217 const FileLocation
* GetIdlHeaderFilename ( const FileLocation
*base
) const;
218 std::string
GetModuleCleanTarget ( const Module
& module
) const;
219 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector
<std::string
>& moduleNames
) const;
221 const Module
& module
;
222 string_list clean_files
;
223 std::string cflagsMacro
;
224 std::string nasmflagsMacro
;
225 std::string windresflagsMacro
;
226 std::string widlflagsMacro
;
227 std::string linkerflagsMacro
;
228 std::string sourcesMacro
;
229 std::string objectsMacro
;
230 std::string libsMacro
;
231 std::string linkDepsMacro
;
235 class MingwBuildToolModuleHandler
: public MingwModuleHandler
238 MingwBuildToolModuleHandler ( const Module
& module
);
239 virtual HostType
DefaultHost() { return HostTrue
; }
240 virtual void Process ();
242 void GenerateBuildToolModuleTarget ();
246 class MingwKernelModuleHandler
: public MingwModuleHandler
249 MingwKernelModuleHandler ( const Module
& module
);
250 virtual HostType
DefaultHost() { return HostFalse
; }
251 virtual void Process ();
253 void GenerateKernelModuleTarget ();
257 class MingwStaticLibraryModuleHandler
: public MingwModuleHandler
260 MingwStaticLibraryModuleHandler ( const Module
& module
);
261 virtual HostType
DefaultHost() { return HostFalse
; }
262 virtual void Process ();
264 void GenerateStaticLibraryModuleTarget ();
268 class MingwObjectLibraryModuleHandler
: public MingwModuleHandler
271 MingwObjectLibraryModuleHandler ( const Module
& module
);
272 virtual HostType
DefaultHost() { return HostFalse
; }
273 virtual void Process ();
275 void GenerateObjectLibraryModuleTarget ();
279 class MingwKernelModeDLLModuleHandler
: public MingwModuleHandler
282 MingwKernelModeDLLModuleHandler ( const Module
& module
);
283 virtual HostType
DefaultHost() { return HostFalse
; }
284 virtual void Process ();
285 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
286 void AddImplicitLibraries ( Module
& module
);
288 void GenerateKernelModeDLLModuleTarget ();
292 class MingwKernelModeDriverModuleHandler
: public MingwModuleHandler
295 MingwKernelModeDriverModuleHandler ( const Module
& module
);
296 virtual HostType
DefaultHost() { return HostFalse
; }
297 virtual void Process ();
298 std::string
TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
299 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
300 void AddImplicitLibraries ( Module
& module
);
302 void GenerateKernelModeDriverModuleTarget ();
306 class MingwNativeDLLModuleHandler
: public MingwModuleHandler
309 MingwNativeDLLModuleHandler ( const Module
& module
);
310 virtual HostType
DefaultHost() { return HostFalse
; }
311 virtual void Process ();
312 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
313 void AddImplicitLibraries ( Module
& module
);
315 void GenerateNativeDLLModuleTarget ();
319 class MingwNativeCUIModuleHandler
: public MingwModuleHandler
322 MingwNativeCUIModuleHandler ( const Module
& module
);
323 virtual HostType
DefaultHost() { return HostFalse
; }
324 virtual void Process ();
325 std::string
TypeSpecificCFlags() { return "-D__NTAPP__"; }
326 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
327 void AddImplicitLibraries ( Module
& module
);
329 void GenerateNativeCUIModuleTarget ();
333 class MingwWin32DLLModuleHandler
: public MingwModuleHandler
336 MingwWin32DLLModuleHandler ( const Module
& module
);
337 virtual HostType
DefaultHost() { return HostFalse
; }
338 virtual void Process ();
339 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
340 void AddImplicitLibraries ( Module
& module
);
342 void GenerateWin32DLLModuleTarget ();
346 class MingwWin32OCXModuleHandler
: public MingwModuleHandler
349 MingwWin32OCXModuleHandler ( const Module
& module
);
350 virtual HostType
DefaultHost() { return HostFalse
; }
351 virtual void Process ();
352 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
353 void AddImplicitLibraries ( Module
& module
);
355 void GenerateWin32OCXModuleTarget ();
359 class MingwWin32CUIModuleHandler
: public MingwModuleHandler
362 MingwWin32CUIModuleHandler ( const Module
& module
);
363 virtual HostType
DefaultHost() { return HostFalse
; }
364 virtual void Process ();
365 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
366 void AddImplicitLibraries ( Module
& module
);
368 void GenerateWin32CUIModuleTarget ();
372 class MingwWin32GUIModuleHandler
: public MingwModuleHandler
375 MingwWin32GUIModuleHandler ( const Module
& module
);
376 virtual HostType
DefaultHost() { return HostFalse
; }
377 virtual void Process ();
378 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
379 void AddImplicitLibraries ( Module
& module
);
381 void GenerateWin32GUIModuleTarget ();
385 class MingwBootLoaderModuleHandler
: public MingwModuleHandler
388 MingwBootLoaderModuleHandler ( const Module
& module
);
389 virtual HostType
DefaultHost() { return HostFalse
; }
390 virtual void Process ();
391 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
393 void GenerateBootLoaderModuleTarget ();
397 class MingwBootSectorModuleHandler
: public MingwModuleHandler
400 MingwBootSectorModuleHandler ( const Module
& module
);
401 virtual HostType
DefaultHost() { return HostFalse
; }
402 virtual void Process ();
403 std::string
TypeSpecificNasmFlags() { return "-f bin"; }
405 void GenerateBootSectorModuleTarget ();
409 class MingwBootProgramModuleHandler
: public MingwModuleHandler
412 MingwBootProgramModuleHandler ( const Module
& module
);
413 virtual HostType
DefaultHost() { return HostFalse
; }
414 virtual void Process ();
415 std::string
GetProgTextAddrMacro ();
416 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
418 void GenerateBootProgramModuleTarget ();
422 class MingwIsoModuleHandler
: public MingwModuleHandler
425 MingwIsoModuleHandler ( const Module
& module
);
426 virtual HostType
DefaultHost() { return HostFalse
; }
427 virtual void Process ();
429 void GenerateIsoModuleTarget ();
430 void GetBootstrapCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
431 void GetNonModuleCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
432 void GetCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
433 void GetBootstrapCdFiles ( std::vector
<FileLocation
>& out
) const;
434 void GetNonModuleCdFiles ( std::vector
<FileLocation
>& out
) const;
435 void GetCdFiles ( std::vector
<FileLocation
>& out
) const;
436 void OutputBootstrapfileCopyCommands ( const std::string
& bootcdDirectory
);
437 void OutputCdfileCopyCommands ( const std::string
& bootcdDirectory
);
441 class MingwLiveIsoModuleHandler
: public MingwModuleHandler
444 MingwLiveIsoModuleHandler ( const Module
& module
);
445 virtual HostType
DefaultHost() { return HostFalse
; }
446 virtual void Process ();
448 void GenerateLiveIsoModuleTarget ();
449 void CreateDirectory ( const std::string
& directory
);
450 void OutputModuleCopyCommands ( std::string
& livecdDirectory
,
451 std::string
& livecdReactos
);
452 void OutputNonModuleCopyCommands ( std::string
& livecdDirectory
,
453 std::string
& livecdReactos
);
454 void OutputProfilesDirectoryCommands ( std::string
& livecdDirectory
);
455 void OutputLoaderCommands ( std::string
& livecdDirectory
);
456 void OutputRegistryCommands ( std::string
& livecdDirectory
);
460 class MingwTestModuleHandler
: public MingwModuleHandler
463 MingwTestModuleHandler ( const Module
& module
);
464 virtual HostType
DefaultHost() { return HostFalse
; }
465 virtual void Process ();
466 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
468 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
470 void GenerateTestModuleTarget ();
474 class MingwRpcServerModuleHandler
: public MingwModuleHandler
477 MingwRpcServerModuleHandler ( const Module
& module
);
478 virtual HostType
DefaultHost() { return HostFalse
; }
479 virtual void Process ();
483 class MingwRpcClientModuleHandler
: public MingwModuleHandler
486 MingwRpcClientModuleHandler ( const Module
& module
);
487 virtual HostType
DefaultHost() { return HostFalse
; }
488 virtual void Process ();
491 class MingwAliasModuleHandler
: public MingwModuleHandler
494 MingwAliasModuleHandler ( const Module
& module
);
495 virtual HostType
DefaultHost() { return HostFalse
; }
496 virtual void Process ();
499 class MingwIdlHeaderModuleHandler
: public MingwModuleHandler
502 MingwIdlHeaderModuleHandler ( const Module
& module
);
503 virtual HostType
DefaultHost() { return HostFalse
; }
504 virtual void Process ();
507 class MingwEmbeddedTypeLibModuleHandler
: public MingwModuleHandler
510 MingwEmbeddedTypeLibModuleHandler ( const Module
& module
);
511 virtual HostType
DefaultHost() { return HostFalse
; }
512 virtual void Process ();
515 class MingwElfExecutableModuleHandler
: public MingwModuleHandler
518 MingwElfExecutableModuleHandler ( const Module
& module
);
519 virtual HostType
DefaultHost() { return HostFalse
; }
520 virtual void Process ();
523 #endif /* MINGW_MODULEHANDLER_H */