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 #include "../../pch.h"
21 #include "../../rbuild.h"
23 #include "modulehandler.h"
28 #define CLEAN_FILE(f) clean_files.push_back ( f );
30 static string ros_temp
= "$(TEMPORARY)";
32 MingwModuleHandler::backend
= NULL
;
34 MingwModuleHandler::fMakefile
= NULL
;
38 const string
& filename
,
39 const string
& prefix
)
41 if ( !prefix
.length() )
44 const char* pfilename
= filename
.c_str();
45 const char* p1
= strrchr ( pfilename
, '/' );
46 const char* p2
= strrchr ( pfilename
, '\\' );
51 out
+= string(pfilename
,p1
-pfilename
) + cSep
;
54 out
+= prefix
+ pfilename
;
59 GetTargetMacro ( const Module
& module
, bool with_dollar
)
61 string
s ( module
.name
);
65 return ssprintf ( "$(%s)", s
.c_str() );
69 MingwModuleHandler::MingwModuleHandler (
70 const Module
& module_
)
77 MingwModuleHandler::~MingwModuleHandler()
82 MingwModuleHandler::SetBackend ( MingwBackend
* backend_
)
88 MingwModuleHandler::SetMakefile ( FILE* f
)
94 MingwModuleHandler::EnablePreCompiledHeaderSupport ()
100 MingwModuleHandler::RemoveVariables ( string path
)
102 size_t i
= path
.find ( '$' );
103 if ( i
!= string::npos
)
105 size_t j
= path
.find ( ')', i
);
106 if ( j
!= string::npos
)
108 if ( j
+ 2 < path
.length () && path
[j
+ 1] == cSep
)
109 return path
.substr ( j
+ 2);
111 return path
.substr ( j
+ 1);
118 MingwModuleHandler::PassThruCacheDirectory (
120 Directory
* directoryTree
)
122 string
directory ( GetDirectory ( RemoveVariables ( file
) ) );
123 if ( directoryTree
== NULL
)
125 string generatedFilesDirectory
= backend
->AddDirectoryTarget ( directory
,
127 if ( directory
.find ( generatedFilesDirectory
) != string::npos
)
128 /* This path already includes the generated files directory variable */
133 return generatedFilesDirectory
;
134 return generatedFilesDirectory
+ sSep
+ file
;
139 MingwModuleHandler::PassThruCacheDirectory (const FileLocation
* fileLocation
)
141 return PassThruCacheDirectory ( fileLocation
->filename
,
142 fileLocation
->directory
);
145 /*static*/ Directory
*
146 MingwModuleHandler::GetTargetDirectoryTree (
147 const Module
& module
)
149 if ( module
.type
== StaticLibrary
)
150 return backend
->intermediateDirectory
;
151 return backend
->outputDirectory
;
155 MingwModuleHandler::GetTargetFilename (
156 const Module
& module
,
157 string_list
* pclean_files
)
159 string target
= PassThruCacheDirectory (
160 NormalizeFilename ( module
.GetPath () ),
161 GetTargetDirectoryTree ( module
) );
164 string_list
& clean_files
= *pclean_files
;
165 CLEAN_FILE ( target
);
171 MingwModuleHandler::GetImportLibraryFilename (
172 const Module
& module
,
173 string_list
* pclean_files
)
175 string target
= PassThruCacheDirectory (
176 NormalizeFilename ( module
.GetDependencyPath () ),
177 backend
->intermediateDirectory
);
180 string_list
& clean_files
= *pclean_files
;
181 CLEAN_FILE ( target
);
186 /*static*/ MingwModuleHandler
*
187 MingwModuleHandler::InstanciateHandler (
188 const Module
& module
,
189 MingwBackend
* backend
)
191 MingwModuleHandler
* handler
;
192 switch ( module
.type
)
195 handler
= new MingwBuildToolModuleHandler ( module
);
198 handler
= new MingwStaticLibraryModuleHandler ( module
);
201 handler
= new MingwObjectLibraryModuleHandler ( module
);
204 handler
= new MingwKernelModuleHandler ( module
);
207 handler
= new MingwNativeCUIModuleHandler ( module
);
210 handler
= new MingwWin32CUIModuleHandler ( module
);
214 handler
= new MingwWin32GUIModuleHandler ( module
);
217 handler
= new MingwKernelModeDLLModuleHandler ( module
);
220 handler
= new MingwNativeDLLModuleHandler ( module
);
223 handler
= new MingwWin32DLLModuleHandler ( module
);
225 case KernelModeDriver
:
226 case ExportDriver
: // maybe change this later
227 handler
= new MingwKernelModeDriverModuleHandler ( module
);
230 handler
= new MingwBootLoaderModuleHandler ( module
);
233 handler
= new MingwBootSectorModuleHandler ( module
);
236 handler
= new MingwBootProgramModuleHandler ( module
);
239 handler
= new MingwIsoModuleHandler ( module
);
242 handler
= new MingwLiveIsoModuleHandler ( module
);
245 handler
= new MingwIsoModuleHandler ( module
);
248 handler
= new MingwLiveIsoModuleHandler ( module
);
251 handler
= new MingwTestModuleHandler ( module
);
254 handler
= new MingwRpcServerModuleHandler ( module
);
257 handler
= new MingwRpcClientModuleHandler ( module
);
260 handler
= new MingwAliasModuleHandler ( module
);
263 handler
= new MingwIdlHeaderModuleHandler ( module
);
266 throw UnknownModuleTypeException (
267 module
.node
.location
,
275 MingwModuleHandler::GetWorkingDirectory () const
281 MingwModuleHandler::GetBasename ( const string
& filename
) const
283 size_t index
= filename
.find_last_of ( '.' );
284 if ( index
!= string::npos
)
285 return filename
.substr ( 0, index
);
290 MingwModuleHandler::GetActualSourceFilename (
291 const FileLocation
* fileLocation
) const
293 string filename
= fileLocation
->filename
;
294 string extension
= GetExtension ( filename
);
295 if ( extension
== ".spec" || extension
== ".SPEC" )
297 string basename
= GetBasename ( filename
);
298 PassThruCacheDirectory ( NormalizeFilename ( basename
+ ".stubs.c" ),
299 backend
->intermediateDirectory
);
300 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( basename
+ ".stubs.c" ) );
302 else if ( extension
== ".idl" || extension
== ".IDL" )
304 string basename
= GetBasename ( filename
);
306 if ( module
.type
== RpcServer
)
307 newname
= basename
+ "_s.c";
308 else if ( module
.type
== RpcClient
)
309 newname
= basename
+ "_c.c";
310 else //if ( module.type == IdlHeader )
311 newname
= basename
+ ".h";
312 PassThruCacheDirectory ( NormalizeFilename ( newname
),
313 backend
->intermediateDirectory
);
314 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( newname
) );
317 return new FileLocation ( fileLocation
->directory
, filename
);
321 MingwModuleHandler::GetExtraDependencies (
322 const string
& filename
) const
324 string extension
= GetExtension ( filename
);
325 if ( extension
== ".idl" || extension
== ".IDL" )
327 string basename
= GetBasename ( filename
);
328 if ( module
.type
== IdlHeader
)
329 return GetIdlHeaderFilename ( basename
);
331 return GetRpcServerHeaderFilename ( basename
) + " " + GetRpcClientHeaderFilename ( basename
);
338 MingwModuleHandler::GetCompilationUnitDependencies (
339 const CompilationUnit
& compilationUnit
) const
341 if ( compilationUnit
.files
.size () <= 1 )
343 vector
<string
> sourceFiles
;
344 for ( size_t i
= 0; i
< compilationUnit
.files
.size (); i
++ )
346 File
& file
= *compilationUnit
.files
[i
];
347 sourceFiles
.push_back ( NormalizeFilename ( file
.name
) );
349 return v2s ( sourceFiles
, 10 );
353 MingwModuleHandler::GetModuleArchiveFilename () const
355 if ( module
.type
== StaticLibrary
)
356 return GetTargetFilename ( module
, NULL
);
357 return PassThruCacheDirectory ( ReplaceExtension (
358 NormalizeFilename ( module
.GetPath () ),
360 backend
->intermediateDirectory
);
364 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
366 string extension
= GetExtension ( file
.name
);
367 return ( extension
== ".spec" || extension
== ".SPEC" );
371 MingwModuleHandler::ReferenceObjects (
372 const Module
& module
)
374 if ( module
.type
== ObjectLibrary
)
376 if ( module
.type
== RpcServer
)
378 if ( module
.type
== RpcClient
)
380 if ( module
.type
== IdlHeader
)
386 MingwModuleHandler::GetImportLibraryDependency (
387 const Module
& importedModule
)
390 if ( ReferenceObjects ( importedModule
) )
391 dep
= GetTargetMacro ( importedModule
);
393 dep
= GetImportLibraryFilename ( importedModule
, NULL
);
398 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
399 string_list
& targets
)
401 if ( dependencyModule
.invocations
.size () > 0 )
403 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
405 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
406 invoke
.GetTargets ( targets
);
410 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
414 MingwModuleHandler::GetModuleDependencies (
415 string_list
& dependencies
)
417 size_t iend
= module
.dependencies
.size ();
422 for ( size_t i
= 0; i
< iend
; i
++ )
424 const Dependency
& dependency
= *module
.dependencies
[i
];
425 const Module
& dependencyModule
= *dependency
.dependencyModule
;
426 GetTargets ( dependencyModule
,
429 GetDefinitionDependencies ( dependencies
);
433 MingwModuleHandler::GetSourceFilenames ( string_list
& list
,
434 bool includeGeneratedFiles
) const
438 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
439 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
441 if ( includeGeneratedFiles
|| !compilationUnits
[i
]->IsGeneratedFile () )
443 FileLocation
* sourceFileLocation
= GetActualSourceFilename (
444 compilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
) );
445 list
.push_back ( PassThruCacheDirectory ( sourceFileLocation
->filename
,
446 sourceFileLocation
->directory
) );
449 // intentionally make a copy so that we can append more work in
450 // the middle of processing without having to go recursive
451 vector
<If
*> v
= module
.non_if_data
.ifs
;
452 for ( i
= 0; i
< v
.size (); i
++ )
456 // check for sub-ifs to add to list
457 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
458 for ( j
= 0; j
< ifs
.size (); j
++ )
459 v
.push_back ( ifs
[j
] );
460 const vector
<CompilationUnit
*>& compilationUnits
= rIf
.data
.compilationUnits
;
461 for ( j
= 0; j
< compilationUnits
.size (); j
++ )
463 CompilationUnit
& compilationUnit
= *compilationUnits
[j
];
464 if ( includeGeneratedFiles
|| !compilationUnit
.IsGeneratedFile () )
466 FileLocation
* sourceFileLocation
= GetActualSourceFilename (
467 compilationUnit
.GetFilename ( backend
->intermediateDirectory
) );
468 list
.push_back ( PassThruCacheDirectory ( sourceFileLocation
->filename
,
469 sourceFileLocation
->directory
) );
476 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
477 string_list
& list
) const
479 GetSourceFilenames ( list
, false );
483 MingwModuleHandler::GetObjectFilename (
484 const FileLocation
* sourceFileLocation
,
485 string_list
* pclean_files
) const
487 string sourceFilename
= sourceFileLocation
->filename
;
488 Directory
* directoryTree
;
490 string extension
= GetExtension ( sourceFilename
);
491 if ( extension
== ".rc" || extension
== ".RC" )
492 newExtension
= ".coff";
493 else if ( extension
== ".spec" || extension
== ".SPEC" )
494 newExtension
= ".stubs.o";
495 else if ( extension
== ".idl" || extension
== ".IDL" )
497 if ( module
.type
== IdlHeader
)
501 if ( module
.type
== RpcServer
)
502 newExtension
= "_s.o";
504 newExtension
= "_c.o";
510 if ( module
.type
== BootSector
)
511 directoryTree
= backend
->outputDirectory
;
513 directoryTree
= backend
->intermediateDirectory
;
515 string obj_file
= PassThruCacheDirectory (
516 NormalizeFilename ( ReplaceExtension (
517 RemoveVariables ( sourceFilename
),
522 string_list
& clean_files
= *pclean_files
;
523 CLEAN_FILE ( obj_file
);
529 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
531 return module
.name
+ "_clean";
535 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
537 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
539 Library
& library
= *module
.non_if_data
.libraries
[i
];
540 if ( library
.importedModule
->type
== ObjectLibrary
)
541 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
546 MingwModuleHandler::GenerateCleanTarget () const
548 if ( module
.type
== Alias
)
552 ".PHONY: %s_clean\n",
553 module
.name
.c_str() );
554 vector
<string
> referencedModuleNames
;
555 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
558 GetModuleCleanTarget ( module
).c_str(),
559 v2s ( referencedModuleNames
, 10 ).c_str () );
560 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
563 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
564 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
566 fprintf ( fMakefile
, " 2>$(NUL)\n" );
567 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
571 MingwModuleHandler::GenerateInstallTarget () const
573 if ( module
.installName
.length () == 0 )
575 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
576 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
577 NormalizeFilename ( module
.installBase
+ sSep
+ module
.installName
),
578 backend
->installDirectory
);
581 module
.name
.c_str (),
582 normalizedTargetFilename
.c_str() );
586 MingwModuleHandler::GenerateDependsTarget () const
589 ".PHONY: %s_depends\n",
590 module
.name
.c_str() );
592 "%s_depends: $(RBUILD_TARGET)\n",
593 module
.name
.c_str () );
595 "\t$(ECHO_RBUILD)\n" );
597 "\t$(Q)$(RBUILD_TARGET) -dm%s mingw\n",
598 module
.name
.c_str () );
602 MingwModuleHandler::GetObjectFilenames ()
604 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
605 if ( compilationUnits
.size () == 0 )
608 string
objectFilenames ( "" );
609 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
611 if ( objectFilenames
.size () > 0 )
612 objectFilenames
+= " ";
613 objectFilenames
+= GetObjectFilename ( compilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
), NULL
);
615 return objectFilenames
;
619 MingwModuleHandler::GenerateGccDefineParametersFromVector (
620 const vector
<Define
*>& defines
)
623 for ( size_t i
= 0; i
< defines
.size (); i
++ )
625 Define
& define
= *defines
[i
];
626 if (parameters
.length () > 0)
629 parameters
+= define
.name
;
630 if (define
.value
.length () > 0)
633 parameters
+= define
.value
;
640 MingwModuleHandler::GenerateGccDefineParameters () const
642 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
643 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
644 if ( s
.length () > 0 )
653 MingwModuleHandler::ConcatenatePaths (
655 const string
& path2
) const
657 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
659 if ( path1
[path1
.length ()] == cSep
)
660 return path1
+ path2
;
662 return path1
+ cSep
+ path2
;
666 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
669 for ( size_t i
= 0; i
< includes
.size (); i
++ )
671 Include
& include
= *includes
[i
];
672 if ( parameters
.length () > 0 )
674 parameters
+= "-I" + include
.directory
;
680 MingwModuleHandler::GenerateGccIncludeParameters () const
682 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
683 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
684 if ( s
.length () > 0 )
693 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
696 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
698 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
699 if ( parameters
.length () > 0 )
701 parameters
+= compilerFlag
.flag
;
707 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
710 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
712 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
713 if ( parameters
.length () > 0 )
715 parameters
+= linkerFlag
.flag
;
721 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
722 const vector
<Library
*>& libraries
)
724 string
dependencies ( "" );
726 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
728 if ( wrap_count
++ == 5 )
729 dependencies
+= " \\\n\t\t", wrap_count
= 0;
730 else if ( dependencies
.size () > 0 )
732 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
738 MingwModuleHandler::GenerateLinkerParameters () const
740 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
744 MingwModuleHandler::GenerateMacro (
745 const char* assignmentOperation
,
747 const IfableData
& data
)
750 bool generateAssignment
;
752 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
753 if ( generateAssignment
)
758 assignmentOperation
);
761 if ( use_pch
&& module
.pch
!= NULL
)
765 GetDirectory ( GetPrecompiledHeaderFilename () ).c_str () );
768 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
769 if ( compilerParameters
.size () > 0 )
774 compilerParameters
.c_str () );
777 for ( i
= 0; i
< data
.includes
.size(); i
++ )
779 const Include
& include
= *data
.includes
[i
];
780 string includeDirectory
;
781 if ( include
.baseModule
!= NULL
&&
782 ( include
.baseModule
->type
== RpcServer
||
783 include
.baseModule
->type
== RpcClient
||
784 include
.baseModule
->type
== IdlHeader
) )
785 includeDirectory
= PassThruCacheDirectory ( NormalizeFilename ( include
.directory
),
786 backend
->intermediateDirectory
);
788 includeDirectory
= include
.directory
;
792 includeDirectory
.c_str() );
794 for ( i
= 0; i
< data
.defines
.size(); i
++ )
796 Define
& d
= *data
.defines
[i
];
801 if ( d
.value
.size() )
807 if ( generateAssignment
)
809 fprintf ( fMakefile
, "\n" );
814 MingwModuleHandler::GenerateMacros (
815 const char* assignmentOperation
,
816 const IfableData
& data
,
817 const vector
<LinkerFlag
*>* linkerFlags
)
821 GenerateMacro ( assignmentOperation
,
824 GenerateMacro ( assignmentOperation
,
828 if ( linkerFlags
!= NULL
)
830 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
831 if ( linkerParameters
.size () > 0 )
836 linkerflagsMacro
.c_str (),
838 linkerParameters
.c_str() );
842 if ( data
.libraries
.size () > 0 )
844 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
845 if ( deps
.size () > 0 )
856 const vector
<If
*>& ifs
= data
.ifs
;
857 for ( i
= 0; i
< ifs
.size(); i
++ )
860 if ( rIf
.data
.defines
.size()
861 || rIf
.data
.includes
.size()
862 || rIf
.data
.libraries
.size()
863 || rIf
.data
.compilationUnits
.size()
864 || rIf
.data
.compilerFlags
.size()
865 || rIf
.data
.ifs
.size() )
869 "%s (\"$(%s)\",\"%s\")\n",
870 rIf
.negated
? "ifneq" : "ifeq",
871 rIf
.property
.c_str(),
885 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
887 for (size_t i
= 0; i
< compilationUnits
.size (); i
++)
888 delete compilationUnits
[i
];
892 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
897 MingwModuleHandler::GenerateObjectMacros (
898 const char* assignmentOperation
,
899 const IfableData
& data
,
900 const vector
<LinkerFlag
*>* linkerFlags
)
904 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
905 if ( compilationUnits
.size () > 0 )
907 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
909 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
910 if ( compilationUnit
.IsFirstFile () )
914 objectsMacro
.c_str(),
915 GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
).c_str (),
916 objectsMacro
.c_str() );
922 objectsMacro
.c_str (),
923 assignmentOperation
);
924 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
926 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
927 if ( !compilationUnit
.IsFirstFile () )
932 ( i
%10 == 9 ? " \\\n\t" : " " ),
933 GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
).c_str () );
936 fprintf ( fMakefile
, "\n" );
939 const vector
<If
*>& ifs
= data
.ifs
;
940 for ( i
= 0; i
< ifs
.size(); i
++ )
943 if ( rIf
.data
.defines
.size()
944 || rIf
.data
.includes
.size()
945 || rIf
.data
.libraries
.size()
946 || rIf
.data
.compilationUnits
.size()
947 || rIf
.data
.compilerFlags
.size()
948 || rIf
.data
.ifs
.size() )
952 "%s (\"$(%s)\",\"%s\")\n",
953 rIf
.negated
? "ifneq" : "ifeq",
954 rIf
.property
.c_str(),
956 GenerateObjectMacros (
966 vector
<CompilationUnit
*> sourceCompilationUnits
;
967 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
968 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
973 objectsMacro
.c_str(),
974 GetObjectFilename ( sourceCompilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
), NULL
).c_str () );
976 CleanupCompilationUnitVector ( sourceCompilationUnits
);
980 MingwModuleHandler::GetPrecompiledHeaderFilename () const
982 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
983 return PassThruCacheDirectory ( NormalizeFilename ( basePchFilename
),
984 backend
->intermediateDirectory
);
988 MingwModuleHandler::GenerateGccCommand (
989 const FileLocation
* sourceFileLocation
,
990 const string
& extraDependencies
,
992 const string
& cflagsMacro
)
994 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
995 string dependencies
= sourceFilename
;
996 if ( extraDependencies
!= "" )
997 dependencies
+= " " + extraDependencies
;
998 if ( module
.pch
&& use_pch
)
999 dependencies
+= " " + GetPrecompiledHeaderFilename ();
1001 /* WIDL generated headers may be used */
1002 vector
<string
> rpcDependencies
;
1003 GetRpcHeaderDependencies ( rpcDependencies
);
1004 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1005 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1007 string objectFilename
= GetObjectFilename (
1008 sourceFileLocation
, &clean_files
);
1009 fprintf ( fMakefile
,
1011 objectFilename
.c_str (),
1012 dependencies
.c_str (),
1013 GetDirectory ( objectFilename
).c_str () );
1014 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
1015 fprintf ( fMakefile
,
1016 "\t%s -c $< -o $@ %s\n",
1018 cflagsMacro
.c_str () );
1022 MingwModuleHandler::GenerateGccAssemblerCommand (
1023 const FileLocation
* sourceFileLocation
,
1025 const string
& cflagsMacro
)
1027 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1028 string dependencies
= sourceFilename
;
1029 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1030 string objectFilename
= GetObjectFilename (
1031 sourceFileLocation
, &clean_files
);
1032 fprintf ( fMakefile
,
1034 objectFilename
.c_str (),
1035 dependencies
.c_str (),
1036 GetDirectory ( objectFilename
).c_str () );
1037 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
1038 fprintf ( fMakefile
,
1039 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
1041 cflagsMacro
.c_str () );
1045 MingwModuleHandler::GenerateNasmCommand (
1046 const FileLocation
* sourceFileLocation
,
1047 const string
& nasmflagsMacro
)
1049 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1050 string dependencies
= sourceFilename
;
1051 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1052 string objectFilename
= GetObjectFilename (
1053 sourceFileLocation
, &clean_files
);
1054 fprintf ( fMakefile
,
1056 objectFilename
.c_str (),
1057 dependencies
.c_str (),
1058 GetDirectory ( objectFilename
).c_str () );
1059 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1060 fprintf ( fMakefile
,
1061 "\t%s -f win32 $< -o $@ %s\n",
1063 nasmflagsMacro
.c_str () );
1067 MingwModuleHandler::GenerateWindresCommand (
1068 const FileLocation
* sourceFileLocation
,
1069 const string
& windresflagsMacro
)
1071 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1072 string dependencies
= sourceFilename
;
1073 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1074 string objectFilename
= GetObjectFilename ( sourceFileLocation
, &clean_files
);
1075 string sourceFilenamePart
= ReplaceExtension ( GetFilename ( sourceFilename
), "" );
1076 string rciFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".rci.tmp";
1077 string resFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".res.tmp";
1078 if ( module
.useWRC
)
1080 fprintf ( fMakefile
,
1081 "%s: %s $(WRC_TARGET) | %s\n",
1082 objectFilename
.c_str (),
1083 dependencies
.c_str (),
1084 GetDirectory ( objectFilename
).c_str () );
1085 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1086 fprintf ( fMakefile
,
1087 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1088 windresflagsMacro
.c_str (),
1089 sourceFilename
.c_str (),
1090 rciFilename
.c_str () );
1091 fprintf ( fMakefile
,
1092 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1093 windresflagsMacro
.c_str (),
1094 rciFilename
.c_str (),
1095 resFilename
.c_str () );
1096 fprintf ( fMakefile
,
1097 "\t-@${rm} %s 2>$(NUL)\n",
1098 rciFilename
.c_str () );
1099 fprintf ( fMakefile
,
1100 "\t${windres} %s -o $@\n",
1101 resFilename
.c_str () );
1102 fprintf ( fMakefile
,
1103 "\t-@${rm} %s 2>$(NUL)\n",
1104 resFilename
.c_str () );
1108 fprintf ( fMakefile
,
1109 "%s: %s $(WRC_TARGET) | %s\n",
1110 objectFilename
.c_str (),
1111 dependencies
.c_str (),
1112 GetDirectory ( objectFilename
).c_str () );
1113 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1114 fprintf ( fMakefile
,
1115 "\t${windres} $(%s) %s -o $@\n",
1116 windresflagsMacro
.c_str (),
1117 sourceFilename
.c_str () );
1122 MingwModuleHandler::GenerateWinebuildCommands (
1123 const FileLocation
* sourceFileLocation
)
1125 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1126 string dependencies
= sourceFilename
;
1127 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1129 string basename
= GetBasename ( sourceFilename
);
1130 string def_file
= PassThruCacheDirectory (
1131 basename
+ ".spec.def",
1132 backend
->intermediateDirectory
);
1133 CLEAN_FILE(def_file
);
1135 string stub_file
= PassThruCacheDirectory (
1136 basename
+ ".stubs.c",
1137 backend
->intermediateDirectory
);
1138 CLEAN_FILE(stub_file
)
1140 fprintf ( fMakefile
,
1141 "%s: %s $(WINEBUILD_TARGET) | %s\n",
1143 dependencies
.c_str (),
1144 GetDirectory ( def_file
).c_str () );
1145 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1146 fprintf ( fMakefile
,
1147 "\t%s -o %s --def -E %s\n",
1148 "$(Q)$(WINEBUILD_TARGET)",
1150 sourceFilename
.c_str () );
1151 fprintf ( fMakefile
,
1152 "%s: %s $(WINEBUILD_TARGET)\n",
1154 sourceFilename
.c_str () );
1155 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1156 fprintf ( fMakefile
,
1157 "\t%s -o %s --pedll %s\n",
1158 "$(Q)$(WINEBUILD_TARGET)",
1160 sourceFilename
.c_str () );
1164 MingwModuleHandler::GetWidlFlags ( const CompilationUnit
& compilationUnit
)
1166 return compilationUnit
.GetSwitches ();
1170 MingwModuleHandler::GetRpcServerHeaderFilename ( string basename
) const
1172 return PassThruCacheDirectory ( basename
+ "_s.h",
1173 backend
->intermediateDirectory
);
1177 MingwModuleHandler::GenerateWidlCommandsServer (
1178 const CompilationUnit
& compilationUnit
,
1179 const string
& widlflagsMacro
)
1181 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1182 string filename
= sourceFileLocation
->filename
;
1183 string dependencies
= filename
;
1184 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1186 string basename
= GetBasename ( filename
);
1188 string generatedHeaderFilename
= GetRpcServerHeaderFilename ( basename
);
1189 CLEAN_FILE(generatedHeaderFilename
);
1191 string generatedServerFilename
= PassThruCacheDirectory (
1193 backend
->intermediateDirectory
);
1194 CLEAN_FILE(generatedServerFilename
);
1196 fprintf ( fMakefile
,
1197 "%s %s: %s $(WIDL_TARGET) | %s\n",
1198 generatedServerFilename
.c_str (),
1199 generatedHeaderFilename
.c_str (),
1200 dependencies
.c_str (),
1201 GetDirectory ( generatedServerFilename
).c_str () );
1202 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1203 fprintf ( fMakefile
,
1204 "\t%s %s %s -h -H %s -s -S %s %s\n",
1205 "$(Q)$(WIDL_TARGET)",
1206 GetWidlFlags ( compilationUnit
).c_str (),
1207 widlflagsMacro
.c_str (),
1208 generatedHeaderFilename
.c_str (),
1209 generatedServerFilename
.c_str (),
1210 filename
.c_str () );
1214 MingwModuleHandler::GetRpcClientHeaderFilename ( string basename
) const
1216 return PassThruCacheDirectory ( basename
+ "_c.h",
1217 backend
->intermediateDirectory
);
1221 MingwModuleHandler::GetIdlHeaderFilename ( string basename
) const
1223 return PassThruCacheDirectory ( basename
+ ".h",
1224 backend
->intermediateDirectory
);
1228 MingwModuleHandler::GenerateWidlCommandsClient (
1229 const CompilationUnit
& compilationUnit
,
1230 const string
& widlflagsMacro
)
1232 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1233 string filename
= sourceFileLocation
->filename
;
1234 string dependencies
= filename
;
1235 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1237 string basename
= GetBasename ( filename
);
1239 string generatedHeaderFilename
= GetRpcClientHeaderFilename ( basename
);
1240 CLEAN_FILE(generatedHeaderFilename
);
1242 string generatedClientFilename
= PassThruCacheDirectory (
1244 backend
->intermediateDirectory
);
1245 CLEAN_FILE(generatedClientFilename
);
1247 fprintf ( fMakefile
,
1248 "%s %s: %s $(WIDL_TARGET) | %s\n",
1249 generatedClientFilename
.c_str (),
1250 generatedHeaderFilename
.c_str (),
1251 dependencies
.c_str (),
1252 GetDirectory ( generatedClientFilename
).c_str () );
1253 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1254 fprintf ( fMakefile
,
1255 "\t%s %s %s -h -H %s -c -C %s %s\n",
1256 "$(Q)$(WIDL_TARGET)",
1257 GetWidlFlags ( compilationUnit
).c_str (),
1258 widlflagsMacro
.c_str (),
1259 generatedHeaderFilename
.c_str (),
1260 generatedClientFilename
.c_str (),
1261 filename
.c_str () );
1265 MingwModuleHandler::GenerateWidlCommandsIdlHeader (
1266 const CompilationUnit
& compilationUnit
,
1267 const string
& widlflagsMacro
)
1269 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1270 string filename
= sourceFileLocation
->filename
;
1271 string dependencies
= filename
;
1272 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1274 string basename
= GetBasename ( filename
);
1276 string generatedHeaderFilename
= GetIdlHeaderFilename ( basename
);
1277 CLEAN_FILE(generatedHeaderFilename
);
1279 fprintf ( fMakefile
,
1280 "%s: %s $(WIDL_TARGET) | %s\n",
1281 generatedHeaderFilename
.c_str (),
1282 dependencies
.c_str (),
1283 GetDirectory ( generatedHeaderFilename
).c_str () );
1284 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1285 fprintf ( fMakefile
,
1286 "\t%s %s %s -h -H %s %s\n",
1287 "$(Q)$(WIDL_TARGET)",
1288 GetWidlFlags ( compilationUnit
).c_str (),
1289 widlflagsMacro
.c_str (),
1290 generatedHeaderFilename
.c_str (),
1291 filename
.c_str () );
1295 MingwModuleHandler::GenerateWidlCommands (
1296 const CompilationUnit
& compilationUnit
,
1297 const string
& widlflagsMacro
)
1299 if ( module
.type
== RpcServer
)
1300 GenerateWidlCommandsServer ( compilationUnit
,
1302 else if ( module
.type
== RpcClient
)
1303 GenerateWidlCommandsClient ( compilationUnit
,
1305 else if ( module
.type
== IdlHeader
)
1306 GenerateWidlCommandsIdlHeader ( compilationUnit
,
1311 MingwModuleHandler::GenerateCommands (
1312 const CompilationUnit
& compilationUnit
,
1315 const string
& cflagsMacro
,
1316 const string
& nasmflagsMacro
,
1317 const string
& windresflagsMacro
,
1318 const string
& widlflagsMacro
)
1320 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1321 string filename
= sourceFileLocation
->filename
;
1322 string extension
= GetExtension ( filename
);
1323 if ( extension
== ".c" || extension
== ".C" )
1325 GenerateGccCommand ( sourceFileLocation
,
1326 GetCompilationUnitDependencies ( compilationUnit
),
1331 else if ( extension
== ".cc" || extension
== ".CC" ||
1332 extension
== ".cpp" || extension
== ".CPP" ||
1333 extension
== ".cxx" || extension
== ".CXX" )
1335 GenerateGccCommand ( sourceFileLocation
,
1336 GetCompilationUnitDependencies ( compilationUnit
),
1341 else if ( extension
== ".s" || extension
== ".S" )
1343 GenerateGccAssemblerCommand ( sourceFileLocation
,
1348 else if ( extension
== ".asm" || extension
== ".ASM" )
1350 GenerateNasmCommand ( sourceFileLocation
,
1354 else if ( extension
== ".rc" || extension
== ".RC" )
1356 GenerateWindresCommand ( sourceFileLocation
,
1357 windresflagsMacro
);
1360 else if ( extension
== ".spec" || extension
== ".SPEC" )
1362 GenerateWinebuildCommands ( sourceFileLocation
);
1363 GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation
),
1369 else if ( extension
== ".idl" || extension
== ".IDL" )
1371 GenerateWidlCommands ( compilationUnit
,
1373 if ( module
.type
!= IdlHeader
)
1375 GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation
),
1376 GetExtraDependencies ( filename
),
1383 throw InvalidOperationException ( __FILE__
,
1385 "Unsupported filename extension '%s' in file '%s'",
1387 filename
.c_str () );
1391 MingwModuleHandler::GenerateBuildMapCode ( const char *mapTarget
)
1393 fprintf ( fMakefile
,
1394 "ifeq ($(ROS_BUILDMAP),full)\n" );
1396 string mapFilename
= PassThruCacheDirectory (
1397 GetBasename ( module
.GetPath () ) + ".map",
1398 backend
->outputDirectory
);
1399 CLEAN_FILE ( mapFilename
);
1401 fprintf ( fMakefile
,
1402 "\t$(ECHO_OBJDUMP)\n" );
1403 fprintf ( fMakefile
,
1404 "\t$(Q)${objdump} -d -S %s > %s\n",
1405 mapTarget
? mapTarget
: "$@",
1406 mapFilename
.c_str () );
1408 fprintf ( fMakefile
,
1410 fprintf ( fMakefile
,
1411 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1413 fprintf ( fMakefile
,
1415 fprintf ( fMakefile
,
1416 "\t$(Q)${nm} --numeric-sort %s > %s\n",
1417 mapTarget
? mapTarget
: "$@",
1418 mapFilename
.c_str () );
1420 fprintf ( fMakefile
,
1423 fprintf ( fMakefile
,
1428 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1430 fprintf ( fMakefile
,
1431 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1433 string filename
= module
.GetPath ();
1434 string outputFilename
= PassThruCacheDirectory (
1436 backend
->outputDirectory
);
1437 string nostripFilename
= PassThruCacheDirectory (
1438 GetBasename ( filename
) + ".nostrip" + GetExtension ( filename
),
1439 backend
->outputDirectory
);
1440 CLEAN_FILE ( nostripFilename
);
1442 fprintf ( fMakefile
,
1444 fprintf ( fMakefile
,
1445 "\t${cp} %s %s 1>$(NUL)\n",
1446 outputFilename
.c_str (),
1447 nostripFilename
.c_str () );
1449 fprintf ( fMakefile
,
1454 MergeStringVector ( const vector
<string
>& input
,
1455 vector
<string
>& output
)
1459 int wrap_count
= -1;
1460 for ( size_t i
= 0; i
< input
.size (); i
++ )
1462 if ( input
[i
].size () == 0 )
1464 if ( wrap_count
++ == wrap_at
)
1466 output
.push_back ( s
);
1470 else if ( s
.size () > 0)
1474 if ( s
.length () > 0 )
1475 output
.push_back ( s
);
1479 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1480 vector
<string
>& objectFiles
) const
1482 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1484 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1485 objectFiles
.push_back ( GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
) );
1490 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1492 if ( backend
->configuration
.CleanAsYouGo
)
1494 vector
<string
> objectFiles
;
1495 GetObjectsVector ( module
.non_if_data
,
1497 vector
<string
> lines
;
1498 MergeStringVector ( objectFiles
,
1500 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1502 fprintf ( fMakefile
,
1503 "\t-@${rm} %s 2>$(NUL)\n",
1504 lines
[i
].c_str () );
1510 MingwModuleHandler::GenerateRunRsymCode () const
1512 fprintf ( fMakefile
,
1513 "\t$(ECHO_RSYM)\n" );
1514 fprintf ( fMakefile
,
1515 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1519 MingwModuleHandler::GenerateRunStripCode () const
1521 fprintf ( fMakefile
,
1522 "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" );
1523 fprintf ( fMakefile
,
1524 "\t$(ECHO_STRIP)\n" );
1525 fprintf ( fMakefile
,
1526 "\t${strip} -s -x -X $@\n\n" );
1527 fprintf ( fMakefile
,
1532 MingwModuleHandler::GenerateLinkerCommand (
1533 const string
& dependencies
,
1534 const string
& linker
,
1535 const string
& linkerParameters
,
1536 const string
& objectsMacro
,
1537 const string
& libsMacro
,
1538 const string
& pefixupParameters
)
1540 string
target ( GetTargetMacro ( module
) );
1541 string
target_folder ( GetDirectory ( GetTargetFilename ( module
, NULL
) ) );
1542 string definitionFilename
= GetDefinitionFilename ();
1544 string linkerScriptArgument
;
1545 if ( module
.linkerScript
!= NULL
)
1546 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", module
.linkerScript
->directory
.c_str () );
1548 linkerScriptArgument
= "";
1550 fprintf ( fMakefile
,
1551 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1553 definitionFilename
.c_str (),
1554 dependencies
.c_str (),
1555 target_folder
.c_str () );
1556 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1557 string
targetName ( module
.GetTargetName () );
1559 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1561 if ( module
.IsDLL () )
1563 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1564 CLEAN_FILE ( temp_exp
);
1566 fprintf ( fMakefile
,
1567 "\t${dlltool} --dllname %s --def %s --output-exp %s %s\n",
1568 targetName
.c_str (),
1569 definitionFilename
.c_str (),
1573 fprintf ( fMakefile
,
1574 "\t%s %s %s %s -o %s %s %s %s\n",
1576 linkerParameters
.c_str (),
1577 linkerScriptArgument
.c_str (),
1580 objectsMacro
.c_str (),
1582 GetLinkerMacro ().c_str () );
1584 fprintf ( fMakefile
,
1585 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1587 pefixupParameters
.c_str() );
1589 fprintf ( fMakefile
,
1590 "\t-@${rm} %s 2>$(NUL)\n",
1591 temp_exp
.c_str () );
1595 fprintf ( fMakefile
,
1596 "\t%s %s %s -o %s %s %s %s\n",
1598 linkerParameters
.c_str (),
1599 linkerScriptArgument
.c_str (),
1601 objectsMacro
.c_str (),
1603 GetLinkerMacro ().c_str () );
1605 #if 0 // causes crashes sometimes
1606 fprintf ( fMakefile
,
1607 "\t${objcopy} -R .edata %s\n",
1612 GenerateBuildMapCode ();
1613 GenerateBuildNonSymbolStrippedCode ();
1614 GenerateRunRsymCode ();
1615 GenerateRunStripCode ();
1616 GenerateCleanObjectsAsYouGoCode ();
1620 MingwModuleHandler::GeneratePhonyTarget() const
1622 string
targetMacro ( GetTargetMacro ( module
) );
1623 fprintf ( fMakefile
,
1625 targetMacro
.c_str ());
1626 fprintf ( fMakefile
, "%s: | %s\n",
1627 targetMacro
.c_str (),
1628 GetDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1632 MingwModuleHandler::GenerateObjectFileTargets (
1633 const IfableData
& data
,
1636 const string
& cflagsMacro
,
1637 const string
& nasmflagsMacro
,
1638 const string
& windresflagsMacro
,
1639 const string
& widlflagsMacro
)
1643 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1644 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1646 GenerateCommands ( *compilationUnits
[i
],
1653 fprintf ( fMakefile
,
1657 const vector
<If
*>& ifs
= data
.ifs
;
1658 for ( i
= 0; i
< ifs
.size(); i
++ )
1660 GenerateObjectFileTargets ( ifs
[i
]->data
,
1669 vector
<CompilationUnit
*> sourceCompilationUnits
;
1670 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1671 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1673 GenerateCommands ( *sourceCompilationUnits
[i
],
1681 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1685 MingwModuleHandler::GenerateObjectFileTargets (
1688 const string
& cflagsMacro
,
1689 const string
& nasmflagsMacro
,
1690 const string
& windresflagsMacro
,
1691 const string
& widlflagsMacro
)
1693 if ( module
.pch
&& use_pch
)
1695 const string
& baseHeaderFilename
= module
.pch
->file
.name
;
1696 const string
& pchFilename
= GetPrecompiledHeaderFilename ();
1697 CLEAN_FILE(pchFilename
);
1698 string dependencies
= baseHeaderFilename
;
1699 /* WIDL generated headers may be used */
1700 vector
<string
> rpcDependencies
;
1701 GetRpcHeaderDependencies ( rpcDependencies
);
1702 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1703 fprintf ( fMakefile
,
1705 pchFilename
.c_str(),
1706 dependencies
.c_str() );
1707 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1708 fprintf ( fMakefile
,
1709 "\t%s -o %s %s -g %s\n\n",
1710 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1711 pchFilename
.c_str(),
1712 cflagsMacro
.c_str(),
1713 baseHeaderFilename
.c_str() );
1716 GenerateObjectFileTargets ( module
.non_if_data
,
1723 fprintf ( fMakefile
, "\n" );
1727 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1728 const string
& objs_macro
) const
1730 string
archiveFilename ( GetModuleArchiveFilename () );
1732 fprintf ( fMakefile
,
1734 archiveFilename
.c_str (),
1735 objs_macro
.c_str (),
1736 GetDirectory(archiveFilename
).c_str() );
1738 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
1740 string
archiveFilename ( GetModuleArchiveFilename () );
1741 string
definitionFilename ( GetDefinitionFilename () );
1743 fprintf ( fMakefile
,
1744 "\t${dlltool} --dllname %s --def %s --output-lib $@ %s -U\n",
1745 module
.importLibrary
->dllname
.c_str (),
1746 definitionFilename
.c_str (),
1747 module
.mangledSymbols
? "" : "--kill-at" );
1750 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1752 fprintf ( fMakefile
,
1755 objs_macro
.c_str ());
1757 GenerateCleanObjectsAsYouGoCode ();
1759 fprintf ( fMakefile
, "\n" );
1761 return archiveFilename
;
1765 MingwModuleHandler::GetCFlagsMacro () const
1767 return ssprintf ( "$(%s_CFLAGS)",
1768 module
.name
.c_str () );
1772 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1774 return ssprintf ( "$(%s_OBJS)",
1775 module
.name
.c_str () );
1779 MingwModuleHandler::GetLinkingDependenciesMacro () const
1781 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1785 MingwModuleHandler::GetLibsMacro () const
1787 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1791 MingwModuleHandler::GetLinkerMacro () const
1793 return ssprintf ( "$(%s_LFLAGS)",
1794 module
.name
.c_str () );
1798 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1800 if ( ReferenceObjects ( module
) )
1801 return GetObjectsMacro ( module
);
1803 return GetTargetFilename ( module
, NULL
);
1807 MingwModuleHandler::GenerateObjectMacro ()
1809 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1811 GenerateObjectMacros (
1814 &module
.linkerFlags
);
1816 // future references to the macro will be to get its values
1817 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1821 MingwModuleHandler::GenerateTargetMacro ()
1823 fprintf ( fMakefile
,
1825 GetTargetMacro ( module
, false ).c_str (),
1826 GetModuleTargets ( module
).c_str () );
1830 MingwModuleHandler::GetRpcHeaderDependencies (
1831 vector
<string
>& dependencies
) const
1833 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1835 Library
& library
= *module
.non_if_data
.libraries
[i
];
1836 if ( library
.importedModule
->type
== RpcServer
||
1837 library
.importedModule
->type
== RpcClient
||
1838 library
.importedModule
->type
== IdlHeader
)
1840 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
1842 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
1843 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1844 string extension
= GetExtension ( sourceFileLocation
->filename
);
1845 if ( extension
== ".idl" || extension
== ".IDL" )
1847 string basename
= GetBasename ( sourceFileLocation
->filename
);
1848 if ( library
.importedModule
->type
== RpcServer
)
1849 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
1850 if ( library
.importedModule
->type
== RpcClient
)
1851 dependencies
.push_back ( GetRpcClientHeaderFilename ( basename
) );
1852 if ( library
.importedModule
->type
== IdlHeader
)
1853 dependencies
.push_back ( GetIdlHeaderFilename ( basename
) );
1861 MingwModuleHandler::GenerateOtherMacros ()
1863 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1864 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1865 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1866 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1867 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1868 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1869 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1874 &module
.linkerFlags
);
1877 if ( module
.importLibrary
)
1879 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
1880 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
1882 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1883 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1884 string extension
= GetExtension ( sourceFileLocation
->filename
);
1885 if ( extension
== ".spec" || extension
== ".SPEC" )
1886 GetSpecObjectDependencies ( s
, sourceFileLocation
->filename
);
1889 if ( s
.size () > 0 )
1894 linkDepsMacro
.c_str() );
1895 for ( size_t i
= 0; i
< s
.size(); i
++ )
1896 fprintf ( fMakefile
,
1899 fprintf ( fMakefile
, "\n" );
1902 string globalCflags
= "-g";
1903 if ( backend
->usePipe
)
1904 globalCflags
+= " -pipe";
1905 if ( !module
.allowWarnings
)
1906 globalCflags
+= " -Werror";
1908 // Always force disabling of sibling calls optimisation for GCC
1909 // (TODO: Move to version-specific once this bug is fixed in GCC)
1910 globalCflags
+= " -fno-optimize-sibling-calls";
1914 "%s += $(PROJECT_CFLAGS) %s\n",
1915 cflagsMacro
.c_str (),
1916 globalCflags
.c_str () );
1920 "%s += $(PROJECT_RCFLAGS)\n",
1921 windresflagsMacro
.c_str () );
1925 "%s += $(PROJECT_WIDLFLAGS)\n",
1926 widlflagsMacro
.c_str () );
1930 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1931 module
.name
.c_str () );
1936 linkDepsMacro
.c_str (),
1937 libsMacro
.c_str () );
1939 string cflags
= TypeSpecificCFlags();
1940 if ( cflags
.size() > 0 )
1942 fprintf ( fMakefile
,
1944 cflagsMacro
.c_str (),
1948 string nasmflags
= TypeSpecificNasmFlags();
1949 if ( nasmflags
.size () > 0 )
1951 fprintf ( fMakefile
,
1953 nasmflagsMacro
.c_str (),
1954 nasmflags
.c_str () );
1957 string linkerflags
= TypeSpecificLinkerFlags();
1958 if ( linkerflags
.size() > 0 )
1960 fprintf ( fMakefile
,
1962 linkerflagsMacro
.c_str (),
1963 linkerflags
.c_str () );
1966 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
1968 fprintf ( fMakefile
,
1969 "%s += -Wno-main\n\n",
1970 cflagsMacro
.c_str () );
1973 fprintf ( fMakefile
, "\n\n" );
1975 // future references to the macros will be to get their values
1976 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1977 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1978 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
1982 MingwModuleHandler::GenerateRules ()
1984 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1985 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1986 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1988 if ( module
.name
!= "zlib" ) /* Avoid make warning */
1990 string proxyMakefile
= PassThruCacheDirectory (
1991 NormalizeFilename ( module
.GetBasePath () + sSep
+ "makefile" ),
1992 backend
->outputDirectory
);
1993 CLEAN_FILE ( proxyMakefile
);
1996 string targetMacro
= GetTargetMacro ( module
);
1997 CLEAN_FILE ( targetMacro
);
1999 // generate phony target for module name
2000 fprintf ( fMakefile
, ".PHONY: %s\n",
2001 module
.name
.c_str () );
2002 string dependencies
= GetTargetMacro ( module
);
2003 if ( module
.type
== Test
)
2004 dependencies
+= " $(REGTESTS_RUN_TARGET)";
2005 fprintf ( fMakefile
, "%s: %s\n\n",
2006 module
.name
.c_str (),
2007 dependencies
.c_str () );
2008 if ( module
.type
== Test
)
2010 fprintf ( fMakefile
,
2012 targetMacro
.c_str ());
2015 if ( !ReferenceObjects ( module
) )
2017 string
ar_target ( GenerateArchiveTarget ( ar
, objectsMacro
) );
2018 if ( targetMacro
!= ar_target
)
2019 CLEAN_FILE ( ar_target
);
2022 GenerateObjectFileTargets ( cc
,
2031 MingwModuleHandler::GetInvocationDependencies (
2032 const Module
& module
,
2033 string_list
& dependencies
)
2035 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
2037 Invoke
& invoke
= *module
.invocations
[i
];
2038 if ( invoke
.invokeModule
== &module
)
2039 /* Protect against circular dependencies */
2041 invoke
.GetTargets ( dependencies
);
2046 MingwModuleHandler::GenerateInvocations () const
2048 if ( module
.invocations
.size () == 0 )
2051 size_t iend
= module
.invocations
.size ();
2052 for ( size_t i
= 0; i
< iend
; i
++ )
2054 const Invoke
& invoke
= *module
.invocations
[i
];
2056 if ( invoke
.invokeModule
->type
!= BuildTool
)
2058 throw XMLInvalidBuildFileException (
2059 module
.node
.location
,
2060 "Only modules of type buildtool can be invoked." );
2063 string invokeTarget
= module
.GetInvocationTarget ( i
);
2064 string_list invoke_targets
;
2065 assert ( invoke_targets
.size() );
2066 invoke
.GetTargets ( invoke_targets
);
2067 fprintf ( fMakefile
,
2069 invokeTarget
.c_str () );
2070 fprintf ( fMakefile
,
2072 invokeTarget
.c_str () );
2073 size_t j
, jend
= invoke_targets
.size();
2074 for ( j
= 0; j
< jend
; j
++ )
2076 fprintf ( fMakefile
,
2078 invoke_targets
[i
].c_str () );
2080 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
2081 for ( j
= 1; j
< jend
; j
++ )
2082 fprintf ( fMakefile
,
2084 invoke_targets
[i
].c_str () );
2085 fprintf ( fMakefile
,
2087 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
2088 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
2089 fprintf ( fMakefile
,
2091 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
2092 invoke
.GetParameters ().c_str () );
2097 MingwModuleHandler::GetPreconditionDependenciesName () const
2099 return module
.name
+ "_precondition";
2103 MingwModuleHandler::GetDefaultDependencies (
2104 string_list
& dependencies
) const
2106 /* Avoid circular dependency */
2107 if ( module
.type
!= BuildTool
2108 && module
.name
!= "zlib"
2109 && module
.name
!= "hostzlib" )
2111 dependencies
.push_back ( "$(INIT)" );
2115 MingwModuleHandler::GeneratePreconditionDependencies ()
2117 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2118 string_list sourceFilenames
;
2119 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
2120 string_list dependencies
;
2121 GetDefaultDependencies ( dependencies
);
2122 GetModuleDependencies ( dependencies
);
2124 GetInvocationDependencies ( module
, dependencies
);
2126 if ( dependencies
.size() )
2128 fprintf ( fMakefile
,
2130 preconditionDependenciesName
.c_str () );
2131 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2132 fprintf ( fMakefile
,
2134 dependencies
[i
].c_str () );
2135 fprintf ( fMakefile
, "\n\n" );
2138 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
2140 fprintf ( fMakefile
,
2142 sourceFilenames
[i
].c_str(),
2143 preconditionDependenciesName
.c_str ());
2145 fprintf ( fMakefile
, "\n" );
2149 MingwModuleHandler::IsWineModule () const
2151 if ( module
.importLibrary
== NULL
)
2154 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
2155 return ( index
!= string::npos
);
2159 MingwModuleHandler::GetDefinitionFilename () const
2161 if ( module
.importLibrary
!= NULL
)
2163 string defFilename
= module
.GetBasePath () + sSep
+ module
.importLibrary
->definition
;
2164 if ( IsWineModule () )
2165 return PassThruCacheDirectory ( NormalizeFilename ( defFilename
),
2166 backend
->intermediateDirectory
);
2171 return "tools" + sSep
+ "rbuild" + sSep
+ "empty.def";
2175 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2177 if ( module
.importLibrary
!= NULL
)
2179 string
library_target (
2180 GetImportLibraryFilename ( module
, &clean_files
) );
2181 string defFilename
= GetDefinitionFilename ();
2184 GetDefinitionDependencies ( deps
);
2186 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2188 fprintf ( fMakefile
, "%s: %s",
2189 library_target
.c_str (),
2190 defFilename
.c_str () );
2192 size_t i
, iend
= deps
.size();
2193 for ( i
= 0; i
< iend
; i
++ )
2194 fprintf ( fMakefile
, " %s",
2197 fprintf ( fMakefile
, " | %s\n",
2198 GetDirectory ( GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2200 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2202 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
2203 fprintf ( fMakefile
,
2204 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
2205 module
.GetTargetName ().c_str (),
2206 defFilename
.c_str (),
2207 library_target
.c_str (),
2213 MingwModuleHandler::GetSpecObjectDependencies (
2214 string_list
& dependencies
,
2215 const string
& filename
) const
2217 string basename
= GetBasename ( filename
);
2218 string defDependency
= PassThruCacheDirectory (
2219 NormalizeFilename ( basename
+ ".spec.def" ),
2220 backend
->intermediateDirectory
);
2221 dependencies
.push_back ( defDependency
);
2222 string stubsDependency
= PassThruCacheDirectory (
2223 NormalizeFilename ( basename
+ ".stubs.c" ),
2224 backend
->intermediateDirectory
);
2225 dependencies
.push_back ( stubsDependency
);
2229 MingwModuleHandler::GetWidlObjectDependencies (
2230 string_list
& dependencies
,
2231 const string
& filename
) const
2233 string basename
= GetBasename ( filename
);
2234 string serverSourceDependency
= PassThruCacheDirectory (
2235 NormalizeFilename ( basename
+ "_s.c" ),
2236 backend
->intermediateDirectory
);
2237 dependencies
.push_back ( serverSourceDependency
);
2238 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
2242 MingwModuleHandler::GetDefinitionDependencies (
2243 string_list
& dependencies
) const
2245 string dkNkmLibNoFixup
= "dk/nkm/lib";
2246 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2247 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2249 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2250 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
2251 string extension
= GetExtension ( sourceFileLocation
->filename
);
2252 if ( extension
== ".spec" || extension
== ".SPEC" )
2253 GetSpecObjectDependencies ( dependencies
, sourceFileLocation
->filename
);
2254 if ( extension
== ".idl" || extension
== ".IDL" )
2255 GetWidlObjectDependencies ( dependencies
, sourceFileLocation
->filename
);
2259 enum DebugSupportType
2266 MingwAddDebugSupportLibraries ( Module
& module
, DebugSupportType type
)
2272 case DebugKernelMode
:
2273 pLibrary
= new Library ( module
, "debugsup_ntoskrnl" );
2277 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2284 module
.non_if_data
.libraries
.push_back(pLibrary
);
2287 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2288 : MingwModuleHandler ( module_
)
2293 MingwBuildToolModuleHandler::Process ()
2295 GenerateBuildToolModuleTarget ();
2299 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2301 string
targetMacro ( GetTargetMacro (module
) );
2302 string objectsMacro
= GetObjectsMacro ( module
);
2303 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2304 string libsMacro
= GetLibsMacro ();
2309 if ( module
.cplusplus
)
2310 linker
= "${host_gpp}";
2312 linker
= "${host_gcc}";
2314 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2315 targetMacro
.c_str (),
2316 objectsMacro
.c_str (),
2317 linkDepsMacro
.c_str (),
2318 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2319 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2320 fprintf ( fMakefile
,
2321 "\t%s %s -o $@ %s %s\n\n",
2323 GetLinkerMacro ().c_str (),
2324 objectsMacro
.c_str (),
2325 libsMacro
.c_str () );
2329 MingwKernelModuleHandler::MingwKernelModuleHandler (
2330 const Module
& module_
)
2332 : MingwModuleHandler ( module_
)
2337 MingwKernelModuleHandler::Process ()
2339 GenerateKernelModuleTarget ();
2343 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2345 string
targetMacro ( GetTargetMacro ( module
) );
2346 string workingDirectory
= GetWorkingDirectory ( );
2347 string objectsMacro
= GetObjectsMacro ( module
);
2348 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2349 string libsMacro
= GetLibsMacro ();
2351 GenerateImportLibraryTargetIfNeeded ();
2353 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2357 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2359 string linkerParameters
= ssprintf ( "-Wl,-T,%s%cntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2360 module
.GetBasePath ().c_str (),
2362 module
.GetEntryPoint(true).c_str (),
2363 module
.baseaddress
.c_str () );
2364 GenerateLinkerCommand ( dependencies
,
2373 GeneratePhonyTarget();
2378 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2379 const Module
& module_
)
2381 : MingwModuleHandler ( module_
)
2386 MingwStaticLibraryModuleHandler::Process ()
2388 GenerateStaticLibraryModuleTarget ();
2392 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2398 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2399 const Module
& module_
)
2401 : MingwModuleHandler ( module_
)
2406 MingwObjectLibraryModuleHandler::Process ()
2408 GenerateObjectLibraryModuleTarget ();
2412 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2418 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2419 const Module
& module_
)
2421 : MingwModuleHandler ( module_
)
2426 MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2428 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2432 MingwKernelModeDLLModuleHandler::Process ()
2434 GenerateKernelModeDLLModuleTarget ();
2438 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2440 string
targetMacro ( GetTargetMacro ( module
) );
2441 string workingDirectory
= GetWorkingDirectory ( );
2442 string objectsMacro
= GetObjectsMacro ( module
);
2443 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2444 string libsMacro
= GetLibsMacro ();
2446 GenerateImportLibraryTargetIfNeeded ();
2448 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2452 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2454 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2455 module
.GetEntryPoint(true).c_str (),
2456 module
.baseaddress
.c_str () );
2457 GenerateLinkerCommand ( dependencies
,
2466 GeneratePhonyTarget();
2471 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2472 const Module
& module_
)
2474 : MingwModuleHandler ( module_
)
2479 MingwKernelModeDriverModuleHandler::AddImplicitLibraries ( Module
& module
)
2481 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2485 MingwKernelModeDriverModuleHandler::Process ()
2487 GenerateKernelModeDriverModuleTarget ();
2492 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2494 string
targetMacro ( GetTargetMacro (module
) );
2495 string workingDirectory
= GetWorkingDirectory ();
2496 string objectsMacro
= GetObjectsMacro ( module
);
2497 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2498 string libsMacro
= GetLibsMacro ();
2500 GenerateImportLibraryTargetIfNeeded ();
2502 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2506 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2508 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2509 module
.GetEntryPoint(true).c_str (),
2510 module
.baseaddress
.c_str () );
2511 GenerateLinkerCommand ( dependencies
,
2520 GeneratePhonyTarget();
2525 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2526 const Module
& module_
)
2528 : MingwModuleHandler ( module_
)
2533 MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2535 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2539 MingwNativeDLLModuleHandler::Process ()
2541 GenerateNativeDLLModuleTarget ();
2545 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2547 string
targetMacro ( GetTargetMacro (module
) );
2548 string workingDirectory
= GetWorkingDirectory ( );
2549 string objectsMacro
= GetObjectsMacro ( module
);
2550 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2551 string libsMacro
= GetLibsMacro ();
2553 GenerateImportLibraryTargetIfNeeded ();
2555 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2559 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2561 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2562 module
.GetEntryPoint(true).c_str (),
2563 module
.baseaddress
.c_str () );
2564 GenerateLinkerCommand ( dependencies
,
2573 GeneratePhonyTarget();
2578 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2579 const Module
& module_
)
2581 : MingwModuleHandler ( module_
)
2586 MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2588 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2592 MingwNativeCUIModuleHandler::Process ()
2594 GenerateNativeCUIModuleTarget ();
2598 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2600 string
targetMacro ( GetTargetMacro (module
) );
2601 string workingDirectory
= GetWorkingDirectory ( );
2602 string objectsMacro
= GetObjectsMacro ( module
);
2603 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2604 string libsMacro
= GetLibsMacro ();
2606 GenerateImportLibraryTargetIfNeeded ();
2608 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2612 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2614 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2615 module
.GetEntryPoint(true).c_str (),
2616 module
.baseaddress
.c_str () );
2617 GenerateLinkerCommand ( dependencies
,
2626 GeneratePhonyTarget();
2631 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2632 const Module
& module_
)
2634 : MingwModuleHandler ( module_
)
2639 MingwAddImplicitLibraries( Module
&module
)
2643 if ( !module
.isDefaultEntryPoint
)
2646 if ( module
.IsDLL () )
2648 //pLibrary = new Library ( module, "__mingw_dllmain" );
2649 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
2653 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
2654 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
2657 pLibrary
= new Library ( module
, "mingw_common" );
2658 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
2660 if ( module
.name
!= "msvcrt" )
2662 // always link in msvcrt to get the basic routines
2663 pLibrary
= new Library ( module
, "msvcrt" );
2664 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2669 MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2671 MingwAddImplicitLibraries ( module
);
2672 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2676 MingwWin32DLLModuleHandler::Process ()
2678 GenerateWin32DLLModuleTarget ();
2682 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2684 string
targetMacro ( GetTargetMacro (module
) );
2685 string workingDirectory
= GetWorkingDirectory ( );
2686 string objectsMacro
= GetObjectsMacro ( module
);
2687 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2688 string libsMacro
= GetLibsMacro ();
2690 GenerateImportLibraryTargetIfNeeded ();
2692 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2696 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2699 if ( module
.cplusplus
)
2704 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2705 module
.GetEntryPoint(true).c_str (),
2706 module
.baseaddress
.c_str () );
2707 GenerateLinkerCommand ( dependencies
,
2716 GeneratePhonyTarget();
2721 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2722 const Module
& module_
)
2724 : MingwModuleHandler ( module_
)
2729 MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2731 MingwAddImplicitLibraries ( module
);
2732 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2736 MingwWin32CUIModuleHandler::Process ()
2738 GenerateWin32CUIModuleTarget ();
2742 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2744 string
targetMacro ( GetTargetMacro (module
) );
2745 string workingDirectory
= GetWorkingDirectory ( );
2746 string objectsMacro
= GetObjectsMacro ( module
);
2747 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2748 string libsMacro
= GetLibsMacro ();
2750 GenerateImportLibraryTargetIfNeeded ();
2752 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2756 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2759 if ( module
.cplusplus
)
2764 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2765 module
.GetEntryPoint(true).c_str (),
2766 module
.baseaddress
.c_str () );
2767 GenerateLinkerCommand ( dependencies
,
2776 GeneratePhonyTarget();
2781 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2782 const Module
& module_
)
2784 : MingwModuleHandler ( module_
)
2789 MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2791 MingwAddImplicitLibraries ( module
);
2792 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2796 MingwWin32GUIModuleHandler::Process ()
2798 GenerateWin32GUIModuleTarget ();
2802 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2804 string
targetMacro ( GetTargetMacro (module
) );
2805 string workingDirectory
= GetWorkingDirectory ( );
2806 string objectsMacro
= GetObjectsMacro ( module
);
2807 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2808 string libsMacro
= GetLibsMacro ();
2810 GenerateImportLibraryTargetIfNeeded ();
2812 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2816 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2819 if ( module
.cplusplus
)
2824 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2825 module
.GetEntryPoint(true).c_str (),
2826 module
.baseaddress
.c_str () );
2827 GenerateLinkerCommand ( dependencies
,
2836 GeneratePhonyTarget();
2841 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2842 const Module
& module_
)
2844 : MingwModuleHandler ( module_
)
2849 MingwBootLoaderModuleHandler::Process ()
2851 GenerateBootLoaderModuleTarget ();
2855 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2857 string
targetName ( module
.GetTargetName () );
2858 string
targetMacro ( GetTargetMacro (module
) );
2859 string workingDirectory
= GetWorkingDirectory ();
2860 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2861 CLEAN_FILE ( junk_tmp
);
2862 string objectsMacro
= GetObjectsMacro ( module
);
2863 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2864 string libsMacro
= GetLibsMacro ();
2868 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2869 targetMacro
.c_str (),
2870 objectsMacro
.c_str (),
2871 linkDepsMacro
.c_str (),
2872 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2874 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2876 fprintf ( fMakefile
,
2877 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2878 GetLinkerMacro ().c_str (),
2880 objectsMacro
.c_str (),
2881 linkDepsMacro
.c_str () );
2882 fprintf ( fMakefile
,
2883 "\t${objcopy} -O binary %s $@\n",
2884 junk_tmp
.c_str () );
2885 GenerateBuildMapCode ( junk_tmp
.c_str() );
2886 fprintf ( fMakefile
,
2887 "\t-@${rm} %s 2>$(NUL)\n",
2888 junk_tmp
.c_str () );
2892 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2893 const Module
& module_
)
2895 : MingwModuleHandler ( module_
)
2900 MingwBootSectorModuleHandler::Process ()
2902 GenerateBootSectorModuleTarget ();
2906 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2908 string objectsMacro
= GetObjectsMacro ( module
);
2912 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2913 module
.name
.c_str ());
2914 fprintf ( fMakefile
,
2916 module
.name
.c_str (),
2917 objectsMacro
.c_str () );
2921 MingwBootProgramModuleHandler::MingwBootProgramModuleHandler (
2922 const Module
& module_
)
2923 : MingwModuleHandler ( module_
)
2928 MingwBootProgramModuleHandler::Process ()
2930 GenerateBootProgramModuleTarget ();
2934 MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
2936 string
targetName ( module
.GetTargetName () );
2937 string
targetMacro ( GetTargetMacro (module
) );
2938 string workingDirectory
= GetWorkingDirectory ();
2939 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2940 string junk_elf
= ros_temp
+ module
.name
+ ".junk.elf";
2941 string junk_cpy
= ros_temp
+ module
.name
+ ".junk.cpy";
2942 CLEAN_FILE ( junk_tmp
);
2943 CLEAN_FILE ( junk_elf
);
2944 CLEAN_FILE ( junk_cpy
);
2945 string objectsMacro
= GetObjectsMacro ( module
);
2946 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2947 string libsMacro
= GetLibsMacro ();
2948 const Module
*payload
= module
.project
.LocateModule ( module
.payload
);
2952 fprintf ( fMakefile
, "%s: %s %s %s | %s\n",
2953 targetMacro
.c_str (),
2954 objectsMacro
.c_str (),
2955 linkDepsMacro
.c_str (),
2956 payload
->name
.c_str (),
2957 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2959 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
2961 fprintf ( fMakefile
, "\t$(BOOTPROG_PREPARE) $(OUTPUT)$(SEP)%s %s\n",
2962 NormalizeFilename( payload
->GetPath() ).c_str (),
2963 junk_cpy
.c_str () );
2965 fprintf ( fMakefile
, "\t${objcopy} $(BOOTPROG_FLATFORMAT) %s %s\n",
2967 junk_tmp
.c_str () );
2969 fprintf ( fMakefile
, "\t${ld} $(BOOTPROG_LINKFORMAT) %s %s -g -o %s\n",
2970 linkDepsMacro
.c_str (),
2972 junk_elf
.c_str () );
2974 fprintf ( fMakefile
, "\t${objcopy} $(BOOTPROG_COPYFORMAT) %s %s\n",
2976 module
.GetPath().c_str () );
2978 fprintf ( fMakefile
,
2979 "\t-@${rm} %s %s %s 2>$(NUL)\n",
2980 junk_tmp
.c_str (), junk_elf
.c_str (), junk_cpy
.c_str () );
2984 MingwIsoModuleHandler::MingwIsoModuleHandler (
2985 const Module
& module_
)
2987 : MingwModuleHandler ( module_
)
2992 MingwIsoModuleHandler::Process ()
2994 GenerateIsoModuleTarget ();
2998 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2999 const string
& bootcdDirectory
)
3001 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3003 const Module
& m
= *module
.project
.modules
[i
];
3006 if ( m
.bootstrap
!= NULL
)
3008 string sourceFilename
= PassThruCacheDirectory (
3009 NormalizeFilename ( m
.GetPath () ),
3010 backend
->outputDirectory
);
3011 string
targetFilenameNoFixup ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
+ sSep
+ m
.bootstrap
->nameoncd
);
3012 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3013 NormalizeFilename ( targetFilenameNoFixup
),
3014 backend
->outputDirectory
);
3015 fprintf ( fMakefile
,
3017 fprintf ( fMakefile
,
3018 "\t${cp} %s %s 1>$(NUL)\n",
3019 sourceFilename
.c_str (),
3020 targetFilename
.c_str () );
3026 MingwIsoModuleHandler::OutputCdfileCopyCommands (
3027 const string
& bootcdDirectory
)
3029 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3031 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3032 string targetFilenameNoFixup
= bootcdDirectory
+ sSep
+ cdfile
.base
+ sSep
+ cdfile
.nameoncd
;
3033 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3034 NormalizeFilename ( targetFilenameNoFixup
),
3035 backend
->outputDirectory
);
3036 fprintf ( fMakefile
,
3038 fprintf ( fMakefile
,
3039 "\t${cp} %s %s 1>$(NUL)\n",
3040 cdfile
.GetPath ().c_str (),
3041 targetFilename
.c_str () );
3046 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
3049 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3051 const Module
& m
= *module
.project
.modules
[i
];
3054 if ( m
.bootstrap
!= NULL
)
3056 string
targetDirectory ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
);
3057 if ( directories
.size () > 0 )
3059 directories
+= PassThruCacheDirectory (
3060 NormalizeFilename ( targetDirectory
),
3061 backend
->outputDirectory
);
3068 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
3071 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3073 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3074 string
targetDirectory ( bootcdDirectory
+ sSep
+ cdfile
.base
);
3075 if ( directories
.size () > 0 )
3077 directories
+= PassThruCacheDirectory (
3078 NormalizeFilename ( targetDirectory
),
3079 backend
->outputDirectory
);
3085 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
3087 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
3088 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
3093 MingwIsoModuleHandler::GetBootstrapCdFiles (
3094 vector
<string
>& out
) const
3096 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3098 const Module
& m
= *module
.project
.modules
[i
];
3101 if ( m
.bootstrap
!= NULL
)
3103 string filename
= PassThruCacheDirectory (
3104 NormalizeFilename ( m
.GetPath () ),
3105 backend
->outputDirectory
);
3106 out
.push_back ( filename
);
3112 MingwIsoModuleHandler::GetNonModuleCdFiles (
3113 vector
<string
>& out
) const
3115 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3117 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3118 out
.push_back ( cdfile
.GetPath () );
3123 MingwIsoModuleHandler::GetCdFiles (
3124 vector
<string
>& out
) const
3126 GetBootstrapCdFiles ( out
);
3127 GetNonModuleCdFiles ( out
);
3131 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
3133 string bootcdDirectory
= "cd";
3134 string bootcd
= PassThruCacheDirectory (
3135 NormalizeFilename ( bootcdDirectory
+ sSep
),
3136 backend
->outputDirectory
);
3141 if (module
.name
== "bootcdregtest")
3143 bootloader
= "isobtrt.o";
3144 IsoName
= "ReactOS-RegTest.iso";
3148 bootloader
= "isoboot.o";
3149 IsoName
= "ReactOS.iso";
3152 string isoboot
= PassThruCacheDirectory (
3153 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ bootloader
.c_str() ),
3154 backend
->outputDirectory
);
3156 string bootcdReactosNoFixup
= bootcdDirectory
+ sSep
+ "reactos";
3157 string bootcdReactos
= PassThruCacheDirectory (
3158 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
),
3159 backend
->outputDirectory
);
3160 CLEAN_FILE ( bootcdReactos
);
3161 string reactosInf
= PassThruCacheDirectory (
3162 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
+ "reactos.inf" ),
3163 backend
->outputDirectory
);
3164 string reactosDff
= NormalizeFilename ( "boot" + sSep
+ "bootdata" + sSep
+ "packages" + sSep
+ "reactos.dff" );
3165 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
3166 vector
<string
> vCdFiles
;
3167 GetCdFiles ( vCdFiles
);
3168 string cdFiles
= v2s ( vCdFiles
, 5 );
3170 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3171 module
.name
.c_str ());
3172 fprintf ( fMakefile
,
3173 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
3174 module
.name
.c_str (),
3176 bootcdReactos
.c_str (),
3177 cdDirectories
.c_str (),
3179 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
3180 fprintf ( fMakefile
,
3181 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
3182 reactosDff
.c_str (),
3183 bootcdReactos
.c_str () );
3184 fprintf ( fMakefile
,
3185 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
3186 reactosDff
.c_str (),
3187 reactosInf
.c_str (),
3188 bootcdReactos
.c_str ());
3189 fprintf ( fMakefile
,
3190 "\t-@${rm} %s 2>$(NUL)\n",
3191 reactosInf
.c_str () );
3192 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
3193 OutputCdfileCopyCommands ( bootcdDirectory
);
3194 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3195 fprintf ( fMakefile
,
3196 "\t$(Q)$(CDMAKE_TARGET) -v -j -m -b %s %s REACTOS %s\n",
3200 fprintf ( fMakefile
,
3205 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
3206 const Module
& module_
)
3208 : MingwModuleHandler ( module_
)
3213 MingwLiveIsoModuleHandler::Process ()
3215 GenerateLiveIsoModuleTarget ();
3219 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
3221 string normalizedDirectory
= MingwModuleHandler::PassThruCacheDirectory (
3222 NormalizeFilename ( directory
) + sSep
,
3223 backend
->outputDirectory
);
3227 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string
& sourceFilename
,
3228 const string
& targetFilename
,
3229 const string
& targetDirectory
)
3231 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3232 NormalizeFilename ( targetDirectory
+ sSep
+ targetFilename
),
3233 backend
->outputDirectory
);
3234 fprintf ( fMakefile
,
3236 fprintf ( fMakefile
,
3237 "\t${cp} %s %s 1>$(NUL)\n",
3238 sourceFilename
.c_str (),
3239 normalizedTargetFilename
.c_str () );
3243 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
3244 string
& reactosDirectory
)
3246 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3248 const Module
& m
= *module
.project
.modules
[i
];
3251 if ( m
.installName
.length () > 0 )
3253 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
3254 string sourceFilename
= MingwModuleHandler::PassThruCacheDirectory (
3255 NormalizeFilename ( aliasedModule
.GetPath () ),
3256 backend
->outputDirectory
);
3257 OutputCopyCommand ( sourceFilename
,
3259 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.installBase
);
3265 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
3266 string
& reactosDirectory
)
3268 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
3270 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
3271 OutputCopyCommand ( installfile
.GetPath (),
3272 installfile
.newname
,
3273 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.base
);
3278 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
3280 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
3281 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
3282 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
3283 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
3284 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
3285 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
3287 string livecdIni
= "boot" + sSep
+ "bootdata" + sSep
+ "livecd.ini";
3288 OutputCopyCommand ( livecdIni
,
3294 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3296 string freeldr
= PassThruCacheDirectory (
3297 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "freeldr" + sSep
+ "freeldr.sys" ),
3298 backend
->outputDirectory
);
3299 CreateDirectory ( livecdDirectory
+ sSep
+ "loader" );
3300 OutputCopyCommand ( freeldr
,
3302 livecdDirectory
+ sSep
+ "loader" );
3306 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3308 string reactosSystem32ConfigDirectory
= NormalizeFilename (
3309 MingwModuleHandler::PassThruCacheDirectory (
3310 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config" + sSep
,
3311 backend
->outputDirectory
) );
3312 fprintf ( fMakefile
,
3313 "\t$(ECHO_MKHIVE)\n" );
3314 fprintf ( fMakefile
,
3315 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%clivecd.inf boot%cbootdata%chiveinst.inf\n",
3316 cSep
, reactosSystem32ConfigDirectory
.c_str (),
3317 cSep
, cSep
, cSep
, cSep
);
3321 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
3323 string livecdDirectory
= module
.name
;
3324 string livecd
= PassThruCacheDirectory (
3325 NormalizeFilename ( livecdDirectory
+ sSep
),
3326 backend
->outputDirectory
);
3331 if (module
.name
== "livecdregtest")
3333 bootloader
= "isobtrt.o";
3334 IsoName
= "ReactOS-LiveCD-RegTest.iso";
3338 bootloader
= "isoboot.o";
3339 IsoName
= "ReactOS-LiveCD.iso";
3342 string isoboot
= PassThruCacheDirectory (
3343 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ bootloader
.c_str() ),
3344 backend
->outputDirectory
);
3346 string reactosDirectory
= "reactos";
3347 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3348 string livecdReactos
= NormalizeFilename ( PassThruCacheDirectory (
3349 NormalizeFilename ( livecdReactosNoFixup
+ sSep
),
3350 backend
->outputDirectory
) );
3351 CLEAN_FILE ( livecdReactos
);
3353 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3354 module
.name
.c_str ());
3355 fprintf ( fMakefile
,
3356 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3357 module
.name
.c_str (),
3359 livecdReactos
.c_str () );
3360 OutputModuleCopyCommands ( livecdDirectory
,
3362 OutputNonModuleCopyCommands ( livecdDirectory
,
3364 OutputProfilesDirectoryCommands ( livecdDirectory
);
3365 OutputLoaderCommands ( livecdDirectory
);
3366 OutputRegistryCommands ( livecdDirectory
);
3367 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3368 fprintf ( fMakefile
,
3369 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS %s\n",
3373 fprintf ( fMakefile
,
3378 MingwTestModuleHandler::MingwTestModuleHandler (
3379 const Module
& module_
)
3381 : MingwModuleHandler ( module_
)
3386 MingwTestModuleHandler::Process ()
3388 GenerateTestModuleTarget ();
3392 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
3394 string basePath
= "$(INTERMEDIATE)" + sSep
+ module
.GetBasePath ();
3395 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_hooks.c", false, "", false ) ) );
3396 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_stubs.S", false, "", false ) ) );
3397 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_startup.c", false, "", false ) ) );
3401 MingwTestModuleHandler::GenerateTestModuleTarget ()
3403 string
targetMacro ( GetTargetMacro ( module
) );
3404 string workingDirectory
= GetWorkingDirectory ( );
3405 string objectsMacro
= GetObjectsMacro ( module
);
3406 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3407 string libsMacro
= GetLibsMacro ();
3409 GenerateImportLibraryTargetIfNeeded ();
3411 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3415 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3418 if ( module
.cplusplus
)
3423 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3424 module
.GetEntryPoint(true).c_str (),
3425 module
.baseaddress
.c_str () );
3426 GenerateLinkerCommand ( dependencies
,
3435 GeneratePhonyTarget();
3440 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3441 const Module
& module_
)
3443 : MingwModuleHandler ( module_
)
3448 MingwRpcServerModuleHandler::Process ()
3454 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3455 const Module
& module_
)
3457 : MingwModuleHandler ( module_
)
3462 MingwRpcClientModuleHandler::Process ()
3468 MingwAliasModuleHandler::MingwAliasModuleHandler (
3469 const Module
& module_
)
3471 : MingwModuleHandler ( module_
)
3476 MingwAliasModuleHandler::Process ()
3480 MingwIdlHeaderModuleHandler::MingwIdlHeaderModuleHandler (
3481 const Module
& module_
)
3483 : MingwModuleHandler ( module_
)
3488 MingwIdlHeaderModuleHandler::Process ()