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 handler
= new MingwKernelModeDriverModuleHandler ( module
);
232 handler
= new MingwBootLoaderModuleHandler ( module
);
235 handler
= new MingwBootSectorModuleHandler ( module
);
238 handler
= new MingwBootProgramModuleHandler ( module
);
241 handler
= new MingwIsoModuleHandler ( module
);
244 handler
= new MingwLiveIsoModuleHandler ( module
);
247 handler
= new MingwIsoModuleHandler ( module
);
250 handler
= new MingwLiveIsoModuleHandler ( module
);
253 handler
= new MingwTestModuleHandler ( module
);
256 handler
= new MingwRpcServerModuleHandler ( module
);
259 handler
= new MingwRpcClientModuleHandler ( module
);
262 handler
= new MingwAliasModuleHandler ( module
);
265 handler
= new MingwIdlHeaderModuleHandler ( module
);
267 case EmbeddedTypeLib
:
268 handler
= new MingwEmbeddedTypeLibModuleHandler ( module
);
271 handler
= new MingwElfExecutableModuleHandler ( module
);
274 throw UnknownModuleTypeException (
275 module
.node
.location
,
283 MingwModuleHandler::GetWorkingDirectory () const
289 MingwModuleHandler::GetBasename ( const string
& filename
) const
291 size_t index
= filename
.find_last_of ( '.' );
292 if ( index
!= string::npos
)
293 return filename
.substr ( 0, index
);
298 MingwModuleHandler::GetActualSourceFilename (
299 const FileLocation
* fileLocation
) const
301 string filename
= fileLocation
->filename
;
302 string extension
= GetExtension ( filename
);
303 if ( extension
== ".spec" || extension
== ".SPEC" )
305 string basename
= GetBasename ( filename
);
306 PassThruCacheDirectory ( NormalizeFilename ( basename
+ ".stubs.c" ),
307 backend
->intermediateDirectory
);
308 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( basename
+ ".stubs.c" ) );
310 else if ( extension
== ".idl" || extension
== ".IDL" )
312 string basename
= GetBasename ( filename
);
314 if ( module
.type
== RpcServer
)
316 newname
= basename
+ "_s.c";
317 PassThruCacheDirectory ( NormalizeFilename ( newname
),
318 backend
->intermediateDirectory
);
319 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( newname
) );
321 else if ( module
.type
== RpcClient
)
323 newname
= basename
+ "_c.c";
324 PassThruCacheDirectory ( NormalizeFilename ( newname
),
325 backend
->intermediateDirectory
);
326 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( newname
) );
328 else if ( module
.type
== IdlHeader
)
330 newname
= basename
+ ".h";
331 PassThruCacheDirectory ( NormalizeFilename ( newname
),
332 backend
->intermediateDirectory
);
333 return new FileLocation ( fileLocation
->directory
, filename
);
337 return new FileLocation ( fileLocation
->directory
, filename
);
341 return new FileLocation ( fileLocation
->directory
, filename
);
345 MingwModuleHandler::GetExtraDependencies (
346 const string
& filename
) const
348 string extension
= GetExtension ( filename
);
349 if ( extension
== ".idl" || extension
== ".IDL" )
351 string basename
= GetBasename ( filename
);
352 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
353 return GetRpcServerHeaderFilename ( basename
) + " " + GetRpcClientHeaderFilename ( basename
);
354 else if ( module
.type
== IdlHeader
)
355 return GetIdlHeaderFilename ( basename
);
364 MingwModuleHandler::GetCompilationUnitDependencies (
365 const CompilationUnit
& compilationUnit
) const
367 if ( compilationUnit
.files
.size () <= 1 )
369 vector
<string
> sourceFiles
;
370 for ( size_t i
= 0; i
< compilationUnit
.files
.size (); i
++ )
372 File
& file
= *compilationUnit
.files
[i
];
373 sourceFiles
.push_back ( NormalizeFilename ( file
.name
) );
375 return v2s ( sourceFiles
, 10 );
379 MingwModuleHandler::GetModuleArchiveFilename () const
381 if ( module
.type
== StaticLibrary
)
382 return GetTargetFilename ( module
, NULL
);
383 return PassThruCacheDirectory ( ReplaceExtension (
384 NormalizeFilename ( module
.GetPath () ),
386 backend
->intermediateDirectory
);
390 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
392 string extension
= GetExtension ( file
.name
);
393 return ( extension
== ".spec" || extension
== ".SPEC" );
397 MingwModuleHandler::ReferenceObjects (
398 const Module
& module
)
400 if ( module
.type
== ObjectLibrary
)
402 if ( module
.type
== RpcServer
)
404 if ( module
.type
== RpcClient
)
406 if ( module
.type
== IdlHeader
)
412 MingwModuleHandler::GetImportLibraryDependency (
413 const Module
& importedModule
)
416 if ( ReferenceObjects ( importedModule
) )
417 dep
= GetTargetMacro ( importedModule
);
419 dep
= GetImportLibraryFilename ( importedModule
, NULL
);
424 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
425 string_list
& targets
)
427 if ( dependencyModule
.invocations
.size () > 0 )
429 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
431 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
432 invoke
.GetTargets ( targets
);
436 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
440 MingwModuleHandler::GetModuleDependencies (
441 string_list
& dependencies
)
443 size_t iend
= module
.dependencies
.size ();
448 for ( size_t i
= 0; i
< iend
; i
++ )
450 const Dependency
& dependency
= *module
.dependencies
[i
];
451 const Module
& dependencyModule
= *dependency
.dependencyModule
;
452 GetTargets ( dependencyModule
,
455 GetDefinitionDependencies ( dependencies
);
459 MingwModuleHandler::GetSourceFilenames ( string_list
& list
,
460 bool includeGeneratedFiles
) const
464 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
465 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
467 if ( includeGeneratedFiles
|| !compilationUnits
[i
]->IsGeneratedFile () )
469 FileLocation
* sourceFileLocation
= GetActualSourceFilename (
470 compilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
) );
471 list
.push_back ( PassThruCacheDirectory ( sourceFileLocation
->filename
,
472 sourceFileLocation
->directory
) );
475 // intentionally make a copy so that we can append more work in
476 // the middle of processing without having to go recursive
477 vector
<If
*> v
= module
.non_if_data
.ifs
;
478 for ( i
= 0; i
< v
.size (); i
++ )
482 // check for sub-ifs to add to list
483 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
484 for ( j
= 0; j
< ifs
.size (); j
++ )
485 v
.push_back ( ifs
[j
] );
486 const vector
<CompilationUnit
*>& compilationUnits
= rIf
.data
.compilationUnits
;
487 for ( j
= 0; j
< compilationUnits
.size (); j
++ )
489 CompilationUnit
& compilationUnit
= *compilationUnits
[j
];
490 if ( includeGeneratedFiles
|| !compilationUnit
.IsGeneratedFile () )
492 FileLocation
* sourceFileLocation
= GetActualSourceFilename (
493 compilationUnit
.GetFilename ( backend
->intermediateDirectory
) );
494 list
.push_back ( PassThruCacheDirectory ( sourceFileLocation
->filename
,
495 sourceFileLocation
->directory
) );
502 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
503 string_list
& list
) const
505 GetSourceFilenames ( list
, false );
509 MingwModuleHandler::GetObjectFilename (
510 const FileLocation
* sourceFileLocation
,
511 string_list
* pclean_files
) const
513 string sourceFilename
= sourceFileLocation
->filename
;
514 Directory
* directoryTree
;
516 string extension
= GetExtension ( sourceFilename
);
517 if ( extension
== ".rc" || extension
== ".RC" )
518 newExtension
= ".coff";
519 else if ( extension
== ".spec" || extension
== ".SPEC" )
520 newExtension
= ".stubs.o";
521 else if ( extension
== ".idl" || extension
== ".IDL" )
523 if ( module
.type
== RpcServer
)
524 newExtension
= "_s.o";
525 else if ( module
.type
== RpcClient
)
526 newExtension
= "_c.o";
533 if ( module
.type
== BootSector
)
534 directoryTree
= backend
->outputDirectory
;
536 directoryTree
= backend
->intermediateDirectory
;
538 string obj_file
= PassThruCacheDirectory (
539 NormalizeFilename ( ReplaceExtension (
540 RemoveVariables ( sourceFilename
),
546 string_list
& clean_files
= *pclean_files
;
547 CLEAN_FILE ( obj_file
);
553 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
555 return module
.name
+ "_clean";
559 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
561 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
563 Library
& library
= *module
.non_if_data
.libraries
[i
];
564 if ( library
.importedModule
->type
== ObjectLibrary
)
565 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
570 MingwModuleHandler::GenerateCleanTarget () const
572 if ( module
.type
== Alias
)
576 ".PHONY: %s_clean\n",
577 module
.name
.c_str() );
578 vector
<string
> referencedModuleNames
;
579 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
582 GetModuleCleanTarget ( module
).c_str(),
583 v2s ( referencedModuleNames
, 10 ).c_str () );
584 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
587 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
588 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
590 fprintf ( fMakefile
, " 2>$(NUL)\n" );
591 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
595 MingwModuleHandler::GenerateInstallTarget () const
597 if ( module
.installName
.length () == 0 )
599 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
600 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
601 NormalizeFilename ( module
.installBase
+ sSep
+ module
.installName
),
602 backend
->installDirectory
);
605 module
.name
.c_str (),
606 normalizedTargetFilename
.c_str() );
610 MingwModuleHandler::GenerateDependsTarget () const
613 ".PHONY: %s_depends\n",
614 module
.name
.c_str() );
616 "%s_depends: $(RBUILD_TARGET)\n",
617 module
.name
.c_str () );
619 "\t$(ECHO_RBUILD)\n" );
621 "\t$(Q)$(RBUILD_TARGET) $(RBUILD_FLAGS) -dm%s mingw\n",
622 module
.name
.c_str () );
626 MingwModuleHandler::GetObjectFilenames ()
628 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
629 if ( compilationUnits
.size () == 0 )
632 string
objectFilenames ( "" );
633 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
635 if ( objectFilenames
.size () > 0 )
636 objectFilenames
+= " ";
637 objectFilenames
+= GetObjectFilename ( compilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
), NULL
);
639 return objectFilenames
;
643 MingwModuleHandler::GenerateGccDefineParametersFromVector (
644 const vector
<Define
*>& defines
)
647 for ( size_t i
= 0; i
< defines
.size (); i
++ )
649 Define
& define
= *defines
[i
];
650 if (parameters
.length () > 0)
653 parameters
+= define
.name
;
654 if (define
.value
.length () > 0)
657 parameters
+= define
.value
;
664 MingwModuleHandler::GenerateGccDefineParameters () const
666 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
667 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
668 if ( s
.length () > 0 )
677 MingwModuleHandler::ConcatenatePaths (
679 const string
& path2
) const
681 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
683 if ( path1
[path1
.length ()] == cSep
)
684 return path1
+ path2
;
686 return path1
+ cSep
+ path2
;
690 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
692 string parameters
, path_prefix
;
693 for ( size_t i
= 0; i
< includes
.size (); i
++ )
695 Include
& include
= *includes
[i
];
696 if ( parameters
.length () > 0 )
698 if ( include
.root
== "intermediate" )
699 path_prefix
= "$(INTERMEDIATE)" + sSep
;
700 else if (include
.root
== "output" )
701 path_prefix
= "$(OUTPUT)" + sSep
;
705 parameters
+= "-I" + path_prefix
+ include
.directory
;
711 MingwModuleHandler::GenerateGccIncludeParameters () const
713 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
714 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
715 if ( s
.length () > 0 )
724 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
727 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
729 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
730 if ( parameters
.length () > 0 )
732 parameters
+= compilerFlag
.flag
;
738 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
741 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
743 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
744 if ( parameters
.length () > 0 )
746 parameters
+= linkerFlag
.flag
;
752 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
753 const vector
<Library
*>& libraries
)
755 string
dependencies ( "" );
757 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
759 if ( wrap_count
++ == 5 )
760 dependencies
+= " \\\n\t\t", wrap_count
= 0;
761 else if ( dependencies
.size () > 0 )
763 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
769 MingwModuleHandler::GenerateLinkerParameters () const
771 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
775 MingwModuleHandler::GenerateMacro (
776 const char* assignmentOperation
,
778 const IfableData
& data
)
781 bool generateAssignment
;
783 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
784 if ( generateAssignment
)
789 assignmentOperation
);
792 if ( use_pch
&& module
.pch
!= NULL
)
796 GetDirectory ( GetPrecompiledHeaderFilename () ).c_str () );
799 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
800 if ( compilerParameters
.size () > 0 )
805 compilerParameters
.c_str () );
808 for ( i
= 0; i
< data
.includes
.size(); i
++ )
810 const Include
& include
= *data
.includes
[i
];
811 string includeDirectory
, path_prefix
;
812 if ( include
.baseModule
!= NULL
&&
813 ( include
.baseModule
->type
== RpcServer
||
814 include
.baseModule
->type
== RpcClient
||
815 include
.baseModule
->type
== IdlHeader
) )
816 includeDirectory
= PassThruCacheDirectory ( NormalizeFilename ( include
.directory
),
817 backend
->intermediateDirectory
);
819 includeDirectory
= include
.directory
;
821 if ( include
.root
== "intermediate" )
822 path_prefix
= "$(INTERMEDIATE)" + sSep
;
823 else if (include
.root
== "output" )
824 path_prefix
= "$(OUTPUT)" + sSep
;
832 includeDirectory
.c_str() );
834 for ( i
= 0; i
< data
.defines
.size(); i
++ )
836 Define
& d
= *data
.defines
[i
];
841 if ( d
.value
.size() )
847 if ( generateAssignment
)
849 fprintf ( fMakefile
, "\n" );
854 MingwModuleHandler::GenerateMacros (
855 const char* assignmentOperation
,
856 const IfableData
& data
,
857 const vector
<LinkerFlag
*>* linkerFlags
)
861 GenerateMacro ( assignmentOperation
,
864 GenerateMacro ( assignmentOperation
,
868 if ( linkerFlags
!= NULL
)
870 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
871 if ( linkerParameters
.size () > 0 )
876 linkerflagsMacro
.c_str (),
878 linkerParameters
.c_str() );
882 if ( data
.libraries
.size () > 0 )
884 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
885 if ( deps
.size () > 0 )
896 const vector
<If
*>& ifs
= data
.ifs
;
897 for ( i
= 0; i
< ifs
.size(); i
++ )
900 if ( rIf
.data
.defines
.size()
901 || rIf
.data
.includes
.size()
902 || rIf
.data
.libraries
.size()
903 || rIf
.data
.compilationUnits
.size()
904 || rIf
.data
.compilerFlags
.size()
905 || rIf
.data
.ifs
.size() )
909 "%s (\"$(%s)\",\"%s\")\n",
910 rIf
.negated
? "ifneq" : "ifeq",
911 rIf
.property
.c_str(),
925 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
927 for (size_t i
= 0; i
< compilationUnits
.size (); i
++)
928 delete compilationUnits
[i
];
932 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
937 MingwModuleHandler::GenerateObjectMacros (
938 const char* assignmentOperation
,
939 const IfableData
& data
,
940 const vector
<LinkerFlag
*>* linkerFlags
)
944 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
945 if ( compilationUnits
.size () > 0 )
947 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
949 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
950 if ( compilationUnit
.IsFirstFile () )
954 objectsMacro
.c_str(),
955 GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
).c_str (),
956 objectsMacro
.c_str() );
962 objectsMacro
.c_str (),
963 assignmentOperation
);
964 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
966 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
967 if ( !compilationUnit
.IsFirstFile () )
972 ( i
%10 == 9 ? " \\\n\t" : " " ),
973 GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
).c_str () );
976 fprintf ( fMakefile
, "\n" );
979 const vector
<If
*>& ifs
= data
.ifs
;
980 for ( i
= 0; i
< ifs
.size(); i
++ )
983 if ( rIf
.data
.defines
.size()
984 || rIf
.data
.includes
.size()
985 || rIf
.data
.libraries
.size()
986 || rIf
.data
.compilationUnits
.size()
987 || rIf
.data
.compilerFlags
.size()
988 || rIf
.data
.ifs
.size() )
992 "%s (\"$(%s)\",\"%s\")\n",
993 rIf
.negated
? "ifneq" : "ifeq",
994 rIf
.property
.c_str(),
996 GenerateObjectMacros (
1006 vector
<CompilationUnit
*> sourceCompilationUnits
;
1007 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1008 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1013 objectsMacro
.c_str(),
1014 GetObjectFilename ( sourceCompilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
), NULL
).c_str () );
1016 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1020 MingwModuleHandler::GetPrecompiledHeaderFilename () const
1022 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
1023 return PassThruCacheDirectory ( NormalizeFilename ( basePchFilename
),
1024 backend
->intermediateDirectory
);
1028 MingwModuleHandler::GenerateGccCommand (
1029 const FileLocation
* sourceFileLocation
,
1030 const string
& extraDependencies
,
1032 const string
& cflagsMacro
)
1034 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1035 string dependencies
= sourceFilename
;
1036 if ( extraDependencies
!= "" )
1037 dependencies
+= " " + extraDependencies
;
1038 if ( module
.pch
&& use_pch
)
1039 dependencies
+= " " + GetPrecompiledHeaderFilename ();
1041 /* WIDL generated headers may be used */
1042 vector
<string
> rpcDependencies
;
1043 GetRpcHeaderDependencies ( rpcDependencies
);
1044 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1045 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1047 string objectFilename
= GetObjectFilename (
1048 sourceFileLocation
, &clean_files
);
1049 fprintf ( fMakefile
,
1051 objectFilename
.c_str (),
1052 dependencies
.c_str (),
1053 GetDirectory ( objectFilename
).c_str () );
1054 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
1055 fprintf ( fMakefile
,
1056 "\t%s -c $< -o $@ %s\n",
1058 cflagsMacro
.c_str () );
1062 MingwModuleHandler::GenerateGccAssemblerCommand (
1063 const FileLocation
* sourceFileLocation
,
1065 const string
& cflagsMacro
)
1067 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1068 string dependencies
= sourceFilename
;
1069 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1070 string objectFilename
= GetObjectFilename (
1071 sourceFileLocation
, &clean_files
);
1072 fprintf ( fMakefile
,
1074 objectFilename
.c_str (),
1075 dependencies
.c_str (),
1076 GetDirectory ( objectFilename
).c_str () );
1077 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
1078 fprintf ( fMakefile
,
1079 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
1081 cflagsMacro
.c_str () );
1085 MingwModuleHandler::GenerateNasmCommand (
1086 const FileLocation
* sourceFileLocation
,
1087 const string
& nasmflagsMacro
)
1089 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1090 string dependencies
= sourceFilename
;
1091 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1092 string objectFilename
= GetObjectFilename (
1093 sourceFileLocation
, &clean_files
);
1094 fprintf ( fMakefile
,
1096 objectFilename
.c_str (),
1097 dependencies
.c_str (),
1098 GetDirectory ( objectFilename
).c_str () );
1099 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1100 fprintf ( fMakefile
,
1101 "\t%s -f win32 $< -o $@ %s\n",
1103 nasmflagsMacro
.c_str () );
1107 MingwModuleHandler::GenerateWindresCommand (
1108 const FileLocation
* sourceFileLocation
,
1109 const string
& windresflagsMacro
)
1111 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1112 string dependencies
= sourceFilename
;
1113 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1114 string objectFilename
= GetObjectFilename ( sourceFileLocation
, &clean_files
);
1115 string sourceFilenamePart
= ReplaceExtension ( GetFilename ( sourceFilename
), "" );
1116 string rciFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".rci.tmp";
1117 string resFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".res.tmp";
1118 if ( module
.useWRC
)
1120 fprintf ( fMakefile
,
1121 "%s: %s $(WRC_TARGET) | %s\n",
1122 objectFilename
.c_str (),
1123 dependencies
.c_str (),
1124 GetDirectory ( objectFilename
).c_str () );
1125 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1126 fprintf ( fMakefile
,
1127 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1128 windresflagsMacro
.c_str (),
1129 sourceFilename
.c_str (),
1130 rciFilename
.c_str () );
1131 fprintf ( fMakefile
,
1132 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1133 windresflagsMacro
.c_str (),
1134 rciFilename
.c_str (),
1135 resFilename
.c_str () );
1136 fprintf ( fMakefile
,
1137 "\t-@${rm} %s 2>$(NUL)\n",
1138 rciFilename
.c_str () );
1139 fprintf ( fMakefile
,
1140 "\t${windres} %s -o $@\n",
1141 resFilename
.c_str () );
1142 fprintf ( fMakefile
,
1143 "\t-@${rm} %s 2>$(NUL)\n",
1144 resFilename
.c_str () );
1148 fprintf ( fMakefile
,
1149 "%s: %s $(WRC_TARGET) | %s\n",
1150 objectFilename
.c_str (),
1151 dependencies
.c_str (),
1152 GetDirectory ( objectFilename
).c_str () );
1153 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1154 fprintf ( fMakefile
,
1155 "\t${windres} $(%s) %s -o $@\n",
1156 windresflagsMacro
.c_str (),
1157 sourceFilename
.c_str () );
1162 MingwModuleHandler::GenerateWinebuildCommands (
1163 const FileLocation
* sourceFileLocation
)
1165 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1166 string dependencies
= sourceFilename
;
1167 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1169 string basename
= GetBasename ( sourceFilename
);
1170 string def_file
= PassThruCacheDirectory (
1171 basename
+ ".spec.def",
1172 backend
->intermediateDirectory
);
1173 CLEAN_FILE(def_file
);
1175 string stub_file
= PassThruCacheDirectory (
1176 basename
+ ".stubs.c",
1177 backend
->intermediateDirectory
);
1178 CLEAN_FILE(stub_file
)
1180 fprintf ( fMakefile
,
1181 "%s: %s $(WINEBUILD_TARGET) | %s\n",
1183 dependencies
.c_str (),
1184 GetDirectory ( def_file
).c_str () );
1185 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1186 fprintf ( fMakefile
,
1187 "\t%s -o %s --def -E %s\n",
1188 "$(Q)$(WINEBUILD_TARGET)",
1190 sourceFilename
.c_str () );
1191 fprintf ( fMakefile
,
1192 "%s: %s $(WINEBUILD_TARGET)\n",
1194 sourceFilename
.c_str () );
1195 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1196 fprintf ( fMakefile
,
1197 "\t%s -o %s --pedll %s\n",
1198 "$(Q)$(WINEBUILD_TARGET)",
1200 sourceFilename
.c_str () );
1204 MingwModuleHandler::GetWidlFlags ( const CompilationUnit
& compilationUnit
)
1206 return compilationUnit
.GetSwitches ();
1210 MingwModuleHandler::GetPropertyValue ( const Module
& module
, const std::string
& name
)
1212 for ( size_t i
= 0; i
< module
.project
.non_if_data
.properties
.size (); i
++ )
1214 const Property
& property
= *module
.project
.non_if_data
.properties
[i
];
1215 if ( property
.name
== name
)
1216 return property
.value
;
1218 return string ( "" );
1222 MingwModuleHandler::GetRpcServerHeaderFilename ( string basename
) const
1224 return PassThruCacheDirectory ( basename
+ "_s.h",
1225 backend
->intermediateDirectory
);
1229 MingwModuleHandler::GenerateWidlCommandsServer (
1230 const CompilationUnit
& compilationUnit
,
1231 const string
& widlflagsMacro
)
1233 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1234 string filename
= sourceFileLocation
->filename
;
1235 string dependencies
= filename
;
1236 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1238 string basename
= GetBasename ( filename
);
1240 string generatedHeaderFilename
= GetRpcServerHeaderFilename ( basename
);
1241 CLEAN_FILE(generatedHeaderFilename
);
1243 string generatedServerFilename
= PassThruCacheDirectory (
1245 backend
->intermediateDirectory
);
1246 CLEAN_FILE(generatedServerFilename
);
1248 fprintf ( fMakefile
,
1249 "%s %s: %s $(WIDL_TARGET) | %s\n",
1250 generatedServerFilename
.c_str (),
1251 generatedHeaderFilename
.c_str (),
1252 dependencies
.c_str (),
1253 GetDirectory ( generatedServerFilename
).c_str () );
1254 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1255 fprintf ( fMakefile
,
1256 "\t%s %s %s -h -H %s -s -S %s %s\n",
1257 "$(Q)$(WIDL_TARGET)",
1258 GetWidlFlags ( compilationUnit
).c_str (),
1259 widlflagsMacro
.c_str (),
1260 generatedHeaderFilename
.c_str (),
1261 generatedServerFilename
.c_str (),
1262 filename
.c_str () );
1266 MingwModuleHandler::GetRpcClientHeaderFilename ( string basename
) const
1268 return PassThruCacheDirectory ( basename
+ "_c.h",
1269 backend
->intermediateDirectory
);
1273 MingwModuleHandler::GetIdlHeaderFilename ( string basename
) const
1275 return PassThruCacheDirectory ( basename
+ ".h",
1276 backend
->intermediateDirectory
);
1280 MingwModuleHandler::GenerateWidlCommandsEmbeddedTypeLib (
1281 const CompilationUnit
& compilationUnit
,
1282 const string
& widlflagsMacro
)
1284 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1285 string filename
= sourceFileLocation
->filename
;
1286 string dependencies
= filename
;
1287 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1289 string basename
= GetBasename ( filename
);
1291 string EmbeddedTypeLibFilename
= PassThruCacheDirectory (
1293 backend
->intermediateDirectory
);
1295 fprintf ( fMakefile
,
1296 "%s: %s $(WIDL_TARGET) | %s\n",
1297 GetTargetMacro ( module
).c_str (),
1298 dependencies
.c_str (),
1299 GetDirectory ( EmbeddedTypeLibFilename
).c_str () );
1300 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1301 fprintf ( fMakefile
,
1302 "\t%s %s %s -t -T %s %s\n",
1303 "$(Q)$(WIDL_TARGET)",
1304 GetWidlFlags ( compilationUnit
).c_str (),
1305 widlflagsMacro
.c_str (),
1306 EmbeddedTypeLibFilename
.c_str(),
1307 filename
.c_str () );
1311 MingwModuleHandler::GenerateWidlCommandsClient (
1312 const CompilationUnit
& compilationUnit
,
1313 const string
& widlflagsMacro
)
1315 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1316 string filename
= sourceFileLocation
->filename
;
1317 string dependencies
= filename
;
1318 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1320 string basename
= GetBasename ( filename
);
1322 string generatedHeaderFilename
= GetRpcClientHeaderFilename ( basename
);
1323 CLEAN_FILE(generatedHeaderFilename
);
1325 string generatedClientFilename
= PassThruCacheDirectory (
1327 backend
->intermediateDirectory
);
1328 CLEAN_FILE(generatedClientFilename
);
1330 fprintf ( fMakefile
,
1331 "%s %s: %s $(WIDL_TARGET) | %s\n",
1332 generatedClientFilename
.c_str (),
1333 generatedHeaderFilename
.c_str (),
1334 dependencies
.c_str (),
1335 GetDirectory ( generatedClientFilename
).c_str () );
1336 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1337 fprintf ( fMakefile
,
1338 "\t%s %s %s -h -H %s -c -C %s %s\n",
1339 "$(Q)$(WIDL_TARGET)",
1340 GetWidlFlags ( compilationUnit
).c_str (),
1341 widlflagsMacro
.c_str (),
1342 generatedHeaderFilename
.c_str (),
1343 generatedClientFilename
.c_str (),
1344 filename
.c_str () );
1348 MingwModuleHandler::GenerateWidlCommandsIdlHeader (
1349 const CompilationUnit
& compilationUnit
,
1350 const string
& widlflagsMacro
)
1352 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1353 string filename
= sourceFileLocation
->filename
;
1354 string dependencies
= filename
;
1355 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1357 string basename
= GetBasename ( filename
);
1359 string generatedHeaderFilename
= GetIdlHeaderFilename ( basename
);
1360 CLEAN_FILE(generatedHeaderFilename
);
1362 fprintf ( fMakefile
,
1363 "%s: %s $(WIDL_TARGET) | %s\n",
1364 generatedHeaderFilename
.c_str (),
1365 dependencies
.c_str (),
1366 GetDirectory ( generatedHeaderFilename
).c_str () );
1367 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1368 fprintf ( fMakefile
,
1369 "\t%s %s %s -h -H %s %s\n",
1370 "$(Q)$(WIDL_TARGET)",
1371 GetWidlFlags ( compilationUnit
).c_str (),
1372 widlflagsMacro
.c_str (),
1373 generatedHeaderFilename
.c_str (),
1374 filename
.c_str () );
1378 MingwModuleHandler::GenerateWidlCommands (
1379 const CompilationUnit
& compilationUnit
,
1380 const string
& widlflagsMacro
)
1382 if ( module
.type
== RpcServer
)
1383 GenerateWidlCommandsServer ( compilationUnit
,
1385 else if ( module
.type
== RpcClient
)
1386 GenerateWidlCommandsClient ( compilationUnit
,
1388 else if ( module
.type
== EmbeddedTypeLib
)
1389 GenerateWidlCommandsEmbeddedTypeLib ( compilationUnit
,
1391 else // applies also for other module.types which include idl files
1392 GenerateWidlCommandsIdlHeader ( compilationUnit
,
1397 MingwModuleHandler::GenerateCommands (
1398 const CompilationUnit
& compilationUnit
,
1401 const string
& cflagsMacro
,
1402 const string
& nasmflagsMacro
,
1403 const string
& windresflagsMacro
,
1404 const string
& widlflagsMacro
)
1406 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1407 string filename
= sourceFileLocation
->filename
;
1408 string extension
= GetExtension ( filename
);
1409 if ( extension
== ".c" || extension
== ".C" )
1411 GenerateGccCommand ( sourceFileLocation
,
1412 GetCompilationUnitDependencies ( compilationUnit
),
1417 else if ( extension
== ".cc" || extension
== ".CC" ||
1418 extension
== ".cpp" || extension
== ".CPP" ||
1419 extension
== ".cxx" || extension
== ".CXX" )
1421 GenerateGccCommand ( sourceFileLocation
,
1422 GetCompilationUnitDependencies ( compilationUnit
),
1427 else if ( extension
== ".s" || extension
== ".S" )
1429 GenerateGccAssemblerCommand ( sourceFileLocation
,
1434 else if ( extension
== ".asm" || extension
== ".ASM" )
1436 GenerateNasmCommand ( sourceFileLocation
,
1440 else if ( extension
== ".rc" || extension
== ".RC" )
1442 GenerateWindresCommand ( sourceFileLocation
,
1443 windresflagsMacro
);
1446 else if ( extension
== ".spec" || extension
== ".SPEC" )
1448 GenerateWinebuildCommands ( sourceFileLocation
);
1449 GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation
),
1455 else if ( extension
== ".idl" || extension
== ".IDL" )
1457 GenerateWidlCommands ( compilationUnit
,
1459 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
1461 GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation
),
1462 GetExtraDependencies ( filename
),
1469 throw InvalidOperationException ( __FILE__
,
1471 "Unsupported filename extension '%s' in file '%s'",
1473 filename
.c_str () );
1477 MingwModuleHandler::GenerateBuildMapCode ( const char *mapTarget
)
1479 fprintf ( fMakefile
,
1480 "ifeq ($(ROS_BUILDMAP),full)\n" );
1482 string mapFilename
= PassThruCacheDirectory (
1483 GetBasename ( module
.GetPath () ) + ".map",
1484 backend
->outputDirectory
);
1485 CLEAN_FILE ( mapFilename
);
1487 fprintf ( fMakefile
,
1488 "\t$(ECHO_OBJDUMP)\n" );
1489 fprintf ( fMakefile
,
1490 "\t$(Q)${objdump} -d -S %s > %s\n",
1491 mapTarget
? mapTarget
: "$@",
1492 mapFilename
.c_str () );
1494 fprintf ( fMakefile
,
1496 fprintf ( fMakefile
,
1497 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1499 fprintf ( fMakefile
,
1501 fprintf ( fMakefile
,
1502 "\t$(Q)${nm} --numeric-sort %s > %s\n",
1503 mapTarget
? mapTarget
: "$@",
1504 mapFilename
.c_str () );
1506 fprintf ( fMakefile
,
1509 fprintf ( fMakefile
,
1514 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1516 fprintf ( fMakefile
,
1517 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1519 string filename
= module
.GetPath ();
1520 string outputFilename
= PassThruCacheDirectory (
1522 backend
->outputDirectory
);
1523 string nostripFilename
= PassThruCacheDirectory (
1524 GetBasename ( filename
) + ".nostrip" + GetExtension ( filename
),
1525 backend
->outputDirectory
);
1526 CLEAN_FILE ( nostripFilename
);
1528 fprintf ( fMakefile
,
1530 fprintf ( fMakefile
,
1531 "\t${cp} %s %s 1>$(NUL)\n",
1532 outputFilename
.c_str (),
1533 nostripFilename
.c_str () );
1535 fprintf ( fMakefile
,
1540 MergeStringVector ( const vector
<string
>& input
,
1541 vector
<string
>& output
)
1545 int wrap_count
= -1;
1546 for ( size_t i
= 0; i
< input
.size (); i
++ )
1548 if ( input
[i
].size () == 0 )
1550 if ( wrap_count
++ == wrap_at
)
1552 output
.push_back ( s
);
1556 else if ( s
.size () > 0)
1560 if ( s
.length () > 0 )
1561 output
.push_back ( s
);
1565 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1566 vector
<string
>& objectFiles
) const
1568 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1570 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1571 objectFiles
.push_back ( GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
) );
1576 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1578 if ( backend
->configuration
.CleanAsYouGo
)
1580 vector
<string
> objectFiles
;
1581 GetObjectsVector ( module
.non_if_data
,
1583 vector
<string
> lines
;
1584 MergeStringVector ( objectFiles
,
1586 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1588 fprintf ( fMakefile
,
1589 "\t-@${rm} %s 2>$(NUL)\n",
1590 lines
[i
].c_str () );
1596 MingwModuleHandler::GenerateRunRsymCode () const
1598 fprintf ( fMakefile
,
1599 "\t$(ECHO_RSYM)\n" );
1600 fprintf ( fMakefile
,
1601 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1605 MingwModuleHandler::GenerateRunStripCode () const
1607 fprintf ( fMakefile
,
1608 "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" );
1609 fprintf ( fMakefile
,
1610 "\t$(ECHO_STRIP)\n" );
1611 fprintf ( fMakefile
,
1612 "\t${strip} -s -x -X $@\n\n" );
1613 fprintf ( fMakefile
,
1618 MingwModuleHandler::GenerateLinkerCommand (
1619 const string
& dependencies
,
1620 const string
& linker
,
1621 const string
& linkerParameters
,
1622 const string
& objectsMacro
,
1623 const string
& libsMacro
,
1624 const string
& pefixupParameters
)
1626 string
target ( GetTargetMacro ( module
) );
1627 string
target_folder ( GetDirectory ( GetTargetFilename ( module
, NULL
) ) );
1628 string definitionFilename
= GetDefinitionFilename ();
1630 string linkerScriptArgument
;
1631 if ( module
.linkerScript
!= NULL
)
1632 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", module
.linkerScript
->directory
.c_str () );
1634 linkerScriptArgument
= "";
1636 fprintf ( fMakefile
,
1637 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1639 definitionFilename
.c_str (),
1640 dependencies
.c_str (),
1641 target_folder
.c_str () );
1642 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1643 string
targetName ( module
.GetTargetName () );
1645 if ( !module
.IsDLL () )
1647 fprintf ( fMakefile
,
1648 "\t%s %s %s -o %s %s %s %s\n",
1650 linkerParameters
.c_str (),
1651 linkerScriptArgument
.c_str (),
1653 objectsMacro
.c_str (),
1655 GetLinkerMacro ().c_str () );
1657 else if ( module
.HasImportLibrary () )
1659 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1660 CLEAN_FILE ( temp_exp
);
1662 fprintf ( fMakefile
,
1663 "\t${dlltool} --dllname %s --def %s --output-exp %s %s %s\n",
1664 targetName
.c_str (),
1665 definitionFilename
.c_str (),
1667 module
.mangledSymbols
? "" : "--kill-at",
1668 module
.underscoreSymbols
? "--add-underscore" : "" );
1670 fprintf ( fMakefile
,
1671 "\t%s %s %s %s -o %s %s %s %s\n",
1673 linkerParameters
.c_str (),
1674 linkerScriptArgument
.c_str (),
1677 objectsMacro
.c_str (),
1679 GetLinkerMacro ().c_str () );
1681 fprintf ( fMakefile
,
1682 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1684 pefixupParameters
.c_str() );
1686 fprintf ( fMakefile
,
1687 "\t-@${rm} %s 2>$(NUL)\n",
1688 temp_exp
.c_str () );
1692 /* XXX: need to workaround binutils bug, which exports
1693 * all functions in a dll if no .def file or an empty
1694 * one has been provided... */
1696 //printf ( "%s will have all its functions exported\n",
1697 // module.GetTargetName ().c_str () );
1698 fprintf ( fMakefile
,
1699 "\t%s %s %s -o %s %s %s %s\n",
1701 linkerParameters
.c_str (),
1702 linkerScriptArgument
.c_str (),
1704 objectsMacro
.c_str (),
1706 GetLinkerMacro ().c_str () );
1709 GenerateBuildMapCode ();
1710 GenerateBuildNonSymbolStrippedCode ();
1711 GenerateRunRsymCode ();
1712 GenerateRunStripCode ();
1713 GenerateCleanObjectsAsYouGoCode ();
1717 MingwModuleHandler::GeneratePhonyTarget() const
1719 string
targetMacro ( GetTargetMacro ( module
) );
1720 fprintf ( fMakefile
,
1722 targetMacro
.c_str ());
1723 fprintf ( fMakefile
, "%s: | %s\n",
1724 targetMacro
.c_str (),
1725 GetDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1729 MingwModuleHandler::GenerateObjectFileTargets (
1730 const IfableData
& data
,
1733 const string
& cflagsMacro
,
1734 const string
& nasmflagsMacro
,
1735 const string
& windresflagsMacro
,
1736 const string
& widlflagsMacro
)
1740 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1741 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1743 GenerateCommands ( *compilationUnits
[i
],
1750 fprintf ( fMakefile
,
1754 const vector
<If
*>& ifs
= data
.ifs
;
1755 for ( i
= 0; i
< ifs
.size(); i
++ )
1757 GenerateObjectFileTargets ( ifs
[i
]->data
,
1766 vector
<CompilationUnit
*> sourceCompilationUnits
;
1767 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1768 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1770 GenerateCommands ( *sourceCompilationUnits
[i
],
1778 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1782 MingwModuleHandler::GenerateObjectFileTargets (
1785 const string
& cflagsMacro
,
1786 const string
& nasmflagsMacro
,
1787 const string
& windresflagsMacro
,
1788 const string
& widlflagsMacro
)
1790 if ( module
.pch
&& use_pch
)
1792 const string
& baseHeaderFilename
= module
.pch
->file
.name
;
1793 const string
& pchFilename
= GetPrecompiledHeaderFilename ();
1794 CLEAN_FILE(pchFilename
);
1795 string dependencies
= baseHeaderFilename
;
1796 /* WIDL generated headers may be used */
1797 vector
<string
> rpcDependencies
;
1798 GetRpcHeaderDependencies ( rpcDependencies
);
1799 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1800 fprintf ( fMakefile
,
1802 pchFilename
.c_str(),
1803 dependencies
.c_str() );
1804 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1805 fprintf ( fMakefile
,
1806 "\t%s -o %s %s -g %s\n\n",
1807 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1808 pchFilename
.c_str(),
1809 cflagsMacro
.c_str(),
1810 baseHeaderFilename
.c_str() );
1813 GenerateObjectFileTargets ( module
.non_if_data
,
1820 fprintf ( fMakefile
, "\n" );
1824 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1825 const string
& objs_macro
) const
1827 string
archiveFilename ( GetModuleArchiveFilename () );
1829 fprintf ( fMakefile
,
1831 archiveFilename
.c_str (),
1832 objs_macro
.c_str (),
1833 GetDirectory(archiveFilename
).c_str() );
1835 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
1837 string
archiveFilename ( GetModuleArchiveFilename () );
1838 string
definitionFilename ( GetDefinitionFilename () );
1840 fprintf ( fMakefile
,
1841 "\t${dlltool} --dllname %s --def %s --output-lib $@ %s %s\n",
1842 module
.importLibrary
->dllname
.c_str (),
1843 definitionFilename
.c_str (),
1844 module
.mangledSymbols
? "" : "--kill-at",
1845 module
.underscoreSymbols
? "--add-underscore" : "" );
1848 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1850 fprintf ( fMakefile
,
1853 objs_macro
.c_str ());
1855 GenerateCleanObjectsAsYouGoCode ();
1857 fprintf ( fMakefile
, "\n" );
1859 return archiveFilename
;
1863 MingwModuleHandler::GetCFlagsMacro () const
1865 return ssprintf ( "$(%s_CFLAGS)",
1866 module
.name
.c_str () );
1870 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1872 return ssprintf ( "$(%s_OBJS)",
1873 module
.name
.c_str () );
1877 MingwModuleHandler::GetLinkingDependenciesMacro () const
1879 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1883 MingwModuleHandler::GetLibsMacro () const
1885 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1889 MingwModuleHandler::GetLinkerMacro () const
1891 return ssprintf ( "$(%s_LFLAGS)",
1892 module
.name
.c_str () );
1896 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1898 if ( ReferenceObjects ( module
) )
1899 return GetObjectsMacro ( module
);
1901 return GetTargetFilename ( module
, NULL
);
1905 MingwModuleHandler::GenerateObjectMacro ()
1907 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1909 GenerateObjectMacros (
1912 &module
.linkerFlags
);
1914 // future references to the macro will be to get its values
1915 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1919 MingwModuleHandler::GenerateTargetMacro ()
1921 fprintf ( fMakefile
,
1923 GetTargetMacro ( module
, false ).c_str (),
1924 GetModuleTargets ( module
).c_str () );
1928 MingwModuleHandler::GetRpcHeaderDependencies (
1929 vector
<string
>& dependencies
) const
1931 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1933 Library
& library
= *module
.non_if_data
.libraries
[i
];
1934 if ( library
.importedModule
->type
== RpcServer
||
1935 library
.importedModule
->type
== RpcClient
||
1936 library
.importedModule
->type
== IdlHeader
)
1938 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
1940 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
1941 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1942 string extension
= GetExtension ( sourceFileLocation
->filename
);
1943 if ( extension
== ".idl" || extension
== ".IDL" )
1945 string basename
= GetBasename ( sourceFileLocation
->filename
);
1946 if ( library
.importedModule
->type
== RpcServer
)
1947 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
1948 if ( library
.importedModule
->type
== RpcClient
)
1949 dependencies
.push_back ( GetRpcClientHeaderFilename ( basename
) );
1950 if ( library
.importedModule
->type
== IdlHeader
)
1951 dependencies
.push_back ( GetIdlHeaderFilename ( basename
) );
1959 MingwModuleHandler::GenerateOtherMacros ()
1961 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1962 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1963 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1964 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1965 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1966 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1967 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1972 &module
.linkerFlags
);
1975 if ( module
.importLibrary
)
1977 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
1978 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
1980 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1981 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1982 string extension
= GetExtension ( sourceFileLocation
->filename
);
1983 if ( extension
== ".spec" || extension
== ".SPEC" )
1984 GetSpecObjectDependencies ( s
, sourceFileLocation
->filename
);
1987 if ( s
.size () > 0 )
1992 linkDepsMacro
.c_str() );
1993 for ( size_t i
= 0; i
< s
.size(); i
++ )
1994 fprintf ( fMakefile
,
1997 fprintf ( fMakefile
, "\n" );
2000 string globalCflags
= "-g";
2001 if ( backend
->usePipe
)
2002 globalCflags
+= " -pipe";
2003 if ( !module
.allowWarnings
)
2004 globalCflags
+= " -Werror";
2005 if ( module
.host
== HostTrue
)
2006 globalCflags
+= " $(HOST_CFLAGS)";
2008 // Always force disabling of sibling calls optimisation for GCC
2009 // (TODO: Move to version-specific once this bug is fixed in GCC)
2010 globalCflags
+= " -fno-optimize-sibling-calls";
2014 "%s += $(PROJECT_CFLAGS) %s\n",
2015 cflagsMacro
.c_str (),
2016 globalCflags
.c_str () );
2020 "%s += $(PROJECT_RCFLAGS)\n",
2021 windresflagsMacro
.c_str () );
2025 "%s += $(PROJECT_WIDLFLAGS) -I%s\n",
2026 widlflagsMacro
.c_str (),
2027 module
.GetBasePath ().c_str () );
2031 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
2032 module
.name
.c_str () );
2037 linkDepsMacro
.c_str (),
2038 libsMacro
.c_str () );
2040 string cflags
= TypeSpecificCFlags();
2041 if ( cflags
.size() > 0 )
2043 fprintf ( fMakefile
,
2045 cflagsMacro
.c_str (),
2049 string nasmflags
= TypeSpecificNasmFlags();
2050 if ( nasmflags
.size () > 0 )
2052 fprintf ( fMakefile
,
2054 nasmflagsMacro
.c_str (),
2055 nasmflags
.c_str () );
2058 string linkerflags
= TypeSpecificLinkerFlags();
2059 if ( linkerflags
.size() > 0 )
2061 fprintf ( fMakefile
,
2063 linkerflagsMacro
.c_str (),
2064 linkerflags
.c_str () );
2067 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
2069 fprintf ( fMakefile
,
2070 "%s += -Wno-main\n\n",
2071 cflagsMacro
.c_str () );
2074 fprintf ( fMakefile
, "\n\n" );
2076 // future references to the macros will be to get their values
2077 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
2078 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
2079 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
2083 MingwModuleHandler::GenerateRules ()
2085 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
2086 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
2087 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
2089 if ( module
.name
!= "zlib" ) /* Avoid make warning */
2091 string proxyMakefile
= PassThruCacheDirectory (
2092 NormalizeFilename ( module
.GetBasePath () + sSep
+ "makefile" ),
2093 backend
->outputDirectory
);
2094 CLEAN_FILE ( proxyMakefile
);
2097 string targetMacro
= GetTargetMacro ( module
);
2098 CLEAN_FILE ( targetMacro
);
2100 // generate phony target for module name
2101 fprintf ( fMakefile
, ".PHONY: %s\n",
2102 module
.name
.c_str () );
2103 string dependencies
= GetTargetMacro ( module
);
2104 if ( module
.type
== Test
)
2105 dependencies
+= " $(REGTESTS_RUN_TARGET)";
2106 fprintf ( fMakefile
, "%s: %s\n\n",
2107 module
.name
.c_str (),
2108 dependencies
.c_str () );
2109 if ( module
.type
== Test
)
2111 fprintf ( fMakefile
,
2113 targetMacro
.c_str ());
2116 if ( !ReferenceObjects ( module
) )
2118 string
ar_target ( GenerateArchiveTarget ( ar
, objectsMacro
) );
2119 if ( targetMacro
!= ar_target
)
2120 CLEAN_FILE ( ar_target
);
2123 GenerateObjectFileTargets ( cc
,
2132 MingwModuleHandler::GetInvocationDependencies (
2133 const Module
& module
,
2134 string_list
& dependencies
)
2136 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
2138 Invoke
& invoke
= *module
.invocations
[i
];
2139 if ( invoke
.invokeModule
== &module
)
2140 /* Protect against circular dependencies */
2142 invoke
.GetTargets ( dependencies
);
2147 MingwModuleHandler::GenerateInvocations () const
2149 if ( module
.invocations
.size () == 0 )
2152 size_t iend
= module
.invocations
.size ();
2153 for ( size_t i
= 0; i
< iend
; i
++ )
2155 const Invoke
& invoke
= *module
.invocations
[i
];
2157 if ( invoke
.invokeModule
->type
!= BuildTool
)
2159 throw XMLInvalidBuildFileException (
2160 module
.node
.location
,
2161 "Only modules of type buildtool can be invoked." );
2164 string invokeTarget
= module
.GetInvocationTarget ( i
);
2165 string_list invoke_targets
;
2166 assert ( invoke_targets
.size() );
2167 invoke
.GetTargets ( invoke_targets
);
2168 fprintf ( fMakefile
,
2170 invokeTarget
.c_str () );
2171 fprintf ( fMakefile
,
2173 invokeTarget
.c_str () );
2174 size_t j
, jend
= invoke_targets
.size();
2175 for ( j
= 0; j
< jend
; j
++ )
2177 fprintf ( fMakefile
,
2179 invoke_targets
[i
].c_str () );
2181 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
2182 for ( j
= 1; j
< jend
; j
++ )
2183 fprintf ( fMakefile
,
2185 invoke_targets
[i
].c_str () );
2186 fprintf ( fMakefile
,
2188 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
2189 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
2190 fprintf ( fMakefile
,
2192 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
2193 invoke
.GetParameters ().c_str () );
2198 MingwModuleHandler::GetPreconditionDependenciesName () const
2200 return module
.name
+ "_precondition";
2204 MingwModuleHandler::GetDefaultDependencies (
2205 string_list
& dependencies
) const
2207 /* Avoid circular dependency */
2208 if ( module
.type
!= BuildTool
2209 && module
.name
!= "zlib"
2210 && module
.name
!= "hostzlib" )
2212 dependencies
.push_back ( "$(INIT)" );
2214 if ( module
.type
!= BuildTool
2215 && module
.name
!= "psdk" )
2217 dependencies
.push_back ( "$(PSDK_TARGET)" );
2221 MingwModuleHandler::GeneratePreconditionDependencies ()
2223 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2224 string_list sourceFilenames
;
2225 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
2226 string_list dependencies
;
2227 GetDefaultDependencies ( dependencies
);
2228 GetModuleDependencies ( dependencies
);
2230 GetInvocationDependencies ( module
, dependencies
);
2232 if ( dependencies
.size() )
2234 fprintf ( fMakefile
,
2236 preconditionDependenciesName
.c_str () );
2237 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2238 fprintf ( fMakefile
,
2240 dependencies
[i
].c_str () );
2241 fprintf ( fMakefile
, "\n\n" );
2244 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
2246 fprintf ( fMakefile
,
2248 sourceFilenames
[i
].c_str(),
2249 preconditionDependenciesName
.c_str ());
2251 fprintf ( fMakefile
, "\n" );
2255 MingwModuleHandler::IsWineModule () const
2257 if ( module
.importLibrary
== NULL
)
2260 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
2261 return ( index
!= string::npos
);
2265 MingwModuleHandler::GetDefinitionFilename () const
2267 if ( module
.importLibrary
!= NULL
)
2269 string defFilename
= module
.GetBasePath () + sSep
+ module
.importLibrary
->definition
;
2270 if ( IsWineModule () )
2271 return PassThruCacheDirectory ( NormalizeFilename ( defFilename
),
2272 backend
->intermediateDirectory
);
2277 return "tools" + sSep
+ "rbuild" + sSep
+ "empty.def";
2281 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2283 if ( module
.importLibrary
!= NULL
)
2285 string
library_target (
2286 GetImportLibraryFilename ( module
, &clean_files
) );
2287 string defFilename
= GetDefinitionFilename ();
2290 GetDefinitionDependencies ( deps
);
2292 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2294 fprintf ( fMakefile
, "%s: %s",
2295 library_target
.c_str (),
2296 defFilename
.c_str () );
2298 size_t i
, iend
= deps
.size();
2299 for ( i
= 0; i
< iend
; i
++ )
2300 fprintf ( fMakefile
, " %s",
2303 fprintf ( fMakefile
, " | %s\n",
2304 GetDirectory ( GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2306 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2308 fprintf ( fMakefile
,
2309 "\t${dlltool} --dllname %s --def %s --output-lib %s %s %s\n\n",
2310 module
.GetTargetName ().c_str (),
2311 defFilename
.c_str (),
2312 library_target
.c_str (),
2313 module
.mangledSymbols
? "" : "--kill-at",
2314 module
.underscoreSymbols
? "--add-underscore" : "" );
2319 MingwModuleHandler::GetSpecObjectDependencies (
2320 string_list
& dependencies
,
2321 const string
& filename
) const
2323 string basename
= GetBasename ( filename
);
2324 string defDependency
= PassThruCacheDirectory (
2325 NormalizeFilename ( basename
+ ".spec.def" ),
2326 backend
->intermediateDirectory
);
2327 dependencies
.push_back ( defDependency
);
2328 string stubsDependency
= PassThruCacheDirectory (
2329 NormalizeFilename ( basename
+ ".stubs.c" ),
2330 backend
->intermediateDirectory
);
2331 dependencies
.push_back ( stubsDependency
);
2335 MingwModuleHandler::GetWidlObjectDependencies (
2336 string_list
& dependencies
,
2337 const string
& filename
) const
2339 string basename
= GetBasename ( filename
);
2340 string serverSourceDependency
= PassThruCacheDirectory (
2341 NormalizeFilename ( basename
+ "_s.c" ),
2342 backend
->intermediateDirectory
);
2343 dependencies
.push_back ( serverSourceDependency
);
2344 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
2348 MingwModuleHandler::GetDefinitionDependencies (
2349 string_list
& dependencies
) const
2351 string dkNkmLibNoFixup
= "dk/nkm/lib";
2352 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2353 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2355 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2356 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
2357 string extension
= GetExtension ( sourceFileLocation
->filename
);
2358 if ( extension
== ".spec" || extension
== ".SPEC" )
2359 GetSpecObjectDependencies ( dependencies
, sourceFileLocation
->filename
);
2360 if ( extension
== ".idl" || extension
== ".IDL" )
2362 if ( ( module
.type
== RpcServer
) || ( module
.type
== RpcClient
) )
2363 GetWidlObjectDependencies ( dependencies
, sourceFileLocation
->filename
);
2368 enum DebugSupportType
2375 MingwAddDebugSupportLibraries ( Module
& module
, DebugSupportType type
)
2381 case DebugKernelMode
:
2382 pLibrary
= new Library ( module
, "debugsup_ntoskrnl" );
2386 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2393 module
.non_if_data
.libraries
.push_back(pLibrary
);
2396 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2397 : MingwModuleHandler ( module_
)
2402 MingwBuildToolModuleHandler::Process ()
2404 GenerateBuildToolModuleTarget ();
2408 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2410 string
targetMacro ( GetTargetMacro (module
) );
2411 string objectsMacro
= GetObjectsMacro ( module
);
2412 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2413 string libsMacro
= GetLibsMacro ();
2418 if ( module
.cplusplus
)
2419 linker
= "${host_gpp}";
2421 linker
= "${host_gcc}";
2423 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2424 targetMacro
.c_str (),
2425 objectsMacro
.c_str (),
2426 linkDepsMacro
.c_str (),
2427 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2428 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2429 fprintf ( fMakefile
,
2430 "\t%s %s -o $@ %s %s\n\n",
2432 GetLinkerMacro ().c_str (),
2433 objectsMacro
.c_str (),
2434 libsMacro
.c_str () );
2438 MingwKernelModuleHandler::MingwKernelModuleHandler (
2439 const Module
& module_
)
2441 : MingwModuleHandler ( module_
)
2446 MingwKernelModuleHandler::Process ()
2448 GenerateKernelModuleTarget ();
2452 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2454 string
targetMacro ( GetTargetMacro ( module
) );
2455 string workingDirectory
= GetWorkingDirectory ( );
2456 string objectsMacro
= GetObjectsMacro ( module
);
2457 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2458 string libsMacro
= GetLibsMacro ();
2460 GenerateImportLibraryTargetIfNeeded ();
2462 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2466 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2468 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",
2469 module
.GetBasePath ().c_str (),
2471 module
.GetEntryPoint(true).c_str (),
2472 module
.baseaddress
.c_str () );
2473 GenerateLinkerCommand ( dependencies
,
2482 GeneratePhonyTarget();
2487 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2488 const Module
& module_
)
2490 : MingwModuleHandler ( module_
)
2495 MingwStaticLibraryModuleHandler::Process ()
2497 GenerateStaticLibraryModuleTarget ();
2501 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2507 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2508 const Module
& module_
)
2510 : MingwModuleHandler ( module_
)
2515 MingwObjectLibraryModuleHandler::Process ()
2517 GenerateObjectLibraryModuleTarget ();
2521 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2527 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2528 const Module
& module_
)
2530 : MingwModuleHandler ( module_
)
2534 MingwEmbeddedTypeLibModuleHandler::MingwEmbeddedTypeLibModuleHandler (
2535 const Module
& module_
)
2537 : MingwModuleHandler ( module_
)
2542 MingwEmbeddedTypeLibModuleHandler::Process ()
2549 MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2551 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2555 MingwKernelModeDLLModuleHandler::Process ()
2557 GenerateKernelModeDLLModuleTarget ();
2561 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2563 string
targetMacro ( GetTargetMacro ( module
) );
2564 string workingDirectory
= GetWorkingDirectory ( );
2565 string objectsMacro
= GetObjectsMacro ( module
);
2566 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2567 string libsMacro
= GetLibsMacro ();
2569 GenerateImportLibraryTargetIfNeeded ();
2571 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2575 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2577 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2578 module
.GetEntryPoint(true).c_str (),
2579 module
.baseaddress
.c_str () );
2580 GenerateLinkerCommand ( dependencies
,
2589 GeneratePhonyTarget();
2594 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2595 const Module
& module_
)
2597 : MingwModuleHandler ( module_
)
2602 MingwKernelModeDriverModuleHandler::AddImplicitLibraries ( Module
& module
)
2604 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2608 MingwKernelModeDriverModuleHandler::Process ()
2610 GenerateKernelModeDriverModuleTarget ();
2615 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2617 string
targetMacro ( GetTargetMacro (module
) );
2618 string workingDirectory
= GetWorkingDirectory ();
2619 string objectsMacro
= GetObjectsMacro ( module
);
2620 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2621 string libsMacro
= GetLibsMacro ();
2623 GenerateImportLibraryTargetIfNeeded ();
2625 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2629 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2631 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2632 module
.GetEntryPoint(true).c_str (),
2633 module
.baseaddress
.c_str () );
2634 GenerateLinkerCommand ( dependencies
,
2643 GeneratePhonyTarget();
2648 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2649 const Module
& module_
)
2651 : MingwModuleHandler ( module_
)
2656 MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2658 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2662 MingwNativeDLLModuleHandler::Process ()
2664 GenerateNativeDLLModuleTarget ();
2668 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2670 string
targetMacro ( GetTargetMacro (module
) );
2671 string workingDirectory
= GetWorkingDirectory ( );
2672 string objectsMacro
= GetObjectsMacro ( module
);
2673 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2674 string libsMacro
= GetLibsMacro ();
2676 GenerateImportLibraryTargetIfNeeded ();
2678 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2682 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2684 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2685 module
.GetEntryPoint(true).c_str (),
2686 module
.baseaddress
.c_str () );
2687 GenerateLinkerCommand ( dependencies
,
2696 GeneratePhonyTarget();
2701 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2702 const Module
& module_
)
2704 : MingwModuleHandler ( module_
)
2709 MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2711 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2715 MingwNativeCUIModuleHandler::Process ()
2717 GenerateNativeCUIModuleTarget ();
2721 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2723 string
targetMacro ( GetTargetMacro (module
) );
2724 string workingDirectory
= GetWorkingDirectory ( );
2725 string objectsMacro
= GetObjectsMacro ( module
);
2726 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2727 string libsMacro
= GetLibsMacro ();
2729 GenerateImportLibraryTargetIfNeeded ();
2731 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2735 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2737 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2738 module
.GetEntryPoint(true).c_str (),
2739 module
.baseaddress
.c_str () );
2740 GenerateLinkerCommand ( dependencies
,
2749 GeneratePhonyTarget();
2754 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2755 const Module
& module_
)
2757 : MingwModuleHandler ( module_
)
2761 MingwWin32OCXModuleHandler::MingwWin32OCXModuleHandler (
2762 const Module
& module_
)
2764 : MingwModuleHandler ( module_
)
2769 MingwAddImplicitLibraries( Module
&module
)
2773 if ( !module
.isDefaultEntryPoint
)
2775 if ( module
.GetEntryPoint(false) == "0" )
2777 pLibrary
= new Library ( module
, "mingw_common" );
2778 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() , pLibrary
);
2779 pLibrary
= new Library ( module
, "msvcrt" );
2780 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2785 if ( module
.IsDLL () )
2787 //pLibrary = new Library ( module, "__mingw_dllmain" );
2788 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
2792 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
2793 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
2796 pLibrary
= new Library ( module
, "mingw_common" );
2797 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
2799 if ( module
.name
!= "msvcrt" )
2801 // always link in msvcrt to get the basic routines
2802 pLibrary
= new Library ( module
, "msvcrt" );
2803 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2808 MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2810 MingwAddImplicitLibraries ( module
);
2811 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2815 MingwWin32DLLModuleHandler::Process ()
2817 GenerateWin32DLLModuleTarget ();
2821 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2823 string
targetMacro ( GetTargetMacro (module
) );
2824 string workingDirectory
= GetWorkingDirectory ( );
2825 string objectsMacro
= GetObjectsMacro ( module
);
2826 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2827 string libsMacro
= GetLibsMacro ();
2829 GenerateImportLibraryTargetIfNeeded ();
2831 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2835 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2838 if ( module
.cplusplus
)
2843 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2844 module
.GetEntryPoint(true).c_str (),
2845 module
.baseaddress
.c_str () );
2846 GenerateLinkerCommand ( dependencies
,
2855 GeneratePhonyTarget();
2861 MingwWin32OCXModuleHandler::AddImplicitLibraries ( Module
& module
)
2863 MingwAddImplicitLibraries ( module
);
2864 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2868 MingwWin32OCXModuleHandler::Process ()
2870 GenerateWin32OCXModuleTarget ();
2874 MingwWin32OCXModuleHandler::GenerateWin32OCXModuleTarget ()
2876 string
targetMacro ( GetTargetMacro (module
) );
2877 string workingDirectory
= GetWorkingDirectory ( );
2878 string objectsMacro
= GetObjectsMacro ( module
);
2879 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2880 string libsMacro
= GetLibsMacro ();
2882 GenerateImportLibraryTargetIfNeeded ();
2884 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2888 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2891 if ( module
.cplusplus
)
2896 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2897 module
.GetEntryPoint(true).c_str (),
2898 module
.baseaddress
.c_str () );
2899 GenerateLinkerCommand ( dependencies
,
2908 GeneratePhonyTarget();
2913 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2914 const Module
& module_
)
2916 : MingwModuleHandler ( module_
)
2921 MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2923 MingwAddImplicitLibraries ( module
);
2924 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2928 MingwWin32CUIModuleHandler::Process ()
2930 GenerateWin32CUIModuleTarget ();
2934 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2936 string
targetMacro ( GetTargetMacro (module
) );
2937 string workingDirectory
= GetWorkingDirectory ( );
2938 string objectsMacro
= GetObjectsMacro ( module
);
2939 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2940 string libsMacro
= GetLibsMacro ();
2942 GenerateImportLibraryTargetIfNeeded ();
2944 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2948 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2951 if ( module
.cplusplus
)
2956 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2957 module
.GetEntryPoint(true).c_str (),
2958 module
.baseaddress
.c_str () );
2959 GenerateLinkerCommand ( dependencies
,
2968 GeneratePhonyTarget();
2973 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2974 const Module
& module_
)
2976 : MingwModuleHandler ( module_
)
2981 MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2983 MingwAddImplicitLibraries ( module
);
2984 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2988 MingwWin32GUIModuleHandler::Process ()
2990 GenerateWin32GUIModuleTarget ();
2994 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2996 string
targetMacro ( GetTargetMacro (module
) );
2997 string workingDirectory
= GetWorkingDirectory ( );
2998 string objectsMacro
= GetObjectsMacro ( module
);
2999 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3000 string libsMacro
= GetLibsMacro ();
3002 GenerateImportLibraryTargetIfNeeded ();
3004 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3008 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3011 if ( module
.cplusplus
)
3016 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3017 module
.GetEntryPoint(true).c_str (),
3018 module
.baseaddress
.c_str () );
3019 GenerateLinkerCommand ( dependencies
,
3028 GeneratePhonyTarget();
3033 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
3034 const Module
& module_
)
3036 : MingwModuleHandler ( module_
)
3041 MingwBootLoaderModuleHandler::Process ()
3043 GenerateBootLoaderModuleTarget ();
3047 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
3049 string
targetName ( module
.GetTargetName () );
3050 string
targetMacro ( GetTargetMacro (module
) );
3051 string workingDirectory
= GetWorkingDirectory ();
3052 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
3053 CLEAN_FILE ( junk_tmp
);
3054 string objectsMacro
= GetObjectsMacro ( module
);
3055 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3056 string libsMacro
= GetLibsMacro ();
3060 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3061 targetMacro
.c_str (),
3062 objectsMacro
.c_str (),
3063 linkDepsMacro
.c_str (),
3064 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
3066 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
3068 fprintf ( fMakefile
,
3069 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
3070 GetLinkerMacro ().c_str (),
3072 objectsMacro
.c_str (),
3073 linkDepsMacro
.c_str () );
3074 fprintf ( fMakefile
,
3075 "\t${objcopy} -O binary %s $@\n",
3076 junk_tmp
.c_str () );
3077 GenerateBuildMapCode ( junk_tmp
.c_str() );
3078 fprintf ( fMakefile
,
3079 "\t-@${rm} %s 2>$(NUL)\n",
3080 junk_tmp
.c_str () );
3084 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
3085 const Module
& module_
)
3087 : MingwModuleHandler ( module_
)
3092 MingwBootSectorModuleHandler::Process ()
3094 GenerateBootSectorModuleTarget ();
3098 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
3100 string objectsMacro
= GetObjectsMacro ( module
);
3104 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3105 module
.name
.c_str ());
3106 fprintf ( fMakefile
,
3108 module
.name
.c_str (),
3109 objectsMacro
.c_str () );
3113 MingwBootProgramModuleHandler::MingwBootProgramModuleHandler (
3114 const Module
& module_
)
3115 : MingwModuleHandler ( module_
)
3120 MingwBootProgramModuleHandler::Process ()
3122 GenerateBootProgramModuleTarget ();
3126 MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
3128 string
targetName ( module
.GetTargetName () );
3129 string
targetMacro ( GetTargetMacro (module
) );
3130 string workingDirectory
= GetWorkingDirectory ();
3131 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
3132 string junk_elf
= ros_temp
+ module
.name
+ ".junk.elf";
3133 string junk_cpy
= ros_temp
+ module
.name
+ ".junk.cpy";
3134 CLEAN_FILE ( junk_tmp
);
3135 CLEAN_FILE ( junk_elf
);
3136 CLEAN_FILE ( junk_cpy
);
3137 string objectsMacro
= GetObjectsMacro ( module
);
3138 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3139 string libsMacro
= GetLibsMacro ();
3140 const Module
*payload
= module
.project
.LocateModule ( module
.payload
);
3144 fprintf ( fMakefile
, "%s: %s %s %s | %s\n",
3145 targetMacro
.c_str (),
3146 objectsMacro
.c_str (),
3147 linkDepsMacro
.c_str (),
3148 payload
->name
.c_str (),
3149 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
3151 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3153 fprintf ( fMakefile
, "\t$(%s_PREPARE) $(OUTPUT)$(SEP)%s %s\n",
3154 module
.buildtype
.c_str (),
3155 NormalizeFilename( payload
->GetPath() ).c_str (),
3156 junk_cpy
.c_str () );
3158 fprintf ( fMakefile
, "\t${objcopy} $(%s_FLATFORMAT) %s %s\n",
3159 module
.buildtype
.c_str (),
3161 junk_tmp
.c_str () );
3163 fprintf ( fMakefile
, "\t${ld} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3164 module
.buildtype
.c_str (),
3165 linkDepsMacro
.c_str (),
3167 junk_elf
.c_str () );
3169 fprintf ( fMakefile
, "\t${objcopy} $(%s_COPYFORMAT) %s $(INTERMEDIATE)$(SEP)%s\n",
3170 module
.buildtype
.c_str (),
3172 module
.GetPath().c_str () );
3174 fprintf ( fMakefile
,
3175 "\t-@${rm} %s %s %s 2>$(NUL)\n",
3176 junk_tmp
.c_str (), junk_elf
.c_str (), junk_cpy
.c_str () );
3180 MingwIsoModuleHandler::MingwIsoModuleHandler (
3181 const Module
& module_
)
3183 : MingwModuleHandler ( module_
)
3188 MingwIsoModuleHandler::Process ()
3190 GenerateIsoModuleTarget ();
3194 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
3195 const string
& bootcdDirectory
)
3197 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3199 const Module
& m
= *module
.project
.modules
[i
];
3202 if ( m
.bootstrap
!= NULL
)
3204 string sourceFilename
= PassThruCacheDirectory (
3205 NormalizeFilename ( m
.GetPath () ),
3206 backend
->outputDirectory
);
3207 string
targetFilenameNoFixup ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
+ sSep
+ m
.bootstrap
->nameoncd
);
3208 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3209 NormalizeFilename ( targetFilenameNoFixup
),
3210 backend
->outputDirectory
);
3211 fprintf ( fMakefile
,
3213 fprintf ( fMakefile
,
3214 "\t${cp} %s %s 1>$(NUL)\n",
3215 sourceFilename
.c_str (),
3216 targetFilename
.c_str () );
3222 MingwIsoModuleHandler::OutputCdfileCopyCommands (
3223 const string
& bootcdDirectory
)
3225 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3227 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3228 string targetFilenameNoFixup
= bootcdDirectory
+ sSep
+ cdfile
.base
+ sSep
+ cdfile
.nameoncd
;
3229 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3230 NormalizeFilename ( targetFilenameNoFixup
),
3231 backend
->outputDirectory
);
3232 fprintf ( fMakefile
,
3234 fprintf ( fMakefile
,
3235 "\t${cp} %s %s 1>$(NUL)\n",
3236 cdfile
.GetPath ().c_str (),
3237 targetFilename
.c_str () );
3242 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
3245 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3247 const Module
& m
= *module
.project
.modules
[i
];
3250 if ( m
.bootstrap
!= NULL
)
3252 string
targetDirectory ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
);
3253 if ( directories
.size () > 0 )
3255 directories
+= PassThruCacheDirectory (
3256 NormalizeFilename ( targetDirectory
),
3257 backend
->outputDirectory
);
3264 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
3267 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3269 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3270 string
targetDirectory ( bootcdDirectory
+ sSep
+ cdfile
.base
);
3271 if ( directories
.size () > 0 )
3273 directories
+= PassThruCacheDirectory (
3274 NormalizeFilename ( targetDirectory
),
3275 backend
->outputDirectory
);
3281 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
3283 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
3284 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
3289 MingwIsoModuleHandler::GetBootstrapCdFiles (
3290 vector
<string
>& out
) const
3292 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3294 const Module
& m
= *module
.project
.modules
[i
];
3297 if ( m
.bootstrap
!= NULL
)
3299 string filename
= PassThruCacheDirectory (
3300 NormalizeFilename ( m
.GetPath () ),
3301 backend
->outputDirectory
);
3302 out
.push_back ( filename
);
3308 MingwIsoModuleHandler::GetNonModuleCdFiles (
3309 vector
<string
>& out
) const
3311 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3313 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3314 out
.push_back ( cdfile
.GetPath () );
3319 MingwIsoModuleHandler::GetCdFiles (
3320 vector
<string
>& out
) const
3322 GetBootstrapCdFiles ( out
);
3323 GetNonModuleCdFiles ( out
);
3327 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
3329 string bootcdDirectory
= "cd";
3330 string srcunattend
= NormalizeFilename("boot/bootdata/bootcdregtest/unattend.inf");
3331 string tarunattend
= NormalizeFilename("$(OUTPUT)/cd/reactos/unattend.inf");
3333 vector
<string
> vCdFiles
;
3334 string bootcd
= PassThruCacheDirectory (
3335 NormalizeFilename ( bootcdDirectory
+ sSep
),
3336 backend
->outputDirectory
);
3341 if (module
.type
== IsoRegTest
)
3343 vCdFiles
.push_back (srcunattend
.c_str ());
3344 bootloader
= "isobtrt.o";
3345 IsoName
= "ReactOS-RegTest.iso";
3349 bootloader
= "isoboot.o";
3350 IsoName
= "ReactOS.iso";
3353 string isoboot
= PassThruCacheDirectory (
3354 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ bootloader
.c_str() ),
3355 backend
->outputDirectory
);
3357 string bootcdReactosNoFixup
= bootcdDirectory
+ sSep
+ Environment::GetCdOutputPath ();
3358 string bootcdReactos
= PassThruCacheDirectory (
3359 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
),
3360 backend
->outputDirectory
);
3361 CLEAN_FILE ( bootcdReactos
);
3362 string reactosInf
= PassThruCacheDirectory (
3363 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
+ "reactos.inf" ),
3364 backend
->outputDirectory
);
3365 string reactosDff
= NormalizeFilename ( "boot" + sSep
+ "bootdata" + sSep
+ "packages" + sSep
+ "reactos.dff" );
3366 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
3367 GetCdFiles ( vCdFiles
);
3368 string cdFiles
= v2s ( vCdFiles
, 5 );
3370 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3371 module
.name
.c_str ());
3372 fprintf ( fMakefile
,
3373 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
3374 module
.name
.c_str (),
3376 bootcdReactos
.c_str (),
3377 cdDirectories
.c_str (),
3379 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
3380 fprintf ( fMakefile
,
3381 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
3382 reactosDff
.c_str (),
3383 bootcdReactos
.c_str () );
3384 fprintf ( fMakefile
,
3385 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
3386 reactosDff
.c_str (),
3387 reactosInf
.c_str (),
3388 bootcdReactos
.c_str ());
3389 fprintf ( fMakefile
,
3390 "\t-@${rm} %s 2>$(NUL)\n",
3391 reactosInf
.c_str () );
3392 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
3393 OutputCdfileCopyCommands ( bootcdDirectory
);
3394 if (module
.type
== IsoRegTest
)
3396 fprintf ( fMakefile
,
3398 fprintf ( fMakefile
,
3399 "\t${cp} %s %s 1>$(NUL)\n",
3400 srcunattend
.c_str (),
3401 tarunattend
.c_str () );
3404 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3405 fprintf ( fMakefile
,
3406 "\t$(Q)$(CDMAKE_TARGET) -v -j -m -b %s %s REACTOS %s\n",
3410 fprintf ( fMakefile
,
3415 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
3416 const Module
& module_
)
3418 : MingwModuleHandler ( module_
)
3423 MingwLiveIsoModuleHandler::Process ()
3425 GenerateLiveIsoModuleTarget ();
3429 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
3431 string normalizedDirectory
= MingwModuleHandler::PassThruCacheDirectory (
3432 NormalizeFilename ( directory
) + sSep
,
3433 backend
->outputDirectory
);
3437 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string
& sourceFilename
,
3438 const string
& targetFilename
,
3439 const string
& targetDirectory
)
3441 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3442 NormalizeFilename ( targetDirectory
+ sSep
+ targetFilename
),
3443 backend
->outputDirectory
);
3444 fprintf ( fMakefile
,
3446 fprintf ( fMakefile
,
3447 "\t${cp} %s %s 1>$(NUL)\n",
3448 sourceFilename
.c_str (),
3449 normalizedTargetFilename
.c_str () );
3453 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
3454 string
& reactosDirectory
)
3456 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3458 const Module
& m
= *module
.project
.modules
[i
];
3461 if ( m
.installName
.length () > 0 )
3463 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
3464 string sourceFilename
= MingwModuleHandler::PassThruCacheDirectory (
3465 NormalizeFilename ( aliasedModule
.GetPath () ),
3466 backend
->outputDirectory
);
3467 OutputCopyCommand ( sourceFilename
,
3469 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.installBase
);
3475 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
3476 string
& reactosDirectory
)
3478 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
3480 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
3481 OutputCopyCommand ( installfile
.GetPath (),
3482 installfile
.newname
,
3483 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.base
);
3488 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
3490 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
3491 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
3492 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
3493 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
3494 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
3495 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
3497 string livecdIni
= "boot" + sSep
+ "bootdata" + sSep
+ "livecd.ini";
3498 OutputCopyCommand ( livecdIni
,
3504 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3506 string freeldr
= PassThruCacheDirectory (
3507 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "freeldr" + sSep
+ "freeldr.sys" ),
3508 backend
->outputDirectory
);
3509 CreateDirectory ( livecdDirectory
+ sSep
+ "loader" );
3510 OutputCopyCommand ( freeldr
,
3512 livecdDirectory
+ sSep
+ "loader" );
3516 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3518 string reactosSystem32ConfigDirectory
= NormalizeFilename (
3519 MingwModuleHandler::PassThruCacheDirectory (
3520 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config" + sSep
,
3521 backend
->outputDirectory
) );
3522 fprintf ( fMakefile
,
3523 "\t$(ECHO_MKHIVE)\n" );
3524 fprintf ( fMakefile
,
3525 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%clivecd.inf boot%cbootdata%chiveinst.inf\n",
3526 cSep
, reactosSystem32ConfigDirectory
.c_str (),
3527 cSep
, cSep
, cSep
, cSep
);
3531 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
3533 string livecdDirectory
= module
.name
;
3534 string livecd
= PassThruCacheDirectory (
3535 NormalizeFilename ( livecdDirectory
+ sSep
),
3536 backend
->outputDirectory
);
3541 if (module
.name
== "livecdregtest")
3543 bootloader
= "isobtrt.o";
3544 IsoName
= "ReactOS-LiveCD-RegTest.iso";
3548 bootloader
= "isoboot.o";
3549 IsoName
= "ReactOS-LiveCD.iso";
3552 string isoboot
= PassThruCacheDirectory (
3553 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ bootloader
.c_str() ),
3554 backend
->outputDirectory
);
3556 string reactosDirectory
= "reactos";
3557 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3558 string livecdReactos
= NormalizeFilename ( PassThruCacheDirectory (
3559 NormalizeFilename ( livecdReactosNoFixup
+ sSep
),
3560 backend
->outputDirectory
) );
3561 CLEAN_FILE ( livecdReactos
);
3563 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3564 module
.name
.c_str ());
3565 fprintf ( fMakefile
,
3566 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3567 module
.name
.c_str (),
3569 livecdReactos
.c_str () );
3570 OutputModuleCopyCommands ( livecdDirectory
,
3572 OutputNonModuleCopyCommands ( livecdDirectory
,
3574 OutputProfilesDirectoryCommands ( livecdDirectory
);
3575 OutputLoaderCommands ( livecdDirectory
);
3576 OutputRegistryCommands ( livecdDirectory
);
3577 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3578 fprintf ( fMakefile
,
3579 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS %s\n",
3583 fprintf ( fMakefile
,
3588 MingwTestModuleHandler::MingwTestModuleHandler (
3589 const Module
& module_
)
3591 : MingwModuleHandler ( module_
)
3596 MingwTestModuleHandler::Process ()
3598 GenerateTestModuleTarget ();
3602 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
3604 string basePath
= "$(INTERMEDIATE)" + sSep
+ module
.GetBasePath ();
3605 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_hooks.c", false, "", false ) ) );
3606 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_stubs.S", false, "", false ) ) );
3607 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_startup.c", false, "", false ) ) );
3611 MingwTestModuleHandler::GenerateTestModuleTarget ()
3613 string
targetMacro ( GetTargetMacro ( module
) );
3614 string workingDirectory
= GetWorkingDirectory ( );
3615 string objectsMacro
= GetObjectsMacro ( module
);
3616 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3617 string libsMacro
= GetLibsMacro ();
3619 GenerateImportLibraryTargetIfNeeded ();
3621 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3625 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3628 if ( module
.cplusplus
)
3633 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3634 module
.GetEntryPoint(true).c_str (),
3635 module
.baseaddress
.c_str () );
3636 GenerateLinkerCommand ( dependencies
,
3645 GeneratePhonyTarget();
3650 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3651 const Module
& module_
)
3653 : MingwModuleHandler ( module_
)
3658 MingwRpcServerModuleHandler::Process ()
3664 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3665 const Module
& module_
)
3667 : MingwModuleHandler ( module_
)
3672 MingwRpcClientModuleHandler::Process ()
3678 MingwAliasModuleHandler::MingwAliasModuleHandler (
3679 const Module
& module_
)
3681 : MingwModuleHandler ( module_
)
3686 MingwAliasModuleHandler::Process ()
3690 MingwIdlHeaderModuleHandler::MingwIdlHeaderModuleHandler (
3691 const Module
& module_
)
3693 : MingwModuleHandler ( module_
)
3698 MingwIdlHeaderModuleHandler::Process ()
3703 MingwElfExecutableModuleHandler::MingwElfExecutableModuleHandler (
3704 const Module
& module_
)
3706 : MingwModuleHandler ( module_
)
3711 MingwElfExecutableModuleHandler::Process ()
3713 string
targetName ( module
.GetTargetName () );
3714 string
targetMacro ( GetTargetMacro (module
) );
3715 string workingDirectory
= GetWorkingDirectory ();
3716 string objectsMacro
= GetObjectsMacro ( module
);
3717 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3718 string libsMacro
= GetLibsMacro ();
3722 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3723 targetMacro
.c_str (),
3724 objectsMacro
.c_str (),
3725 linkDepsMacro
.c_str (),
3726 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
3728 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3730 fprintf ( fMakefile
, "\t${ld} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3731 module
.buildtype
.c_str(),
3732 objectsMacro
.c_str(),
3734 targetMacro
.c_str () );