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"
28 GetTargetMacro ( const Module
&, bool with_dollar
= true );
32 const std::string
& filename
,
33 const std::string
& prefix
);
35 class MingwModuleHandler
38 MingwModuleHandler ( const Module
& module_
);
39 virtual ~MingwModuleHandler();
41 static void SetBackend ( MingwBackend
* backend_
);
42 static void SetMakefile ( FILE* f
);
43 void EnablePreCompiledHeaderSupport ();
45 static const FileLocation
* PassThruCacheDirectory (const FileLocation
* fileLocation
);
47 static const FileLocation
* GetTargetFilename (
49 string_list
* pclean_files
);
51 static const FileLocation
* GetImportLibraryFilename (
53 string_list
* pclean_files
);
55 static std::string
GenerateGccDefineParametersFromVector ( const std::vector
<Define
*>& defines
, std::set
<std::string
> &used_defs
);
56 static std::string
GenerateGccIncludeParametersFromVector ( const std::vector
<Include
*>& includes
);
58 std::string
GetModuleTargets ( const Module
& module
);
59 void GetObjectsVector ( const IfableData
& data
,
60 std::vector
<FileLocation
>& objectFiles
) const;
61 void GenerateSourceMacro();
62 void GenerateObjectMacro();
63 void GenerateTargetMacro();
64 void GenerateOtherMacros();
66 static MingwModuleHandler
* InstanciateHandler ( const Module
& module_
,
67 MingwBackend
* backend_
);
68 virtual HostType
DefaultHost() = 0;
69 void GeneratePreconditionDependencies ();
70 virtual void Process () = 0;
71 virtual std::string
TypeSpecificCFlags() { return ""; }
72 virtual std::string
TypeSpecificNasmFlags() { return ""; }
73 virtual std::string
TypeSpecificLinkerFlags() { return ""; }
74 void GenerateInvocations () const;
75 void GenerateCleanTarget () const;
76 void GenerateInstallTarget () const;
77 void GenerateDependsTarget () const;
78 static bool ReferenceObjects ( const Module
& module
);
79 virtual void AddImplicitLibraries ( Module
& module
) { return; }
81 void OutputCopyCommand ( const FileLocation
& source
,
82 const FileLocation
& destination
);
84 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
85 std::string
GetWorkingDirectory () const;
86 std::string
GetBasename ( const std::string
& filename
) const;
87 const FileLocation
* GetActualSourceFilename ( const FileLocation
* file
) const;
88 std::string
GetExtraDependencies ( const FileLocation
*file
) const;
89 std::string
GetCompilationUnitDependencies ( const CompilationUnit
& compilationUnit
) const;
90 const FileLocation
* GetModuleArchiveFilename () const;
91 bool IsGeneratedFile ( const File
& file
) const;
92 std::string
GetImportLibraryDependency ( const Module
& importedModule
);
93 void GetTargets ( const Module
& dependencyModule
,
94 string_list
& targets
);
95 void GetModuleDependencies ( string_list
& dependencies
);
96 std::string
GetAllDependencies () const;
97 void GetSourceFilenames ( std::vector
<FileLocation
>& list
,
98 bool includeGeneratedFiles
) const;
99 void GetSourceFilenamesWithoutGeneratedFiles ( std::vector
<FileLocation
>& list
) const;
100 const FileLocation
* GetObjectFilename ( const FileLocation
* sourceFile
,
101 const Module
& module
) 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
& linkerParameters
,
116 const std::string
& pefixupParameters
);
117 void GeneratePhonyTarget() const;
118 void GenerateBuildMapCode ( const FileLocation
*mapTarget
= NULL
);
119 void GenerateRules ();
120 void GenerateImportLibraryTargetIfNeeded ();
121 void GetDefinitionDependencies ( std::vector
<FileLocation
>& dependencies
) const;
122 std::string
GetLinkingDependencies () const;
123 static MingwBackend
* backend
;
124 static FILE* fMakefile
;
127 std::string
ConcatenatePaths ( const std::string
& path1
,
128 const std::string
& path2
) const;
129 std::string
GenerateGccDefineParameters () const;
130 std::string
GenerateCompilerParametersFromVector ( const std::vector
<CompilerFlag
*>& compilerFlags
, const CompilerType type
) const;
131 std::string
GenerateLinkerParametersFromVector ( const std::vector
<LinkerFlag
*>& linkerFlags
) const;
132 std::string
GenerateImportLibraryDependenciesFromVector ( const std::vector
<Library
*>& libraries
);
133 std::string
GenerateLinkerParameters () const;
134 void GenerateMacro ( const char* assignmentOperation
,
135 const std::string
& macro
,
136 const IfableData
& data
,
137 std::set
<const Define
*>* used_defs
,
138 bool generatingCompilerMacro
);
139 void GenerateMacros ( const char* op
,
140 const IfableData
& data
,
141 const std::vector
<LinkerFlag
*>* linkerFlags
,
142 std::set
<const Define
*>& used_defs
);
143 void GenerateSourceMacros ( const char* assignmentOperation
,
144 const IfableData
& data
);
145 void GenerateObjectMacros ( const char* assignmentOperation
,
146 const IfableData
& data
);
147 std::string
GenerateGccIncludeParameters () const;
148 std::string
GenerateGccParameters () const;
149 std::string
GenerateNasmParameters () const;
150 const FileLocation
* GetPrecompiledHeaderFilename () const;
151 void GenerateGccCommand ( const FileLocation
* sourceFile
,
153 const std::string
& extraDependencies
);
154 void GenerateCommands ( const CompilationUnit
& compilationUnit
,
155 const std::string
& extraDependencies
);
156 void GenerateObjectFileTargets ( const IfableData
& data
);
157 void GenerateObjectFileTargets ();
158 const FileLocation
* GenerateArchiveTarget ();
159 void GetMcObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
160 const FileLocation
*file
) const;
161 void GetSpecObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
162 const FileLocation
*file
) const;
163 void GetWidlObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
164 const FileLocation
*file
) const;
165 void GetDefaultDependencies ( string_list
& dependencies
) const;
166 void GetInvocationDependencies ( const Module
& module
, string_list
& dependencies
);
167 bool IsWineModule () const;
168 const FileLocation
* GetDefinitionFilename () const;
169 void GenerateBuildNonSymbolStrippedCode ();
170 void CleanupCompilationUnitVector ( std::vector
<CompilationUnit
*>& compilationUnits
);
171 void GetRpcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
172 void GetMcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
173 static std::string
GetPropertyValue ( const Module
& module
, const std::string
& name
);
174 const FileLocation
* GetRpcServerHeaderFilename ( const FileLocation
*base
) const;
175 const FileLocation
* GetRpcClientHeaderFilename ( const FileLocation
*base
) const;
176 const FileLocation
* GetRpcProxyHeaderFilename ( const FileLocation
*base
) const;
177 const FileLocation
* GetIdlHeaderFilename ( const FileLocation
*base
) const;
178 const FileLocation
* GetMcHeaderFilename ( const FileLocation
*base
) const;
179 std::string
GetModuleCleanTarget ( const Module
& module
) const;
180 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector
<std::string
>& moduleNames
) const;
182 const Module
& module
;
183 string_list clean_files
;
184 std::string cflagsMacro
;
185 std::string nasmflagsMacro
;
186 std::string windresflagsMacro
;
187 std::string widlflagsMacro
;
188 std::string linkerflagsMacro
;
189 std::string sourcesMacro
;
190 std::string objectsMacro
;
191 std::string libsMacro
;
192 std::string linkDepsMacro
;
196 class MingwBuildToolModuleHandler
: public MingwModuleHandler
199 MingwBuildToolModuleHandler ( const Module
& module
);
200 virtual HostType
DefaultHost() { return HostTrue
; }
201 virtual void Process ();
203 void GenerateBuildToolModuleTarget ();
207 class MingwKernelModuleHandler
: public MingwModuleHandler
210 MingwKernelModuleHandler ( const Module
& module
);
211 virtual HostType
DefaultHost() { return HostFalse
; }
212 virtual void Process ();
214 void GenerateKernelModuleTarget ();
218 class MingwStaticLibraryModuleHandler
: public MingwModuleHandler
221 MingwStaticLibraryModuleHandler ( const Module
& module
);
222 virtual HostType
DefaultHost() { return HostFalse
; }
223 virtual void Process ();
225 void GenerateStaticLibraryModuleTarget ();
229 class MingwHostStaticLibraryModuleHandler
: public MingwModuleHandler
232 MingwHostStaticLibraryModuleHandler ( const Module
& module
);
233 virtual HostType
DefaultHost() { return HostTrue
; }
234 virtual void Process ();
236 void GenerateHostStaticLibraryModuleTarget ();
240 class MingwObjectLibraryModuleHandler
: public MingwModuleHandler
243 MingwObjectLibraryModuleHandler ( const Module
& module
);
244 virtual HostType
DefaultHost() { return HostFalse
; }
245 virtual void Process ();
247 void GenerateObjectLibraryModuleTarget ();
251 class MingwKernelModeDLLModuleHandler
: public MingwModuleHandler
254 MingwKernelModeDLLModuleHandler ( const Module
& module
);
255 virtual HostType
DefaultHost() { return HostFalse
; }
256 virtual void Process ();
257 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
258 void AddImplicitLibraries ( Module
& module
);
260 void GenerateKernelModeDLLModuleTarget ();
264 class MingwKernelModeDriverModuleHandler
: public MingwModuleHandler
267 MingwKernelModeDriverModuleHandler ( const Module
& module
);
268 virtual HostType
DefaultHost() { return HostFalse
; }
269 virtual void Process ();
270 std::string
TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
271 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
272 void AddImplicitLibraries ( Module
& module
);
274 void GenerateKernelModeDriverModuleTarget ();
278 class MingwNativeDLLModuleHandler
: public MingwModuleHandler
281 MingwNativeDLLModuleHandler ( const Module
& module
);
282 virtual HostType
DefaultHost() { return HostFalse
; }
283 virtual void Process ();
284 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
285 void AddImplicitLibraries ( Module
& module
);
287 void GenerateNativeDLLModuleTarget ();
291 class MingwNativeCUIModuleHandler
: public MingwModuleHandler
294 MingwNativeCUIModuleHandler ( const Module
& module
);
295 virtual HostType
DefaultHost() { return HostFalse
; }
296 virtual void Process ();
297 std::string
TypeSpecificCFlags() { return "-D__NTAPP__"; }
298 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
299 void AddImplicitLibraries ( Module
& module
);
301 void GenerateNativeCUIModuleTarget ();
305 class MingwWin32DLLModuleHandler
: public MingwModuleHandler
308 MingwWin32DLLModuleHandler ( const Module
& module
);
309 virtual HostType
DefaultHost() { return HostFalse
; }
310 virtual void Process ();
311 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
312 void AddImplicitLibraries ( Module
& module
);
314 void GenerateWin32DLLModuleTarget ();
318 class MingwWin32OCXModuleHandler
: public MingwModuleHandler
321 MingwWin32OCXModuleHandler ( const Module
& module
);
322 virtual HostType
DefaultHost() { return HostFalse
; }
323 virtual void Process ();
324 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
325 void AddImplicitLibraries ( Module
& module
);
327 void GenerateWin32OCXModuleTarget ();
331 class MingwWin32CUIModuleHandler
: public MingwModuleHandler
334 MingwWin32CUIModuleHandler ( const Module
& module
);
335 virtual HostType
DefaultHost() { return HostFalse
; }
336 virtual void Process ();
337 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
338 void AddImplicitLibraries ( Module
& module
);
340 void GenerateWin32CUIModuleTarget ();
344 class MingwWin32GUIModuleHandler
: public MingwModuleHandler
347 MingwWin32GUIModuleHandler ( const Module
& module
);
348 virtual HostType
DefaultHost() { return HostFalse
; }
349 virtual void Process ();
350 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
351 void AddImplicitLibraries ( Module
& module
);
353 void GenerateWin32GUIModuleTarget ();
357 class MingwBootLoaderModuleHandler
: public MingwModuleHandler
360 MingwBootLoaderModuleHandler ( const Module
& module
);
361 virtual HostType
DefaultHost() { return HostFalse
; }
362 virtual void Process ();
363 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
365 void GenerateBootLoaderModuleTarget ();
369 class MingwBootSectorModuleHandler
: public MingwModuleHandler
372 MingwBootSectorModuleHandler ( const Module
& module
);
373 virtual HostType
DefaultHost() { return HostFalse
; }
374 virtual void Process ();
375 std::string
TypeSpecificNasmFlags() { return "-f bin"; }
377 void GenerateBootSectorModuleTarget ();
381 class MingwBootProgramModuleHandler
: public MingwModuleHandler
384 MingwBootProgramModuleHandler ( const Module
& module
);
385 virtual HostType
DefaultHost() { return HostFalse
; }
386 virtual void Process ();
387 std::string
GetProgTextAddrMacro ();
388 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
390 void GenerateBootProgramModuleTarget ();
394 class MingwIsoModuleHandler
: public MingwModuleHandler
397 MingwIsoModuleHandler ( const Module
& module
);
398 virtual HostType
DefaultHost() { return HostFalse
; }
399 virtual void Process ();
401 void GenerateIsoModuleTarget ();
402 void GetBootstrapCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
403 void GetNonModuleCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
404 void GetCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
405 void GetBootstrapCdFiles ( std::vector
<FileLocation
>& out
) const;
406 void GetNonModuleCdFiles ( std::vector
<FileLocation
>& out
) const;
407 void GetCdFiles ( std::vector
<FileLocation
>& out
) const;
408 void OutputBootstrapfileCopyCommands ( const std::string
& bootcdDirectory
);
409 void OutputCdfileCopyCommands ( const std::string
& bootcdDirectory
);
413 class MingwLiveIsoModuleHandler
: public MingwModuleHandler
416 MingwLiveIsoModuleHandler ( const Module
& module
);
417 virtual HostType
DefaultHost() { return HostFalse
; }
418 virtual void Process ();
420 void GenerateLiveIsoModuleTarget ();
421 void CreateDirectory ( const std::string
& directory
);
422 void OutputModuleCopyCommands ( std::string
& livecdDirectory
,
423 std::string
& livecdReactos
);
424 void OutputNonModuleCopyCommands ( std::string
& livecdDirectory
,
425 std::string
& livecdReactos
);
426 void OutputProfilesDirectoryCommands ( std::string
& livecdDirectory
);
427 void OutputLoaderCommands ( std::string
& livecdDirectory
);
428 void OutputRegistryCommands ( std::string
& livecdDirectory
);
432 class MingwTestModuleHandler
: public MingwModuleHandler
435 MingwTestModuleHandler ( const Module
& module
);
436 virtual HostType
DefaultHost() { return HostFalse
; }
437 virtual void Process ();
438 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
440 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
442 void GenerateTestModuleTarget ();
446 class MingwRpcServerModuleHandler
: public MingwModuleHandler
449 MingwRpcServerModuleHandler ( const Module
& module
);
450 virtual HostType
DefaultHost() { return HostFalse
; }
451 virtual void Process ();
455 class MingwRpcClientModuleHandler
: public MingwModuleHandler
458 MingwRpcClientModuleHandler ( const Module
& module
);
459 virtual HostType
DefaultHost() { return HostFalse
; }
460 virtual void Process ();
464 class MingwRpcProxyModuleHandler
: public MingwModuleHandler
467 MingwRpcProxyModuleHandler ( const Module
& module
);
468 virtual HostType
DefaultHost() { return HostFalse
; }
469 virtual void Process ();
473 class MingwAliasModuleHandler
: public MingwModuleHandler
476 MingwAliasModuleHandler ( const Module
& module
);
477 virtual HostType
DefaultHost() { return HostFalse
; }
478 virtual void Process ();
481 class MingwIdlHeaderModuleHandler
: public MingwModuleHandler
484 MingwIdlHeaderModuleHandler ( const Module
& module
);
485 virtual HostType
DefaultHost() { return HostFalse
; }
486 virtual void Process ();
489 class MingwEmbeddedTypeLibModuleHandler
: public MingwModuleHandler
492 MingwEmbeddedTypeLibModuleHandler ( const Module
& module
);
493 virtual HostType
DefaultHost() { return HostFalse
; }
494 virtual void Process ();
497 class MingwElfExecutableModuleHandler
: public MingwModuleHandler
500 MingwElfExecutableModuleHandler ( const Module
& module
);
501 virtual HostType
DefaultHost() { return HostFalse
; }
502 virtual void Process ();
505 #endif /* MINGW_MODULEHANDLER_H */