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
);
86 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
87 std::string
GetWorkingDirectory () const;
88 std::string
GetBasename ( const std::string
& filename
) const;
89 FileLocation
* GetActualSourceFilename ( const FileLocation
* fileLocation
) const;
90 std::string
GetExtraDependencies ( const std::string
& filename
) const;
91 std::string
MingwModuleHandler::GetCompilationUnitDependencies ( const CompilationUnit
& compilationUnit
) const;
92 std::string
GetModuleArchiveFilename () const;
93 bool IsGeneratedFile ( const File
& file
) const;
94 std::string
GetImportLibraryDependency ( const Module
& importedModule
);
95 void GetTargets ( const Module
& dependencyModule
,
96 string_list
& targets
);
97 void GetModuleDependencies ( string_list
& dependencies
);
98 std::string
GetAllDependencies () const;
99 void GetSourceFilenames ( string_list
& list
,
100 bool includeGeneratedFiles
) const;
101 void GetSourceFilenamesWithoutGeneratedFiles ( string_list
& list
) const;
102 std::string
GetObjectFilename ( const FileLocation
* sourceFileLocation
,
103 string_list
* pclean_files
) const;
105 std::string
GetObjectFilenames ();
107 std::string
GetPreconditionDependenciesName () const;
108 std::string
GetCFlagsMacro () const;
109 static std::string
GetObjectsMacro ( const Module
& );
110 std::string
GetLinkingDependenciesMacro () const;
111 std::string
GetLibsMacro () const;
112 std::string
GetLinkerMacro () const;
113 void GenerateCleanObjectsAsYouGoCode () const;
114 void GenerateRunRsymCode () const;
115 void GenerateLinkerCommand ( const std::string
& dependencies
,
116 const std::string
& linker
,
117 const std::string
& linkerParameters
,
118 const std::string
& objectsMacro
,
119 const std::string
& libsMacro
,
120 const std::string
& pefixupParameters
);
121 void GeneratePhonyTarget() const;
122 void GenerateBuildMapCode ( const char *mapTarget
= NULL
);
123 void GenerateRules ();
124 void GenerateImportLibraryTargetIfNeeded ();
125 void GetDefinitionDependencies ( string_list
& dependencies
) const;
126 std::string
GetLinkingDependencies () const;
127 static MingwBackend
* backend
;
128 static FILE* fMakefile
;
131 std::string
ConcatenatePaths ( const std::string
& path1
,
132 const std::string
& path2
) const;
133 std::string
GenerateGccDefineParameters () const;
134 std::string
GenerateCompilerParametersFromVector ( const std::vector
<CompilerFlag
*>& compilerFlags
) const;
135 std::string
GenerateLinkerParametersFromVector ( const std::vector
<LinkerFlag
*>& linkerFlags
) const;
136 std::string
GenerateImportLibraryDependenciesFromVector ( const std::vector
<Library
*>& libraries
);
137 std::string
GenerateLinkerParameters () const;
138 void GenerateMacro ( const char* assignmentOperation
,
139 const std::string
& macro
,
140 const IfableData
& data
);
141 void GenerateMacros ( const char* op
,
142 const IfableData
& data
,
143 const std::vector
<LinkerFlag
*>* linkerFlags
);
144 void GenerateObjectMacros ( const char* assignmentOperation
,
145 const IfableData
& data
,
146 const std::vector
<LinkerFlag
*>* linkerFlags
);
147 std::string
GenerateGccIncludeParameters () const;
148 std::string
GenerateGccParameters () const;
149 std::string
GenerateNasmParameters () const;
150 std::string
MingwModuleHandler::GetPrecompiledHeaderFilename () const;
151 void GenerateGccCommand ( const FileLocation
* sourceFileLocation
,
152 const std::string
& extraDependencies
,
153 const std::string
& cc
,
154 const std::string
& cflagsMacro
);
155 void GenerateGccAssemblerCommand ( const FileLocation
* sourceFileLocation
,
156 const std::string
& cc
,
157 const std::string
& cflagsMacro
);
158 void GenerateNasmCommand ( const FileLocation
* sourceFileLocation
,
159 const std::string
& nasmflagsMacro
);
160 void GenerateWindresCommand ( const FileLocation
* sourceFileLocation
,
161 const std::string
& windresflagsMacro
);
162 void GenerateWinebuildCommands ( const FileLocation
* sourceFileLocation
);
163 std::string
GetWidlFlags ( const CompilationUnit
& compilationUnit
);
164 void GenerateWidlCommandsServer (
165 const CompilationUnit
& compilationUnit
,
166 const std::string
& widlflagsMacro
);
167 void GenerateWidlCommandsClient (
168 const CompilationUnit
& compilationUnit
,
169 const std::string
& widlflagsMacro
);
170 void GenerateWidlCommands ( const CompilationUnit
& compilationUnit
,
171 const std::string
& widlflagsMacro
);
172 void GenerateCommands ( const CompilationUnit
& compilationUnit
,
173 const std::string
& cc
,
174 const std::string
& cppc
,
175 const std::string
& cflagsMacro
,
176 const std::string
& nasmflagsMacro
,
177 const std::string
& windresflagsMacro
,
178 const std::string
& widlflagsMacro
);
179 void GenerateObjectFileTargets ( const IfableData
& data
,
180 const std::string
& cc
,
181 const std::string
& cppc
,
182 const std::string
& cflagsMacro
,
183 const std::string
& nasmflagsMacro
,
184 const std::string
& windresflagsMacro
,
185 const std::string
& widlflagsMacro
);
186 void GenerateObjectFileTargets ( const std::string
& cc
,
187 const std::string
& cppc
,
188 const std::string
& cflagsMacro
,
189 const std::string
& nasmflagsMacro
,
190 const std::string
& windresflagsMacro
,
191 const std::string
& widlflagsMacro
);
192 std::string
GenerateArchiveTarget ( const std::string
& ar
,
193 const std::string
& objs_macro
) const;
194 void GetSpecObjectDependencies ( string_list
& dependencies
,
195 const std::string
& filename
) const;
196 void GetWidlObjectDependencies ( string_list
& dependencies
,
197 const std::string
& filename
) const;
198 void GetDefaultDependencies ( string_list
& dependencies
) const;
199 void GetInvocationDependencies ( const Module
& module
, string_list
& dependencies
);
200 bool IsWineModule () const;
201 std::string
GetDefinitionFilename () const;
202 static std::string
RemoveVariables ( std::string path
);
203 void GenerateBuildNonSymbolStrippedCode ();
204 void CleanupCompilationUnitVector ( std::vector
<CompilationUnit
*>& compilationUnits
);
205 void GetRpcHeaderDependencies ( std::vector
<std::string
>& dependencies
) const;
206 std::string
GetRpcServerHeaderFilename ( std::string basename
) const;
207 std::string
GetRpcClientHeaderFilename ( std::string basename
) const;
208 std::string
GetModuleCleanTarget ( const Module
& module
) const;
209 void GetReferencedObjectLibraryModuleCleanTargets ( std::vector
<std::string
>& moduleNames
) const;
211 const Module
& module
;
212 string_list clean_files
;
213 std::string cflagsMacro
;
214 std::string nasmflagsMacro
;
215 std::string windresflagsMacro
;
216 std::string widlflagsMacro
;
217 std::string linkerflagsMacro
;
218 std::string objectsMacro
;
219 std::string libsMacro
;
220 std::string linkDepsMacro
;
224 class MingwBuildToolModuleHandler
: public MingwModuleHandler
227 MingwBuildToolModuleHandler ( const Module
& module
);
228 virtual HostType
DefaultHost() { return HostTrue
; }
229 virtual void Process ();
231 void GenerateBuildToolModuleTarget ();
235 class MingwKernelModuleHandler
: public MingwModuleHandler
238 MingwKernelModuleHandler ( const Module
& module
);
239 virtual HostType
DefaultHost() { return HostFalse
; }
240 virtual void Process ();
241 std::string
TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
243 void GenerateKernelModuleTarget ();
247 class MingwStaticLibraryModuleHandler
: public MingwModuleHandler
250 MingwStaticLibraryModuleHandler ( const Module
& module
);
251 virtual HostType
DefaultHost() { return HostFalse
; }
252 virtual void Process ();
254 void GenerateStaticLibraryModuleTarget ();
258 class MingwObjectLibraryModuleHandler
: public MingwModuleHandler
261 MingwObjectLibraryModuleHandler ( const Module
& module
);
262 virtual HostType
DefaultHost() { return HostFalse
; }
263 virtual void Process ();
265 void GenerateObjectLibraryModuleTarget ();
269 class MingwKernelModeDLLModuleHandler
: public MingwModuleHandler
272 MingwKernelModeDLLModuleHandler ( const Module
& module
);
273 virtual HostType
DefaultHost() { return HostFalse
; }
274 virtual void Process ();
275 std::string
TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
276 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
278 void GenerateKernelModeDLLModuleTarget ();
282 class MingwKernelModeDriverModuleHandler
: public MingwModuleHandler
285 MingwKernelModeDriverModuleHandler ( const Module
& module
);
286 virtual HostType
DefaultHost() { return HostFalse
; }
287 virtual void Process ();
288 std::string
TypeSpecificCFlags() { return "-D__NTDRIVER__ -D_SEH_NO_NATIVE_NLG"; }
289 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
291 void GenerateKernelModeDriverModuleTarget ();
295 class MingwNativeDLLModuleHandler
: public MingwModuleHandler
298 MingwNativeDLLModuleHandler ( const Module
& module
);
299 virtual HostType
DefaultHost() { return HostFalse
; }
300 virtual void Process ();
301 std::string
TypeSpecificCFlags() { return "-D_SEH_NO_NATIVE_NLG"; }
302 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
304 void GenerateNativeDLLModuleTarget ();
308 class MingwNativeCUIModuleHandler
: public MingwModuleHandler
311 MingwNativeCUIModuleHandler ( const Module
& module
);
312 virtual HostType
DefaultHost() { return HostFalse
; }
313 virtual void Process ();
314 std::string
TypeSpecificCFlags() { return "-D__NTAPP__ -D_SEH_NO_NATIVE_NLG"; }
315 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
317 void GenerateNativeCUIModuleTarget ();
321 class MingwWin32DLLModuleHandler
: public MingwModuleHandler
324 MingwWin32DLLModuleHandler ( const Module
& module
);
325 virtual HostType
DefaultHost() { return HostFalse
; }
326 virtual void Process ();
328 void GenerateWin32DLLModuleTarget ();
332 class MingwWin32CUIModuleHandler
: public MingwModuleHandler
335 MingwWin32CUIModuleHandler ( const Module
& module
);
336 virtual HostType
DefaultHost() { return HostFalse
; }
337 virtual void Process ();
339 void GenerateWin32CUIModuleTarget ();
343 class MingwWin32GUIModuleHandler
: public MingwModuleHandler
346 MingwWin32GUIModuleHandler ( const Module
& module
);
347 virtual HostType
DefaultHost() { return HostFalse
; }
348 virtual void Process ();
350 void GenerateWin32GUIModuleTarget ();
354 class MingwBootLoaderModuleHandler
: public MingwModuleHandler
357 MingwBootLoaderModuleHandler ( const Module
& module
);
358 virtual HostType
DefaultHost() { return HostFalse
; }
359 virtual void Process ();
360 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
362 void GenerateBootLoaderModuleTarget ();
366 class MingwBootSectorModuleHandler
: public MingwModuleHandler
369 MingwBootSectorModuleHandler ( const Module
& module
);
370 virtual HostType
DefaultHost() { return HostFalse
; }
371 virtual void Process ();
372 std::string
TypeSpecificNasmFlags() { return "-f bin"; }
374 void GenerateBootSectorModuleTarget ();
378 class MingwBootProgramModuleHandler
: public MingwModuleHandler
381 MingwBootProgramModuleHandler ( const Module
& module
);
382 virtual HostType
DefaultHost() { return HostFalse
; }
383 virtual void Process ();
384 std::string
GetProgTextAddrMacro ();
385 std::string
TypeSpecificLinkerFlags() { return "-nostartfiles -nostdlib"; }
387 void GenerateBootProgramModuleTarget ();
391 class MingwIsoModuleHandler
: public MingwModuleHandler
394 MingwIsoModuleHandler ( const Module
& module
);
395 virtual HostType
DefaultHost() { return HostFalse
; }
396 virtual void Process ();
398 void GenerateIsoModuleTarget ();
399 std::string
GetBootstrapCdDirectories ( const std::string
& bootcdDirectory
);
400 std::string
GetNonModuleCdDirectories ( const std::string
& bootcdDirectory
);
401 std::string
GetCdDirectories ( const std::string
& bootcdDirectory
);
402 void GetBootstrapCdFiles ( std::vector
<std::string
>& out
) const;
403 void GetNonModuleCdFiles ( std::vector
<std::string
>& out
) const;
404 void GetCdFiles ( std::vector
<std::string
>& out
) const;
405 void OutputBootstrapfileCopyCommands ( const std::string
& bootcdDirectory
);
406 void OutputCdfileCopyCommands ( const std::string
& bootcdDirectory
);
410 class MingwLiveIsoModuleHandler
: public MingwModuleHandler
413 MingwLiveIsoModuleHandler ( const Module
& module
);
414 virtual HostType
DefaultHost() { return HostFalse
; }
415 virtual void Process ();
417 void GenerateLiveIsoModuleTarget ();
418 void CreateDirectory ( const std::string
& directory
);
419 void OutputCopyCommand ( const std::string
& sourceFilename
,
420 const std::string
& targetFilename
,
421 const std::string
& targetDirectory
);
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 ();
439 virtual void GetModuleSpecificCompilationUnits ( std::vector
<CompilationUnit
*>& compilationUnits
);
441 void GenerateTestModuleTarget ();
445 class MingwRpcServerModuleHandler
: public MingwModuleHandler
448 MingwRpcServerModuleHandler ( const Module
& module
);
449 virtual HostType
DefaultHost() { return HostFalse
; }
450 virtual void Process ();
454 class MingwRpcClientModuleHandler
: public MingwModuleHandler
457 MingwRpcClientModuleHandler ( const Module
& module
);
458 virtual HostType
DefaultHost() { return HostFalse
; }
459 virtual void Process ();
462 class MingwAliasModuleHandler
: public MingwModuleHandler
465 MingwAliasModuleHandler ( const Module
& module
);
466 virtual HostType
DefaultHost() { return HostFalse
; }
467 virtual void Process ();
470 #endif /* MINGW_MODULEHANDLER_H */