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 std::string
PassThruCacheDirectory (
46 Directory
* directoryTree
);
48 static std::string
PassThruCacheDirectory (const FileLocation
* fileLocation
);
50 static Directory
* GetTargetDirectoryTree (
51 const Module
& module
);
53 static std::string
GetTargetFilename (
55 string_list
* pclean_files
);
58 GetImportLibraryFilename (
60 string_list
* pclean_files
);
62 static std::string
GenerateGccDefineParametersFromVector ( const std::vector
<Define
*>& defines
);
63 static std::string
GenerateGccIncludeParametersFromVector ( const std::vector
<Include
*>& includes
);
65 std::string
GetModuleTargets ( const Module
& module
);
66 void GetObjectsVector ( const IfableData
& data
,
67 std::vector
<std::string
>& objectFiles
) const;
68 void GenerateObjectMacro();
69 void GenerateTargetMacro();
70 void GenerateOtherMacros();
72 static MingwModuleHandler
* InstanciateHandler ( const Module
& module_
,
73 MingwBackend
* backend_
);
74 virtual HostType
DefaultHost() = 0;
75 void GeneratePreconditionDependencies ();
76 virtual void Process () = 0;
77 virtual std::string
TypeSpecificCFlags() { return ""; }
78 virtual std::string
TypeSpecificNasmFlags() { return ""; }
79 virtual std::string
TypeSpecificLinkerFlags() { return ""; }
80 void GenerateInvocations () const;
81 void GenerateCleanTarget () const;
82 void GenerateInstallTarget () const;
83 void GenerateDependsTarget () const;
84 static bool ReferenceObjects ( const Module
& module
);
85 virtual void AddImplicitLibraries ( Module
& module
) { return; }
87 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
88 std::string
GetWorkingDirectory () const;
89 std::string
GetBasename ( const std::string
& filename
) const;
90 FileLocation
* GetActualSourceFilename ( const FileLocation
* fileLocation
) const;
91 std::string
GetExtraDependencies ( const std::string
& filename
) const;
92 std::string
GetCompilationUnitDependencies ( const CompilationUnit
& compilationUnit
) const;
93 std::string
GetModuleArchiveFilename () const;
94 bool IsGeneratedFile ( const File
& file
) const;
95 std::string
GetImportLibraryDependency ( const Module
& importedModule
);
96 void GetTargets ( const Module
& dependencyModule
,
97 string_list
& targets
);
98 void GetModuleDependencies ( string_list
& dependencies
);
99 std::string
GetAllDependencies () const;
100 void GetSourceFilenames ( string_list
& list
,
101 bool includeGeneratedFiles
) const;
102 void GetSourceFilenamesWithoutGeneratedFiles ( string_list
& list
) const;
103 std::string
GetObjectFilename ( const FileLocation
* sourceFileLocation
,
104 string_list
* pclean_files
) const;
106 std::string
GetObjectFilenames ();
108 std::string
GetPreconditionDependenciesName () const;
109 std::string
GetCFlagsMacro () const;
110 static std::string
GetObjectsMacro ( const Module
& );
111 std::string
GetLinkingDependenciesMacro () const;
112 std::string
GetLibsMacro () const;
113 std::string
GetLinkerMacro () const;
114 void GenerateCleanObjectsAsYouGoCode () const;
115 void GenerateRunRsymCode () const;
116 void GenerateRunStripCode () const;
117 void GenerateLinkerCommand ( const std::string
& dependencies
,
118 const std::string
& linker
,
119 const std::string
& linkerParameters
,
120 const std::string
& objectsMacro
,
121 const std::string
& libsMacro
,
122 const std::string
& pefixupParameters
);
123 void GeneratePhonyTarget() const;
124 void GenerateBuildMapCode ( const char *mapTarget
= NULL
);
125 void GenerateRules ();
126 void GenerateImportLibraryTargetIfNeeded ();
127 void GetDefinitionDependencies ( string_list
& dependencies
) const;
128 std::string
GetLinkingDependencies () const;
129 static MingwBackend
* backend
;
130 static FILE* fMakefile
;
133 std::string
ConcatenatePaths ( const std::string
& path1
,
134 const std::string
& path2
) const;
135 std::string
GenerateGccDefineParameters () const;
136 std::string
GenerateCompilerParametersFromVector ( const std::vector
<CompilerFlag
*>& compilerFlags
) const;
137 std::string
GenerateLinkerParametersFromVector ( const std::vector
<LinkerFlag
*>& linkerFlags
) const;
138 std::string
GenerateImportLibraryDependenciesFromVector ( const std::vector
<Library
*>& libraries
);
139 std::string
GenerateLinkerParameters () const;
140 void GenerateMacro ( const char* assignmentOperation
,
141 const std::string
& macro
,
142 const IfableData
& data
);
143 void GenerateMacros ( const char* op
,
144 const IfableData
& data
,
145 const std::vector
<LinkerFlag
*>* linkerFlags
);
146 void GenerateObjectMacros ( const char* assignmentOperation
,
147 const IfableData
& data
,
148 const std::vector
<LinkerFlag
*>* linkerFlags
);
149 std::string
GenerateGccIncludeParameters () const;
150 std::string
GenerateGccParameters () const;
151 std::string
GenerateNasmParameters () const;
152 std::string
GetPrecompiledHeaderFilename () const;
153 void GenerateGccCommand ( const FileLocation
* sourceFileLocation
,
154 const std::string
& extraDependencies
,
155 const std::string
& cc
,
156 const std::string
& cflagsMacro
);
157 void GenerateGccAssemblerCommand ( const FileLocation
* sourceFileLocation
,
158 const std::string
& cc
,
159 const std::string
& cflagsMacro
);
160 void GenerateNasmCommand ( const FileLocation
* sourceFileLocation
,
161 const std::string
& nasmflagsMacro
);
162 void GenerateWindresCommand ( const FileLocation
* sourceFileLocation
,
163 const std::string
& windresflagsMacro
);
164 void GenerateWinebuildCommands ( const FileLocation
* sourceFileLocation
);
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
& cc
,
182 const std::string
& cppc
,
183 const std::string
& cflagsMacro
,
184 const std::string
& nasmflagsMacro
,
185 const std::string
& windresflagsMacro
,
186 const std::string
& widlflagsMacro
);
187 void GenerateObjectFileTargets ( const IfableData
& data
,
188 const std::string
& cc
,
189 const std::string
& cppc
,
190 const std::string
& cflagsMacro
,
191 const std::string
& nasmflagsMacro
,
192 const std::string
& windresflagsMacro
,
193 const std::string
& widlflagsMacro
);
194 void GenerateObjectFileTargets ( const std::string
& cc
,
195 const std::string
& cppc
,
196 const std::string
& cflagsMacro
,
197 const std::string
& nasmflagsMacro
,
198 const std::string
& windresflagsMacro
,
199 const std::string
& widlflagsMacro
);
200 std::string
GenerateArchiveTarget ( const std::string
& ar
,
201 const std::string
& objs_macro
) const;
202 void GetSpecObjectDependencies ( string_list
& dependencies
,
203 const std::string
& filename
) const;
204 void GetWidlObjectDependencies ( string_list
& dependencies
,
205 const std::string
& filename
) const;
206 void GetDefaultDependencies ( string_list
& dependencies
) const;
207 void GetInvocationDependencies ( const Module
& module
, string_list
& dependencies
);
208 bool IsWineModule () const;
209 std::string
GetDefinitionFilename () const;
210 static std::string
RemoveVariables ( std::string path
);
211 void GenerateBuildNonSymbolStrippedCode ();
212 void CleanupCompilationUnitVector ( std::vector
<CompilationUnit
*>& compilationUnits
);
213 void GetRpcHeaderDependencies ( std::vector
<std::string
>& dependencies
) const;
214 static std::string
GetPropertyValue ( const Module
& module
, const std::string
& name
);
215 std::string
GetRpcServerHeaderFilename ( std::string basename
) const;
216 std::string
GetRpcClientHeaderFilename ( std::string basename
) const;
217 std::string
GetIdlHeaderFilename ( std::string basename
) 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 objectsMacro
;
229 std::string libsMacro
;
230 std::string linkDepsMacro
;
234 class MingwBuildToolModuleHandler
: public MingwModuleHandler
237 MingwBuildToolModuleHandler ( const Module
& module
);
238 virtual HostType
DefaultHost() { return HostTrue
; }
239 virtual void Process ();
241 void GenerateBuildToolModuleTarget ();
245 class MingwKernelModuleHandler
: public MingwModuleHandler
248 MingwKernelModuleHandler ( const Module
& module
);
249 virtual HostType
DefaultHost() { return HostFalse
; }
250 virtual void Process ();
252 void GenerateKernelModuleTarget ();
256 class MingwStaticLibraryModuleHandler
: public MingwModuleHandler
259 MingwStaticLibraryModuleHandler ( const Module
& module
);
260 virtual HostType
DefaultHost() { return HostFalse
; }
261 virtual void Process ();
263 void GenerateStaticLibraryModuleTarget ();
267 class MingwObjectLibraryModuleHandler
: public MingwModuleHandler
270 MingwObjectLibraryModuleHandler ( const Module
& module
);
271 virtual HostType
DefaultHost() { return HostFalse
; }
272 virtual void Process ();
274 void GenerateObjectLibraryModuleTarget ();
278 class MingwKernelModeDLLModuleHandler
: public MingwModuleHandler
281 MingwKernelModeDLLModuleHandler ( 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 GenerateKernelModeDLLModuleTarget ();
291 class MingwKernelModeDriverModuleHandler
: public MingwModuleHandler
294 MingwKernelModeDriverModuleHandler ( const Module
& module
);
295 virtual HostType
DefaultHost() { return HostFalse
; }
296 virtual void Process ();
297 std::string
TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
298 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
299 void AddImplicitLibraries ( Module
& module
);
301 void GenerateKernelModeDriverModuleTarget ();
305 class MingwNativeDLLModuleHandler
: public MingwModuleHandler
308 MingwNativeDLLModuleHandler ( const Module
& module
);
309 virtual HostType
DefaultHost() { return HostFalse
; }
310 virtual void Process ();
311 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
312 void AddImplicitLibraries ( Module
& module
);
314 void GenerateNativeDLLModuleTarget ();
318 class MingwNativeCUIModuleHandler
: public MingwModuleHandler
321 MingwNativeCUIModuleHandler ( const Module
& module
);
322 virtual HostType
DefaultHost() { return HostFalse
; }
323 virtual void Process ();
324 std::string
TypeSpecificCFlags() { return "-D__NTAPP__"; }
325 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
326 void AddImplicitLibraries ( Module
& module
);
328 void GenerateNativeCUIModuleTarget ();
332 class MingwWin32DLLModuleHandler
: public MingwModuleHandler
335 MingwWin32DLLModuleHandler ( const Module
& module
);
336 virtual HostType
DefaultHost() { return HostFalse
; }
337 virtual void Process ();
338 std::string
TypeSpecificLinkerFlags() { return module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
339 void AddImplicitLibraries ( Module
& module
);
341 void GenerateWin32DLLModuleTarget ();
345 class MingwWin32OCXModuleHandler
: public MingwModuleHandler
348 MingwWin32OCXModuleHandler ( const Module
& module
);
349 virtual HostType
DefaultHost() { return HostFalse
; }
350 virtual void Process ();
351 std::string
TypeSpecificLinkerFlags() { return module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
352 void AddImplicitLibraries ( Module
& module
);
354 void GenerateWin32OCXModuleTarget ();
358 class MingwWin32CUIModuleHandler
: public MingwModuleHandler
361 MingwWin32CUIModuleHandler ( const Module
& module
);
362 virtual HostType
DefaultHost() { return HostFalse
; }
363 virtual void Process ();
364 std::string
TypeSpecificLinkerFlags() { return module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
365 void AddImplicitLibraries ( Module
& module
);
367 void GenerateWin32CUIModuleTarget ();
371 class MingwWin32GUIModuleHandler
: public MingwModuleHandler
374 MingwWin32GUIModuleHandler ( const Module
& module
);
375 virtual HostType
DefaultHost() { return HostFalse
; }
376 virtual void Process ();
377 std::string
TypeSpecificLinkerFlags() { return module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
378 void AddImplicitLibraries ( Module
& module
);
380 void GenerateWin32GUIModuleTarget ();
384 class MingwBootLoaderModuleHandler
: public MingwModuleHandler
387 MingwBootLoaderModuleHandler ( const Module
& module
);
388 virtual HostType
DefaultHost() { return HostFalse
; }
389 virtual void Process ();
390 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
392 void GenerateBootLoaderModuleTarget ();
396 class MingwBootSectorModuleHandler
: public MingwModuleHandler
399 MingwBootSectorModuleHandler ( const Module
& module
);
400 virtual HostType
DefaultHost() { return HostFalse
; }
401 virtual void Process ();
402 std::string
TypeSpecificNasmFlags() { return "-f bin"; }
404 void GenerateBootSectorModuleTarget ();
408 class MingwBootProgramModuleHandler
: public MingwModuleHandler
411 MingwBootProgramModuleHandler ( const Module
& module
);
412 virtual HostType
DefaultHost() { return HostFalse
; }
413 virtual void Process ();
414 std::string
GetProgTextAddrMacro ();
415 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
417 void GenerateBootProgramModuleTarget ();
421 class MingwIsoModuleHandler
: public MingwModuleHandler
424 MingwIsoModuleHandler ( const Module
& module
);
425 virtual HostType
DefaultHost() { return HostFalse
; }
426 virtual void Process ();
428 void GenerateIsoModuleTarget ();
429 std::string
GetBootstrapCdDirectories ( const std::string
& bootcdDirectory
);
430 std::string
GetNonModuleCdDirectories ( const std::string
& bootcdDirectory
);
431 std::string
GetCdDirectories ( const std::string
& bootcdDirectory
);
432 void GetBootstrapCdFiles ( std::vector
<std::string
>& out
) const;
433 void GetNonModuleCdFiles ( std::vector
<std::string
>& out
) const;
434 void GetCdFiles ( std::vector
<std::string
>& out
) const;
435 void OutputBootstrapfileCopyCommands ( const std::string
& bootcdDirectory
);
436 void OutputCdfileCopyCommands ( const std::string
& bootcdDirectory
);
440 class MingwLiveIsoModuleHandler
: public MingwModuleHandler
443 MingwLiveIsoModuleHandler ( const Module
& module
);
444 virtual HostType
DefaultHost() { return HostFalse
; }
445 virtual void Process ();
447 void GenerateLiveIsoModuleTarget ();
448 void CreateDirectory ( const std::string
& directory
);
449 void OutputCopyCommand ( const std::string
& sourceFilename
,
450 const std::string
& targetFilename
,
451 const std::string
& targetDirectory
);
452 void OutputModuleCopyCommands ( std::string
& livecdDirectory
,
453 std::string
& livecdReactos
);
454 void OutputNonModuleCopyCommands ( std::string
& livecdDirectory
,
455 std::string
& livecdReactos
);
456 void OutputProfilesDirectoryCommands ( std::string
& livecdDirectory
);
457 void OutputLoaderCommands ( std::string
& livecdDirectory
);
458 void OutputRegistryCommands ( std::string
& livecdDirectory
);
462 class MingwTestModuleHandler
: public MingwModuleHandler
465 MingwTestModuleHandler ( const Module
& module
);
466 virtual HostType
DefaultHost() { return HostFalse
; }
467 virtual void Process ();
468 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
470 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
472 void GenerateTestModuleTarget ();
476 class MingwRpcServerModuleHandler
: public MingwModuleHandler
479 MingwRpcServerModuleHandler ( const Module
& module
);
480 virtual HostType
DefaultHost() { return HostFalse
; }
481 virtual void Process ();
485 class MingwRpcClientModuleHandler
: public MingwModuleHandler
488 MingwRpcClientModuleHandler ( const Module
& module
);
489 virtual HostType
DefaultHost() { return HostFalse
; }
490 virtual void Process ();
493 class MingwAliasModuleHandler
: public MingwModuleHandler
496 MingwAliasModuleHandler ( const Module
& module
);
497 virtual HostType
DefaultHost() { return HostFalse
; }
498 virtual void Process ();
501 class MingwIdlHeaderModuleHandler
: public MingwModuleHandler
504 MingwIdlHeaderModuleHandler ( const Module
& module
);
505 virtual HostType
DefaultHost() { return HostFalse
; }
506 virtual void Process ();
509 class MingwEmbeddedTypeLibModuleHandler
: public MingwModuleHandler
512 MingwEmbeddedTypeLibModuleHandler ( const Module
& module
);
513 virtual HostType
DefaultHost() { return HostFalse
; }
514 virtual void Process ();
517 #endif /* MINGW_MODULEHANDLER_H */