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)->name.length () > 0 ? strFile ( f ) : strDirectory ( f ) );
31 MingwModuleHandler::backend
= NULL
;
33 MingwModuleHandler::fMakefile
= NULL
;
36 strDirectory ( const FileLocation
*file
);
38 strFile ( const FileLocation
*file
);
42 const string
& filename
,
43 const string
& prefix
)
45 if ( !prefix
.length() )
48 const char* pfilename
= filename
.c_str();
49 const char* p1
= strrchr ( pfilename
, '/' );
50 const char* p2
= strrchr ( pfilename
, '\\' );
55 out
+= string(pfilename
,p1
-pfilename
) + cSep
;
58 out
+= prefix
+ pfilename
;
63 GetTargetMacro ( const Module
& module
, bool with_dollar
)
65 string
s ( module
.name
);
69 return ssprintf ( "$(%s)", s
.c_str() );
73 MingwModuleHandler::MingwModuleHandler (
74 const Module
& module_
)
81 MingwModuleHandler::~MingwModuleHandler()
86 MingwModuleHandler::SetBackend ( MingwBackend
* backend_
)
92 MingwModuleHandler::SetMakefile ( FILE* f
)
98 MingwModuleHandler::EnablePreCompiledHeaderSupport ()
103 /*static*/ const FileLocation
*
104 MingwModuleHandler::PassThruCacheDirectory (const FileLocation
* file
)
106 switch ( file
->directory
)
108 case IntermediateDirectory
:
109 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->intermediateDirectory
);
111 case OutputDirectory
:
112 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->outputDirectory
);
114 case InstallDirectory
:
115 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->installDirectory
);
118 throw InvalidOperationException ( __FILE__
,
120 "Invalid directory %d.",
127 /*static*/ DirectoryLocation
128 MingwModuleHandler::GetTargetDirectoryTree (
129 const Module
& module
)
131 if ( module
.type
== StaticLibrary
)
132 return IntermediateDirectory
;
133 return OutputDirectory
;
136 /*static*/ const FileLocation
*
137 MingwModuleHandler::GetTargetFilename (
138 const Module
& module
,
139 string_list
* pclean_files
)
141 FileLocation
*target
= new FileLocation ( GetTargetDirectoryTree ( module
), module
.GetBasePath (), module
.GetTargetName () );
144 string_list
& clean_files
= *pclean_files
;
145 CLEAN_FILE ( target
);
150 /*static*/ const FileLocation
*
151 MingwModuleHandler::GetImportLibraryFilename (
152 const Module
& module
,
153 string_list
* pclean_files
)
155 FileLocation
*target
= new FileLocation ( IntermediateDirectory
, module
.GetBasePath (), module
.GetDependencyTargetName () );
158 string_list
& clean_files
= *pclean_files
;
159 CLEAN_FILE ( target
);
164 /*static*/ MingwModuleHandler
*
165 MingwModuleHandler::InstanciateHandler (
166 const Module
& module
,
167 MingwBackend
* backend
)
169 MingwModuleHandler
* handler
;
170 switch ( module
.type
)
173 handler
= new MingwBuildToolModuleHandler ( module
);
176 handler
= new MingwStaticLibraryModuleHandler ( module
);
179 handler
= new MingwObjectLibraryModuleHandler ( module
);
182 handler
= new MingwKernelModuleHandler ( module
);
185 handler
= new MingwNativeCUIModuleHandler ( module
);
188 handler
= new MingwWin32CUIModuleHandler ( module
);
192 handler
= new MingwWin32GUIModuleHandler ( module
);
195 handler
= new MingwKernelModeDLLModuleHandler ( module
);
198 handler
= new MingwNativeDLLModuleHandler ( module
);
201 handler
= new MingwWin32DLLModuleHandler ( module
);
204 handler
= new MingwWin32OCXModuleHandler ( module
);
206 case KernelModeDriver
:
207 handler
= new MingwKernelModeDriverModuleHandler ( module
);
210 handler
= new MingwBootLoaderModuleHandler ( module
);
213 handler
= new MingwBootSectorModuleHandler ( module
);
216 handler
= new MingwBootProgramModuleHandler ( module
);
219 handler
= new MingwIsoModuleHandler ( module
);
222 handler
= new MingwLiveIsoModuleHandler ( module
);
225 handler
= new MingwIsoModuleHandler ( module
);
228 handler
= new MingwLiveIsoModuleHandler ( module
);
231 handler
= new MingwTestModuleHandler ( module
);
234 handler
= new MingwRpcServerModuleHandler ( module
);
237 handler
= new MingwRpcClientModuleHandler ( module
);
240 handler
= new MingwAliasModuleHandler ( module
);
243 handler
= new MingwIdlHeaderModuleHandler ( module
);
245 case EmbeddedTypeLib
:
246 handler
= new MingwEmbeddedTypeLibModuleHandler ( module
);
249 handler
= new MingwElfExecutableModuleHandler ( module
);
252 throw UnknownModuleTypeException (
253 module
.node
.location
,
261 MingwModuleHandler::GetWorkingDirectory () const
267 MingwModuleHandler::GetBasename ( const string
& filename
) const
269 size_t index
= filename
.find_last_of ( '.' );
270 if ( index
!= string::npos
)
271 return filename
.substr ( 0, index
);
276 MingwModuleHandler::GetActualSourceFilename (
277 const FileLocation
* file
) const
279 string filename
= file
->name
;
281 string extension
= GetExtension ( filename
);
282 if ( extension
== ".spec" || extension
== ".SPEC" )
284 string basename
= GetBasename ( filename
);
285 return new FileLocation (
286 IntermediateDirectory
,
288 basename
+ ".stubs.c" );
290 else if ( extension
== ".idl" || extension
== ".IDL" )
292 string basename
= GetBasename ( filename
);
293 if ( module
.type
== RpcServer
)
295 return new FileLocation (
296 IntermediateDirectory
,
300 else if ( module
.type
== RpcClient
)
302 return new FileLocation (
303 IntermediateDirectory
,
309 return new FileLocation ( *file
);
313 return new FileLocation ( *file
);
317 MingwModuleHandler::GetExtraDependencies (
318 const FileLocation
*file
) const
320 string extension
= GetExtension ( file
->name
);
321 if ( extension
== ".idl" || extension
== ".IDL" )
323 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
324 return strFile ( GetRpcServerHeaderFilename ( file
) )
326 + strFile ( GetRpcClientHeaderFilename ( file
) );
327 else if ( module
.type
== IdlHeader
)
328 return strFile ( GetIdlHeaderFilename ( file
) );
337 MingwModuleHandler::GetCompilationUnitDependencies (
338 const CompilationUnit
& compilationUnit
) const
340 if ( compilationUnit
.files
.size () <= 1 )
342 vector
<string
> sourceFiles
;
343 for ( size_t i
= 0; i
< compilationUnit
.files
.size (); i
++ )
345 File
& file
= *compilationUnit
.files
[i
];
346 sourceFiles
.push_back ( NormalizeFilename ( file
.name
) );
348 return v2s ( sourceFiles
, 10 );
352 MingwModuleHandler::GetModuleArchiveFilename () const
354 if ( module
.type
== StaticLibrary
)
355 return new FileLocation ( *GetTargetFilename ( module
, NULL
) );
356 return new FileLocation ( IntermediateDirectory
,
357 module
.GetBasePath (),
358 ReplaceExtension ( module
.name
, ".temp.a" ) );
362 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
364 string extension
= GetExtension ( file
.name
);
365 return ( extension
== ".spec" || extension
== ".SPEC" );
369 MingwModuleHandler::ReferenceObjects (
370 const Module
& module
)
372 if ( module
.type
== ObjectLibrary
)
374 if ( module
.type
== RpcServer
)
376 if ( module
.type
== RpcClient
)
378 if ( module
.type
== IdlHeader
)
384 MingwModuleHandler::OutputCopyCommand ( const FileLocation
& source
,
385 const FileLocation
& destination
)
390 "\t${cp} %s %s 1>$(NUL)\n",
391 strFile ( &source
).c_str (),
392 strFile ( &destination
).c_str () );
396 MingwModuleHandler::GetImportLibraryDependency (
397 const Module
& importedModule
)
400 if ( ReferenceObjects ( importedModule
) )
401 dep
= GetTargetMacro ( importedModule
);
403 dep
= strFile ( GetImportLibraryFilename ( importedModule
, NULL
) );
408 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
409 string_list
& targets
)
411 if ( dependencyModule
.invocations
.size () > 0 )
413 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
415 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
416 invoke
.GetTargets ( targets
);
420 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
424 MingwModuleHandler::GetModuleDependencies (
425 string_list
& dependencies
)
427 size_t iend
= module
.dependencies
.size ();
432 for ( size_t i
= 0; i
< iend
; i
++ )
434 const Dependency
& dependency
= *module
.dependencies
[i
];
435 const Module
& dependencyModule
= *dependency
.dependencyModule
;
436 GetTargets ( dependencyModule
,
439 vector
<FileLocation
> v
;
440 GetDefinitionDependencies ( v
);
441 for ( size_t i
= 0; i
< v
.size (); i
++ )
443 const FileLocation
& file
= v
[i
];
444 dependencies
.push_back ( strFile ( &file
) );
449 MingwModuleHandler::GetSourceFilenames ( vector
<FileLocation
>& list
,
450 bool includeGeneratedFiles
) const
454 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
455 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
457 if ( includeGeneratedFiles
|| !compilationUnits
[i
]->IsGeneratedFile () )
459 const FileLocation
* sourceFileLocation
= GetActualSourceFilename (
460 compilationUnits
[i
]->GetFilename () );
461 list
.push_back ( *sourceFileLocation
);
464 // intentionally make a copy so that we can append more work in
465 // the middle of processing without having to go recursive
466 vector
<If
*> v
= module
.non_if_data
.ifs
;
467 for ( i
= 0; i
< v
.size (); i
++ )
471 // check for sub-ifs to add to list
472 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
473 for ( j
= 0; j
< ifs
.size (); j
++ )
474 v
.push_back ( ifs
[j
] );
475 const vector
<CompilationUnit
*>& compilationUnits
= rIf
.data
.compilationUnits
;
476 for ( j
= 0; j
< compilationUnits
.size (); j
++ )
478 CompilationUnit
& compilationUnit
= *compilationUnits
[j
];
479 if ( includeGeneratedFiles
|| !compilationUnit
.IsGeneratedFile () )
481 const FileLocation
* sourceFileLocation
= GetActualSourceFilename (
482 compilationUnit
.GetFilename () );
483 list
.push_back ( *sourceFileLocation
);
490 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
491 vector
<FileLocation
>& list
) const
493 GetSourceFilenames ( list
, false );
497 MingwModuleHandler::GetObjectFilename (
498 const FileLocation
* sourceFile
,
499 string_list
* pclean_files
) const
501 string sourceFilename
= sourceFile
->name
;
502 DirectoryLocation destination_directory
;
504 string extension
= GetExtension ( sourceFilename
);
505 if ( extension
== ".rc" || extension
== ".RC" )
506 newExtension
= ".coff";
507 else if ( extension
== ".spec" || extension
== ".SPEC" )
508 newExtension
= ".stubs.o";
509 else if ( extension
== ".idl" || extension
== ".IDL" )
511 if ( module
.type
== RpcServer
)
512 newExtension
= "_s.o";
513 else if ( module
.type
== RpcClient
)
514 newExtension
= "_c.o";
521 if ( module
.type
== BootSector
)
522 destination_directory
= OutputDirectory
;
524 destination_directory
= IntermediateDirectory
;
526 const FileLocation
*obj_file
= new FileLocation(
527 destination_directory
,
528 sourceFile
->relative_path
,
529 ReplaceExtension ( sourceFile
->name
, newExtension
) );
533 string_list
& clean_files
= *pclean_files
;
534 CLEAN_FILE ( obj_file
);
540 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
542 return module
.name
+ "_clean";
546 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
548 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
550 Library
& library
= *module
.non_if_data
.libraries
[i
];
551 if ( library
.importedModule
->type
== ObjectLibrary
)
552 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
557 MingwModuleHandler::GenerateCleanTarget () const
559 if ( module
.type
== Alias
)
563 ".PHONY: %s_clean\n",
564 module
.name
.c_str() );
565 vector
<string
> referencedModuleNames
;
566 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
569 GetModuleCleanTarget ( module
).c_str(),
570 v2s ( referencedModuleNames
, 10 ).c_str () );
571 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
573 if ( ( i
+ 1 ) % 10 == 9 )
574 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
575 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
577 fprintf ( fMakefile
, " 2>$(NUL)\n" );
578 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
582 MingwModuleHandler::GenerateInstallTarget () const
584 if ( module
.installName
.length () == 0 )
586 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
587 string normalizedTargetFilename
=
588 NormalizeFilename ( module
.installBase
+ sSep
+ module
.installName
);
590 "%s_install: $(INSTALL)%c%s\n",
591 module
.name
.c_str (),
593 normalizedTargetFilename
.c_str() );
597 MingwModuleHandler::GenerateDependsTarget () const
600 ".PHONY: %s_depends\n",
601 module
.name
.c_str() );
603 "%s_depends: $(RBUILD_TARGET)\n",
604 module
.name
.c_str () );
606 "\t$(ECHO_RBUILD)\n" );
608 "\t$(Q)$(RBUILD_TARGET) $(RBUILD_FLAGS) -dm%s mingw\n",
609 module
.name
.c_str () );
613 MingwModuleHandler::GetObjectFilenames ()
615 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
616 if ( compilationUnits
.size () == 0 )
619 string
objectFilenames ( "" );
620 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
622 if ( objectFilenames
.size () > 0 )
623 objectFilenames
+= " ";
624 objectFilenames
+= strFile ( GetObjectFilename ( compilationUnits
[i
]->GetFilename (), NULL
) );
626 return objectFilenames
;
630 MingwModuleHandler::GenerateGccDefineParametersFromVector (
631 const vector
<Define
*>& defines
)
634 for ( size_t i
= 0; i
< defines
.size (); i
++ )
636 Define
& define
= *defines
[i
];
637 if (parameters
.length () > 0)
640 parameters
+= define
.name
;
641 if (define
.value
.length () > 0)
644 parameters
+= define
.value
;
651 MingwModuleHandler::GenerateGccDefineParameters () const
653 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
654 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
655 if ( s
.length () > 0 )
664 MingwModuleHandler::ConcatenatePaths (
666 const string
& path2
) const
668 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
670 if ( path1
[path1
.length ()] == cSep
)
671 return path1
+ path2
;
673 return path1
+ cSep
+ path2
;
677 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
679 string parameters
, path_prefix
;
680 for ( size_t i
= 0; i
< includes
.size (); i
++ )
682 Include
& include
= *includes
[i
];
683 if ( parameters
.length () > 0 )
685 if ( include
.root
== "intermediate" )
686 path_prefix
= "$(INTERMEDIATE)" + sSep
;
687 else if (include
.root
== "output" )
688 path_prefix
= "$(OUTPUT)" + sSep
;
692 parameters
+= "-I" + path_prefix
+ include
.directory
;
698 MingwModuleHandler::GenerateGccIncludeParameters () const
700 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
701 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
702 if ( s
.length () > 0 )
711 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
714 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
716 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
717 if ( parameters
.length () > 0 )
719 parameters
+= compilerFlag
.flag
;
725 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
728 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
730 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
731 if ( parameters
.length () > 0 )
733 parameters
+= linkerFlag
.flag
;
739 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
740 const vector
<Library
*>& libraries
)
742 string
dependencies ( "" );
744 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
746 if ( wrap_count
++ == 5 )
747 dependencies
+= " \\\n\t\t", wrap_count
= 0;
748 else if ( dependencies
.size () > 0 )
750 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
756 MingwModuleHandler::GenerateLinkerParameters () const
758 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
762 MingwModuleHandler::GenerateMacro (
763 const char* assignmentOperation
,
765 const IfableData
& data
)
768 bool generateAssignment
;
770 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
771 if ( generateAssignment
)
776 assignmentOperation
);
779 if ( use_pch
&& module
.pch
!= NULL
)
783 strDirectory ( GetPrecompiledHeaderFilename () ).c_str () );
786 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
787 if ( compilerParameters
.size () > 0 )
792 compilerParameters
.c_str () );
795 for ( i
= 0; i
< data
.includes
.size(); i
++ )
797 const Include
& include
= *data
.includes
[i
];
798 string includeDirectory
, path_prefix
;
799 if ( include
.baseModule
!= NULL
&&
800 ( include
.baseModule
->type
== RpcServer
||
801 include
.baseModule
->type
== RpcClient
||
802 include
.baseModule
->type
== IdlHeader
) )
804 path_prefix
= "$(INTERMEDIATE)" + sSep
;
805 includeDirectory
= NormalizeFilename ( include
.directory
);
808 includeDirectory
= include
.directory
;
810 if ( include
.root
== "intermediate" )
811 path_prefix
= "$(INTERMEDIATE)" + sSep
;
812 else if (include
.root
== "output" )
813 path_prefix
= "$(OUTPUT)" + sSep
;
814 else if ( include
.root
!= "" )
815 throw InvalidOperationException ( __FILE__
,
817 "Unsupported root prefix '%s'",
818 include
.root
.c_str () );
824 includeDirectory
.c_str() );
826 for ( i
= 0; i
< data
.defines
.size(); i
++ )
828 Define
& d
= *data
.defines
[i
];
833 if ( d
.value
.size() )
839 if ( generateAssignment
)
841 fprintf ( fMakefile
, "\n" );
846 MingwModuleHandler::GenerateMacros (
847 const char* assignmentOperation
,
848 const IfableData
& data
,
849 const vector
<LinkerFlag
*>* linkerFlags
)
853 GenerateMacro ( assignmentOperation
,
856 GenerateMacro ( assignmentOperation
,
860 if ( linkerFlags
!= NULL
)
862 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
863 if ( linkerParameters
.size () > 0 )
868 linkerflagsMacro
.c_str (),
870 linkerParameters
.c_str() );
874 if ( data
.libraries
.size () > 0 )
876 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
877 if ( deps
.size () > 0 )
888 const vector
<If
*>& ifs
= data
.ifs
;
889 for ( i
= 0; i
< ifs
.size(); i
++ )
892 if ( rIf
.data
.defines
.size()
893 || rIf
.data
.includes
.size()
894 || rIf
.data
.libraries
.size()
895 || rIf
.data
.compilationUnits
.size()
896 || rIf
.data
.compilerFlags
.size()
897 || rIf
.data
.ifs
.size() )
901 "%s (\"$(%s)\",\"%s\")\n",
902 rIf
.negated
? "ifneq" : "ifeq",
903 rIf
.property
.c_str(),
917 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
919 for (size_t i
= 0; i
< compilationUnits
.size (); i
++)
920 delete compilationUnits
[i
];
924 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
929 MingwModuleHandler::GenerateObjectMacros (
930 const char* assignmentOperation
,
931 const IfableData
& data
,
932 const vector
<LinkerFlag
*>* linkerFlags
)
936 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
937 if ( compilationUnits
.size () > 0 )
939 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
941 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
942 if ( compilationUnit
.IsFirstFile () )
946 objectsMacro
.c_str(),
947 strFile ( GetObjectFilename ( compilationUnit
.GetFilename (), NULL
) ).c_str (),
948 objectsMacro
.c_str() );
954 objectsMacro
.c_str (),
955 assignmentOperation
);
956 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
958 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
959 if ( !compilationUnit
.IsFirstFile () )
964 ( i
%10 == 9 ? " \\\n\t" : " " ),
965 strFile ( GetObjectFilename ( compilationUnit
.GetFilename (), NULL
) ).c_str () );
968 fprintf ( fMakefile
, "\n" );
971 const vector
<If
*>& ifs
= data
.ifs
;
972 for ( i
= 0; i
< ifs
.size(); i
++ )
975 if ( rIf
.data
.defines
.size()
976 || rIf
.data
.includes
.size()
977 || rIf
.data
.libraries
.size()
978 || rIf
.data
.compilationUnits
.size()
979 || rIf
.data
.compilerFlags
.size()
980 || rIf
.data
.ifs
.size() )
984 "%s (\"$(%s)\",\"%s\")\n",
985 rIf
.negated
? "ifneq" : "ifeq",
986 rIf
.property
.c_str(),
988 GenerateObjectMacros (
998 vector
<CompilationUnit
*> sourceCompilationUnits
;
999 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1000 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1005 objectsMacro
.c_str(),
1006 strFile ( GetObjectFilename ( sourceCompilationUnits
[i
]->GetFilename (), NULL
) ).c_str () );
1008 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1012 MingwModuleHandler::GetPrecompiledHeaderFilename () const
1014 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
1015 return new FileLocation ( IntermediateDirectory
,
1016 module
.pch
->file
.relative_path
,
1021 MingwModuleHandler::GenerateGccCommand (
1022 const FileLocation
* sourceFile
,
1023 const string
& extraDependencies
,
1025 const string
& cflagsMacro
)
1027 string dependencies
= strFile ( sourceFile
);
1028 if ( extraDependencies
!= "" )
1029 dependencies
+= " " + extraDependencies
;
1030 if ( module
.pch
&& use_pch
)
1031 dependencies
+= " " + strFile ( GetPrecompiledHeaderFilename () );
1033 /* WIDL generated headers may be used */
1034 vector
<FileLocation
> rpcDependencies
;
1035 GetRpcHeaderDependencies ( rpcDependencies
);
1036 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1037 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1039 const FileLocation
*objectFilename
= GetObjectFilename (
1040 sourceFile
, &clean_files
);
1041 fprintf ( fMakefile
,
1043 strFile ( objectFilename
).c_str (),
1044 dependencies
.c_str (),
1045 strDirectory ( objectFilename
).c_str () );
1046 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
1047 fprintf ( fMakefile
,
1048 "\t%s -c $< -o $@ %s\n",
1050 cflagsMacro
.c_str () );
1054 MingwModuleHandler::GenerateGccAssemblerCommand (
1055 const FileLocation
* sourceFile
,
1057 const string
& cflagsMacro
)
1059 string dependencies
= strFile ( sourceFile
);
1060 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1062 const FileLocation
*objectFilename
= GetObjectFilename (
1063 sourceFile
, &clean_files
);
1064 fprintf ( fMakefile
,
1066 strFile ( objectFilename
).c_str (),
1067 dependencies
.c_str (),
1068 strDirectory ( objectFilename
).c_str () );
1069 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
1070 fprintf ( fMakefile
,
1071 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
1073 cflagsMacro
.c_str () );
1077 MingwModuleHandler::GenerateNasmCommand (
1078 const FileLocation
* sourceFile
,
1079 const string
& nasmflagsMacro
)
1081 string dependencies
= strFile ( sourceFile
);
1082 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1084 const FileLocation
*objectFilename
= GetObjectFilename (
1085 sourceFile
, &clean_files
);
1086 fprintf ( fMakefile
,
1088 strFile ( objectFilename
).c_str (),
1089 dependencies
.c_str (),
1090 strDirectory ( objectFilename
).c_str () );
1091 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1092 fprintf ( fMakefile
,
1093 "\t%s -f win32 $< -o $@ %s\n",
1095 nasmflagsMacro
.c_str () );
1099 MingwModuleHandler::GenerateWindresCommand (
1100 const FileLocation
* sourceFile
,
1101 const string
& windresflagsMacro
)
1103 string dependencies
= strFile ( sourceFile
);
1104 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1106 const FileLocation
*objectFilename
= GetObjectFilename ( sourceFile
, &clean_files
);
1108 if ( module
.useWRC
)
1110 string sourceFilenamePart
= module
.name
+ "." + ReplaceExtension ( sourceFile
->name
, "" );
1111 FileLocation
rciFilename ( TemporaryDirectory
,
1113 sourceFilenamePart
+ ".rci.tmp" );
1114 FileLocation
resFilename ( TemporaryDirectory
,
1116 sourceFilenamePart
+ ".res.tmp" );
1118 fprintf ( fMakefile
,
1119 "%s: %s $(WRC_TARGET) | %s\n",
1120 strFile ( objectFilename
).c_str (),
1121 dependencies
.c_str (),
1122 strDirectory ( 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 strFile ( sourceFile
).c_str (),
1128 strFile ( &rciFilename
).c_str () );
1129 fprintf ( fMakefile
,
1130 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1131 windresflagsMacro
.c_str (),
1132 strFile ( &rciFilename
).c_str (),
1133 strFile ( &resFilename
).c_str () );
1134 fprintf ( fMakefile
,
1135 "\t-@${rm} %s 2>$(NUL)\n",
1136 strFile ( &rciFilename
).c_str () );
1137 fprintf ( fMakefile
,
1138 "\t${windres} %s -o $@\n",
1139 strFile ( &resFilename
).c_str () );
1140 fprintf ( fMakefile
,
1141 "\t-@${rm} %s 2>$(NUL)\n",
1142 strFile ( &resFilename
).c_str () );
1146 fprintf ( fMakefile
,
1147 "%s: %s $(WRC_TARGET) | %s\n",
1148 strFile ( objectFilename
).c_str (),
1149 dependencies
.c_str (),
1150 strDirectory ( 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 strFile ( sourceFile
).c_str () );
1160 MingwModuleHandler::GenerateWinebuildCommands (
1161 const FileLocation
* sourceFile
)
1163 string dependencies
= strFile ( sourceFile
);
1164 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1166 string basename
= GetBasename ( sourceFile
->name
);
1167 FileLocation
def_file ( IntermediateDirectory
,
1168 sourceFile
->relative_path
,
1169 basename
+ ".spec.def" );
1170 CLEAN_FILE ( &def_file
);
1172 FileLocation
stub_file ( IntermediateDirectory
,
1173 sourceFile
->relative_path
,
1174 basename
+ ".stubs.c" );
1175 CLEAN_FILE ( &stub_file
);
1177 fprintf ( fMakefile
,
1178 "%s: %s $(WINEBUILD_TARGET) | %s\n",
1179 strFile ( &def_file
).c_str (),
1180 dependencies
.c_str (),
1181 strDirectory ( &def_file
).c_str () );
1182 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1183 fprintf ( fMakefile
,
1184 "\t%s -o %s --def -E %s\n",
1185 "$(Q)$(WINEBUILD_TARGET)",
1186 strFile ( &def_file
).c_str (),
1187 strFile ( sourceFile
).c_str () );
1188 fprintf ( fMakefile
,
1189 "%s: %s $(WINEBUILD_TARGET)\n",
1190 strFile ( &stub_file
).c_str (),
1191 strFile ( sourceFile
).c_str () );
1192 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1193 fprintf ( fMakefile
,
1194 "\t%s -o %s --pedll %s\n",
1195 "$(Q)$(WINEBUILD_TARGET)",
1196 strFile ( &stub_file
).c_str (),
1197 strFile ( sourceFile
).c_str () );
1201 MingwModuleHandler::GetWidlFlags ( const CompilationUnit
& compilationUnit
)
1203 return compilationUnit
.GetSwitches ();
1207 MingwModuleHandler::GetPropertyValue ( const Module
& module
, const std::string
& name
)
1209 for ( size_t i
= 0; i
< module
.project
.non_if_data
.properties
.size (); i
++ )
1211 const Property
& property
= *module
.project
.non_if_data
.properties
[i
];
1212 if ( property
.name
== name
)
1213 return property
.value
;
1215 return string ( "" );
1219 MingwModuleHandler::GetRpcServerHeaderFilename ( const FileLocation
*base
) const
1221 string newname
= GetBasename ( base
->name
) + "_s.h";
1222 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1226 MingwModuleHandler::GenerateWidlCommandsServer (
1227 const CompilationUnit
& compilationUnit
,
1228 const string
& widlflagsMacro
)
1230 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1231 string dependencies
= strFile ( sourceFile
);
1232 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1234 string basename
= GetBasename ( sourceFile
->name
);
1236 const FileLocation
*generatedHeaderFilename
= GetRpcServerHeaderFilename ( sourceFile
);
1237 CLEAN_FILE(generatedHeaderFilename
);
1239 FileLocation
generatedServerFilename ( IntermediateDirectory
,
1240 sourceFile
->relative_path
,
1241 basename
+ "_s.c" );
1242 CLEAN_FILE(&generatedServerFilename
);
1244 fprintf ( fMakefile
,
1245 "%s %s: %s $(WIDL_TARGET) | %s\n",
1246 strFile ( &generatedServerFilename
).c_str (),
1247 strFile ( generatedHeaderFilename
).c_str (),
1248 dependencies
.c_str (),
1249 strDirectory ( &generatedServerFilename
).c_str () );
1250 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1251 fprintf ( fMakefile
,
1252 "\t%s %s %s -h -H %s -s -S %s %s\n",
1253 "$(Q)$(WIDL_TARGET)",
1254 GetWidlFlags ( compilationUnit
).c_str (),
1255 widlflagsMacro
.c_str (),
1256 strFile ( generatedHeaderFilename
).c_str (),
1257 strFile ( &generatedServerFilename
).c_str (),
1258 strFile ( sourceFile
).c_str () );
1262 MingwModuleHandler::GetRpcClientHeaderFilename ( const FileLocation
*base
) const
1264 string newname
= GetBasename ( base
->name
) + "_c.h";
1265 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1269 MingwModuleHandler::GetIdlHeaderFilename ( const FileLocation
*base
) const
1271 string newname
= GetBasename ( base
->name
) + ".h";
1272 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1276 MingwModuleHandler::GenerateWidlCommandsEmbeddedTypeLib (
1277 const CompilationUnit
& compilationUnit
,
1278 const string
& widlflagsMacro
)
1280 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1281 string dependencies
= strFile ( sourceFile
);
1282 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1284 string basename
= GetBasename ( sourceFile
->name
);
1286 FileLocation
EmbeddedTypeLibFilename ( IntermediateDirectory
,
1287 sourceFile
->relative_path
,
1288 basename
+ ".tlb" );
1290 fprintf ( fMakefile
,
1291 "%s: %s $(WIDL_TARGET) | %s\n",
1292 GetTargetMacro ( module
).c_str (),
1293 dependencies
.c_str (),
1294 strDirectory ( &EmbeddedTypeLibFilename
).c_str () );
1295 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1296 fprintf ( fMakefile
,
1297 "\t%s %s %s -t -T %s %s\n",
1298 "$(Q)$(WIDL_TARGET)",
1299 GetWidlFlags ( compilationUnit
).c_str (),
1300 widlflagsMacro
.c_str (),
1301 strFile ( &EmbeddedTypeLibFilename
).c_str(),
1302 strFile ( sourceFile
).c_str () );
1306 MingwModuleHandler::GenerateWidlCommandsClient (
1307 const CompilationUnit
& compilationUnit
,
1308 const string
& widlflagsMacro
)
1310 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1311 string dependencies
= strFile ( sourceFile
);
1312 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1314 string basename
= GetBasename ( sourceFile
->name
);
1316 const FileLocation
*generatedHeaderFilename
= GetRpcClientHeaderFilename ( sourceFile
);
1317 CLEAN_FILE(generatedHeaderFilename
);
1319 FileLocation
generatedClientFilename ( IntermediateDirectory
,
1320 sourceFile
->relative_path
,
1321 basename
+ "_c.c" );
1322 CLEAN_FILE(&generatedClientFilename
);
1324 fprintf ( fMakefile
,
1325 "%s %s: %s $(WIDL_TARGET) | %s\n",
1326 strFile ( &generatedClientFilename
).c_str (),
1327 strFile ( generatedHeaderFilename
).c_str (),
1328 dependencies
.c_str (),
1329 strDirectory ( &generatedClientFilename
).c_str () );
1330 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1331 fprintf ( fMakefile
,
1332 "\t%s %s %s -h -H %s -c -C %s %s\n",
1333 "$(Q)$(WIDL_TARGET)",
1334 GetWidlFlags ( compilationUnit
).c_str (),
1335 widlflagsMacro
.c_str (),
1336 strFile ( generatedHeaderFilename
).c_str (),
1337 strFile ( &generatedClientFilename
).c_str (),
1338 strFile ( sourceFile
).c_str () );
1342 MingwModuleHandler::GenerateWidlCommandsIdlHeader (
1343 const CompilationUnit
& compilationUnit
,
1344 const string
& widlflagsMacro
)
1346 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1347 string dependencies
= strFile ( sourceFile
);
1348 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1350 string basename
= GetBasename ( sourceFile
->name
);
1352 const FileLocation
*generatedHeader
= GetIdlHeaderFilename ( sourceFile
);
1353 CLEAN_FILE(generatedHeader
);
1355 fprintf ( fMakefile
,
1356 "%s: %s $(WIDL_TARGET) | %s\n",
1357 strFile( generatedHeader
).c_str (),
1358 dependencies
.c_str (),
1359 strDirectory ( generatedHeader
).c_str () );
1360 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1361 fprintf ( fMakefile
,
1362 "\t%s %s %s -h -H %s %s\n",
1363 "$(Q)$(WIDL_TARGET)",
1364 GetWidlFlags ( compilationUnit
).c_str (),
1365 widlflagsMacro
.c_str (),
1366 strFile( generatedHeader
).c_str (),
1367 strFile ( sourceFile
).c_str () );
1371 MingwModuleHandler::GenerateWidlCommands (
1372 const CompilationUnit
& compilationUnit
,
1373 const string
& widlflagsMacro
)
1375 if ( module
.type
== RpcServer
)
1376 GenerateWidlCommandsServer ( compilationUnit
,
1378 else if ( module
.type
== RpcClient
)
1379 GenerateWidlCommandsClient ( compilationUnit
,
1381 else if ( module
.type
== EmbeddedTypeLib
)
1382 GenerateWidlCommandsEmbeddedTypeLib ( compilationUnit
,
1384 else // applies also for other module.types which include idl files
1385 GenerateWidlCommandsIdlHeader ( compilationUnit
,
1390 MingwModuleHandler::GenerateCommands (
1391 const CompilationUnit
& compilationUnit
,
1394 const string
& cflagsMacro
,
1395 const string
& nasmflagsMacro
,
1396 const string
& windresflagsMacro
,
1397 const string
& widlflagsMacro
)
1399 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1400 string filename
= strFile ( sourceFile
);
1401 string extension
= GetExtension ( filename
);
1402 if ( extension
== ".c" || extension
== ".C" )
1404 GenerateGccCommand ( sourceFile
,
1405 GetCompilationUnitDependencies ( compilationUnit
),
1410 else if ( extension
== ".cc" || extension
== ".CC" ||
1411 extension
== ".cpp" || extension
== ".CPP" ||
1412 extension
== ".cxx" || extension
== ".CXX" )
1414 GenerateGccCommand ( sourceFile
,
1415 GetCompilationUnitDependencies ( compilationUnit
),
1420 else if ( extension
== ".s" || extension
== ".S" )
1422 GenerateGccAssemblerCommand ( sourceFile
,
1427 else if ( extension
== ".asm" || extension
== ".ASM" )
1429 GenerateNasmCommand ( sourceFile
,
1433 else if ( extension
== ".rc" || extension
== ".RC" )
1435 GenerateWindresCommand ( sourceFile
,
1436 windresflagsMacro
);
1439 else if ( extension
== ".spec" || extension
== ".SPEC" )
1441 GenerateWinebuildCommands ( sourceFile
);
1442 GenerateGccCommand ( GetActualSourceFilename ( sourceFile
),
1448 else if ( extension
== ".idl" || extension
== ".IDL" )
1450 GenerateWidlCommands ( compilationUnit
,
1452 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
1454 GenerateGccCommand ( GetActualSourceFilename ( sourceFile
),
1455 GetExtraDependencies ( sourceFile
),
1462 throw InvalidOperationException ( __FILE__
,
1464 "Unsupported filename extension '%s' in file '%s'",
1466 filename
.c_str () );
1470 MingwModuleHandler::GenerateBuildMapCode ( const FileLocation
*mapTarget
)
1472 fprintf ( fMakefile
,
1473 "ifeq ($(ROS_BUILDMAP),full)\n" );
1475 FileLocation
mapFilename ( OutputDirectory
,
1476 module
.GetBasePath (),
1477 GetBasename ( module
.GetTargetName () ) + ".map" );
1478 CLEAN_FILE ( &mapFilename
);
1480 fprintf ( fMakefile
,
1481 "\t$(ECHO_OBJDUMP)\n" );
1482 fprintf ( fMakefile
,
1483 "\t$(Q)${objdump} -d -S %s > %s\n",
1484 mapTarget
? strFile ( mapTarget
).c_str () : "$@",
1485 strFile ( &mapFilename
).c_str () );
1487 fprintf ( fMakefile
,
1489 fprintf ( fMakefile
,
1490 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1492 fprintf ( fMakefile
,
1494 fprintf ( fMakefile
,
1495 "\t$(Q)${nm} --numeric-sort %s > %s\n",
1496 mapTarget
? strFile ( mapTarget
).c_str () : "$@",
1497 strFile ( &mapFilename
).c_str () );
1499 fprintf ( fMakefile
,
1502 fprintf ( fMakefile
,
1507 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1509 fprintf ( fMakefile
,
1510 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1512 string filename
= module
.GetTargetName ();
1513 FileLocation
outputFilename ( OutputDirectory
,
1514 module
.GetBasePath (),
1516 FileLocation
nostripFilename ( OutputDirectory
,
1517 module
.GetBasePath (),
1518 GetBasename ( filename
) + ".nostrip" + GetExtension ( filename
) );
1519 CLEAN_FILE ( &nostripFilename
);
1521 OutputCopyCommand ( outputFilename
, nostripFilename
);
1523 fprintf ( fMakefile
,
1528 MergeStringVector ( const vector
<FileLocation
>& input
,
1529 vector
<string
>& output
)
1533 int wrap_count
= -1;
1534 for ( size_t i
= 0; i
< input
.size (); i
++ )
1536 if ( wrap_count
++ == wrap_at
)
1538 output
.push_back ( s
);
1542 else if ( s
.size () > 0)
1544 s
+= strFile ( &input
[i
] );
1546 if ( s
.length () > 0 )
1547 output
.push_back ( s
);
1551 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1552 vector
<FileLocation
>& objectFiles
) const
1554 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1556 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1557 objectFiles
.push_back ( *GetObjectFilename ( compilationUnit
.GetFilename (), NULL
) );
1562 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1564 if ( backend
->configuration
.CleanAsYouGo
)
1566 vector
<FileLocation
> objectFiles
;
1567 GetObjectsVector ( module
.non_if_data
,
1569 vector
<string
> lines
;
1570 MergeStringVector ( objectFiles
,
1572 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1574 fprintf ( fMakefile
,
1575 "\t-@${rm} %s 2>$(NUL)\n",
1576 lines
[i
].c_str () );
1582 MingwModuleHandler::GenerateRunRsymCode () const
1584 fprintf ( fMakefile
,
1585 "\t$(ECHO_RSYM)\n" );
1586 fprintf ( fMakefile
,
1587 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1591 MingwModuleHandler::GenerateRunStripCode () const
1593 fprintf ( fMakefile
,
1594 "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" );
1595 fprintf ( fMakefile
,
1596 "\t$(ECHO_STRIP)\n" );
1597 fprintf ( fMakefile
,
1598 "\t${strip} -s -x -X $@\n\n" );
1599 fprintf ( fMakefile
,
1604 MingwModuleHandler::GenerateLinkerCommand (
1605 const string
& dependencies
,
1606 const string
& linker
,
1607 const string
& linkerParameters
,
1608 const string
& objectsMacro
,
1609 const string
& libsMacro
,
1610 const string
& pefixupParameters
)
1612 string
target ( GetTargetMacro ( module
) );
1613 string
target_folder ( strDirectory ( GetTargetFilename ( module
, NULL
) ) );
1614 const FileLocation
*definitionFilename
= GetDefinitionFilename ();
1616 string linkerScriptArgument
;
1617 if ( module
.linkerScript
!= NULL
)
1618 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", module
.linkerScript
->directory
.c_str () );
1620 linkerScriptArgument
= "";
1622 fprintf ( fMakefile
,
1623 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1625 strFile ( definitionFilename
).c_str (),
1626 dependencies
.c_str (),
1627 target_folder
.c_str () );
1628 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1629 string
targetName ( module
.GetTargetName () );
1631 if ( !module
.IsDLL () )
1633 fprintf ( fMakefile
,
1634 "\t%s %s %s -o %s %s %s %s\n",
1636 linkerParameters
.c_str (),
1637 linkerScriptArgument
.c_str (),
1639 objectsMacro
.c_str (),
1641 GetLinkerMacro ().c_str () );
1643 else if ( module
.HasImportLibrary () )
1645 FileLocation
temp_exp ( TemporaryDirectory
,
1647 module
.name
+ ".temp.exp" );
1648 CLEAN_FILE ( &temp_exp
);
1650 fprintf ( fMakefile
,
1651 "\t${dlltool} --dllname %s --def %s --output-exp %s %s %s\n",
1652 targetName
.c_str (),
1653 strFile ( definitionFilename
).c_str (),
1654 strFile ( &temp_exp
).c_str (),
1655 module
.mangledSymbols
? "" : "--kill-at",
1656 module
.underscoreSymbols
? "--add-underscore" : "" );
1658 fprintf ( fMakefile
,
1659 "\t%s %s %s %s -o %s %s %s %s\n",
1661 linkerParameters
.c_str (),
1662 linkerScriptArgument
.c_str (),
1663 strFile ( &temp_exp
).c_str (),
1665 objectsMacro
.c_str (),
1667 GetLinkerMacro ().c_str () );
1669 fprintf ( fMakefile
,
1670 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1672 pefixupParameters
.c_str() );
1674 fprintf ( fMakefile
,
1675 "\t-@${rm} %s 2>$(NUL)\n",
1676 strFile ( &temp_exp
).c_str () );
1680 /* XXX: need to workaround binutils bug, which exports
1681 * all functions in a dll if no .def file or an empty
1682 * one has been provided... */
1684 //printf ( "%s will have all its functions exported\n",
1685 // module.GetTargetName ().c_str () );
1686 fprintf ( fMakefile
,
1687 "\t%s %s %s -o %s %s %s %s\n",
1689 linkerParameters
.c_str (),
1690 linkerScriptArgument
.c_str (),
1692 objectsMacro
.c_str (),
1694 GetLinkerMacro ().c_str () );
1697 GenerateBuildMapCode ();
1698 GenerateBuildNonSymbolStrippedCode ();
1699 GenerateRunRsymCode ();
1700 GenerateRunStripCode ();
1701 GenerateCleanObjectsAsYouGoCode ();
1705 MingwModuleHandler::GeneratePhonyTarget() const
1707 string
targetMacro ( GetTargetMacro ( module
) );
1708 fprintf ( fMakefile
,
1710 targetMacro
.c_str ());
1711 fprintf ( fMakefile
, "%s: | %s\n",
1712 targetMacro
.c_str (),
1713 strDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1717 MingwModuleHandler::GenerateObjectFileTargets (
1718 const IfableData
& data
,
1721 const string
& cflagsMacro
,
1722 const string
& nasmflagsMacro
,
1723 const string
& windresflagsMacro
,
1724 const string
& widlflagsMacro
)
1728 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1729 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1731 GenerateCommands ( *compilationUnits
[i
],
1738 fprintf ( fMakefile
,
1742 const vector
<If
*>& ifs
= data
.ifs
;
1743 for ( i
= 0; i
< ifs
.size(); i
++ )
1745 GenerateObjectFileTargets ( ifs
[i
]->data
,
1754 vector
<CompilationUnit
*> sourceCompilationUnits
;
1755 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1756 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1758 GenerateCommands ( *sourceCompilationUnits
[i
],
1766 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1770 MingwModuleHandler::GenerateObjectFileTargets (
1773 const string
& cflagsMacro
,
1774 const string
& nasmflagsMacro
,
1775 const string
& windresflagsMacro
,
1776 const string
& widlflagsMacro
)
1778 if ( module
.pch
&& use_pch
)
1780 const FileLocation
& baseHeaderFile
= module
.pch
->file
;
1781 const FileLocation
*pchFilename
= GetPrecompiledHeaderFilename ();
1782 CLEAN_FILE(pchFilename
);
1783 string dependencies
= strFile ( &baseHeaderFile
);
1784 /* WIDL generated headers may be used */
1785 vector
<FileLocation
> rpcDependencies
;
1786 GetRpcHeaderDependencies ( rpcDependencies
);
1787 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1788 fprintf ( fMakefile
,
1790 strFile ( pchFilename
).c_str(),
1791 dependencies
.c_str() );
1792 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1793 fprintf ( fMakefile
,
1794 "\t%s -o %s %s -g %s\n\n",
1795 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1796 strFile ( pchFilename
).c_str(),
1797 cflagsMacro
.c_str(),
1798 strFile ( &baseHeaderFile
).c_str() );
1801 GenerateObjectFileTargets ( module
.non_if_data
,
1808 fprintf ( fMakefile
, "\n" );
1812 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1813 const string
& objs_macro
) const
1815 const FileLocation
*archiveFilename
= GetModuleArchiveFilename ();
1817 fprintf ( fMakefile
,
1819 strFile ( archiveFilename
).c_str (),
1820 objs_macro
.c_str (),
1821 strDirectory ( archiveFilename
).c_str() );
1823 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
1825 const FileLocation
*definitionFilename ( GetDefinitionFilename () );
1827 fprintf ( fMakefile
,
1828 "\t${dlltool} --dllname %s --def %s --output-lib $@ %s %s\n",
1829 module
.importLibrary
->dllname
.c_str (),
1830 strFile ( definitionFilename
).c_str (),
1831 module
.mangledSymbols
? "" : "--kill-at",
1832 module
.underscoreSymbols
? "--add-underscore" : "" );
1835 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1837 fprintf ( fMakefile
,
1840 objs_macro
.c_str ());
1842 GenerateCleanObjectsAsYouGoCode ();
1844 fprintf ( fMakefile
, "\n" );
1846 return archiveFilename
;
1850 MingwModuleHandler::GetCFlagsMacro () const
1852 return ssprintf ( "$(%s_CFLAGS)",
1853 module
.name
.c_str () );
1857 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1859 return ssprintf ( "$(%s_OBJS)",
1860 module
.name
.c_str () );
1864 MingwModuleHandler::GetLinkingDependenciesMacro () const
1866 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1870 MingwModuleHandler::GetLibsMacro () const
1872 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1876 MingwModuleHandler::GetLinkerMacro () const
1878 return ssprintf ( "$(%s_LFLAGS)",
1879 module
.name
.c_str () );
1883 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1885 if ( ReferenceObjects ( module
) )
1886 return GetObjectsMacro ( module
);
1888 return strFile ( GetTargetFilename ( module
, NULL
) ).c_str ();
1892 MingwModuleHandler::GenerateObjectMacro ()
1894 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1896 GenerateObjectMacros (
1899 &module
.linkerFlags
);
1901 // future references to the macro will be to get its values
1902 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1906 MingwModuleHandler::GenerateTargetMacro ()
1908 fprintf ( fMakefile
,
1910 GetTargetMacro ( module
, false ).c_str (),
1911 GetModuleTargets ( module
).c_str () );
1915 MingwModuleHandler::GetRpcHeaderDependencies (
1916 vector
<FileLocation
>& dependencies
) const
1918 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1920 Library
& library
= *module
.non_if_data
.libraries
[i
];
1921 if ( library
.importedModule
->type
== RpcServer
||
1922 library
.importedModule
->type
== RpcClient
||
1923 library
.importedModule
->type
== IdlHeader
)
1925 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
1927 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
1928 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1929 string extension
= GetExtension ( sourceFile
->name
);
1930 if ( extension
== ".idl" || extension
== ".IDL" )
1932 string basename
= GetBasename ( sourceFile
->name
);
1933 if ( library
.importedModule
->type
== RpcServer
)
1934 dependencies
.push_back ( *GetRpcServerHeaderFilename ( sourceFile
) );
1935 if ( library
.importedModule
->type
== RpcClient
)
1936 dependencies
.push_back ( *GetRpcClientHeaderFilename ( sourceFile
) );
1937 if ( library
.importedModule
->type
== IdlHeader
)
1938 dependencies
.push_back ( *GetIdlHeaderFilename ( sourceFile
) );
1946 MingwModuleHandler::GenerateOtherMacros ()
1948 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1949 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1950 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1951 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1952 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1953 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1954 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1959 &module
.linkerFlags
);
1961 vector
<FileLocation
> s
;
1962 if ( module
.importLibrary
)
1964 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
1965 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
1967 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1968 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1969 string extension
= GetExtension ( sourceFile
->name
);
1970 if ( extension
== ".spec" || extension
== ".SPEC" )
1971 GetSpecObjectDependencies ( s
, sourceFile
);
1974 if ( s
.size () > 0 )
1979 linkDepsMacro
.c_str() );
1980 for ( size_t i
= 0; i
< s
.size(); i
++ )
1981 fprintf ( fMakefile
,
1983 strFile ( &s
[i
] ).c_str () );
1984 fprintf ( fMakefile
, "\n" );
1987 string globalCflags
= "-g";
1988 if ( backend
->usePipe
)
1989 globalCflags
+= " -pipe";
1990 if ( !module
.allowWarnings
)
1991 globalCflags
+= " -Werror";
1992 if ( module
.host
== HostTrue
)
1993 globalCflags
+= " $(HOST_CFLAGS)";
1995 // Always force disabling of sibling calls optimisation for GCC
1996 // (TODO: Move to version-specific once this bug is fixed in GCC)
1997 globalCflags
+= " -fno-optimize-sibling-calls";
2001 "%s += $(PROJECT_CFLAGS) %s\n",
2002 cflagsMacro
.c_str (),
2003 globalCflags
.c_str () );
2007 "%s += $(PROJECT_RCFLAGS)\n",
2008 windresflagsMacro
.c_str () );
2012 "%s += $(PROJECT_WIDLFLAGS) -I%s\n",
2013 widlflagsMacro
.c_str (),
2014 module
.GetBasePath ().c_str () );
2018 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
2019 module
.name
.c_str () );
2024 linkDepsMacro
.c_str (),
2025 libsMacro
.c_str () );
2027 string cflags
= TypeSpecificCFlags();
2028 if ( cflags
.size() > 0 )
2030 fprintf ( fMakefile
,
2032 cflagsMacro
.c_str (),
2036 string nasmflags
= TypeSpecificNasmFlags();
2037 if ( nasmflags
.size () > 0 )
2039 fprintf ( fMakefile
,
2041 nasmflagsMacro
.c_str (),
2042 nasmflags
.c_str () );
2045 string linkerflags
= TypeSpecificLinkerFlags();
2046 if ( linkerflags
.size() > 0 )
2048 fprintf ( fMakefile
,
2050 linkerflagsMacro
.c_str (),
2051 linkerflags
.c_str () );
2054 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
2056 fprintf ( fMakefile
,
2057 "%s += -Wno-main\n\n",
2058 cflagsMacro
.c_str () );
2061 fprintf ( fMakefile
, "\n\n" );
2063 // future references to the macros will be to get their values
2064 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
2065 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
2066 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
2070 MingwModuleHandler::GenerateRules ()
2072 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
2073 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
2074 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
2076 if ( module
.name
!= "zlib" ) /* Avoid make warning */
2078 FileLocation
proxyMakefile ( OutputDirectory
,
2079 module
.GetBasePath (),
2081 CLEAN_FILE ( &proxyMakefile
);
2084 string targetMacro
= GetTargetMacro ( module
);
2085 //CLEAN_FILE ( &targetMacro );
2086 CLEAN_FILE ( new FileLocation ( SourceDirectory
, "", targetMacro
) );
2088 // generate phony target for module name
2089 fprintf ( fMakefile
, ".PHONY: %s\n",
2090 module
.name
.c_str () );
2091 string dependencies
= GetTargetMacro ( module
);
2092 if ( module
.type
== Test
)
2093 dependencies
+= " $(REGTESTS_RUN_TARGET)";
2094 fprintf ( fMakefile
, "%s: %s\n\n",
2095 module
.name
.c_str (),
2096 dependencies
.c_str () );
2097 if ( module
.type
== Test
)
2099 fprintf ( fMakefile
,
2101 targetMacro
.c_str ());
2104 if ( !ReferenceObjects ( module
) )
2106 const FileLocation
* ar_target
= GenerateArchiveTarget ( ar
, objectsMacro
);
2107 CLEAN_FILE ( ar_target
);
2110 GenerateObjectFileTargets ( cc
,
2119 MingwModuleHandler::GetInvocationDependencies (
2120 const Module
& module
,
2121 string_list
& dependencies
)
2123 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
2125 Invoke
& invoke
= *module
.invocations
[i
];
2126 if ( invoke
.invokeModule
== &module
)
2127 /* Protect against circular dependencies */
2129 invoke
.GetTargets ( dependencies
);
2134 MingwModuleHandler::GenerateInvocations () const
2136 if ( module
.invocations
.size () == 0 )
2139 size_t iend
= module
.invocations
.size ();
2140 for ( size_t i
= 0; i
< iend
; i
++ )
2142 const Invoke
& invoke
= *module
.invocations
[i
];
2144 if ( invoke
.invokeModule
->type
!= BuildTool
)
2146 throw XMLInvalidBuildFileException (
2147 module
.node
.location
,
2148 "Only modules of type buildtool can be invoked." );
2151 string invokeTarget
= module
.GetInvocationTarget ( i
);
2152 string_list invoke_targets
;
2153 assert ( invoke_targets
.size() );
2154 invoke
.GetTargets ( invoke_targets
);
2155 fprintf ( fMakefile
,
2157 invokeTarget
.c_str () );
2158 fprintf ( fMakefile
,
2160 invokeTarget
.c_str () );
2161 size_t j
, jend
= invoke_targets
.size();
2162 for ( j
= 0; j
< jend
; j
++ )
2164 fprintf ( fMakefile
,
2166 invoke_targets
[i
].c_str () );
2168 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
2169 for ( j
= 1; j
< jend
; j
++ )
2170 fprintf ( fMakefile
,
2172 invoke_targets
[i
].c_str () );
2173 fprintf ( fMakefile
,
2175 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
2176 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
2177 fprintf ( fMakefile
,
2179 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
2180 invoke
.GetParameters ().c_str () );
2185 MingwModuleHandler::GetPreconditionDependenciesName () const
2187 return module
.name
+ "_precondition";
2191 MingwModuleHandler::GetDefaultDependencies (
2192 string_list
& dependencies
) const
2194 /* Avoid circular dependency */
2195 if ( module
.type
!= BuildTool
2196 && module
.name
!= "zlib"
2197 && module
.name
!= "hostzlib" )
2199 dependencies
.push_back ( "$(INIT)" );
2201 if ( module
.type
!= BuildTool
2202 && module
.name
!= "psdk" )
2204 dependencies
.push_back ( "$(PSDK_TARGET)" );
2208 MingwModuleHandler::GeneratePreconditionDependencies ()
2210 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2211 vector
<FileLocation
> sourceFilenames
;
2212 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
2213 string_list dependencies
;
2214 GetDefaultDependencies ( dependencies
);
2215 GetModuleDependencies ( dependencies
);
2217 GetInvocationDependencies ( module
, dependencies
);
2219 if ( dependencies
.size() )
2221 fprintf ( fMakefile
,
2223 preconditionDependenciesName
.c_str () );
2224 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2225 fprintf ( fMakefile
,
2227 dependencies
[i
].c_str () );
2228 fprintf ( fMakefile
, "\n\n" );
2231 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
2233 fprintf ( fMakefile
,
2235 strFile ( &sourceFilenames
[i
] ).c_str (),
2236 preconditionDependenciesName
.c_str ());
2238 fprintf ( fMakefile
, "\n" );
2242 MingwModuleHandler::IsWineModule () const
2244 if ( module
.importLibrary
== NULL
)
2247 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
2248 return ( index
!= string::npos
);
2252 MingwModuleHandler::GetDefinitionFilename () const
2254 if ( module
.importLibrary
!= NULL
)
2256 DirectoryLocation directory
;
2257 if ( IsWineModule () )
2258 directory
= IntermediateDirectory
;
2260 directory
= SourceDirectory
;
2262 size_t pos
= module
.importLibrary
->definition
.find_last_of ( "/\\" );
2263 if ( pos
== string::npos
)
2265 return new FileLocation ( directory
,
2266 module
.GetBasePath (),
2267 module
.importLibrary
->definition
);
2270 string dir
= module
.importLibrary
->definition
.substr ( 0, pos
);
2271 string name
= module
.importLibrary
->definition
.substr ( pos
+ 1);
2272 return new FileLocation ( directory
,
2273 NormalizeFilename ( module
.GetBasePath () + sSep
+ dir
),
2277 return new FileLocation ( SourceDirectory
, "tools" + sSep
+ "rbuild", "empty.def" );
2281 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2283 if ( module
.importLibrary
!= NULL
)
2285 const FileLocation
*library_target
= GetImportLibraryFilename ( module
, &clean_files
);
2286 const FileLocation
*defFilename
= GetDefinitionFilename ();
2288 vector
<FileLocation
> deps
;
2289 GetDefinitionDependencies ( deps
);
2291 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2293 fprintf ( fMakefile
, "%s: %s",
2294 strFile ( library_target
).c_str (),
2295 strFile ( defFilename
).c_str () );
2297 size_t i
, iend
= deps
.size();
2298 for ( i
= 0; i
< iend
; i
++ )
2299 fprintf ( fMakefile
, " %s",
2300 strFile ( &deps
[i
] ).c_str () );
2302 fprintf ( fMakefile
, " | %s\n",
2303 strDirectory ( GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2305 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2307 fprintf ( fMakefile
,
2308 "\t${dlltool} --dllname %s --def %s --output-lib %s %s %s\n\n",
2309 module
.GetTargetName ().c_str (),
2310 strFile ( defFilename
).c_str (),
2311 strFile ( library_target
).c_str (),
2312 module
.mangledSymbols
? "" : "--kill-at",
2313 module
.underscoreSymbols
? "--add-underscore" : "" );
2318 MingwModuleHandler::GetSpecObjectDependencies (
2319 vector
<FileLocation
>& dependencies
,
2320 const FileLocation
*file
) const
2322 string basename
= GetBasename ( file
->name
);
2324 FileLocation
defDependency ( IntermediateDirectory
,
2325 file
->relative_path
,
2326 basename
+ ".spec.def" );
2327 dependencies
.push_back ( defDependency
);
2329 FileLocation
stubsDependency ( IntermediateDirectory
,
2330 file
->relative_path
,
2331 basename
+ ".stubs.c" );
2332 dependencies
.push_back ( stubsDependency
);
2336 MingwModuleHandler::GetWidlObjectDependencies (
2337 vector
<FileLocation
>& dependencies
,
2338 const FileLocation
*file
) const
2340 string basename
= GetBasename ( file
->name
);
2342 FileLocation
serverSourceDependency ( IntermediateDirectory
,
2343 file
->relative_path
,
2344 basename
+ "_s.c" );
2345 dependencies
.push_back ( serverSourceDependency
);
2346 dependencies
.push_back ( *GetRpcServerHeaderFilename ( file
) );
2350 MingwModuleHandler::GetDefinitionDependencies (
2351 vector
<FileLocation
>& dependencies
) const
2353 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2354 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2356 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2357 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
2358 string extension
= GetExtension ( sourceFile
->name
);
2359 if ( extension
== ".spec" || extension
== ".SPEC" )
2360 GetSpecObjectDependencies ( dependencies
, sourceFile
);
2361 if ( extension
== ".idl" || extension
== ".IDL" )
2363 if ( ( module
.type
== RpcServer
) || ( module
.type
== RpcClient
) )
2364 GetWidlObjectDependencies ( dependencies
, sourceFile
);
2369 enum DebugSupportType
2376 MingwAddDebugSupportLibraries ( Module
& module
, DebugSupportType type
)
2382 case DebugKernelMode
:
2383 pLibrary
= new Library ( module
, "debugsup_ntoskrnl" );
2387 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2394 module
.non_if_data
.libraries
.push_back(pLibrary
);
2397 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2398 : MingwModuleHandler ( module_
)
2403 MingwBuildToolModuleHandler::Process ()
2405 GenerateBuildToolModuleTarget ();
2409 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2411 string
targetMacro ( GetTargetMacro (module
) );
2412 string objectsMacro
= GetObjectsMacro ( module
);
2413 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2414 string libsMacro
= GetLibsMacro ();
2419 if ( module
.cplusplus
)
2420 linker
= "${host_gpp}";
2422 linker
= "${host_gcc}";
2424 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2425 targetMacro
.c_str (),
2426 objectsMacro
.c_str (),
2427 linkDepsMacro
.c_str (),
2428 strDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2429 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2430 fprintf ( fMakefile
,
2431 "\t%s %s -o $@ %s %s\n\n",
2433 GetLinkerMacro ().c_str (),
2434 objectsMacro
.c_str (),
2435 libsMacro
.c_str () );
2439 MingwKernelModuleHandler::MingwKernelModuleHandler (
2440 const Module
& module_
)
2442 : MingwModuleHandler ( module_
)
2447 MingwKernelModuleHandler::Process ()
2449 GenerateKernelModuleTarget ();
2453 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2455 string
targetMacro ( GetTargetMacro ( module
) );
2456 string workingDirectory
= GetWorkingDirectory ( );
2457 string objectsMacro
= GetObjectsMacro ( module
);
2458 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2459 string libsMacro
= GetLibsMacro ();
2461 GenerateImportLibraryTargetIfNeeded ();
2463 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2467 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2469 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",
2470 module
.GetBasePath ().c_str (),
2472 module
.GetEntryPoint(true).c_str (),
2473 module
.baseaddress
.c_str () );
2474 GenerateLinkerCommand ( dependencies
,
2483 GeneratePhonyTarget();
2488 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2489 const Module
& module_
)
2491 : MingwModuleHandler ( module_
)
2496 MingwStaticLibraryModuleHandler::Process ()
2498 GenerateStaticLibraryModuleTarget ();
2502 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2508 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2509 const Module
& module_
)
2511 : MingwModuleHandler ( module_
)
2516 MingwObjectLibraryModuleHandler::Process ()
2518 GenerateObjectLibraryModuleTarget ();
2522 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2528 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2529 const Module
& module_
)
2531 : MingwModuleHandler ( module_
)
2535 MingwEmbeddedTypeLibModuleHandler::MingwEmbeddedTypeLibModuleHandler (
2536 const Module
& module_
)
2538 : MingwModuleHandler ( module_
)
2543 MingwEmbeddedTypeLibModuleHandler::Process ()
2550 MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2552 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2556 MingwKernelModeDLLModuleHandler::Process ()
2558 GenerateKernelModeDLLModuleTarget ();
2562 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2564 string
targetMacro ( GetTargetMacro ( module
) );
2565 string workingDirectory
= GetWorkingDirectory ( );
2566 string objectsMacro
= GetObjectsMacro ( module
);
2567 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2568 string libsMacro
= GetLibsMacro ();
2570 GenerateImportLibraryTargetIfNeeded ();
2572 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2576 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2578 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2579 module
.GetEntryPoint(true).c_str (),
2580 module
.baseaddress
.c_str () );
2581 GenerateLinkerCommand ( dependencies
,
2590 GeneratePhonyTarget();
2595 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2596 const Module
& module_
)
2598 : MingwModuleHandler ( module_
)
2603 MingwKernelModeDriverModuleHandler::AddImplicitLibraries ( Module
& module
)
2605 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2609 MingwKernelModeDriverModuleHandler::Process ()
2611 GenerateKernelModeDriverModuleTarget ();
2616 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2618 string
targetMacro ( GetTargetMacro (module
) );
2619 string workingDirectory
= GetWorkingDirectory ();
2620 string objectsMacro
= GetObjectsMacro ( module
);
2621 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2622 string libsMacro
= GetLibsMacro ();
2624 GenerateImportLibraryTargetIfNeeded ();
2626 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2630 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2632 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2633 module
.GetEntryPoint(true).c_str (),
2634 module
.baseaddress
.c_str () );
2635 GenerateLinkerCommand ( dependencies
,
2644 GeneratePhonyTarget();
2649 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2650 const Module
& module_
)
2652 : MingwModuleHandler ( module_
)
2657 MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2659 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2663 MingwNativeDLLModuleHandler::Process ()
2665 GenerateNativeDLLModuleTarget ();
2669 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2671 string
targetMacro ( GetTargetMacro (module
) );
2672 string workingDirectory
= GetWorkingDirectory ( );
2673 string objectsMacro
= GetObjectsMacro ( module
);
2674 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2675 string libsMacro
= GetLibsMacro ();
2677 GenerateImportLibraryTargetIfNeeded ();
2679 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2683 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2685 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2686 module
.GetEntryPoint(true).c_str (),
2687 module
.baseaddress
.c_str () );
2688 GenerateLinkerCommand ( dependencies
,
2697 GeneratePhonyTarget();
2702 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2703 const Module
& module_
)
2705 : MingwModuleHandler ( module_
)
2710 MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2712 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2716 MingwNativeCUIModuleHandler::Process ()
2718 GenerateNativeCUIModuleTarget ();
2722 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2724 string
targetMacro ( GetTargetMacro (module
) );
2725 string workingDirectory
= GetWorkingDirectory ( );
2726 string objectsMacro
= GetObjectsMacro ( module
);
2727 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2728 string libsMacro
= GetLibsMacro ();
2730 GenerateImportLibraryTargetIfNeeded ();
2732 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2736 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2738 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2739 module
.GetEntryPoint(true).c_str (),
2740 module
.baseaddress
.c_str () );
2741 GenerateLinkerCommand ( dependencies
,
2750 GeneratePhonyTarget();
2755 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2756 const Module
& module_
)
2758 : MingwModuleHandler ( module_
)
2762 MingwWin32OCXModuleHandler::MingwWin32OCXModuleHandler (
2763 const Module
& module_
)
2765 : MingwModuleHandler ( module_
)
2770 MingwAddImplicitLibraries( Module
&module
)
2774 if ( !module
.isDefaultEntryPoint
)
2776 if ( module
.GetEntryPoint(false) == "0" )
2778 pLibrary
= new Library ( module
, "mingw_common" );
2779 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() , pLibrary
);
2780 pLibrary
= new Library ( module
, "msvcrt" );
2781 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2786 if ( module
.IsDLL () )
2788 //pLibrary = new Library ( module, "__mingw_dllmain" );
2789 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
2793 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
2794 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
2797 pLibrary
= new Library ( module
, "mingw_common" );
2798 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
2800 if ( module
.name
!= "msvcrt" )
2802 // always link in msvcrt to get the basic routines
2803 pLibrary
= new Library ( module
, "msvcrt" );
2804 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2809 MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2811 MingwAddImplicitLibraries ( module
);
2812 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2816 MingwWin32DLLModuleHandler::Process ()
2818 GenerateWin32DLLModuleTarget ();
2822 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2824 string
targetMacro ( GetTargetMacro (module
) );
2825 string workingDirectory
= GetWorkingDirectory ( );
2826 string objectsMacro
= GetObjectsMacro ( module
);
2827 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2828 string libsMacro
= GetLibsMacro ();
2830 GenerateImportLibraryTargetIfNeeded ();
2832 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2836 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2839 if ( module
.cplusplus
)
2844 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2845 module
.GetEntryPoint(true).c_str (),
2846 module
.baseaddress
.c_str () );
2847 GenerateLinkerCommand ( dependencies
,
2856 GeneratePhonyTarget();
2862 MingwWin32OCXModuleHandler::AddImplicitLibraries ( Module
& module
)
2864 MingwAddImplicitLibraries ( module
);
2865 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2869 MingwWin32OCXModuleHandler::Process ()
2871 GenerateWin32OCXModuleTarget ();
2875 MingwWin32OCXModuleHandler::GenerateWin32OCXModuleTarget ()
2877 string
targetMacro ( GetTargetMacro (module
) );
2878 string workingDirectory
= GetWorkingDirectory ( );
2879 string objectsMacro
= GetObjectsMacro ( module
);
2880 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2881 string libsMacro
= GetLibsMacro ();
2883 GenerateImportLibraryTargetIfNeeded ();
2885 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2889 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2892 if ( module
.cplusplus
)
2897 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2898 module
.GetEntryPoint(true).c_str (),
2899 module
.baseaddress
.c_str () );
2900 GenerateLinkerCommand ( dependencies
,
2909 GeneratePhonyTarget();
2914 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2915 const Module
& module_
)
2917 : MingwModuleHandler ( module_
)
2922 MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2924 MingwAddImplicitLibraries ( module
);
2925 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2929 MingwWin32CUIModuleHandler::Process ()
2931 GenerateWin32CUIModuleTarget ();
2935 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2937 string
targetMacro ( GetTargetMacro (module
) );
2938 string workingDirectory
= GetWorkingDirectory ( );
2939 string objectsMacro
= GetObjectsMacro ( module
);
2940 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2941 string libsMacro
= GetLibsMacro ();
2943 GenerateImportLibraryTargetIfNeeded ();
2945 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2949 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2952 if ( module
.cplusplus
)
2957 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2958 module
.GetEntryPoint(true).c_str (),
2959 module
.baseaddress
.c_str () );
2960 GenerateLinkerCommand ( dependencies
,
2969 GeneratePhonyTarget();
2974 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2975 const Module
& module_
)
2977 : MingwModuleHandler ( module_
)
2982 MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2984 MingwAddImplicitLibraries ( module
);
2985 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2989 MingwWin32GUIModuleHandler::Process ()
2991 GenerateWin32GUIModuleTarget ();
2995 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2997 string
targetMacro ( GetTargetMacro (module
) );
2998 string workingDirectory
= GetWorkingDirectory ( );
2999 string objectsMacro
= GetObjectsMacro ( module
);
3000 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3001 string libsMacro
= GetLibsMacro ();
3003 GenerateImportLibraryTargetIfNeeded ();
3005 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3009 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3012 if ( module
.cplusplus
)
3017 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3018 module
.GetEntryPoint(true).c_str (),
3019 module
.baseaddress
.c_str () );
3020 GenerateLinkerCommand ( dependencies
,
3029 GeneratePhonyTarget();
3034 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
3035 const Module
& module_
)
3037 : MingwModuleHandler ( module_
)
3042 MingwBootLoaderModuleHandler::Process ()
3044 GenerateBootLoaderModuleTarget ();
3048 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
3050 string
targetName ( module
.GetTargetName () );
3051 string
targetMacro ( GetTargetMacro (module
) );
3052 string workingDirectory
= GetWorkingDirectory ();
3053 FileLocation
junk_tmp ( TemporaryDirectory
,
3055 module
.name
+ ".junk.tmp" );
3056 CLEAN_FILE ( &junk_tmp
);
3057 string objectsMacro
= GetObjectsMacro ( module
);
3058 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3059 string libsMacro
= GetLibsMacro ();
3063 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3064 targetMacro
.c_str (),
3065 objectsMacro
.c_str (),
3066 linkDepsMacro
.c_str (),
3067 strDirectory(GetTargetFilename(module
,NULL
)).c_str () );
3069 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
3071 fprintf ( fMakefile
,
3072 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
3073 GetLinkerMacro ().c_str (),
3074 strFile ( &junk_tmp
).c_str (),
3075 objectsMacro
.c_str (),
3076 linkDepsMacro
.c_str () );
3077 fprintf ( fMakefile
,
3078 "\t${objcopy} -O binary %s $@\n",
3079 strFile ( &junk_tmp
).c_str () );
3080 GenerateBuildMapCode ( &junk_tmp
);
3081 fprintf ( fMakefile
,
3082 "\t-@${rm} %s 2>$(NUL)\n",
3083 strFile ( &junk_tmp
).c_str () );
3087 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
3088 const Module
& module_
)
3090 : MingwModuleHandler ( module_
)
3095 MingwBootSectorModuleHandler::Process ()
3097 GenerateBootSectorModuleTarget ();
3101 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
3103 string objectsMacro
= GetObjectsMacro ( module
);
3107 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3108 module
.name
.c_str ());
3109 fprintf ( fMakefile
,
3111 module
.name
.c_str (),
3112 objectsMacro
.c_str () );
3116 MingwBootProgramModuleHandler::MingwBootProgramModuleHandler (
3117 const Module
& module_
)
3118 : MingwModuleHandler ( module_
)
3123 MingwBootProgramModuleHandler::Process ()
3125 GenerateBootProgramModuleTarget ();
3129 MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
3131 string
targetName ( module
.GetTargetName () );
3132 string
targetMacro ( GetTargetMacro (module
) );
3133 string workingDirectory
= GetWorkingDirectory ();
3134 FileLocation
junk_tmp ( TemporaryDirectory
,
3136 module
.name
+ ".junk.tmp" );
3137 FileLocation
junk_elf ( TemporaryDirectory
,
3139 module
.name
+ ".junk.elf" );
3140 FileLocation
junk_cpy ( TemporaryDirectory
,
3142 module
.name
+ ".junk.elf" );
3143 CLEAN_FILE ( &junk_tmp
);
3144 CLEAN_FILE ( &junk_elf
);
3145 CLEAN_FILE ( &junk_cpy
);
3146 string objectsMacro
= GetObjectsMacro ( module
);
3147 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3148 string libsMacro
= GetLibsMacro ();
3149 const Module
*payload
= module
.project
.LocateModule ( module
.payload
);
3153 fprintf ( fMakefile
, "%s: %s %s %s | %s\n",
3154 targetMacro
.c_str (),
3155 objectsMacro
.c_str (),
3156 linkDepsMacro
.c_str (),
3157 payload
->name
.c_str (),
3158 strDirectory(GetTargetFilename(module
,NULL
)).c_str () );
3160 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3162 fprintf ( fMakefile
, "\t$(%s_PREPARE) $(OUTPUT)$(SEP)%s %s\n",
3163 module
.buildtype
.c_str (),
3164 NormalizeFilename( payload
->GetPath() ).c_str (),
3165 strFile ( &junk_cpy
).c_str () );
3167 fprintf ( fMakefile
, "\t${objcopy} $(%s_FLATFORMAT) %s %s\n",
3168 module
.buildtype
.c_str (),
3169 strFile ( &junk_cpy
).c_str (),
3170 strFile ( &junk_tmp
).c_str () );
3172 fprintf ( fMakefile
, "\t${ld} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3173 module
.buildtype
.c_str (),
3174 linkDepsMacro
.c_str (),
3175 strFile ( &junk_tmp
).c_str (),
3176 strFile ( &junk_elf
).c_str () );
3178 fprintf ( fMakefile
, "\t${objcopy} $(%s_COPYFORMAT) %s $(INTERMEDIATE)$(SEP)%s\n",
3179 module
.buildtype
.c_str (),
3180 strFile ( &junk_elf
).c_str (),
3181 module
.GetPath().c_str () );
3183 fprintf ( fMakefile
,
3184 "\t-@${rm} %s %s %s 2>$(NUL)\n",
3185 strFile ( &junk_tmp
).c_str (), strFile ( &junk_elf
).c_str (), strFile ( &junk_cpy
).c_str () );
3189 MingwIsoModuleHandler::MingwIsoModuleHandler (
3190 const Module
& module_
)
3192 : MingwModuleHandler ( module_
)
3197 MingwIsoModuleHandler::Process ()
3199 GenerateIsoModuleTarget ();
3203 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
3204 const string
& bootcdDirectory
)
3206 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3208 const Module
& m
= *module
.project
.modules
[i
];
3211 if ( m
.bootstrap
!= NULL
)
3213 FileLocation
sourceFile ( OutputDirectory
,
3215 m
.GetTargetName () );
3216 FileLocation
targetFile ( OutputDirectory
,
3217 bootcdDirectory
+ sSep
+ m
.bootstrap
->base
,
3218 m
.bootstrap
->nameoncd
);
3219 OutputCopyCommand ( sourceFile
, targetFile
);
3225 MingwIsoModuleHandler::OutputCdfileCopyCommands (
3226 const string
& bootcdDirectory
)
3228 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3230 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3231 FileLocation
targetFile ( OutputDirectory
,
3232 cdfile
.target
->relative_path
.length () > 0
3233 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3235 cdfile
.target
->name
);
3236 OutputCopyCommand ( *cdfile
.source
, targetFile
);
3241 MingwIsoModuleHandler::GetBootstrapCdDirectories ( vector
<FileLocation
>& out
,
3242 const string
& bootcdDirectory
)
3244 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3246 const Module
& m
= *module
.project
.modules
[i
];
3249 if ( m
.bootstrap
!= NULL
)
3251 FileLocation
targetDirectory ( OutputDirectory
,
3252 bootcdDirectory
+ sSep
+ m
.bootstrap
->base
,
3254 out
.push_back ( targetDirectory
);
3260 MingwIsoModuleHandler::GetNonModuleCdDirectories ( vector
<FileLocation
>& out
,
3261 const string
& bootcdDirectory
)
3263 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3265 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3266 FileLocation
targetDirectory ( OutputDirectory
,
3267 cdfile
.target
->relative_path
.length () > 0
3268 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3271 out
.push_back( targetDirectory
);
3276 MingwIsoModuleHandler::GetCdDirectories ( vector
<FileLocation
>& out
,
3277 const string
& bootcdDirectory
)
3279 GetBootstrapCdDirectories ( out
, bootcdDirectory
);
3280 GetNonModuleCdDirectories ( out
, bootcdDirectory
);
3284 MingwIsoModuleHandler::GetBootstrapCdFiles (
3285 vector
<FileLocation
>& out
) const
3287 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3289 const Module
& m
= *module
.project
.modules
[i
];
3292 if ( m
.bootstrap
!= NULL
)
3294 FileLocation
file ( OutputDirectory
,
3296 m
.GetTargetName () );
3297 out
.push_back ( file
);
3303 MingwIsoModuleHandler::GetNonModuleCdFiles (
3304 vector
<FileLocation
>& out
) const
3306 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3308 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3309 out
.push_back ( *cdfile
.source
);
3314 MingwIsoModuleHandler::GetCdFiles (
3315 vector
<FileLocation
>& out
) const
3317 GetBootstrapCdFiles ( out
);
3318 GetNonModuleCdFiles ( out
);
3322 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
3324 string bootcdDirectory
= "cd";
3325 FileLocation
bootcd ( OutputDirectory
,
3328 FileLocation
bootcdReactos ( OutputDirectory
,
3329 bootcdDirectory
+ sSep
+ Environment::GetCdOutputPath (),
3331 vector
<FileLocation
> vSourceFiles
, vCdFiles
;
3332 vector
<FileLocation
> vCdDirectories
;
3335 FileLocation
srcunattend ( SourceDirectory
,
3336 "boot" + sSep
+ "bootdata" + sSep
+ "bootcdregtest",
3338 FileLocation
tarunattend ( bootcdReactos
.directory
,
3339 bootcdReactos
.relative_path
,
3341 if (module
.type
== IsoRegTest
)
3342 vSourceFiles
.push_back ( srcunattend
);
3345 FileLocation
isoboot ( OutputDirectory
,
3346 "boot" + sSep
+ "freeldr" + sSep
+ "bootsect",
3347 module
.type
== IsoRegTest
3350 vSourceFiles
.push_back ( isoboot
);
3352 // prepare reactos.dff and reactos.inf
3353 FileLocation
reactosDff ( SourceDirectory
,
3354 "boot" + sSep
+ "bootdata" + sSep
+ "packages",
3356 FileLocation
reactosInf ( TemporaryDirectory
,
3359 vSourceFiles
.push_back ( reactosDff
);
3363 if (module
.type
== IsoRegTest
)
3364 IsoName
= "ReactOS-RegTest.iso";
3366 IsoName
= "ReactOS.iso";
3369 string sourceFiles
= v2s ( vSourceFiles
, 5 );
3372 GetCdDirectories ( vCdDirectories
, bootcdDirectory
);
3373 GetCdFiles ( vCdFiles
);
3374 string cdDirectories
= v2s ( vCdDirectories
, 5 );
3375 string cdFiles
= v2s ( vCdFiles
, 5 );
3377 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3378 module
.name
.c_str ());
3379 fprintf ( fMakefile
,
3380 "%s: all %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET) | %s\n",
3381 module
.name
.c_str (),
3382 strFile ( &isoboot
).c_str (),
3383 sourceFiles
.c_str (),
3385 cdDirectories
.c_str () );
3386 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
3387 fprintf ( fMakefile
,
3388 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
3389 strFile ( &reactosDff
).c_str (),
3390 strDirectory ( &bootcdReactos
).c_str () );
3391 fprintf ( fMakefile
,
3392 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
3393 strFile ( &reactosDff
).c_str (),
3394 strFile ( &reactosInf
).c_str (),
3395 strDirectory ( &bootcdReactos
).c_str ());
3396 fprintf ( fMakefile
,
3397 "\t-@${rm} %s 2>$(NUL)\n",
3398 strFile ( &reactosInf
).c_str () );
3399 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
3400 OutputCdfileCopyCommands ( bootcdDirectory
);
3402 if (module
.type
== IsoRegTest
)
3403 OutputCopyCommand ( srcunattend
, tarunattend
);
3405 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3406 fprintf ( fMakefile
,
3407 "\t$(Q)$(CDMAKE_TARGET) -v -j -m -b %s %s REACTOS %s\n",
3408 strFile ( &isoboot
).c_str (),
3409 strDirectory ( &bootcd
).c_str (),
3411 fprintf ( fMakefile
,
3416 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
3417 const Module
& module_
)
3419 : MingwModuleHandler ( module_
)
3424 MingwLiveIsoModuleHandler::Process ()
3426 GenerateLiveIsoModuleTarget ();
3430 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
3432 FileLocation
dir ( OutputDirectory
,
3435 MingwModuleHandler::PassThruCacheDirectory ( &dir
);
3439 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
3440 string
& reactosDirectory
)
3442 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3444 const Module
& m
= *module
.project
.modules
[i
];
3447 if ( m
.installName
.length () > 0 )
3449 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
3450 FileLocation
source ( OutputDirectory
,
3451 aliasedModule
.GetBasePath (),
3452 aliasedModule
.GetTargetName () );
3453 FileLocation
destination ( OutputDirectory
,
3454 m
.installBase
.length () > 0
3455 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.installBase
3456 : livecdDirectory
+ sSep
+ reactosDirectory
,
3458 OutputCopyCommand ( source
,
3465 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
3466 string
& reactosDirectory
)
3468 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
3470 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
3471 FileLocation
target ( OutputDirectory
,
3472 installfile
.target
->relative_path
.length () > 0
3473 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.target
->relative_path
3474 : livecdDirectory
+ sSep
+ reactosDirectory
,
3475 installfile
.target
->name
);
3476 OutputCopyCommand ( *installfile
.source
, target
);
3481 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
3483 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
3484 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
3485 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
3486 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
3487 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
3488 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
3490 FileLocation
livecdIni ( SourceDirectory
,
3491 "boot" + sSep
+ "bootdata",
3493 FileLocation
destination ( OutputDirectory
,
3496 OutputCopyCommand ( livecdIni
,
3501 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3503 FileLocation
freeldr ( OutputDirectory
,
3504 "boot" + sSep
+ "freeldr" + sSep
+ "freeldr",
3506 FileLocation
destination ( OutputDirectory
,
3507 livecdDirectory
+ sSep
+ "loader",
3509 OutputCopyCommand ( freeldr
,
3514 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3516 FileLocation
reactosSystem32ConfigDirectory ( OutputDirectory
,
3517 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config",
3519 fprintf ( fMakefile
,
3520 "\t$(ECHO_MKHIVE)\n" );
3521 fprintf ( fMakefile
,
3522 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%clivecd.inf boot%cbootdata%chiveinst.inf\n",
3523 cSep
, strDirectory ( &reactosSystem32ConfigDirectory
).c_str (),
3524 cSep
, cSep
, cSep
, cSep
);
3528 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
3530 string livecdDirectory
= module
.name
;
3531 FileLocation
livecd ( OutputDirectory
, livecdDirectory
, "" );
3536 if (module
.name
== "livecdregtest")
3538 bootloader
= "isobtrt.o";
3539 IsoName
= "ReactOS-LiveCD-RegTest.iso";
3543 bootloader
= "isoboot.o";
3544 IsoName
= "ReactOS-LiveCD.iso";
3547 FileLocation
isoboot ( OutputDirectory
, "boot" + sSep
+ "freeldr" + sSep
+ "bootsect", bootloader
);
3549 string reactosDirectory
= "reactos";
3550 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3551 FileLocation
livecdReactos ( OutputDirectory
,
3552 livecdReactosNoFixup
,
3554 CLEAN_FILE ( &livecdReactos
);
3556 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3557 module
.name
.c_str ());
3558 fprintf ( fMakefile
,
3559 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3560 module
.name
.c_str (),
3561 strFile ( &isoboot
) .c_str (),
3562 strDirectory ( &livecdReactos
).c_str () );
3563 OutputModuleCopyCommands ( livecdDirectory
,
3565 OutputNonModuleCopyCommands ( livecdDirectory
,
3567 OutputProfilesDirectoryCommands ( livecdDirectory
);
3568 OutputLoaderCommands ( livecdDirectory
);
3569 OutputRegistryCommands ( livecdDirectory
);
3570 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3571 fprintf ( fMakefile
,
3572 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS %s\n",
3573 strFile( &isoboot
).c_str (),
3574 strDirectory ( &livecd
).c_str (),
3576 fprintf ( fMakefile
,
3581 MingwTestModuleHandler::MingwTestModuleHandler (
3582 const Module
& module_
)
3584 : MingwModuleHandler ( module_
)
3589 MingwTestModuleHandler::Process ()
3591 GenerateTestModuleTarget ();
3595 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
3597 string basePath
= "$(INTERMEDIATE)" + sSep
+ module
.GetBasePath ();
3598 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_hooks.c", false, "", false ) ) );
3599 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_stubs.S", false, "", false ) ) );
3600 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_startup.c", false, "", false ) ) );
3604 MingwTestModuleHandler::GenerateTestModuleTarget ()
3606 string
targetMacro ( GetTargetMacro ( module
) );
3607 string workingDirectory
= GetWorkingDirectory ( );
3608 string objectsMacro
= GetObjectsMacro ( module
);
3609 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3610 string libsMacro
= GetLibsMacro ();
3612 GenerateImportLibraryTargetIfNeeded ();
3614 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3618 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3621 if ( module
.cplusplus
)
3626 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3627 module
.GetEntryPoint(true).c_str (),
3628 module
.baseaddress
.c_str () );
3629 GenerateLinkerCommand ( dependencies
,
3638 GeneratePhonyTarget();
3643 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3644 const Module
& module_
)
3646 : MingwModuleHandler ( module_
)
3651 MingwRpcServerModuleHandler::Process ()
3657 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3658 const Module
& module_
)
3660 : MingwModuleHandler ( module_
)
3665 MingwRpcClientModuleHandler::Process ()
3671 MingwAliasModuleHandler::MingwAliasModuleHandler (
3672 const Module
& module_
)
3674 : MingwModuleHandler ( module_
)
3679 MingwAliasModuleHandler::Process ()
3683 MingwIdlHeaderModuleHandler::MingwIdlHeaderModuleHandler (
3684 const Module
& module_
)
3686 : MingwModuleHandler ( module_
)
3691 MingwIdlHeaderModuleHandler::Process ()
3696 MingwElfExecutableModuleHandler::MingwElfExecutableModuleHandler (
3697 const Module
& module_
)
3699 : MingwModuleHandler ( module_
)
3704 MingwElfExecutableModuleHandler::Process ()
3706 string
targetName ( module
.GetTargetName () );
3707 string
targetMacro ( GetTargetMacro (module
) );
3708 string workingDirectory
= GetWorkingDirectory ();
3709 string objectsMacro
= GetObjectsMacro ( module
);
3710 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3711 string libsMacro
= GetLibsMacro ();
3715 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3716 targetMacro
.c_str (),
3717 objectsMacro
.c_str (),
3718 linkDepsMacro
.c_str (),
3719 strDirectory(GetTargetFilename(module
,NULL
)).c_str () );
3721 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3723 fprintf ( fMakefile
, "\t${ld} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3724 module
.buildtype
.c_str(),
3725 objectsMacro
.c_str(),
3727 targetMacro
.c_str () );