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 GenerateWidlCommands ( const CompilationUnit
& compilationUnit
,
176 const std::string
& widlflagsMacro
);
177 void GenerateCommands ( const CompilationUnit
& compilationUnit
,
178 const std::string
& cc
,
179 const std::string
& cppc
,
180 const std::string
& cflagsMacro
,
181 const std::string
& nasmflagsMacro
,
182 const std::string
& windresflagsMacro
,
183 const std::string
& widlflagsMacro
);
184 void GenerateObjectFileTargets ( const IfableData
& data
,
185 const std::string
& cc
,
186 const std::string
& cppc
,
187 const std::string
& cflagsMacro
,
188 const std::string
& nasmflagsMacro
,
189 const std::string
& windresflagsMacro
,
190 const std::string
& widlflagsMacro
);
191 void GenerateObjectFileTargets ( const std::string
& cc
,
192 const std::string
& cppc
,
193 const std::string
& cflagsMacro
,
194 const std::string
& nasmflagsMacro
,
195 const std::string
& windresflagsMacro
,
196 const std::string
& widlflagsMacro
);
197 std::string
GenerateArchiveTarget ( const std::string
& ar
,
198 const std::string
& objs_macro
) const;
199 void GetSpecObjectDependencies ( string_list
& dependencies
,
200 const std::string
& filename
) const;
201 void GetWidlObjectDependencies ( string_list
& dependencies
,
202 const std::string
& filename
) const;
203 void GetDefaultDependencies ( string_list
& dependencies
) const;
204 void GetInvocationDependencies ( const Module
& module
, string_list
& dependencies
);
205 bool IsWineModule () const;
206 std::string
GetDefinitionFilename () const;
207 static std::string
RemoveVariables ( std::string path
);
208 void GenerateBuildNonSymbolStrippedCode ();
209 void CleanupCompilationUnitVector ( std::vector
<CompilationUnit
*>& compilationUnits
);
210 void GetRpcHeaderDependencies ( std::vector
<std::string
>& dependencies
) const;
211 std::string
GetRpcServerHeaderFilename ( std::string basename
) const;
212 std::string
GetRpcClientHeaderFilename ( std::string basename
) const;
213 std::string
GetIdlHeaderFilename ( std::string basename
) const;
214 std::string
GetModuleCleanTarget ( const Module
& module
) const;
215 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector
<std::string
>& moduleNames
) const;
217 const Module
& module
;
218 string_list clean_files
;
219 std::string cflagsMacro
;
220 std::string nasmflagsMacro
;
221 std::string windresflagsMacro
;
222 std::string widlflagsMacro
;
223 std::string linkerflagsMacro
;
224 std::string objectsMacro
;
225 std::string libsMacro
;
226 std::string linkDepsMacro
;
230 class MingwBuildToolModuleHandler
: public MingwModuleHandler
233 MingwBuildToolModuleHandler ( const Module
& module
);
234 virtual HostType
DefaultHost() { return HostTrue
; }
235 virtual void Process ();
237 void GenerateBuildToolModuleTarget ();
241 class MingwKernelModuleHandler
: public MingwModuleHandler
244 MingwKernelModuleHandler ( const Module
& module
);
245 virtual HostType
DefaultHost() { return HostFalse
; }
246 virtual void Process ();
248 void GenerateKernelModuleTarget ();
252 class MingwStaticLibraryModuleHandler
: public MingwModuleHandler
255 MingwStaticLibraryModuleHandler ( const Module
& module
);
256 virtual HostType
DefaultHost() { return HostFalse
; }
257 virtual void Process ();
259 void GenerateStaticLibraryModuleTarget ();
263 class MingwObjectLibraryModuleHandler
: public MingwModuleHandler
266 MingwObjectLibraryModuleHandler ( const Module
& module
);
267 virtual HostType
DefaultHost() { return HostFalse
; }
268 virtual void Process ();
270 void GenerateObjectLibraryModuleTarget ();
274 class MingwKernelModeDLLModuleHandler
: public MingwModuleHandler
277 MingwKernelModeDLLModuleHandler ( const Module
& module
);
278 virtual HostType
DefaultHost() { return HostFalse
; }
279 virtual void Process ();
280 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
281 void AddImplicitLibraries ( Module
& module
);
283 void GenerateKernelModeDLLModuleTarget ();
287 class MingwKernelModeDriverModuleHandler
: public MingwModuleHandler
290 MingwKernelModeDriverModuleHandler ( const Module
& module
);
291 virtual HostType
DefaultHost() { return HostFalse
; }
292 virtual void Process ();
293 std::string
TypeSpecificCFlags() { return "-D__NTDRIVER__"; }
294 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
295 void AddImplicitLibraries ( Module
& module
);
297 void GenerateKernelModeDriverModuleTarget ();
301 class MingwNativeDLLModuleHandler
: public MingwModuleHandler
304 MingwNativeDLLModuleHandler ( const Module
& module
);
305 virtual HostType
DefaultHost() { return HostFalse
; }
306 virtual void Process ();
307 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
308 void AddImplicitLibraries ( Module
& module
);
310 void GenerateNativeDLLModuleTarget ();
314 class MingwNativeCUIModuleHandler
: public MingwModuleHandler
317 MingwNativeCUIModuleHandler ( const Module
& module
);
318 virtual HostType
DefaultHost() { return HostFalse
; }
319 virtual void Process ();
320 std::string
TypeSpecificCFlags() { return "-D__NTAPP__"; }
321 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
322 void AddImplicitLibraries ( Module
& module
);
324 void GenerateNativeCUIModuleTarget ();
328 class MingwWin32DLLModuleHandler
: public MingwModuleHandler
331 MingwWin32DLLModuleHandler ( const Module
& module
);
332 virtual HostType
DefaultHost() { return HostFalse
; }
333 virtual void Process ();
334 std::string
TypeSpecificLinkerFlags() { return module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
335 void AddImplicitLibraries ( Module
& module
);
337 void GenerateWin32DLLModuleTarget ();
341 class MingwWin32CUIModuleHandler
: public MingwModuleHandler
344 MingwWin32CUIModuleHandler ( const Module
& module
);
345 virtual HostType
DefaultHost() { return HostFalse
; }
346 virtual void Process ();
347 std::string
TypeSpecificLinkerFlags() { return module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
348 void AddImplicitLibraries ( Module
& module
);
350 void GenerateWin32CUIModuleTarget ();
354 class MingwWin32GUIModuleHandler
: public MingwModuleHandler
357 MingwWin32GUIModuleHandler ( const Module
& module
);
358 virtual HostType
DefaultHost() { return HostFalse
; }
359 virtual void Process ();
360 std::string
TypeSpecificLinkerFlags() { return module
.useHostStdlib
? "-nostartfiles -lgcc" : "-nostartfiles -nostdlib -lgcc"; }
361 void AddImplicitLibraries ( Module
& module
);
363 void GenerateWin32GUIModuleTarget ();
367 class MingwBootLoaderModuleHandler
: public MingwModuleHandler
370 MingwBootLoaderModuleHandler ( const Module
& module
);
371 virtual HostType
DefaultHost() { return HostFalse
; }
372 virtual void Process ();
373 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
375 void GenerateBootLoaderModuleTarget ();
379 class MingwBootSectorModuleHandler
: public MingwModuleHandler
382 MingwBootSectorModuleHandler ( const Module
& module
);
383 virtual HostType
DefaultHost() { return HostFalse
; }
384 virtual void Process ();
385 std::string
TypeSpecificNasmFlags() { return "-f bin"; }
387 void GenerateBootSectorModuleTarget ();
391 class MingwBootProgramModuleHandler
: public MingwModuleHandler
394 MingwBootProgramModuleHandler ( const Module
& module
);
395 virtual HostType
DefaultHost() { return HostFalse
; }
396 virtual void Process ();
397 std::string
GetProgTextAddrMacro ();
398 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
400 void GenerateBootProgramModuleTarget ();
404 class MingwIsoModuleHandler
: public MingwModuleHandler
407 MingwIsoModuleHandler ( const Module
& module
);
408 virtual HostType
DefaultHost() { return HostFalse
; }
409 virtual void Process ();
411 void GenerateIsoModuleTarget ();
412 std::string
GetBootstrapCdDirectories ( const std::string
& bootcdDirectory
);
413 std::string
GetNonModuleCdDirectories ( const std::string
& bootcdDirectory
);
414 std::string
GetCdDirectories ( const std::string
& bootcdDirectory
);
415 void GetBootstrapCdFiles ( std::vector
<std::string
>& out
) const;
416 void GetNonModuleCdFiles ( std::vector
<std::string
>& out
) const;
417 void GetCdFiles ( std::vector
<std::string
>& out
) const;
418 void OutputBootstrapfileCopyCommands ( const std::string
& bootcdDirectory
);
419 void OutputCdfileCopyCommands ( const std::string
& bootcdDirectory
);
423 class MingwLiveIsoModuleHandler
: public MingwModuleHandler
426 MingwLiveIsoModuleHandler ( const Module
& module
);
427 virtual HostType
DefaultHost() { return HostFalse
; }
428 virtual void Process ();
430 void GenerateLiveIsoModuleTarget ();
431 void CreateDirectory ( const std::string
& directory
);
432 void OutputCopyCommand ( const std::string
& sourceFilename
,
433 const std::string
& targetFilename
,
434 const std::string
& targetDirectory
);
435 void OutputModuleCopyCommands ( std::string
& livecdDirectory
,
436 std::string
& livecdReactos
);
437 void OutputNonModuleCopyCommands ( std::string
& livecdDirectory
,
438 std::string
& livecdReactos
);
439 void OutputProfilesDirectoryCommands ( std::string
& livecdDirectory
);
440 void OutputLoaderCommands ( std::string
& livecdDirectory
);
441 void OutputRegistryCommands ( std::string
& livecdDirectory
);
445 class MingwTestModuleHandler
: public MingwModuleHandler
448 MingwTestModuleHandler ( const Module
& module
);
449 virtual HostType
DefaultHost() { return HostFalse
; }
450 virtual void Process ();
451 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
453 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
455 void GenerateTestModuleTarget ();
459 class MingwRpcServerModuleHandler
: public MingwModuleHandler
462 MingwRpcServerModuleHandler ( const Module
& module
);
463 virtual HostType
DefaultHost() { return HostFalse
; }
464 virtual void Process ();
468 class MingwRpcClientModuleHandler
: public MingwModuleHandler
471 MingwRpcClientModuleHandler ( const Module
& module
);
472 virtual HostType
DefaultHost() { return HostFalse
; }
473 virtual void Process ();
476 class MingwAliasModuleHandler
: public MingwModuleHandler
479 MingwAliasModuleHandler ( const Module
& module
);
480 virtual HostType
DefaultHost() { return HostFalse
; }
481 virtual void Process ();
484 class MingwIdlHeaderModuleHandler
: public MingwModuleHandler
487 MingwIdlHeaderModuleHandler ( const Module
& module
);
488 virtual HostType
DefaultHost() { return HostFalse
; }
489 virtual void Process ();
492 #endif /* MINGW_MODULEHANDLER_H */