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
);
226 handler
= new MingwWin32OCXModuleHandler ( module
);
228 case KernelModeDriver
:
229 case ExportDriver
: // maybe change this later
230 handler
= new MingwKernelModeDriverModuleHandler ( module
);
233 handler
= new MingwBootLoaderModuleHandler ( module
);
236 handler
= new MingwBootSectorModuleHandler ( module
);
239 handler
= new MingwBootProgramModuleHandler ( module
);
242 handler
= new MingwIsoModuleHandler ( module
);
245 handler
= new MingwLiveIsoModuleHandler ( module
);
248 handler
= new MingwIsoModuleHandler ( module
);
251 handler
= new MingwLiveIsoModuleHandler ( module
);
254 handler
= new MingwTestModuleHandler ( module
);
257 handler
= new MingwRpcServerModuleHandler ( module
);
260 handler
= new MingwRpcClientModuleHandler ( module
);
263 handler
= new MingwAliasModuleHandler ( module
);
266 handler
= new MingwIdlHeaderModuleHandler ( module
);
268 case EmbeddedTypeLib
:
269 handler
= new MingwEmbeddedTypeLibModuleHandler ( module
);
272 throw UnknownModuleTypeException (
273 module
.node
.location
,
281 MingwModuleHandler::GetWorkingDirectory () const
287 MingwModuleHandler::GetBasename ( const string
& filename
) const
289 size_t index
= filename
.find_last_of ( '.' );
290 if ( index
!= string::npos
)
291 return filename
.substr ( 0, index
);
296 MingwModuleHandler::GetActualSourceFilename (
297 const FileLocation
* fileLocation
) const
299 string filename
= fileLocation
->filename
;
300 string extension
= GetExtension ( filename
);
301 if ( extension
== ".spec" || extension
== ".SPEC" )
303 string basename
= GetBasename ( filename
);
304 PassThruCacheDirectory ( NormalizeFilename ( basename
+ ".stubs.c" ),
305 backend
->intermediateDirectory
);
306 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( basename
+ ".stubs.c" ) );
308 else if ( extension
== ".idl" || extension
== ".IDL" )
310 string basename
= GetBasename ( filename
);
312 if ( module
.type
== RpcServer
)
314 newname
= basename
+ "_s.c";
315 PassThruCacheDirectory ( NormalizeFilename ( newname
),
316 backend
->intermediateDirectory
);
317 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( newname
) );
319 else if ( module
.type
== RpcClient
)
321 newname
= basename
+ "_c.c";
322 PassThruCacheDirectory ( NormalizeFilename ( newname
),
323 backend
->intermediateDirectory
);
324 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( newname
) );
326 else if ( module
.type
== IdlHeader
)
328 newname
= basename
+ ".h";
329 PassThruCacheDirectory ( NormalizeFilename ( newname
),
330 backend
->intermediateDirectory
);
331 return new FileLocation ( fileLocation
->directory
, filename
);
335 return new FileLocation ( fileLocation
->directory
, filename
);
339 return new FileLocation ( fileLocation
->directory
, filename
);
343 MingwModuleHandler::GetExtraDependencies (
344 const string
& filename
) const
346 string extension
= GetExtension ( filename
);
347 if ( extension
== ".idl" || extension
== ".IDL" )
349 string basename
= GetBasename ( filename
);
350 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
351 return GetRpcServerHeaderFilename ( basename
) + " " + GetRpcClientHeaderFilename ( basename
);
352 else if ( module
.type
== IdlHeader
)
353 return GetIdlHeaderFilename ( basename
);
362 MingwModuleHandler::GetCompilationUnitDependencies (
363 const CompilationUnit
& compilationUnit
) const
365 if ( compilationUnit
.files
.size () <= 1 )
367 vector
<string
> sourceFiles
;
368 for ( size_t i
= 0; i
< compilationUnit
.files
.size (); i
++ )
370 File
& file
= *compilationUnit
.files
[i
];
371 sourceFiles
.push_back ( NormalizeFilename ( file
.name
) );
373 return v2s ( sourceFiles
, 10 );
377 MingwModuleHandler::GetModuleArchiveFilename () const
379 if ( module
.type
== StaticLibrary
)
380 return GetTargetFilename ( module
, NULL
);
381 return PassThruCacheDirectory ( ReplaceExtension (
382 NormalizeFilename ( module
.GetPath () ),
384 backend
->intermediateDirectory
);
388 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
390 string extension
= GetExtension ( file
.name
);
391 return ( extension
== ".spec" || extension
== ".SPEC" );
395 MingwModuleHandler::ReferenceObjects (
396 const Module
& module
)
398 if ( module
.type
== ObjectLibrary
)
400 if ( module
.type
== RpcServer
)
402 if ( module
.type
== RpcClient
)
404 if ( module
.type
== IdlHeader
)
410 MingwModuleHandler::GetImportLibraryDependency (
411 const Module
& importedModule
)
414 if ( ReferenceObjects ( importedModule
) )
415 dep
= GetTargetMacro ( importedModule
);
417 dep
= GetImportLibraryFilename ( importedModule
, NULL
);
422 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
423 string_list
& targets
)
425 if ( dependencyModule
.invocations
.size () > 0 )
427 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
429 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
430 invoke
.GetTargets ( targets
);
434 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
438 MingwModuleHandler::GetModuleDependencies (
439 string_list
& dependencies
)
441 size_t iend
= module
.dependencies
.size ();
446 for ( size_t i
= 0; i
< iend
; i
++ )
448 const Dependency
& dependency
= *module
.dependencies
[i
];
449 const Module
& dependencyModule
= *dependency
.dependencyModule
;
450 GetTargets ( dependencyModule
,
453 GetDefinitionDependencies ( dependencies
);
457 MingwModuleHandler::GetSourceFilenames ( string_list
& list
,
458 bool includeGeneratedFiles
) const
462 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
463 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
465 if ( includeGeneratedFiles
|| !compilationUnits
[i
]->IsGeneratedFile () )
467 FileLocation
* sourceFileLocation
= GetActualSourceFilename (
468 compilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
) );
469 list
.push_back ( PassThruCacheDirectory ( sourceFileLocation
->filename
,
470 sourceFileLocation
->directory
) );
473 // intentionally make a copy so that we can append more work in
474 // the middle of processing without having to go recursive
475 vector
<If
*> v
= module
.non_if_data
.ifs
;
476 for ( i
= 0; i
< v
.size (); i
++ )
480 // check for sub-ifs to add to list
481 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
482 for ( j
= 0; j
< ifs
.size (); j
++ )
483 v
.push_back ( ifs
[j
] );
484 const vector
<CompilationUnit
*>& compilationUnits
= rIf
.data
.compilationUnits
;
485 for ( j
= 0; j
< compilationUnits
.size (); j
++ )
487 CompilationUnit
& compilationUnit
= *compilationUnits
[j
];
488 if ( includeGeneratedFiles
|| !compilationUnit
.IsGeneratedFile () )
490 FileLocation
* sourceFileLocation
= GetActualSourceFilename (
491 compilationUnit
.GetFilename ( backend
->intermediateDirectory
) );
492 list
.push_back ( PassThruCacheDirectory ( sourceFileLocation
->filename
,
493 sourceFileLocation
->directory
) );
500 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
501 string_list
& list
) const
503 GetSourceFilenames ( list
, false );
507 MingwModuleHandler::GetObjectFilename (
508 const FileLocation
* sourceFileLocation
,
509 string_list
* pclean_files
) const
511 string sourceFilename
= sourceFileLocation
->filename
;
512 Directory
* directoryTree
;
514 string extension
= GetExtension ( sourceFilename
);
515 if ( extension
== ".rc" || extension
== ".RC" )
516 newExtension
= ".coff";
517 else if ( extension
== ".spec" || extension
== ".SPEC" )
518 newExtension
= ".stubs.o";
519 else if ( extension
== ".idl" || extension
== ".IDL" )
521 if ( module
.type
== RpcServer
)
522 newExtension
= "_s.o";
523 else if ( module
.type
== RpcClient
)
524 newExtension
= "_c.o";
531 if ( module
.type
== BootSector
)
532 directoryTree
= backend
->outputDirectory
;
534 directoryTree
= backend
->intermediateDirectory
;
536 string obj_file
= PassThruCacheDirectory (
537 NormalizeFilename ( ReplaceExtension (
538 RemoveVariables ( sourceFilename
),
544 string_list
& clean_files
= *pclean_files
;
545 CLEAN_FILE ( obj_file
);
551 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
553 return module
.name
+ "_clean";
557 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
559 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
561 Library
& library
= *module
.non_if_data
.libraries
[i
];
562 if ( library
.importedModule
->type
== ObjectLibrary
)
563 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
568 MingwModuleHandler::GenerateCleanTarget () const
570 if ( module
.type
== Alias
)
574 ".PHONY: %s_clean\n",
575 module
.name
.c_str() );
576 vector
<string
> referencedModuleNames
;
577 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
580 GetModuleCleanTarget ( module
).c_str(),
581 v2s ( referencedModuleNames
, 10 ).c_str () );
582 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
585 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
586 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
588 fprintf ( fMakefile
, " 2>$(NUL)\n" );
589 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
593 MingwModuleHandler::GenerateInstallTarget () const
595 if ( module
.installName
.length () == 0 )
597 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
598 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
599 NormalizeFilename ( module
.installBase
+ sSep
+ module
.installName
),
600 backend
->installDirectory
);
603 module
.name
.c_str (),
604 normalizedTargetFilename
.c_str() );
608 MingwModuleHandler::GenerateDependsTarget () const
611 ".PHONY: %s_depends\n",
612 module
.name
.c_str() );
614 "%s_depends: $(RBUILD_TARGET)\n",
615 module
.name
.c_str () );
617 "\t$(ECHO_RBUILD)\n" );
619 "\t$(Q)$(RBUILD_TARGET) -dm%s mingw\n",
620 module
.name
.c_str () );
624 MingwModuleHandler::GetObjectFilenames ()
626 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
627 if ( compilationUnits
.size () == 0 )
630 string
objectFilenames ( "" );
631 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
633 if ( objectFilenames
.size () > 0 )
634 objectFilenames
+= " ";
635 objectFilenames
+= GetObjectFilename ( compilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
), NULL
);
637 return objectFilenames
;
641 MingwModuleHandler::GenerateGccDefineParametersFromVector (
642 const vector
<Define
*>& defines
)
645 for ( size_t i
= 0; i
< defines
.size (); i
++ )
647 Define
& define
= *defines
[i
];
648 if (parameters
.length () > 0)
651 parameters
+= define
.name
;
652 if (define
.value
.length () > 0)
655 parameters
+= define
.value
;
662 MingwModuleHandler::GenerateGccDefineParameters () const
664 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
665 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
666 if ( s
.length () > 0 )
675 MingwModuleHandler::ConcatenatePaths (
677 const string
& path2
) const
679 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
681 if ( path1
[path1
.length ()] == cSep
)
682 return path1
+ path2
;
684 return path1
+ cSep
+ path2
;
688 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
690 string parameters
, path_prefix
;
691 for ( size_t i
= 0; i
< includes
.size (); i
++ )
693 Include
& include
= *includes
[i
];
694 if ( parameters
.length () > 0 )
696 if ( include
.root
== "intermediate" )
697 path_prefix
= backend
->intermediateDirectory
->name
+ cSep
;
698 else if (include
.root
== "output" )
699 path_prefix
= backend
->outputDirectory
->name
+ cSep
;
703 parameters
+= "-I" + path_prefix
+ include
.directory
;
709 MingwModuleHandler::GenerateGccIncludeParameters () const
711 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
712 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
713 if ( s
.length () > 0 )
722 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
725 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
727 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
728 if ( parameters
.length () > 0 )
730 parameters
+= compilerFlag
.flag
;
736 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
739 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
741 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
742 if ( parameters
.length () > 0 )
744 parameters
+= linkerFlag
.flag
;
750 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
751 const vector
<Library
*>& libraries
)
753 string
dependencies ( "" );
755 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
757 if ( wrap_count
++ == 5 )
758 dependencies
+= " \\\n\t\t", wrap_count
= 0;
759 else if ( dependencies
.size () > 0 )
761 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
767 MingwModuleHandler::GenerateLinkerParameters () const
769 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
773 MingwModuleHandler::GenerateMacro (
774 const char* assignmentOperation
,
776 const IfableData
& data
)
779 bool generateAssignment
;
781 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
782 if ( generateAssignment
)
787 assignmentOperation
);
790 if ( use_pch
&& module
.pch
!= NULL
)
794 GetDirectory ( GetPrecompiledHeaderFilename () ).c_str () );
797 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
798 if ( compilerParameters
.size () > 0 )
803 compilerParameters
.c_str () );
806 for ( i
= 0; i
< data
.includes
.size(); i
++ )
808 const Include
& include
= *data
.includes
[i
];
809 string includeDirectory
, path_prefix
;
810 if ( include
.baseModule
!= NULL
&&
811 ( include
.baseModule
->type
== RpcServer
||
812 include
.baseModule
->type
== RpcClient
||
813 include
.baseModule
->type
== IdlHeader
) )
814 includeDirectory
= PassThruCacheDirectory ( NormalizeFilename ( include
.directory
),
815 backend
->intermediateDirectory
);
817 includeDirectory
= include
.directory
;
819 if ( include
.root
== "intermediate" )
820 path_prefix
= backend
->intermediateDirectory
->name
+ cSep
;
821 else if (include
.root
== "output" )
822 path_prefix
= backend
->outputDirectory
->name
+ cSep
;
830 includeDirectory
.c_str() );
832 for ( i
= 0; i
< data
.defines
.size(); i
++ )
834 Define
& d
= *data
.defines
[i
];
839 if ( d
.value
.size() )
845 if ( generateAssignment
)
847 fprintf ( fMakefile
, "\n" );
852 MingwModuleHandler::GenerateMacros (
853 const char* assignmentOperation
,
854 const IfableData
& data
,
855 const vector
<LinkerFlag
*>* linkerFlags
)
859 GenerateMacro ( assignmentOperation
,
862 GenerateMacro ( assignmentOperation
,
866 if ( linkerFlags
!= NULL
)
868 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
869 if ( linkerParameters
.size () > 0 )
874 linkerflagsMacro
.c_str (),
876 linkerParameters
.c_str() );
880 if ( data
.libraries
.size () > 0 )
882 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
883 if ( deps
.size () > 0 )
894 const vector
<If
*>& ifs
= data
.ifs
;
895 for ( i
= 0; i
< ifs
.size(); i
++ )
898 if ( rIf
.data
.defines
.size()
899 || rIf
.data
.includes
.size()
900 || rIf
.data
.libraries
.size()
901 || rIf
.data
.compilationUnits
.size()
902 || rIf
.data
.compilerFlags
.size()
903 || rIf
.data
.ifs
.size() )
907 "%s (\"$(%s)\",\"%s\")\n",
908 rIf
.negated
? "ifneq" : "ifeq",
909 rIf
.property
.c_str(),
923 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
925 for (size_t i
= 0; i
< compilationUnits
.size (); i
++)
926 delete compilationUnits
[i
];
930 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
935 MingwModuleHandler::GenerateObjectMacros (
936 const char* assignmentOperation
,
937 const IfableData
& data
,
938 const vector
<LinkerFlag
*>* linkerFlags
)
942 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
943 if ( compilationUnits
.size () > 0 )
945 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
947 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
948 if ( compilationUnit
.IsFirstFile () )
952 objectsMacro
.c_str(),
953 GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
).c_str (),
954 objectsMacro
.c_str() );
960 objectsMacro
.c_str (),
961 assignmentOperation
);
962 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
964 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
965 if ( !compilationUnit
.IsFirstFile () )
970 ( i
%10 == 9 ? " \\\n\t" : " " ),
971 GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
).c_str () );
974 fprintf ( fMakefile
, "\n" );
977 const vector
<If
*>& ifs
= data
.ifs
;
978 for ( i
= 0; i
< ifs
.size(); i
++ )
981 if ( rIf
.data
.defines
.size()
982 || rIf
.data
.includes
.size()
983 || rIf
.data
.libraries
.size()
984 || rIf
.data
.compilationUnits
.size()
985 || rIf
.data
.compilerFlags
.size()
986 || rIf
.data
.ifs
.size() )
990 "%s (\"$(%s)\",\"%s\")\n",
991 rIf
.negated
? "ifneq" : "ifeq",
992 rIf
.property
.c_str(),
994 GenerateObjectMacros (
1004 vector
<CompilationUnit
*> sourceCompilationUnits
;
1005 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1006 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1011 objectsMacro
.c_str(),
1012 GetObjectFilename ( sourceCompilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
), NULL
).c_str () );
1014 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1018 MingwModuleHandler::GetPrecompiledHeaderFilename () const
1020 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
1021 return PassThruCacheDirectory ( NormalizeFilename ( basePchFilename
),
1022 backend
->intermediateDirectory
);
1026 MingwModuleHandler::GenerateGccCommand (
1027 const FileLocation
* sourceFileLocation
,
1028 const string
& extraDependencies
,
1030 const string
& cflagsMacro
)
1032 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1033 string dependencies
= sourceFilename
;
1034 if ( extraDependencies
!= "" )
1035 dependencies
+= " " + extraDependencies
;
1036 if ( module
.pch
&& use_pch
)
1037 dependencies
+= " " + GetPrecompiledHeaderFilename ();
1039 /* WIDL generated headers may be used */
1040 vector
<string
> rpcDependencies
;
1041 GetRpcHeaderDependencies ( rpcDependencies
);
1042 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1043 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1045 string objectFilename
= GetObjectFilename (
1046 sourceFileLocation
, &clean_files
);
1047 fprintf ( fMakefile
,
1049 objectFilename
.c_str (),
1050 dependencies
.c_str (),
1051 GetDirectory ( objectFilename
).c_str () );
1052 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
1053 fprintf ( fMakefile
,
1054 "\t%s -c $< -o $@ %s\n",
1056 cflagsMacro
.c_str () );
1060 MingwModuleHandler::GenerateGccAssemblerCommand (
1061 const FileLocation
* sourceFileLocation
,
1063 const string
& cflagsMacro
)
1065 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1066 string dependencies
= sourceFilename
;
1067 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1068 string objectFilename
= GetObjectFilename (
1069 sourceFileLocation
, &clean_files
);
1070 fprintf ( fMakefile
,
1072 objectFilename
.c_str (),
1073 dependencies
.c_str (),
1074 GetDirectory ( objectFilename
).c_str () );
1075 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
1076 fprintf ( fMakefile
,
1077 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
1079 cflagsMacro
.c_str () );
1083 MingwModuleHandler::GenerateNasmCommand (
1084 const FileLocation
* sourceFileLocation
,
1085 const string
& nasmflagsMacro
)
1087 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1088 string dependencies
= sourceFilename
;
1089 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1090 string objectFilename
= GetObjectFilename (
1091 sourceFileLocation
, &clean_files
);
1092 fprintf ( fMakefile
,
1094 objectFilename
.c_str (),
1095 dependencies
.c_str (),
1096 GetDirectory ( objectFilename
).c_str () );
1097 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1098 fprintf ( fMakefile
,
1099 "\t%s -f win32 $< -o $@ %s\n",
1101 nasmflagsMacro
.c_str () );
1105 MingwModuleHandler::GenerateWindresCommand (
1106 const FileLocation
* sourceFileLocation
,
1107 const string
& windresflagsMacro
)
1109 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1110 string dependencies
= sourceFilename
;
1111 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1112 string objectFilename
= GetObjectFilename ( sourceFileLocation
, &clean_files
);
1113 string sourceFilenamePart
= ReplaceExtension ( GetFilename ( sourceFilename
), "" );
1114 string rciFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".rci.tmp";
1115 string resFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".res.tmp";
1116 if ( module
.useWRC
)
1118 fprintf ( fMakefile
,
1119 "%s: %s $(WRC_TARGET) | %s\n",
1120 objectFilename
.c_str (),
1121 dependencies
.c_str (),
1122 GetDirectory ( objectFilename
).c_str () );
1123 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1124 fprintf ( fMakefile
,
1125 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1126 windresflagsMacro
.c_str (),
1127 sourceFilename
.c_str (),
1128 rciFilename
.c_str () );
1129 fprintf ( fMakefile
,
1130 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1131 windresflagsMacro
.c_str (),
1132 rciFilename
.c_str (),
1133 resFilename
.c_str () );
1134 fprintf ( fMakefile
,
1135 "\t-@${rm} %s 2>$(NUL)\n",
1136 rciFilename
.c_str () );
1137 fprintf ( fMakefile
,
1138 "\t${windres} %s -o $@\n",
1139 resFilename
.c_str () );
1140 fprintf ( fMakefile
,
1141 "\t-@${rm} %s 2>$(NUL)\n",
1142 resFilename
.c_str () );
1146 fprintf ( fMakefile
,
1147 "%s: %s $(WRC_TARGET) | %s\n",
1148 objectFilename
.c_str (),
1149 dependencies
.c_str (),
1150 GetDirectory ( objectFilename
).c_str () );
1151 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1152 fprintf ( fMakefile
,
1153 "\t${windres} $(%s) %s -o $@\n",
1154 windresflagsMacro
.c_str (),
1155 sourceFilename
.c_str () );
1160 MingwModuleHandler::GenerateWinebuildCommands (
1161 const FileLocation
* sourceFileLocation
)
1163 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1164 string dependencies
= sourceFilename
;
1165 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1167 string basename
= GetBasename ( sourceFilename
);
1168 string def_file
= PassThruCacheDirectory (
1169 basename
+ ".spec.def",
1170 backend
->intermediateDirectory
);
1171 CLEAN_FILE(def_file
);
1173 string stub_file
= PassThruCacheDirectory (
1174 basename
+ ".stubs.c",
1175 backend
->intermediateDirectory
);
1176 CLEAN_FILE(stub_file
)
1178 fprintf ( fMakefile
,
1179 "%s: %s $(WINEBUILD_TARGET) | %s\n",
1181 dependencies
.c_str (),
1182 GetDirectory ( def_file
).c_str () );
1183 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1184 fprintf ( fMakefile
,
1185 "\t%s -o %s --def -E %s\n",
1186 "$(Q)$(WINEBUILD_TARGET)",
1188 sourceFilename
.c_str () );
1189 fprintf ( fMakefile
,
1190 "%s: %s $(WINEBUILD_TARGET)\n",
1192 sourceFilename
.c_str () );
1193 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1194 fprintf ( fMakefile
,
1195 "\t%s -o %s --pedll %s\n",
1196 "$(Q)$(WINEBUILD_TARGET)",
1198 sourceFilename
.c_str () );
1202 MingwModuleHandler::GetWidlFlags ( const CompilationUnit
& compilationUnit
)
1204 return compilationUnit
.GetSwitches ();
1208 MingwModuleHandler::GetRpcServerHeaderFilename ( string basename
) const
1210 return PassThruCacheDirectory ( basename
+ "_s.h",
1211 backend
->intermediateDirectory
);
1215 MingwModuleHandler::GenerateWidlCommandsServer (
1216 const CompilationUnit
& compilationUnit
,
1217 const string
& widlflagsMacro
)
1219 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1220 string filename
= sourceFileLocation
->filename
;
1221 string dependencies
= filename
;
1222 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1224 string basename
= GetBasename ( filename
);
1226 string generatedHeaderFilename
= GetRpcServerHeaderFilename ( basename
);
1227 CLEAN_FILE(generatedHeaderFilename
);
1229 string generatedServerFilename
= PassThruCacheDirectory (
1231 backend
->intermediateDirectory
);
1232 CLEAN_FILE(generatedServerFilename
);
1234 fprintf ( fMakefile
,
1235 "%s %s: %s $(WIDL_TARGET) | %s\n",
1236 generatedServerFilename
.c_str (),
1237 generatedHeaderFilename
.c_str (),
1238 dependencies
.c_str (),
1239 GetDirectory ( generatedServerFilename
).c_str () );
1240 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1241 fprintf ( fMakefile
,
1242 "\t%s %s %s -h -H %s -s -S %s %s\n",
1243 "$(Q)$(WIDL_TARGET)",
1244 GetWidlFlags ( compilationUnit
).c_str (),
1245 widlflagsMacro
.c_str (),
1246 generatedHeaderFilename
.c_str (),
1247 generatedServerFilename
.c_str (),
1248 filename
.c_str () );
1252 MingwModuleHandler::GetRpcClientHeaderFilename ( string basename
) const
1254 return PassThruCacheDirectory ( basename
+ "_c.h",
1255 backend
->intermediateDirectory
);
1259 MingwModuleHandler::GetIdlHeaderFilename ( string basename
) const
1261 return PassThruCacheDirectory ( basename
+ ".h",
1262 backend
->intermediateDirectory
);
1266 MingwModuleHandler::GenerateWidlCommandsEmbeddedTypeLib (
1267 const CompilationUnit
& compilationUnit
,
1268 const string
& widlflagsMacro
)
1270 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1271 string filename
= sourceFileLocation
->filename
;
1272 string dependencies
= filename
;
1273 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1275 string basename
= GetBasename ( filename
);
1276 string EmbeddedTypeLibFilename
= basename
+ ".tlb";
1278 fprintf ( fMakefile
,
1279 "%s: %s $(WIDL_TARGET) | %s\n",
1280 GetTargetMacro ( module
).c_str (),
1281 dependencies
.c_str (),
1282 GetDirectory ( EmbeddedTypeLibFilename
).c_str () );
1283 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1284 fprintf ( fMakefile
,
1285 //"\t%s %s %s -t -T $@ %s\n",
1286 "\t%s %s %s -t -T %s %s\n",
1287 "$(Q)$(WIDL_TARGET)",
1288 GetWidlFlags ( compilationUnit
).c_str (),
1289 widlflagsMacro
.c_str (),
1290 EmbeddedTypeLibFilename
.c_str(),
1291 filename
.c_str () );
1295 MingwModuleHandler::GenerateWidlCommandsClient (
1296 const CompilationUnit
& compilationUnit
,
1297 const string
& widlflagsMacro
)
1299 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1300 string filename
= sourceFileLocation
->filename
;
1301 string dependencies
= filename
;
1302 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1304 string basename
= GetBasename ( filename
);
1306 string generatedHeaderFilename
= GetRpcClientHeaderFilename ( basename
);
1307 CLEAN_FILE(generatedHeaderFilename
);
1309 string generatedClientFilename
= PassThruCacheDirectory (
1311 backend
->intermediateDirectory
);
1312 CLEAN_FILE(generatedClientFilename
);
1314 fprintf ( fMakefile
,
1315 "%s %s: %s $(WIDL_TARGET) | %s\n",
1316 generatedClientFilename
.c_str (),
1317 generatedHeaderFilename
.c_str (),
1318 dependencies
.c_str (),
1319 GetDirectory ( generatedClientFilename
).c_str () );
1320 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1321 fprintf ( fMakefile
,
1322 "\t%s %s %s -h -H %s -c -C %s %s\n",
1323 "$(Q)$(WIDL_TARGET)",
1324 GetWidlFlags ( compilationUnit
).c_str (),
1325 widlflagsMacro
.c_str (),
1326 generatedHeaderFilename
.c_str (),
1327 generatedClientFilename
.c_str (),
1328 filename
.c_str () );
1332 MingwModuleHandler::GenerateWidlCommandsIdlHeader (
1333 const CompilationUnit
& compilationUnit
,
1334 const string
& widlflagsMacro
)
1336 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1337 string filename
= sourceFileLocation
->filename
;
1338 string dependencies
= filename
;
1339 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1341 string basename
= GetBasename ( filename
);
1343 string generatedHeaderFilename
= GetIdlHeaderFilename ( basename
);
1344 CLEAN_FILE(generatedHeaderFilename
);
1346 fprintf ( fMakefile
,
1347 "%s: %s $(WIDL_TARGET) | %s\n",
1348 generatedHeaderFilename
.c_str (),
1349 dependencies
.c_str (),
1350 GetDirectory ( generatedHeaderFilename
).c_str () );
1351 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1352 fprintf ( fMakefile
,
1353 "\t%s %s %s -h -H %s %s\n",
1354 "$(Q)$(WIDL_TARGET)",
1355 GetWidlFlags ( compilationUnit
).c_str (),
1356 widlflagsMacro
.c_str (),
1357 generatedHeaderFilename
.c_str (),
1358 filename
.c_str () );
1362 MingwModuleHandler::GenerateWidlCommands (
1363 const CompilationUnit
& compilationUnit
,
1364 const string
& widlflagsMacro
)
1366 if ( module
.type
== RpcServer
)
1367 GenerateWidlCommandsServer ( compilationUnit
,
1369 else if ( module
.type
== RpcClient
)
1370 GenerateWidlCommandsClient ( compilationUnit
,
1372 else if ( module
.type
== EmbeddedTypeLib
)
1373 GenerateWidlCommandsEmbeddedTypeLib ( compilationUnit
,
1375 else // applies also for other module.types which include idl files
1376 GenerateWidlCommandsIdlHeader ( compilationUnit
,
1381 MingwModuleHandler::GenerateCommands (
1382 const CompilationUnit
& compilationUnit
,
1385 const string
& cflagsMacro
,
1386 const string
& nasmflagsMacro
,
1387 const string
& windresflagsMacro
,
1388 const string
& widlflagsMacro
)
1390 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1391 string filename
= sourceFileLocation
->filename
;
1392 string extension
= GetExtension ( filename
);
1393 if ( extension
== ".c" || extension
== ".C" )
1395 GenerateGccCommand ( sourceFileLocation
,
1396 GetCompilationUnitDependencies ( compilationUnit
),
1401 else if ( extension
== ".cc" || extension
== ".CC" ||
1402 extension
== ".cpp" || extension
== ".CPP" ||
1403 extension
== ".cxx" || extension
== ".CXX" )
1405 GenerateGccCommand ( sourceFileLocation
,
1406 GetCompilationUnitDependencies ( compilationUnit
),
1411 else if ( extension
== ".s" || extension
== ".S" )
1413 GenerateGccAssemblerCommand ( sourceFileLocation
,
1418 else if ( extension
== ".asm" || extension
== ".ASM" )
1420 GenerateNasmCommand ( sourceFileLocation
,
1424 else if ( extension
== ".rc" || extension
== ".RC" )
1426 GenerateWindresCommand ( sourceFileLocation
,
1427 windresflagsMacro
);
1430 else if ( extension
== ".spec" || extension
== ".SPEC" )
1432 GenerateWinebuildCommands ( sourceFileLocation
);
1433 GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation
),
1439 else if ( extension
== ".idl" || extension
== ".IDL" )
1441 GenerateWidlCommands ( compilationUnit
,
1443 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
1445 GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation
),
1446 GetExtraDependencies ( filename
),
1453 throw InvalidOperationException ( __FILE__
,
1455 "Unsupported filename extension '%s' in file '%s'",
1457 filename
.c_str () );
1461 MingwModuleHandler::GenerateBuildMapCode ( const char *mapTarget
)
1463 fprintf ( fMakefile
,
1464 "ifeq ($(ROS_BUILDMAP),full)\n" );
1466 string mapFilename
= PassThruCacheDirectory (
1467 GetBasename ( module
.GetPath () ) + ".map",
1468 backend
->outputDirectory
);
1469 CLEAN_FILE ( mapFilename
);
1471 fprintf ( fMakefile
,
1472 "\t$(ECHO_OBJDUMP)\n" );
1473 fprintf ( fMakefile
,
1474 "\t$(Q)${objdump} -d -S %s > %s\n",
1475 mapTarget
? mapTarget
: "$@",
1476 mapFilename
.c_str () );
1478 fprintf ( fMakefile
,
1480 fprintf ( fMakefile
,
1481 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1483 fprintf ( fMakefile
,
1485 fprintf ( fMakefile
,
1486 "\t$(Q)${nm} --numeric-sort %s > %s\n",
1487 mapTarget
? mapTarget
: "$@",
1488 mapFilename
.c_str () );
1490 fprintf ( fMakefile
,
1493 fprintf ( fMakefile
,
1498 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1500 fprintf ( fMakefile
,
1501 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1503 string filename
= module
.GetPath ();
1504 string outputFilename
= PassThruCacheDirectory (
1506 backend
->outputDirectory
);
1507 string nostripFilename
= PassThruCacheDirectory (
1508 GetBasename ( filename
) + ".nostrip" + GetExtension ( filename
),
1509 backend
->outputDirectory
);
1510 CLEAN_FILE ( nostripFilename
);
1512 fprintf ( fMakefile
,
1514 fprintf ( fMakefile
,
1515 "\t${cp} %s %s 1>$(NUL)\n",
1516 outputFilename
.c_str (),
1517 nostripFilename
.c_str () );
1519 fprintf ( fMakefile
,
1524 MergeStringVector ( const vector
<string
>& input
,
1525 vector
<string
>& output
)
1529 int wrap_count
= -1;
1530 for ( size_t i
= 0; i
< input
.size (); i
++ )
1532 if ( input
[i
].size () == 0 )
1534 if ( wrap_count
++ == wrap_at
)
1536 output
.push_back ( s
);
1540 else if ( s
.size () > 0)
1544 if ( s
.length () > 0 )
1545 output
.push_back ( s
);
1549 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1550 vector
<string
>& objectFiles
) const
1552 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1554 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1555 objectFiles
.push_back ( GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
) );
1560 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1562 if ( backend
->configuration
.CleanAsYouGo
)
1564 vector
<string
> objectFiles
;
1565 GetObjectsVector ( module
.non_if_data
,
1567 vector
<string
> lines
;
1568 MergeStringVector ( objectFiles
,
1570 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1572 fprintf ( fMakefile
,
1573 "\t-@${rm} %s 2>$(NUL)\n",
1574 lines
[i
].c_str () );
1580 MingwModuleHandler::GenerateRunRsymCode () const
1582 fprintf ( fMakefile
,
1583 "\t$(ECHO_RSYM)\n" );
1584 fprintf ( fMakefile
,
1585 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1589 MingwModuleHandler::GenerateRunStripCode () const
1591 fprintf ( fMakefile
,
1592 "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" );
1593 fprintf ( fMakefile
,
1594 "\t$(ECHO_STRIP)\n" );
1595 fprintf ( fMakefile
,
1596 "\t${strip} -s -x -X $@\n\n" );
1597 fprintf ( fMakefile
,
1602 MingwModuleHandler::GenerateLinkerCommand (
1603 const string
& dependencies
,
1604 const string
& linker
,
1605 const string
& linkerParameters
,
1606 const string
& objectsMacro
,
1607 const string
& libsMacro
,
1608 const string
& pefixupParameters
)
1610 string
target ( GetTargetMacro ( module
) );
1611 string
target_folder ( GetDirectory ( GetTargetFilename ( module
, NULL
) ) );
1612 string definitionFilename
= GetDefinitionFilename ();
1614 string linkerScriptArgument
;
1615 if ( module
.linkerScript
!= NULL
)
1616 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", module
.linkerScript
->directory
.c_str () );
1618 linkerScriptArgument
= "";
1620 fprintf ( fMakefile
,
1621 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1623 definitionFilename
.c_str (),
1624 dependencies
.c_str (),
1625 target_folder
.c_str () );
1626 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1627 string
targetName ( module
.GetTargetName () );
1629 if ( module
.IsDLL () )
1631 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1632 CLEAN_FILE ( temp_exp
);
1634 fprintf ( fMakefile
,
1635 "\t${dlltool} --dllname %s --def %s --output-exp %s %s %s\n",
1636 targetName
.c_str (),
1637 definitionFilename
.c_str (),
1639 module
.mangledSymbols
? "" : "--kill-at",
1640 module
.underscoreSymbols
? "--add-underscore" : "" );
1642 fprintf ( fMakefile
,
1643 "\t%s %s %s %s -o %s %s %s %s\n",
1645 linkerParameters
.c_str (),
1646 linkerScriptArgument
.c_str (),
1649 objectsMacro
.c_str (),
1651 GetLinkerMacro ().c_str () );
1653 fprintf ( fMakefile
,
1654 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1656 pefixupParameters
.c_str() );
1658 fprintf ( fMakefile
,
1659 "\t-@${rm} %s 2>$(NUL)\n",
1660 temp_exp
.c_str () );
1664 fprintf ( fMakefile
,
1665 "\t%s %s %s -o %s %s %s %s\n",
1667 linkerParameters
.c_str (),
1668 linkerScriptArgument
.c_str (),
1670 objectsMacro
.c_str (),
1672 GetLinkerMacro ().c_str () );
1674 #if 0 // causes crashes sometimes
1675 fprintf ( fMakefile
,
1676 "\t${objcopy} -R .edata %s\n",
1681 GenerateBuildMapCode ();
1682 GenerateBuildNonSymbolStrippedCode ();
1683 GenerateRunRsymCode ();
1684 GenerateRunStripCode ();
1685 GenerateCleanObjectsAsYouGoCode ();
1689 MingwModuleHandler::GeneratePhonyTarget() const
1691 string
targetMacro ( GetTargetMacro ( module
) );
1692 fprintf ( fMakefile
,
1694 targetMacro
.c_str ());
1695 fprintf ( fMakefile
, "%s: | %s\n",
1696 targetMacro
.c_str (),
1697 GetDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1701 MingwModuleHandler::GenerateObjectFileTargets (
1702 const IfableData
& data
,
1705 const string
& cflagsMacro
,
1706 const string
& nasmflagsMacro
,
1707 const string
& windresflagsMacro
,
1708 const string
& widlflagsMacro
)
1712 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1713 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1715 GenerateCommands ( *compilationUnits
[i
],
1722 fprintf ( fMakefile
,
1726 const vector
<If
*>& ifs
= data
.ifs
;
1727 for ( i
= 0; i
< ifs
.size(); i
++ )
1729 GenerateObjectFileTargets ( ifs
[i
]->data
,
1738 vector
<CompilationUnit
*> sourceCompilationUnits
;
1739 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1740 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1742 GenerateCommands ( *sourceCompilationUnits
[i
],
1750 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1754 MingwModuleHandler::GenerateObjectFileTargets (
1757 const string
& cflagsMacro
,
1758 const string
& nasmflagsMacro
,
1759 const string
& windresflagsMacro
,
1760 const string
& widlflagsMacro
)
1762 if ( module
.pch
&& use_pch
)
1764 const string
& baseHeaderFilename
= module
.pch
->file
.name
;
1765 const string
& pchFilename
= GetPrecompiledHeaderFilename ();
1766 CLEAN_FILE(pchFilename
);
1767 string dependencies
= baseHeaderFilename
;
1768 /* WIDL generated headers may be used */
1769 vector
<string
> rpcDependencies
;
1770 GetRpcHeaderDependencies ( rpcDependencies
);
1771 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1772 fprintf ( fMakefile
,
1774 pchFilename
.c_str(),
1775 dependencies
.c_str() );
1776 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1777 fprintf ( fMakefile
,
1778 "\t%s -o %s %s -g %s\n\n",
1779 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1780 pchFilename
.c_str(),
1781 cflagsMacro
.c_str(),
1782 baseHeaderFilename
.c_str() );
1785 GenerateObjectFileTargets ( module
.non_if_data
,
1792 fprintf ( fMakefile
, "\n" );
1796 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1797 const string
& objs_macro
) const
1799 string
archiveFilename ( GetModuleArchiveFilename () );
1801 fprintf ( fMakefile
,
1803 archiveFilename
.c_str (),
1804 objs_macro
.c_str (),
1805 GetDirectory(archiveFilename
).c_str() );
1807 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
1809 string
archiveFilename ( GetModuleArchiveFilename () );
1810 string
definitionFilename ( GetDefinitionFilename () );
1812 fprintf ( fMakefile
,
1813 "\t${dlltool} --dllname %s --def %s --output-lib $@ %s %s\n",
1814 module
.importLibrary
->dllname
.c_str (),
1815 definitionFilename
.c_str (),
1816 module
.mangledSymbols
? "" : "--kill-at",
1817 module
.underscoreSymbols
? "--add-underscore" : "" );
1820 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1822 fprintf ( fMakefile
,
1825 objs_macro
.c_str ());
1827 GenerateCleanObjectsAsYouGoCode ();
1829 fprintf ( fMakefile
, "\n" );
1831 return archiveFilename
;
1835 MingwModuleHandler::GetCFlagsMacro () const
1837 return ssprintf ( "$(%s_CFLAGS)",
1838 module
.name
.c_str () );
1842 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1844 return ssprintf ( "$(%s_OBJS)",
1845 module
.name
.c_str () );
1849 MingwModuleHandler::GetLinkingDependenciesMacro () const
1851 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1855 MingwModuleHandler::GetLibsMacro () const
1857 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1861 MingwModuleHandler::GetLinkerMacro () const
1863 return ssprintf ( "$(%s_LFLAGS)",
1864 module
.name
.c_str () );
1868 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1870 if ( ReferenceObjects ( module
) )
1871 return GetObjectsMacro ( module
);
1873 return GetTargetFilename ( module
, NULL
);
1877 MingwModuleHandler::GenerateObjectMacro ()
1879 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1881 GenerateObjectMacros (
1884 &module
.linkerFlags
);
1886 // future references to the macro will be to get its values
1887 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1891 MingwModuleHandler::GenerateTargetMacro ()
1893 fprintf ( fMakefile
,
1895 GetTargetMacro ( module
, false ).c_str (),
1896 GetModuleTargets ( module
).c_str () );
1900 MingwModuleHandler::GetRpcHeaderDependencies (
1901 vector
<string
>& dependencies
) const
1903 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1905 Library
& library
= *module
.non_if_data
.libraries
[i
];
1906 if ( library
.importedModule
->type
== RpcServer
||
1907 library
.importedModule
->type
== RpcClient
||
1908 library
.importedModule
->type
== IdlHeader
)
1910 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
1912 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
1913 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1914 string extension
= GetExtension ( sourceFileLocation
->filename
);
1915 if ( extension
== ".idl" || extension
== ".IDL" )
1917 string basename
= GetBasename ( sourceFileLocation
->filename
);
1918 if ( library
.importedModule
->type
== RpcServer
)
1919 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
1920 if ( library
.importedModule
->type
== RpcClient
)
1921 dependencies
.push_back ( GetRpcClientHeaderFilename ( basename
) );
1922 if ( library
.importedModule
->type
== IdlHeader
)
1923 dependencies
.push_back ( GetIdlHeaderFilename ( basename
) );
1931 MingwModuleHandler::GenerateOtherMacros ()
1933 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1934 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1935 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1936 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1937 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1938 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1939 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1944 &module
.linkerFlags
);
1947 if ( module
.importLibrary
)
1949 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
1950 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
1952 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1953 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1954 string extension
= GetExtension ( sourceFileLocation
->filename
);
1955 if ( extension
== ".spec" || extension
== ".SPEC" )
1956 GetSpecObjectDependencies ( s
, sourceFileLocation
->filename
);
1959 if ( s
.size () > 0 )
1964 linkDepsMacro
.c_str() );
1965 for ( size_t i
= 0; i
< s
.size(); i
++ )
1966 fprintf ( fMakefile
,
1969 fprintf ( fMakefile
, "\n" );
1972 string globalCflags
= "-g";
1973 if ( backend
->usePipe
)
1974 globalCflags
+= " -pipe";
1975 if ( !module
.allowWarnings
)
1976 globalCflags
+= " -Werror";
1978 // Always force disabling of sibling calls optimisation for GCC
1979 // (TODO: Move to version-specific once this bug is fixed in GCC)
1980 globalCflags
+= " -fno-optimize-sibling-calls";
1984 "%s += $(PROJECT_CFLAGS) %s\n",
1985 cflagsMacro
.c_str (),
1986 globalCflags
.c_str () );
1990 "%s += $(PROJECT_RCFLAGS)\n",
1991 windresflagsMacro
.c_str () );
1995 "%s += $(PROJECT_WIDLFLAGS)\n",
1996 widlflagsMacro
.c_str () );
2000 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
2001 module
.name
.c_str () );
2006 linkDepsMacro
.c_str (),
2007 libsMacro
.c_str () );
2009 string cflags
= TypeSpecificCFlags();
2010 if ( cflags
.size() > 0 )
2012 fprintf ( fMakefile
,
2014 cflagsMacro
.c_str (),
2018 string nasmflags
= TypeSpecificNasmFlags();
2019 if ( nasmflags
.size () > 0 )
2021 fprintf ( fMakefile
,
2023 nasmflagsMacro
.c_str (),
2024 nasmflags
.c_str () );
2027 string linkerflags
= TypeSpecificLinkerFlags();
2028 if ( linkerflags
.size() > 0 )
2030 fprintf ( fMakefile
,
2032 linkerflagsMacro
.c_str (),
2033 linkerflags
.c_str () );
2036 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
2038 fprintf ( fMakefile
,
2039 "%s += -Wno-main\n\n",
2040 cflagsMacro
.c_str () );
2043 fprintf ( fMakefile
, "\n\n" );
2045 // future references to the macros will be to get their values
2046 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
2047 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
2048 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
2052 MingwModuleHandler::GenerateRules ()
2054 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
2055 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
2056 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
2058 if ( module
.name
!= "zlib" ) /* Avoid make warning */
2060 string proxyMakefile
= PassThruCacheDirectory (
2061 NormalizeFilename ( module
.GetBasePath () + sSep
+ "makefile" ),
2062 backend
->outputDirectory
);
2063 CLEAN_FILE ( proxyMakefile
);
2066 string targetMacro
= GetTargetMacro ( module
);
2067 CLEAN_FILE ( targetMacro
);
2069 // generate phony target for module name
2070 fprintf ( fMakefile
, ".PHONY: %s\n",
2071 module
.name
.c_str () );
2072 string dependencies
= GetTargetMacro ( module
);
2073 if ( module
.type
== Test
)
2074 dependencies
+= " $(REGTESTS_RUN_TARGET)";
2075 fprintf ( fMakefile
, "%s: %s\n\n",
2076 module
.name
.c_str (),
2077 dependencies
.c_str () );
2078 if ( module
.type
== Test
)
2080 fprintf ( fMakefile
,
2082 targetMacro
.c_str ());
2085 if ( !ReferenceObjects ( module
) )
2087 string
ar_target ( GenerateArchiveTarget ( ar
, objectsMacro
) );
2088 if ( targetMacro
!= ar_target
)
2089 CLEAN_FILE ( ar_target
);
2092 GenerateObjectFileTargets ( cc
,
2101 MingwModuleHandler::GetInvocationDependencies (
2102 const Module
& module
,
2103 string_list
& dependencies
)
2105 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
2107 Invoke
& invoke
= *module
.invocations
[i
];
2108 if ( invoke
.invokeModule
== &module
)
2109 /* Protect against circular dependencies */
2111 invoke
.GetTargets ( dependencies
);
2116 MingwModuleHandler::GenerateInvocations () const
2118 if ( module
.invocations
.size () == 0 )
2121 size_t iend
= module
.invocations
.size ();
2122 for ( size_t i
= 0; i
< iend
; i
++ )
2124 const Invoke
& invoke
= *module
.invocations
[i
];
2126 if ( invoke
.invokeModule
->type
!= BuildTool
)
2128 throw XMLInvalidBuildFileException (
2129 module
.node
.location
,
2130 "Only modules of type buildtool can be invoked." );
2133 string invokeTarget
= module
.GetInvocationTarget ( i
);
2134 string_list invoke_targets
;
2135 assert ( invoke_targets
.size() );
2136 invoke
.GetTargets ( invoke_targets
);
2137 fprintf ( fMakefile
,
2139 invokeTarget
.c_str () );
2140 fprintf ( fMakefile
,
2142 invokeTarget
.c_str () );
2143 size_t j
, jend
= invoke_targets
.size();
2144 for ( j
= 0; j
< jend
; j
++ )
2146 fprintf ( fMakefile
,
2148 invoke_targets
[i
].c_str () );
2150 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
2151 for ( j
= 1; j
< jend
; j
++ )
2152 fprintf ( fMakefile
,
2154 invoke_targets
[i
].c_str () );
2155 fprintf ( fMakefile
,
2157 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
2158 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
2159 fprintf ( fMakefile
,
2161 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
2162 invoke
.GetParameters ().c_str () );
2167 MingwModuleHandler::GetPreconditionDependenciesName () const
2169 return module
.name
+ "_precondition";
2173 MingwModuleHandler::GetDefaultDependencies (
2174 string_list
& dependencies
) const
2176 /* Avoid circular dependency */
2177 if ( module
.type
!= BuildTool
2178 && module
.name
!= "zlib"
2179 && module
.name
!= "hostzlib" )
2181 dependencies
.push_back ( "$(INIT)" );
2185 MingwModuleHandler::GeneratePreconditionDependencies ()
2187 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2188 string_list sourceFilenames
;
2189 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
2190 string_list dependencies
;
2191 GetDefaultDependencies ( dependencies
);
2192 GetModuleDependencies ( dependencies
);
2194 GetInvocationDependencies ( module
, dependencies
);
2196 if ( dependencies
.size() )
2198 fprintf ( fMakefile
,
2200 preconditionDependenciesName
.c_str () );
2201 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2202 fprintf ( fMakefile
,
2204 dependencies
[i
].c_str () );
2205 fprintf ( fMakefile
, "\n\n" );
2208 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
2210 fprintf ( fMakefile
,
2212 sourceFilenames
[i
].c_str(),
2213 preconditionDependenciesName
.c_str ());
2215 fprintf ( fMakefile
, "\n" );
2219 MingwModuleHandler::IsWineModule () const
2221 if ( module
.importLibrary
== NULL
)
2224 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
2225 return ( index
!= string::npos
);
2229 MingwModuleHandler::GetDefinitionFilename () const
2231 if ( module
.importLibrary
!= NULL
)
2233 string defFilename
= module
.GetBasePath () + sSep
+ module
.importLibrary
->definition
;
2234 if ( IsWineModule () )
2235 return PassThruCacheDirectory ( NormalizeFilename ( defFilename
),
2236 backend
->intermediateDirectory
);
2241 return "tools" + sSep
+ "rbuild" + sSep
+ "empty.def";
2245 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2247 if ( module
.importLibrary
!= NULL
)
2249 string
library_target (
2250 GetImportLibraryFilename ( module
, &clean_files
) );
2251 string defFilename
= GetDefinitionFilename ();
2254 GetDefinitionDependencies ( deps
);
2256 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2258 fprintf ( fMakefile
, "%s: %s",
2259 library_target
.c_str (),
2260 defFilename
.c_str () );
2262 size_t i
, iend
= deps
.size();
2263 for ( i
= 0; i
< iend
; i
++ )
2264 fprintf ( fMakefile
, " %s",
2267 fprintf ( fMakefile
, " | %s\n",
2268 GetDirectory ( GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2270 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2272 fprintf ( fMakefile
,
2273 "\t${dlltool} --dllname %s --def %s --output-lib %s %s %s\n\n",
2274 module
.GetTargetName ().c_str (),
2275 defFilename
.c_str (),
2276 library_target
.c_str (),
2277 module
.mangledSymbols
? "" : "--kill-at",
2278 module
.underscoreSymbols
? "--add-underscore" : "" );
2283 MingwModuleHandler::GetSpecObjectDependencies (
2284 string_list
& dependencies
,
2285 const string
& filename
) const
2287 string basename
= GetBasename ( filename
);
2288 string defDependency
= PassThruCacheDirectory (
2289 NormalizeFilename ( basename
+ ".spec.def" ),
2290 backend
->intermediateDirectory
);
2291 dependencies
.push_back ( defDependency
);
2292 string stubsDependency
= PassThruCacheDirectory (
2293 NormalizeFilename ( basename
+ ".stubs.c" ),
2294 backend
->intermediateDirectory
);
2295 dependencies
.push_back ( stubsDependency
);
2299 MingwModuleHandler::GetWidlObjectDependencies (
2300 string_list
& dependencies
,
2301 const string
& filename
) const
2303 string basename
= GetBasename ( filename
);
2304 string serverSourceDependency
= PassThruCacheDirectory (
2305 NormalizeFilename ( basename
+ "_s.c" ),
2306 backend
->intermediateDirectory
);
2307 dependencies
.push_back ( serverSourceDependency
);
2308 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
2312 MingwModuleHandler::GetDefinitionDependencies (
2313 string_list
& dependencies
) const
2315 string dkNkmLibNoFixup
= "dk/nkm/lib";
2316 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2317 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2319 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2320 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
2321 string extension
= GetExtension ( sourceFileLocation
->filename
);
2322 if ( extension
== ".spec" || extension
== ".SPEC" )
2323 GetSpecObjectDependencies ( dependencies
, sourceFileLocation
->filename
);
2324 if ( extension
== ".idl" || extension
== ".IDL" )
2326 if ( ( module
.type
== RpcServer
) || ( module
.type
== RpcClient
) )
2327 GetWidlObjectDependencies ( dependencies
, sourceFileLocation
->filename
);
2332 enum DebugSupportType
2339 MingwAddDebugSupportLibraries ( Module
& module
, DebugSupportType type
)
2345 case DebugKernelMode
:
2346 pLibrary
= new Library ( module
, "debugsup_ntoskrnl" );
2350 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2357 module
.non_if_data
.libraries
.push_back(pLibrary
);
2360 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2361 : MingwModuleHandler ( module_
)
2366 MingwBuildToolModuleHandler::Process ()
2368 GenerateBuildToolModuleTarget ();
2372 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2374 string
targetMacro ( GetTargetMacro (module
) );
2375 string objectsMacro
= GetObjectsMacro ( module
);
2376 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2377 string libsMacro
= GetLibsMacro ();
2382 if ( module
.cplusplus
)
2383 linker
= "${host_gpp}";
2385 linker
= "${host_gcc}";
2387 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2388 targetMacro
.c_str (),
2389 objectsMacro
.c_str (),
2390 linkDepsMacro
.c_str (),
2391 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2392 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2393 fprintf ( fMakefile
,
2394 "\t%s %s -o $@ %s %s\n\n",
2396 GetLinkerMacro ().c_str (),
2397 objectsMacro
.c_str (),
2398 libsMacro
.c_str () );
2402 MingwKernelModuleHandler::MingwKernelModuleHandler (
2403 const Module
& module_
)
2405 : MingwModuleHandler ( module_
)
2410 MingwKernelModuleHandler::Process ()
2412 GenerateKernelModuleTarget ();
2416 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2418 string
targetMacro ( GetTargetMacro ( module
) );
2419 string workingDirectory
= GetWorkingDirectory ( );
2420 string objectsMacro
= GetObjectsMacro ( module
);
2421 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2422 string libsMacro
= GetLibsMacro ();
2424 GenerateImportLibraryTargetIfNeeded ();
2426 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2430 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2432 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",
2433 module
.GetBasePath ().c_str (),
2435 module
.GetEntryPoint(true).c_str (),
2436 module
.baseaddress
.c_str () );
2437 GenerateLinkerCommand ( dependencies
,
2446 GeneratePhonyTarget();
2451 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2452 const Module
& module_
)
2454 : MingwModuleHandler ( module_
)
2459 MingwStaticLibraryModuleHandler::Process ()
2461 GenerateStaticLibraryModuleTarget ();
2465 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2471 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2472 const Module
& module_
)
2474 : MingwModuleHandler ( module_
)
2479 MingwObjectLibraryModuleHandler::Process ()
2481 GenerateObjectLibraryModuleTarget ();
2485 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2491 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2492 const Module
& module_
)
2494 : MingwModuleHandler ( module_
)
2498 MingwEmbeddedTypeLibModuleHandler::MingwEmbeddedTypeLibModuleHandler (
2499 const Module
& module_
)
2501 : MingwModuleHandler ( module_
)
2506 MingwEmbeddedTypeLibModuleHandler::Process ()
2513 MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2515 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2519 MingwKernelModeDLLModuleHandler::Process ()
2521 GenerateKernelModeDLLModuleTarget ();
2525 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2527 string
targetMacro ( GetTargetMacro ( module
) );
2528 string workingDirectory
= GetWorkingDirectory ( );
2529 string objectsMacro
= GetObjectsMacro ( module
);
2530 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2531 string libsMacro
= GetLibsMacro ();
2533 GenerateImportLibraryTargetIfNeeded ();
2535 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2539 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2541 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2542 module
.GetEntryPoint(true).c_str (),
2543 module
.baseaddress
.c_str () );
2544 GenerateLinkerCommand ( dependencies
,
2553 GeneratePhonyTarget();
2558 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2559 const Module
& module_
)
2561 : MingwModuleHandler ( module_
)
2566 MingwKernelModeDriverModuleHandler::AddImplicitLibraries ( Module
& module
)
2568 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2572 MingwKernelModeDriverModuleHandler::Process ()
2574 GenerateKernelModeDriverModuleTarget ();
2579 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2581 string
targetMacro ( GetTargetMacro (module
) );
2582 string workingDirectory
= GetWorkingDirectory ();
2583 string objectsMacro
= GetObjectsMacro ( module
);
2584 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2585 string libsMacro
= GetLibsMacro ();
2587 GenerateImportLibraryTargetIfNeeded ();
2589 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2593 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2595 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2596 module
.GetEntryPoint(true).c_str (),
2597 module
.baseaddress
.c_str () );
2598 GenerateLinkerCommand ( dependencies
,
2607 GeneratePhonyTarget();
2612 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2613 const Module
& module_
)
2615 : MingwModuleHandler ( module_
)
2620 MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2622 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2626 MingwNativeDLLModuleHandler::Process ()
2628 GenerateNativeDLLModuleTarget ();
2632 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2634 string
targetMacro ( GetTargetMacro (module
) );
2635 string workingDirectory
= GetWorkingDirectory ( );
2636 string objectsMacro
= GetObjectsMacro ( module
);
2637 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2638 string libsMacro
= GetLibsMacro ();
2640 GenerateImportLibraryTargetIfNeeded ();
2642 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2646 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2648 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2649 module
.GetEntryPoint(true).c_str (),
2650 module
.baseaddress
.c_str () );
2651 GenerateLinkerCommand ( dependencies
,
2660 GeneratePhonyTarget();
2665 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2666 const Module
& module_
)
2668 : MingwModuleHandler ( module_
)
2673 MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2675 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2679 MingwNativeCUIModuleHandler::Process ()
2681 GenerateNativeCUIModuleTarget ();
2685 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2687 string
targetMacro ( GetTargetMacro (module
) );
2688 string workingDirectory
= GetWorkingDirectory ( );
2689 string objectsMacro
= GetObjectsMacro ( module
);
2690 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2691 string libsMacro
= GetLibsMacro ();
2693 GenerateImportLibraryTargetIfNeeded ();
2695 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2699 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2701 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2702 module
.GetEntryPoint(true).c_str (),
2703 module
.baseaddress
.c_str () );
2704 GenerateLinkerCommand ( dependencies
,
2713 GeneratePhonyTarget();
2718 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2719 const Module
& module_
)
2721 : MingwModuleHandler ( module_
)
2725 MingwWin32OCXModuleHandler::MingwWin32OCXModuleHandler (
2726 const Module
& module_
)
2728 : MingwModuleHandler ( module_
)
2733 MingwAddImplicitLibraries( Module
&module
)
2737 if ( !module
.isDefaultEntryPoint
)
2739 if ( module
.GetEntryPoint(false) == "0" )
2741 pLibrary
= new Library ( module
, "mingw_common" );
2742 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() , pLibrary
);
2743 pLibrary
= new Library ( module
, "msvcrt" );
2744 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2749 if ( module
.IsDLL () )
2751 //pLibrary = new Library ( module, "__mingw_dllmain" );
2752 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
2756 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
2757 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
2760 pLibrary
= new Library ( module
, "mingw_common" );
2761 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
2763 if ( module
.name
!= "msvcrt" )
2765 // always link in msvcrt to get the basic routines
2766 pLibrary
= new Library ( module
, "msvcrt" );
2767 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2772 MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2774 MingwAddImplicitLibraries ( module
);
2775 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2779 MingwWin32DLLModuleHandler::Process ()
2781 GenerateWin32DLLModuleTarget ();
2785 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2787 string
targetMacro ( GetTargetMacro (module
) );
2788 string workingDirectory
= GetWorkingDirectory ( );
2789 string objectsMacro
= GetObjectsMacro ( module
);
2790 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2791 string libsMacro
= GetLibsMacro ();
2793 GenerateImportLibraryTargetIfNeeded ();
2795 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2799 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2802 if ( module
.cplusplus
)
2807 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2808 module
.GetEntryPoint(true).c_str (),
2809 module
.baseaddress
.c_str () );
2810 GenerateLinkerCommand ( dependencies
,
2819 GeneratePhonyTarget();
2825 MingwWin32OCXModuleHandler::AddImplicitLibraries ( Module
& module
)
2827 MingwAddImplicitLibraries ( module
);
2828 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2832 MingwWin32OCXModuleHandler::Process ()
2834 GenerateWin32OCXModuleTarget ();
2838 MingwWin32OCXModuleHandler::GenerateWin32OCXModuleTarget ()
2840 string
targetMacro ( GetTargetMacro (module
) );
2841 string workingDirectory
= GetWorkingDirectory ( );
2842 string objectsMacro
= GetObjectsMacro ( module
);
2843 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2844 string libsMacro
= GetLibsMacro ();
2846 GenerateImportLibraryTargetIfNeeded ();
2848 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2852 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2855 if ( module
.cplusplus
)
2860 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2861 module
.GetEntryPoint(true).c_str (),
2862 module
.baseaddress
.c_str () );
2863 GenerateLinkerCommand ( dependencies
,
2872 GeneratePhonyTarget();
2877 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2878 const Module
& module_
)
2880 : MingwModuleHandler ( module_
)
2885 MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2887 MingwAddImplicitLibraries ( module
);
2888 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2892 MingwWin32CUIModuleHandler::Process ()
2894 GenerateWin32CUIModuleTarget ();
2898 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2900 string
targetMacro ( GetTargetMacro (module
) );
2901 string workingDirectory
= GetWorkingDirectory ( );
2902 string objectsMacro
= GetObjectsMacro ( module
);
2903 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2904 string libsMacro
= GetLibsMacro ();
2906 GenerateImportLibraryTargetIfNeeded ();
2908 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2912 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2915 if ( module
.cplusplus
)
2920 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2921 module
.GetEntryPoint(true).c_str (),
2922 module
.baseaddress
.c_str () );
2923 GenerateLinkerCommand ( dependencies
,
2932 GeneratePhonyTarget();
2937 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2938 const Module
& module_
)
2940 : MingwModuleHandler ( module_
)
2945 MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2947 MingwAddImplicitLibraries ( module
);
2948 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2952 MingwWin32GUIModuleHandler::Process ()
2954 GenerateWin32GUIModuleTarget ();
2958 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2960 string
targetMacro ( GetTargetMacro (module
) );
2961 string workingDirectory
= GetWorkingDirectory ( );
2962 string objectsMacro
= GetObjectsMacro ( module
);
2963 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2964 string libsMacro
= GetLibsMacro ();
2966 GenerateImportLibraryTargetIfNeeded ();
2968 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2972 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2975 if ( module
.cplusplus
)
2980 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2981 module
.GetEntryPoint(true).c_str (),
2982 module
.baseaddress
.c_str () );
2983 GenerateLinkerCommand ( dependencies
,
2992 GeneratePhonyTarget();
2997 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2998 const Module
& module_
)
3000 : MingwModuleHandler ( module_
)
3005 MingwBootLoaderModuleHandler::Process ()
3007 GenerateBootLoaderModuleTarget ();
3011 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
3013 string
targetName ( module
.GetTargetName () );
3014 string
targetMacro ( GetTargetMacro (module
) );
3015 string workingDirectory
= GetWorkingDirectory ();
3016 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
3017 CLEAN_FILE ( junk_tmp
);
3018 string objectsMacro
= GetObjectsMacro ( module
);
3019 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3020 string libsMacro
= GetLibsMacro ();
3024 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3025 targetMacro
.c_str (),
3026 objectsMacro
.c_str (),
3027 linkDepsMacro
.c_str (),
3028 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
3030 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
3032 fprintf ( fMakefile
,
3033 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
3034 GetLinkerMacro ().c_str (),
3036 objectsMacro
.c_str (),
3037 linkDepsMacro
.c_str () );
3038 fprintf ( fMakefile
,
3039 "\t${objcopy} -O binary %s $@\n",
3040 junk_tmp
.c_str () );
3041 GenerateBuildMapCode ( junk_tmp
.c_str() );
3042 fprintf ( fMakefile
,
3043 "\t-@${rm} %s 2>$(NUL)\n",
3044 junk_tmp
.c_str () );
3048 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
3049 const Module
& module_
)
3051 : MingwModuleHandler ( module_
)
3056 MingwBootSectorModuleHandler::Process ()
3058 GenerateBootSectorModuleTarget ();
3062 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
3064 string objectsMacro
= GetObjectsMacro ( module
);
3068 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3069 module
.name
.c_str ());
3070 fprintf ( fMakefile
,
3072 module
.name
.c_str (),
3073 objectsMacro
.c_str () );
3077 MingwBootProgramModuleHandler::MingwBootProgramModuleHandler (
3078 const Module
& module_
)
3079 : MingwModuleHandler ( module_
)
3084 MingwBootProgramModuleHandler::Process ()
3086 GenerateBootProgramModuleTarget ();
3090 MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
3092 string
targetName ( module
.GetTargetName () );
3093 string
targetMacro ( GetTargetMacro (module
) );
3094 string workingDirectory
= GetWorkingDirectory ();
3095 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
3096 string junk_elf
= ros_temp
+ module
.name
+ ".junk.elf";
3097 string junk_cpy
= ros_temp
+ module
.name
+ ".junk.cpy";
3098 CLEAN_FILE ( junk_tmp
);
3099 CLEAN_FILE ( junk_elf
);
3100 CLEAN_FILE ( junk_cpy
);
3101 string objectsMacro
= GetObjectsMacro ( module
);
3102 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3103 string libsMacro
= GetLibsMacro ();
3104 const Module
*payload
= module
.project
.LocateModule ( module
.payload
);
3108 fprintf ( fMakefile
, "%s: %s %s %s | %s\n",
3109 targetMacro
.c_str (),
3110 objectsMacro
.c_str (),
3111 linkDepsMacro
.c_str (),
3112 payload
->name
.c_str (),
3113 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
3115 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3117 fprintf ( fMakefile
, "\t$(BOOTPROG_PREPARE) $(OUTPUT)$(SEP)%s %s\n",
3118 NormalizeFilename( payload
->GetPath() ).c_str (),
3119 junk_cpy
.c_str () );
3121 fprintf ( fMakefile
, "\t${objcopy} $(BOOTPROG_FLATFORMAT) %s %s\n",
3123 junk_tmp
.c_str () );
3125 fprintf ( fMakefile
, "\t${ld} $(BOOTPROG_LINKFORMAT) %s %s -g -o %s\n",
3126 linkDepsMacro
.c_str (),
3128 junk_elf
.c_str () );
3130 fprintf ( fMakefile
, "\t${objcopy} $(BOOTPROG_COPYFORMAT) %s %s\n",
3132 module
.GetPath().c_str () );
3134 fprintf ( fMakefile
,
3135 "\t-@${rm} %s %s %s 2>$(NUL)\n",
3136 junk_tmp
.c_str (), junk_elf
.c_str (), junk_cpy
.c_str () );
3140 MingwIsoModuleHandler::MingwIsoModuleHandler (
3141 const Module
& module_
)
3143 : MingwModuleHandler ( module_
)
3148 MingwIsoModuleHandler::Process ()
3150 GenerateIsoModuleTarget ();
3154 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
3155 const string
& bootcdDirectory
)
3157 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3159 const Module
& m
= *module
.project
.modules
[i
];
3162 if ( m
.bootstrap
!= NULL
)
3164 string sourceFilename
= PassThruCacheDirectory (
3165 NormalizeFilename ( m
.GetPath () ),
3166 backend
->outputDirectory
);
3167 string
targetFilenameNoFixup ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
+ sSep
+ m
.bootstrap
->nameoncd
);
3168 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3169 NormalizeFilename ( targetFilenameNoFixup
),
3170 backend
->outputDirectory
);
3171 fprintf ( fMakefile
,
3173 fprintf ( fMakefile
,
3174 "\t${cp} %s %s 1>$(NUL)\n",
3175 sourceFilename
.c_str (),
3176 targetFilename
.c_str () );
3182 MingwIsoModuleHandler::OutputCdfileCopyCommands (
3183 const string
& bootcdDirectory
)
3185 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3187 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3188 string targetFilenameNoFixup
= bootcdDirectory
+ sSep
+ cdfile
.base
+ sSep
+ cdfile
.nameoncd
;
3189 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3190 NormalizeFilename ( targetFilenameNoFixup
),
3191 backend
->outputDirectory
);
3192 fprintf ( fMakefile
,
3194 fprintf ( fMakefile
,
3195 "\t${cp} %s %s 1>$(NUL)\n",
3196 cdfile
.GetPath ().c_str (),
3197 targetFilename
.c_str () );
3202 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
3205 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3207 const Module
& m
= *module
.project
.modules
[i
];
3210 if ( m
.bootstrap
!= NULL
)
3212 string
targetDirectory ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
);
3213 if ( directories
.size () > 0 )
3215 directories
+= PassThruCacheDirectory (
3216 NormalizeFilename ( targetDirectory
),
3217 backend
->outputDirectory
);
3224 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
3227 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3229 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3230 string
targetDirectory ( bootcdDirectory
+ sSep
+ cdfile
.base
);
3231 if ( directories
.size () > 0 )
3233 directories
+= PassThruCacheDirectory (
3234 NormalizeFilename ( targetDirectory
),
3235 backend
->outputDirectory
);
3241 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
3243 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
3244 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
3249 MingwIsoModuleHandler::GetBootstrapCdFiles (
3250 vector
<string
>& out
) const
3252 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3254 const Module
& m
= *module
.project
.modules
[i
];
3257 if ( m
.bootstrap
!= NULL
)
3259 string filename
= PassThruCacheDirectory (
3260 NormalizeFilename ( m
.GetPath () ),
3261 backend
->outputDirectory
);
3262 out
.push_back ( filename
);
3268 MingwIsoModuleHandler::GetNonModuleCdFiles (
3269 vector
<string
>& out
) const
3271 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3273 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3274 out
.push_back ( cdfile
.GetPath () );
3279 MingwIsoModuleHandler::GetCdFiles (
3280 vector
<string
>& out
) const
3282 GetBootstrapCdFiles ( out
);
3283 GetNonModuleCdFiles ( out
);
3287 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
3289 string bootcdDirectory
= "cd";
3290 string bootcd
= PassThruCacheDirectory (
3291 NormalizeFilename ( bootcdDirectory
+ sSep
),
3292 backend
->outputDirectory
);
3297 if (module
.name
== "bootcdregtest")
3299 bootloader
= "isobtrt.o";
3300 IsoName
= "ReactOS-RegTest.iso";
3304 bootloader
= "isoboot.o";
3305 IsoName
= "ReactOS.iso";
3308 string isoboot
= PassThruCacheDirectory (
3309 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ bootloader
.c_str() ),
3310 backend
->outputDirectory
);
3312 string bootcdReactosNoFixup
= bootcdDirectory
+ sSep
+ Environment::GetCdOutputPath ();
3313 string bootcdReactos
= PassThruCacheDirectory (
3314 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
),
3315 backend
->outputDirectory
);
3316 CLEAN_FILE ( bootcdReactos
);
3317 string reactosInf
= PassThruCacheDirectory (
3318 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
+ "reactos.inf" ),
3319 backend
->outputDirectory
);
3320 string reactosDff
= NormalizeFilename ( "boot" + sSep
+ "bootdata" + sSep
+ "packages" + sSep
+ "reactos.dff" );
3321 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
3322 vector
<string
> vCdFiles
;
3323 GetCdFiles ( vCdFiles
);
3324 string cdFiles
= v2s ( vCdFiles
, 5 );
3326 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3327 module
.name
.c_str ());
3328 fprintf ( fMakefile
,
3329 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
3330 module
.name
.c_str (),
3332 bootcdReactos
.c_str (),
3333 cdDirectories
.c_str (),
3335 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
3336 fprintf ( fMakefile
,
3337 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
3338 reactosDff
.c_str (),
3339 bootcdReactos
.c_str () );
3340 fprintf ( fMakefile
,
3341 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
3342 reactosDff
.c_str (),
3343 reactosInf
.c_str (),
3344 bootcdReactos
.c_str ());
3345 fprintf ( fMakefile
,
3346 "\t-@${rm} %s 2>$(NUL)\n",
3347 reactosInf
.c_str () );
3348 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
3349 OutputCdfileCopyCommands ( bootcdDirectory
);
3350 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3351 fprintf ( fMakefile
,
3352 "\t$(Q)$(CDMAKE_TARGET) -v -j -m -b %s %s REACTOS %s\n",
3356 fprintf ( fMakefile
,
3361 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
3362 const Module
& module_
)
3364 : MingwModuleHandler ( module_
)
3369 MingwLiveIsoModuleHandler::Process ()
3371 GenerateLiveIsoModuleTarget ();
3375 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
3377 string normalizedDirectory
= MingwModuleHandler::PassThruCacheDirectory (
3378 NormalizeFilename ( directory
) + sSep
,
3379 backend
->outputDirectory
);
3383 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string
& sourceFilename
,
3384 const string
& targetFilename
,
3385 const string
& targetDirectory
)
3387 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3388 NormalizeFilename ( targetDirectory
+ sSep
+ targetFilename
),
3389 backend
->outputDirectory
);
3390 fprintf ( fMakefile
,
3392 fprintf ( fMakefile
,
3393 "\t${cp} %s %s 1>$(NUL)\n",
3394 sourceFilename
.c_str (),
3395 normalizedTargetFilename
.c_str () );
3399 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
3400 string
& reactosDirectory
)
3402 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3404 const Module
& m
= *module
.project
.modules
[i
];
3407 if ( m
.installName
.length () > 0 )
3409 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
3410 string sourceFilename
= MingwModuleHandler::PassThruCacheDirectory (
3411 NormalizeFilename ( aliasedModule
.GetPath () ),
3412 backend
->outputDirectory
);
3413 OutputCopyCommand ( sourceFilename
,
3415 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.installBase
);
3421 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
3422 string
& reactosDirectory
)
3424 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
3426 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
3427 OutputCopyCommand ( installfile
.GetPath (),
3428 installfile
.newname
,
3429 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.base
);
3434 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
3436 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
3437 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
3438 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
3439 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
3440 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
3441 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
3443 string livecdIni
= "boot" + sSep
+ "bootdata" + sSep
+ "livecd.ini";
3444 OutputCopyCommand ( livecdIni
,
3450 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3452 string freeldr
= PassThruCacheDirectory (
3453 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "freeldr" + sSep
+ "freeldr.sys" ),
3454 backend
->outputDirectory
);
3455 CreateDirectory ( livecdDirectory
+ sSep
+ "loader" );
3456 OutputCopyCommand ( freeldr
,
3458 livecdDirectory
+ sSep
+ "loader" );
3462 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3464 string reactosSystem32ConfigDirectory
= NormalizeFilename (
3465 MingwModuleHandler::PassThruCacheDirectory (
3466 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config" + sSep
,
3467 backend
->outputDirectory
) );
3468 fprintf ( fMakefile
,
3469 "\t$(ECHO_MKHIVE)\n" );
3470 fprintf ( fMakefile
,
3471 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%clivecd.inf boot%cbootdata%chiveinst.inf\n",
3472 cSep
, reactosSystem32ConfigDirectory
.c_str (),
3473 cSep
, cSep
, cSep
, cSep
);
3477 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
3479 string livecdDirectory
= module
.name
;
3480 string livecd
= PassThruCacheDirectory (
3481 NormalizeFilename ( livecdDirectory
+ sSep
),
3482 backend
->outputDirectory
);
3487 if (module
.name
== "livecdregtest")
3489 bootloader
= "isobtrt.o";
3490 IsoName
= "ReactOS-LiveCD-RegTest.iso";
3494 bootloader
= "isoboot.o";
3495 IsoName
= "ReactOS-LiveCD.iso";
3498 string isoboot
= PassThruCacheDirectory (
3499 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ bootloader
.c_str() ),
3500 backend
->outputDirectory
);
3502 string reactosDirectory
= "reactos";
3503 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3504 string livecdReactos
= NormalizeFilename ( PassThruCacheDirectory (
3505 NormalizeFilename ( livecdReactosNoFixup
+ sSep
),
3506 backend
->outputDirectory
) );
3507 CLEAN_FILE ( livecdReactos
);
3509 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3510 module
.name
.c_str ());
3511 fprintf ( fMakefile
,
3512 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3513 module
.name
.c_str (),
3515 livecdReactos
.c_str () );
3516 OutputModuleCopyCommands ( livecdDirectory
,
3518 OutputNonModuleCopyCommands ( livecdDirectory
,
3520 OutputProfilesDirectoryCommands ( livecdDirectory
);
3521 OutputLoaderCommands ( livecdDirectory
);
3522 OutputRegistryCommands ( livecdDirectory
);
3523 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3524 fprintf ( fMakefile
,
3525 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS %s\n",
3529 fprintf ( fMakefile
,
3534 MingwTestModuleHandler::MingwTestModuleHandler (
3535 const Module
& module_
)
3537 : MingwModuleHandler ( module_
)
3542 MingwTestModuleHandler::Process ()
3544 GenerateTestModuleTarget ();
3548 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
3550 string basePath
= "$(INTERMEDIATE)" + sSep
+ module
.GetBasePath ();
3551 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_hooks.c", false, "", false ) ) );
3552 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_stubs.S", false, "", false ) ) );
3553 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_startup.c", false, "", false ) ) );
3557 MingwTestModuleHandler::GenerateTestModuleTarget ()
3559 string
targetMacro ( GetTargetMacro ( module
) );
3560 string workingDirectory
= GetWorkingDirectory ( );
3561 string objectsMacro
= GetObjectsMacro ( module
);
3562 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3563 string libsMacro
= GetLibsMacro ();
3565 GenerateImportLibraryTargetIfNeeded ();
3567 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3571 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3574 if ( module
.cplusplus
)
3579 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3580 module
.GetEntryPoint(true).c_str (),
3581 module
.baseaddress
.c_str () );
3582 GenerateLinkerCommand ( dependencies
,
3591 GeneratePhonyTarget();
3596 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3597 const Module
& module_
)
3599 : MingwModuleHandler ( module_
)
3604 MingwRpcServerModuleHandler::Process ()
3610 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3611 const Module
& module_
)
3613 : MingwModuleHandler ( module_
)
3618 MingwRpcClientModuleHandler::Process ()
3624 MingwAliasModuleHandler::MingwAliasModuleHandler (
3625 const Module
& module_
)
3627 : MingwModuleHandler ( module_
)
3632 MingwAliasModuleHandler::Process ()
3636 MingwIdlHeaderModuleHandler::MingwIdlHeaderModuleHandler (
3637 const Module
& module_
)
3639 : MingwModuleHandler ( module_
)
3644 MingwIdlHeaderModuleHandler::Process ()