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
) 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;
124 std::string
GetLinkingDependencies () const;
125 static MingwBackend
* backend
;
126 static FILE* fMakefile
;
129 std::string
ConcatenatePaths ( const std::string
& path1
,
130 const std::string
& path2
) const;
131 std::string
GenerateGccDefineParameters () const;
132 std::string
GenerateCompilerParametersFromVector ( const std::vector
<CompilerFlag
*>& compilerFlags
, const CompilerType type
) const;
133 std::string
GenerateLinkerParametersFromVector ( const std::vector
<LinkerFlag
*>& linkerFlags
) const;
134 std::string
GenerateImportLibraryDependenciesFromVector ( const std::vector
<Library
*>& libraries
);
135 std::string
GenerateLinkerParameters () const;
136 void GenerateMacro ( const char* assignmentOperation
,
137 const std::string
& macro
,
138 const IfableData
& data
,
139 std::set
<const Define
*>* used_defs
,
140 bool generatingCompilerMacro
);
141 void GenerateMacros ( const char* op
,
142 const IfableData
& data
,
143 const std::vector
<LinkerFlag
*>* linkerFlags
,
144 std::set
<const Define
*>& 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 void GenerateCommands ( const CompilationUnit
& compilationUnit
,
156 const std::string
& extraDependencies
);
157 void GenerateObjectFileTargets ( const IfableData
& data
);
158 void GenerateObjectFileTargets ();
159 const FileLocation
* GenerateArchiveTarget ();
160 void GetMcObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
161 const FileLocation
*file
) const;
162 void GetSpecObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
163 const FileLocation
*file
) const;
164 void GetWidlObjectDependencies ( std::vector
<FileLocation
>& dependencies
,
165 const FileLocation
*file
) const;
166 void GetDefaultDependencies ( string_list
& dependencies
) const;
167 void GetInvocationDependencies ( const Module
& module
, string_list
& dependencies
);
168 bool IsWineModule () const;
169 const FileLocation
* GetDefinitionFilename () const;
170 void GenerateBuildNonSymbolStrippedCode ();
171 void CleanupCompilationUnitVector ( std::vector
<CompilationUnit
*>& compilationUnits
);
172 void GetRpcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
173 void GetMcHeaderDependencies ( std::vector
<FileLocation
>& dependencies
) const;
174 static std::string
GetPropertyValue ( const Module
& module
, const std::string
& name
);
175 const FileLocation
* GetRpcServerHeaderFilename ( const FileLocation
*base
) const;
176 const FileLocation
* GetRpcClientHeaderFilename ( const FileLocation
*base
) const;
177 const FileLocation
* GetRpcProxyHeaderFilename ( const FileLocation
*base
) const;
178 const FileLocation
* GetIdlHeaderFilename ( const FileLocation
*base
) const;
179 const FileLocation
* GetMcHeaderFilename ( const FileLocation
*base
) const;
180 std::string
GetModuleCleanTarget ( const Module
& module
) const;
181 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector
<std::string
>& moduleNames
) const;
183 const Module
& module
;
184 string_list clean_files
;
185 std::string cflagsMacro
;
186 std::string nasmflagsMacro
;
187 std::string windresflagsMacro
;
188 std::string widlflagsMacro
;
189 std::string linkerflagsMacro
;
190 std::string sourcesMacro
;
191 std::string objectsMacro
;
192 std::string libsMacro
;
193 std::string linkDepsMacro
;
197 class MingwBuildToolModuleHandler
: public MingwModuleHandler
200 MingwBuildToolModuleHandler ( const Module
& module
);
201 virtual HostType
DefaultHost() { return HostTrue
; }
202 virtual void Process ();
204 void GenerateBuildToolModuleTarget ();
208 class MingwKernelModuleHandler
: public MingwModuleHandler
211 MingwKernelModuleHandler ( const Module
& module
);
212 virtual HostType
DefaultHost() { return HostFalse
; }
213 virtual void Process ();
215 void GenerateKernelModuleTarget ();
219 class MingwStaticLibraryModuleHandler
: public MingwModuleHandler
222 MingwStaticLibraryModuleHandler ( const Module
& module
);
223 virtual HostType
DefaultHost() { return HostFalse
; }
224 virtual void Process ();
226 void GenerateStaticLibraryModuleTarget ();
230 class MingwObjectLibraryModuleHandler
: public MingwModuleHandler
233 MingwObjectLibraryModuleHandler ( const Module
& module
);
234 virtual HostType
DefaultHost() { return HostFalse
; }
235 virtual void Process ();
237 void GenerateObjectLibraryModuleTarget ();
241 class MingwKernelModeDLLModuleHandler
: public MingwModuleHandler
244 MingwKernelModeDLLModuleHandler ( const Module
& module
);
245 virtual HostType
DefaultHost() { return HostFalse
; }
246 virtual void Process ();
247 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
248 void AddImplicitLibraries ( Module
& module
);
250 void GenerateKernelModeDLLModuleTarget ();
254 class MingwKernelModeDriverModuleHandler
: public MingwModuleHandler
257 MingwKernelModeDriverModuleHandler ( const Module
& module
);
258 virtual HostType
DefaultHost() { return HostFalse
; }
259 virtual void Process ();
260 std::string
TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
261 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
262 void AddImplicitLibraries ( Module
& module
);
264 void GenerateKernelModeDriverModuleTarget ();
268 class MingwNativeDLLModuleHandler
: public MingwModuleHandler
271 MingwNativeDLLModuleHandler ( const Module
& module
);
272 virtual HostType
DefaultHost() { return HostFalse
; }
273 virtual void Process ();
274 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
275 void AddImplicitLibraries ( Module
& module
);
277 void GenerateNativeDLLModuleTarget ();
281 class MingwNativeCUIModuleHandler
: public MingwModuleHandler
284 MingwNativeCUIModuleHandler ( const Module
& module
);
285 virtual HostType
DefaultHost() { return HostFalse
; }
286 virtual void Process ();
287 std::string
TypeSpecificCFlags() { return "-D__NTAPP__"; }
288 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
289 void AddImplicitLibraries ( Module
& module
);
291 void GenerateNativeCUIModuleTarget ();
295 class MingwWin32DLLModuleHandler
: public MingwModuleHandler
298 MingwWin32DLLModuleHandler ( const Module
& module
);
299 virtual HostType
DefaultHost() { return HostFalse
; }
300 virtual void Process ();
301 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
302 void AddImplicitLibraries ( Module
& module
);
304 void GenerateWin32DLLModuleTarget ();
308 class MingwWin32OCXModuleHandler
: public MingwModuleHandler
311 MingwWin32OCXModuleHandler ( const Module
& module
);
312 virtual HostType
DefaultHost() { return HostFalse
; }
313 virtual void Process ();
314 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
315 void AddImplicitLibraries ( Module
& module
);
317 void GenerateWin32OCXModuleTarget ();
321 class MingwWin32CUIModuleHandler
: public MingwModuleHandler
324 MingwWin32CUIModuleHandler ( const Module
& module
);
325 virtual HostType
DefaultHost() { return HostFalse
; }
326 virtual void Process ();
327 std::string
TypeSpecificLinkerFlags() { return module
.cplusplus
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
328 void AddImplicitLibraries ( Module
& module
);
330 void GenerateWin32CUIModuleTarget ();
334 class MingwWin32GUIModuleHandler
: public MingwModuleHandler
337 MingwWin32GUIModuleHandler ( 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 GenerateWin32GUIModuleTarget ();
347 class MingwBootLoaderModuleHandler
: public MingwModuleHandler
350 MingwBootLoaderModuleHandler ( const Module
& module
);
351 virtual HostType
DefaultHost() { return HostFalse
; }
352 virtual void Process ();
353 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
355 void GenerateBootLoaderModuleTarget ();
359 class MingwBootSectorModuleHandler
: public MingwModuleHandler
362 MingwBootSectorModuleHandler ( const Module
& module
);
363 virtual HostType
DefaultHost() { return HostFalse
; }
364 virtual void Process ();
365 std::string
TypeSpecificNasmFlags() { return "-f bin"; }
367 void GenerateBootSectorModuleTarget ();
371 class MingwBootProgramModuleHandler
: public MingwModuleHandler
374 MingwBootProgramModuleHandler ( const Module
& module
);
375 virtual HostType
DefaultHost() { return HostFalse
; }
376 virtual void Process ();
377 std::string
GetProgTextAddrMacro ();
378 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
380 void GenerateBootProgramModuleTarget ();
384 class MingwIsoModuleHandler
: public MingwModuleHandler
387 MingwIsoModuleHandler ( const Module
& module
);
388 virtual HostType
DefaultHost() { return HostFalse
; }
389 virtual void Process ();
391 void GenerateIsoModuleTarget ();
392 void GetBootstrapCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
393 void GetNonModuleCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
394 void GetCdDirectories ( std::vector
<FileLocation
>& out
, const std::string
& bootcdDirectory
);
395 void GetBootstrapCdFiles ( std::vector
<FileLocation
>& out
) const;
396 void GetNonModuleCdFiles ( std::vector
<FileLocation
>& out
) const;
397 void GetCdFiles ( std::vector
<FileLocation
>& out
) const;
398 void OutputBootstrapfileCopyCommands ( const std::string
& bootcdDirectory
);
399 void OutputCdfileCopyCommands ( const std::string
& bootcdDirectory
);
403 class MingwLiveIsoModuleHandler
: public MingwModuleHandler
406 MingwLiveIsoModuleHandler ( const Module
& module
);
407 virtual HostType
DefaultHost() { return HostFalse
; }
408 virtual void Process ();
410 void GenerateLiveIsoModuleTarget ();
411 void CreateDirectory ( const std::string
& directory
);
412 void OutputModuleCopyCommands ( std::string
& livecdDirectory
,
413 std::string
& livecdReactos
);
414 void OutputNonModuleCopyCommands ( std::string
& livecdDirectory
,
415 std::string
& livecdReactos
);
416 void OutputProfilesDirectoryCommands ( std::string
& livecdDirectory
);
417 void OutputLoaderCommands ( std::string
& livecdDirectory
);
418 void OutputRegistryCommands ( std::string
& livecdDirectory
);
422 class MingwTestModuleHandler
: public MingwModuleHandler
425 MingwTestModuleHandler ( const Module
& module
);
426 virtual HostType
DefaultHost() { return HostFalse
; }
427 virtual void Process ();
428 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
430 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
432 void GenerateTestModuleTarget ();
436 class MingwRpcServerModuleHandler
: public MingwModuleHandler
439 MingwRpcServerModuleHandler ( const Module
& module
);
440 virtual HostType
DefaultHost() { return HostFalse
; }
441 virtual void Process ();
445 class MingwRpcClientModuleHandler
: public MingwModuleHandler
448 MingwRpcClientModuleHandler ( const Module
& module
);
449 virtual HostType
DefaultHost() { return HostFalse
; }
450 virtual void Process ();
454 class MingwRpcProxyModuleHandler
: public MingwModuleHandler
457 MingwRpcProxyModuleHandler ( const Module
& module
);
458 virtual HostType
DefaultHost() { return HostFalse
; }
459 virtual void Process ();
463 class MingwAliasModuleHandler
: public MingwModuleHandler
466 MingwAliasModuleHandler ( const Module
& module
);
467 virtual HostType
DefaultHost() { return HostFalse
; }
468 virtual void Process ();
471 class MingwIdlHeaderModuleHandler
: public MingwModuleHandler
474 MingwIdlHeaderModuleHandler ( const Module
& module
);
475 virtual HostType
DefaultHost() { return HostFalse
; }
476 virtual void Process ();
479 class MingwEmbeddedTypeLibModuleHandler
: public MingwModuleHandler
482 MingwEmbeddedTypeLibModuleHandler ( const Module
& module
);
483 virtual HostType
DefaultHost() { return HostFalse
; }
484 virtual void Process ();
487 class MingwElfExecutableModuleHandler
: public MingwModuleHandler
490 MingwElfExecutableModuleHandler ( const Module
& module
);
491 virtual HostType
DefaultHost() { return HostFalse
; }
492 virtual void Process ();
495 #endif /* MINGW_MODULEHANDLER_H */