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 void GenerateCommands ( const CompilationUnit
& compilationUnit
,
157 const std::string
& extraDependencies
);
158 void GenerateObjectFileTargets ( const IfableData
& data
);
159 void GenerateObjectFileTargets ();
160 const FileLocation
* GenerateArchiveTarget ();
161 void GetMcObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
162 const FileLocation
*file
) const;
163 void GetSpecObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
164 const FileLocation
*file
) const;
165 void GetWidlObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
166 const FileLocation
*file
) const;
167 void GetDefaultDependencies ( string_list
& dependencies
) const;
168 void GetInvocationDependencies ( const Module
& module
, string_list
& dependencies
);
169 bool IsWineModule () const;
170 const FileLocation
* GetDefinitionFilename () const;
171 void GenerateBuildNonSymbolStrippedCode ();
172 void CleanupCompilationUnitVector ( std::vector
<CompilationUnit
*>& compilationUnits
);
173 void GetRpcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
174 void GetMcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
175 static std::string
GetPropertyValue ( const Module
& module
, const std::string
& name
);
176 const FileLocation
* GetRpcServerHeaderFilename ( const FileLocation
*base
) const;
177 const FileLocation
* GetRpcClientHeaderFilename ( const FileLocation
*base
) const;
178 const FileLocation
* GetRpcProxyHeaderFilename ( const FileLocation
*base
) const;
179 const FileLocation
* GetIdlHeaderFilename ( const FileLocation
*base
) const;
180 const FileLocation
* GetMcHeaderFilename ( const FileLocation
*base
) const;
181 std::string
GetModuleCleanTarget ( const Module
& module
) const;
182 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector
<std::string
>& moduleNames
) const;
184 const Module
& module
;
185 string_list clean_files
;
186 std::string cflagsMacro
;
187 std::string nasmflagsMacro
;
188 std::string windresflagsMacro
;
189 std::string widlflagsMacro
;
190 std::string linkerflagsMacro
;
191 std::string sourcesMacro
;
192 std::string objectsMacro
;
193 std::string libsMacro
;
194 std::string linkDepsMacro
;
198 class MingwBuildToolModuleHandler
: public MingwModuleHandler
201 MingwBuildToolModuleHandler ( const Module
& module
);
202 virtual HostType
DefaultHost() { return HostTrue
; }
203 virtual void Process ();
205 void GenerateBuildToolModuleTarget ();
209 class MingwKernelModuleHandler
: public MingwModuleHandler
212 MingwKernelModuleHandler ( const Module
& module
);
213 virtual HostType
DefaultHost() { return HostFalse
; }
214 virtual void Process ();
216 void GenerateKernelModuleTarget ();
220 class MingwStaticLibraryModuleHandler
: public MingwModuleHandler
223 MingwStaticLibraryModuleHandler ( const Module
& module
);
224 virtual HostType
DefaultHost() { return HostFalse
; }
225 virtual void Process ();
227 void GenerateStaticLibraryModuleTarget ();
231 class MingwObjectLibraryModuleHandler
: public MingwModuleHandler
234 MingwObjectLibraryModuleHandler ( const Module
& module
);
235 virtual HostType
DefaultHost() { return HostFalse
; }
236 virtual void Process ();
238 void GenerateObjectLibraryModuleTarget ();
242 class MingwKernelModeDLLModuleHandler
: public MingwModuleHandler
245 MingwKernelModeDLLModuleHandler ( const Module
& module
);
246 virtual HostType
DefaultHost() { return HostFalse
; }
247 virtual void Process ();
248 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
249 void AddImplicitLibraries ( Module
& module
);
251 void GenerateKernelModeDLLModuleTarget ();
255 class MingwKernelModeDriverModuleHandler
: public MingwModuleHandler
258 MingwKernelModeDriverModuleHandler ( const Module
& module
);
259 virtual HostType
DefaultHost() { return HostFalse
; }
260 virtual void Process ();
261 std::string
TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
262 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
263 void AddImplicitLibraries ( Module
& module
);
265 void GenerateKernelModeDriverModuleTarget ();
269 class MingwNativeDLLModuleHandler
: public MingwModuleHandler
272 MingwNativeDLLModuleHandler ( const Module
& module
);
273 virtual HostType
DefaultHost() { return HostFalse
; }
274 virtual void Process ();
275 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
276 void AddImplicitLibraries ( Module
& module
);
278 void GenerateNativeDLLModuleTarget ();
282 class MingwNativeCUIModuleHandler
: public MingwModuleHandler
285 MingwNativeCUIModuleHandler ( const Module
& module
);
286 virtual HostType
DefaultHost() { return HostFalse
; }
287 virtual void Process ();
288 std::string
TypeSpecificCFlags() { return "-D__NTAPP__"; }
289 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
290 void AddImplicitLibraries ( Module
& module
);
292 void GenerateNativeCUIModuleTarget ();
296 class MingwWin32DLLModuleHandler
: public MingwModuleHandler
299 MingwWin32DLLModuleHandler ( const Module
& module
);
300 virtual HostType
DefaultHost() { return HostFalse
; }
301 virtual void Process ();
302 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
303 void AddImplicitLibraries ( Module
& module
);
305 void GenerateWin32DLLModuleTarget ();
309 class MingwWin32OCXModuleHandler
: public MingwModuleHandler
312 MingwWin32OCXModuleHandler ( const Module
& module
);
313 virtual HostType
DefaultHost() { return HostFalse
; }
314 virtual void Process ();
315 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
316 void AddImplicitLibraries ( Module
& module
);
318 void GenerateWin32OCXModuleTarget ();
322 class MingwWin32CUIModuleHandler
: public MingwModuleHandler
325 MingwWin32CUIModuleHandler ( const Module
& module
);
326 virtual HostType
DefaultHost() { return HostFalse
; }
327 virtual void Process ();
328 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
329 void AddImplicitLibraries ( Module
& module
);
331 void GenerateWin32CUIModuleTarget ();
335 class MingwWin32GUIModuleHandler
: public MingwModuleHandler
338 MingwWin32GUIModuleHandler ( 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 GenerateWin32GUIModuleTarget ();
348 class MingwBootLoaderModuleHandler
: public MingwModuleHandler
351 MingwBootLoaderModuleHandler ( const Module
& module
);
352 virtual HostType
DefaultHost() { return HostFalse
; }
353 virtual void Process ();
354 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
356 void GenerateBootLoaderModuleTarget ();
360 class MingwBootSectorModuleHandler
: public MingwModuleHandler
363 MingwBootSectorModuleHandler ( const Module
& module
);
364 virtual HostType
DefaultHost() { return HostFalse
; }
365 virtual void Process ();
366 std::string
TypeSpecificNasmFlags() { return "-f bin"; }
368 void GenerateBootSectorModuleTarget ();
372 class MingwBootProgramModuleHandler
: public MingwModuleHandler
375 MingwBootProgramModuleHandler ( const Module
& module
);
376 virtual HostType
DefaultHost() { return HostFalse
; }
377 virtual void Process ();
378 std::string
GetProgTextAddrMacro ();
379 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
381 void GenerateBootProgramModuleTarget ();
385 class MingwIsoModuleHandler
: public MingwModuleHandler
388 MingwIsoModuleHandler ( const Module
& module
);
389 virtual HostType
DefaultHost() { return HostFalse
; }
390 virtual void Process ();
392 void GenerateIsoModuleTarget ();
393 void GetBootstrapCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
394 void GetNonModuleCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
395 void GetCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
396 void GetBootstrapCdFiles ( std::vector
<FileLocation
>& out
) const;
397 void GetNonModuleCdFiles ( std::vector
<FileLocation
>& out
) const;
398 void GetCdFiles ( std::vector
<FileLocation
>& out
) const;
399 void OutputBootstrapfileCopyCommands ( const std::string
& bootcdDirectory
);
400 void OutputCdfileCopyCommands ( const std::string
& bootcdDirectory
);
404 class MingwLiveIsoModuleHandler
: public MingwModuleHandler
407 MingwLiveIsoModuleHandler ( const Module
& module
);
408 virtual HostType
DefaultHost() { return HostFalse
; }
409 virtual void Process ();
411 void GenerateLiveIsoModuleTarget ();
412 void CreateDirectory ( const std::string
& directory
);
413 void OutputModuleCopyCommands ( std::string
& livecdDirectory
,
414 std::string
& livecdReactos
);
415 void OutputNonModuleCopyCommands ( std::string
& livecdDirectory
,
416 std::string
& livecdReactos
);
417 void OutputProfilesDirectoryCommands ( std::string
& livecdDirectory
);
418 void OutputLoaderCommands ( std::string
& livecdDirectory
);
419 void OutputRegistryCommands ( std::string
& livecdDirectory
);
423 class MingwTestModuleHandler
: public MingwModuleHandler
426 MingwTestModuleHandler ( const Module
& module
);
427 virtual HostType
DefaultHost() { return HostFalse
; }
428 virtual void Process ();
429 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
431 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
433 void GenerateTestModuleTarget ();
437 class MingwRpcServerModuleHandler
: public MingwModuleHandler
440 MingwRpcServerModuleHandler ( const Module
& module
);
441 virtual HostType
DefaultHost() { return HostFalse
; }
442 virtual void Process ();
446 class MingwRpcClientModuleHandler
: public MingwModuleHandler
449 MingwRpcClientModuleHandler ( const Module
& module
);
450 virtual HostType
DefaultHost() { return HostFalse
; }
451 virtual void Process ();
455 class MingwRpcProxyModuleHandler
: public MingwModuleHandler
458 MingwRpcProxyModuleHandler ( const Module
& module
);
459 virtual HostType
DefaultHost() { return HostFalse
; }
460 virtual void Process ();
464 class MingwAliasModuleHandler
: public MingwModuleHandler
467 MingwAliasModuleHandler ( const Module
& module
);
468 virtual HostType
DefaultHost() { return HostFalse
; }
469 virtual void Process ();
472 class MingwIdlHeaderModuleHandler
: public MingwModuleHandler
475 MingwIdlHeaderModuleHandler ( const Module
& module
);
476 virtual HostType
DefaultHost() { return HostFalse
; }
477 virtual void Process ();
480 class MingwEmbeddedTypeLibModuleHandler
: public MingwModuleHandler
483 MingwEmbeddedTypeLibModuleHandler ( const Module
& module
);
484 virtual HostType
DefaultHost() { return HostFalse
; }
485 virtual void Process ();
488 class MingwElfExecutableModuleHandler
: public MingwModuleHandler
491 MingwElfExecutableModuleHandler ( const Module
& module
);
492 virtual HostType
DefaultHost() { return HostFalse
; }
493 virtual void Process ();
496 #endif /* MINGW_MODULEHANDLER_H */