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 ? backend->GetFullName ( f ) : backend->GetFullPath ( f ) );
31 MingwModuleHandler::backend
= NULL
;
33 MingwModuleHandler::fMakefile
= NULL
;
37 const string
& filename
,
38 const string
& prefix
)
40 if ( !prefix
.length() )
43 const char* pfilename
= filename
.c_str();
44 const char* p1
= strrchr ( pfilename
, '/' );
45 const char* p2
= strrchr ( pfilename
, '\\' );
50 out
+= string(pfilename
,p1
-pfilename
) + cSep
;
53 out
+= prefix
+ pfilename
;
58 GetTargetMacro ( const Module
& module
, bool with_dollar
)
60 string
s ( module
.name
);
64 return ssprintf ( "$(%s)", s
.c_str() );
68 MingwModuleHandler::MingwModuleHandler (
69 const Module
& module_
)
76 MingwModuleHandler::~MingwModuleHandler()
81 MingwModuleHandler::SetBackend ( MingwBackend
* backend_
)
87 MingwModuleHandler::SetMakefile ( FILE* f
)
93 MingwModuleHandler::EnablePreCompiledHeaderSupport ()
98 /*static*/ const FileLocation
*
99 MingwModuleHandler::PassThruCacheDirectory (const FileLocation
* file
)
101 switch ( file
->directory
)
103 case SourceDirectory
:
105 case IntermediateDirectory
:
106 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->intermediateDirectory
);
108 case OutputDirectory
:
109 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->outputDirectory
);
111 case InstallDirectory
:
112 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->installDirectory
);
115 throw InvalidOperationException ( __FILE__
,
117 "Invalid directory %d.",
124 /*static*/ const FileLocation
*
125 MingwModuleHandler::GetTargetFilename (
126 const Module
& module
,
127 string_list
* pclean_files
)
129 FileLocation
*target
= new FileLocation ( *module
.output
);
132 string_list
& clean_files
= *pclean_files
;
133 CLEAN_FILE ( *target
);
138 /*static*/ const FileLocation
*
139 MingwModuleHandler::GetImportLibraryFilename (
140 const Module
& module
,
141 string_list
* pclean_files
)
143 FileLocation
*target
= new FileLocation ( *module
.dependency
);
146 string_list
& clean_files
= *pclean_files
;
147 CLEAN_FILE ( *target
);
152 /*static*/ MingwModuleHandler
*
153 MingwModuleHandler::InstanciateHandler (
154 const Module
& module
,
155 MingwBackend
* backend
)
157 MingwModuleHandler
* handler
;
158 switch ( module
.type
)
161 handler
= new MingwBuildToolModuleHandler ( module
);
164 handler
= new MingwStaticLibraryModuleHandler ( module
);
167 handler
= new MingwObjectLibraryModuleHandler ( module
);
170 handler
= new MingwKernelModuleHandler ( module
);
173 handler
= new MingwNativeCUIModuleHandler ( module
);
176 handler
= new MingwWin32CUIModuleHandler ( module
);
180 handler
= new MingwWin32GUIModuleHandler ( module
);
183 handler
= new MingwKernelModeDLLModuleHandler ( module
);
186 handler
= new MingwNativeDLLModuleHandler ( module
);
189 handler
= new MingwWin32DLLModuleHandler ( module
);
192 handler
= new MingwWin32OCXModuleHandler ( module
);
194 case KernelModeDriver
:
195 handler
= new MingwKernelModeDriverModuleHandler ( module
);
198 handler
= new MingwBootLoaderModuleHandler ( module
);
201 handler
= new MingwBootSectorModuleHandler ( module
);
204 handler
= new MingwBootProgramModuleHandler ( module
);
207 handler
= new MingwIsoModuleHandler ( module
);
210 handler
= new MingwLiveIsoModuleHandler ( module
);
213 handler
= new MingwIsoModuleHandler ( module
);
216 handler
= new MingwLiveIsoModuleHandler ( module
);
219 handler
= new MingwTestModuleHandler ( module
);
222 handler
= new MingwRpcServerModuleHandler ( module
);
225 handler
= new MingwRpcClientModuleHandler ( module
);
228 handler
= new MingwAliasModuleHandler ( module
);
231 handler
= new MingwIdlHeaderModuleHandler ( module
);
233 case EmbeddedTypeLib
:
234 handler
= new MingwEmbeddedTypeLibModuleHandler ( module
);
237 handler
= new MingwElfExecutableModuleHandler ( module
);
240 throw UnknownModuleTypeException (
241 module
.node
.location
,
249 MingwModuleHandler::GetWorkingDirectory () const
255 MingwModuleHandler::GetBasename ( const string
& filename
) const
257 size_t index
= filename
.find_last_of ( '.' );
258 if ( index
!= string::npos
)
259 return filename
.substr ( 0, index
);
264 MingwModuleHandler::GetActualSourceFilename (
265 const FileLocation
* file
) const
267 string filename
= file
->name
;
269 string extension
= GetExtension ( *file
);
270 if ( extension
== ".spec" || extension
== ".SPEC" )
272 string basename
= GetBasename ( filename
);
273 return new FileLocation (
274 IntermediateDirectory
,
276 basename
+ ".stubs.c" );
278 else if ( extension
== ".idl" || extension
== ".IDL" )
280 string basename
= GetBasename ( filename
);
281 if ( module
.type
== RpcServer
)
283 return new FileLocation (
284 IntermediateDirectory
,
288 else if ( module
.type
== RpcClient
)
290 return new FileLocation (
291 IntermediateDirectory
,
297 return new FileLocation ( *file
);
301 return new FileLocation ( *file
);
305 MingwModuleHandler::GetExtraDependencies (
306 const FileLocation
*file
) const
308 string extension
= GetExtension ( *file
);
309 if ( extension
== ".idl" || extension
== ".IDL" )
311 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
312 return backend
->GetFullName ( *GetRpcServerHeaderFilename ( file
) )
314 + backend
->GetFullName ( *GetRpcClientHeaderFilename ( file
) );
315 else if ( module
.type
== IdlHeader
)
316 return backend
->GetFullName ( *GetIdlHeaderFilename ( file
) );
325 MingwModuleHandler::GetCompilationUnitDependencies (
326 const CompilationUnit
& compilationUnit
) const
328 if ( compilationUnit
.files
.size () <= 1 )
330 vector
<string
> sourceFiles
;
331 for ( size_t i
= 0; i
< compilationUnit
.files
.size (); i
++ )
333 File
& file
= *compilationUnit
.files
[i
];
334 sourceFiles
.push_back ( backend
->GetFullName ( file
.file
) );
336 return v2s ( sourceFiles
, 10 );
340 MingwModuleHandler::GetModuleArchiveFilename () const
342 if ( module
.type
== StaticLibrary
)
343 return new FileLocation ( *GetTargetFilename ( module
, NULL
) );
344 return new FileLocation ( IntermediateDirectory
,
345 module
.output
->relative_path
,
346 ReplaceExtension ( module
.name
, ".temp.a" ) );
350 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
352 string extension
= GetExtension ( file
.file
);
353 return ( extension
== ".spec" || extension
== ".SPEC" );
357 MingwModuleHandler::ReferenceObjects (
358 const Module
& module
)
360 if ( module
.type
== ObjectLibrary
)
362 if ( module
.type
== RpcServer
)
364 if ( module
.type
== RpcClient
)
366 if ( module
.type
== IdlHeader
)
372 MingwModuleHandler::OutputCopyCommand ( const FileLocation
& source
,
373 const FileLocation
& destination
)
378 "\t${cp} %s %s 1>$(NUL)\n",
379 backend
->GetFullName ( source
).c_str (),
380 backend
->GetFullName ( *PassThruCacheDirectory ( &destination
) ).c_str () );
384 MingwModuleHandler::GetImportLibraryDependency (
385 const Module
& importedModule
)
388 if ( ReferenceObjects ( importedModule
) )
389 dep
= GetTargetMacro ( importedModule
);
391 dep
= backend
->GetFullName ( *GetImportLibraryFilename ( importedModule
, NULL
) );
396 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
397 string_list
& targets
)
399 if ( dependencyModule
.invocations
.size () > 0 )
401 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
403 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
404 invoke
.GetTargets ( targets
);
408 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
412 MingwModuleHandler::GetModuleDependencies (
413 string_list
& dependencies
)
415 size_t iend
= module
.dependencies
.size ();
420 for ( size_t i
= 0; i
< iend
; i
++ )
422 const Dependency
& dependency
= *module
.dependencies
[i
];
423 const Module
& dependencyModule
= *dependency
.dependencyModule
;
424 GetTargets ( dependencyModule
,
427 vector
<FileLocation
> v
;
428 GetDefinitionDependencies ( v
);
429 for ( size_t i
= 0; i
< v
.size (); i
++ )
431 const FileLocation
& file
= v
[i
];
432 dependencies
.push_back ( backend
->GetFullName ( file
) );
437 MingwModuleHandler::GetSourceFilenames ( vector
<FileLocation
>& list
,
438 bool includeGeneratedFiles
) const
442 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
443 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
445 if ( includeGeneratedFiles
|| !compilationUnits
[i
]->IsGeneratedFile () )
447 const FileLocation
* sourceFileLocation
= GetActualSourceFilename (
448 compilationUnits
[i
]->GetFilename () );
449 list
.push_back ( *sourceFileLocation
);
452 // intentionally make a copy so that we can append more work in
453 // the middle of processing without having to go recursive
454 vector
<If
*> v
= module
.non_if_data
.ifs
;
455 for ( i
= 0; i
< v
.size (); i
++ )
459 // check for sub-ifs to add to list
460 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
461 for ( j
= 0; j
< ifs
.size (); j
++ )
462 v
.push_back ( ifs
[j
] );
463 const vector
<CompilationUnit
*>& compilationUnits
= rIf
.data
.compilationUnits
;
464 for ( j
= 0; j
< compilationUnits
.size (); j
++ )
466 CompilationUnit
& compilationUnit
= *compilationUnits
[j
];
467 if ( includeGeneratedFiles
|| !compilationUnit
.IsGeneratedFile () )
469 const FileLocation
* sourceFileLocation
= GetActualSourceFilename (
470 compilationUnit
.GetFilename () );
471 list
.push_back ( *sourceFileLocation
);
478 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
479 vector
<FileLocation
>& list
) const
481 GetSourceFilenames ( list
, false );
485 MingwModuleHandler::GetObjectFilename (
486 const FileLocation
* sourceFile
,
487 string_list
* pclean_files
) const
489 DirectoryLocation destination_directory
;
491 string extension
= GetExtension ( *sourceFile
);
492 if ( extension
== ".rc" || extension
== ".RC" )
493 newExtension
= ".coff";
494 else if ( extension
== ".spec" || extension
== ".SPEC" )
495 newExtension
= ".stubs.o";
496 else if ( extension
== ".idl" || extension
== ".IDL" )
498 if ( module
.type
== RpcServer
)
499 newExtension
= "_s.o";
500 else if ( module
.type
== RpcClient
)
501 newExtension
= "_c.o";
508 if ( module
.type
== BootSector
)
509 destination_directory
= OutputDirectory
;
511 destination_directory
= IntermediateDirectory
;
513 const FileLocation
*obj_file
= new FileLocation(
514 destination_directory
,
515 sourceFile
->relative_path
,
516 ReplaceExtension ( sourceFile
->name
, newExtension
) );
520 string_list
& clean_files
= *pclean_files
;
521 CLEAN_FILE ( *obj_file
);
527 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
529 return module
.name
+ "_clean";
533 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
535 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
537 Library
& library
= *module
.non_if_data
.libraries
[i
];
538 if ( library
.importedModule
->type
== ObjectLibrary
)
539 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
544 MingwModuleHandler::GenerateCleanTarget () const
546 if ( module
.type
== Alias
)
550 ".PHONY: %s_clean\n",
551 module
.name
.c_str() );
552 vector
<string
> referencedModuleNames
;
553 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
556 GetModuleCleanTarget ( module
).c_str(),
557 v2s ( referencedModuleNames
, 10 ).c_str () );
558 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
560 if ( ( i
+ 1 ) % 10 == 9 )
561 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
562 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
564 fprintf ( fMakefile
, " 2>$(NUL)\n" );
565 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
569 MingwModuleHandler::GenerateInstallTarget () const
571 if ( !module
.install
)
573 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
576 module
.name
.c_str (),
577 backend
->GetFullName ( *module
.install
).c_str () );
581 MingwModuleHandler::GenerateDependsTarget () const
584 ".PHONY: %s_depends\n",
585 module
.name
.c_str() );
587 "%s_depends: $(RBUILD_TARGET)\n",
588 module
.name
.c_str () );
590 "\t$(ECHO_RBUILD)\n" );
592 "\t$(Q)$(RBUILD_TARGET) $(RBUILD_FLAGS) -dm%s mingw\n",
593 module
.name
.c_str () );
597 MingwModuleHandler::GetObjectFilenames ()
599 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
600 if ( compilationUnits
.size () == 0 )
603 string
objectFilenames ( "" );
604 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
606 if ( objectFilenames
.size () > 0 )
607 objectFilenames
+= " ";
608 objectFilenames
+= backend
->GetFullName ( *GetObjectFilename ( compilationUnits
[i
]->GetFilename (), NULL
) );
610 return objectFilenames
;
614 MingwModuleHandler::GenerateGccDefineParametersFromVector (
615 const vector
<Define
*>& defines
)
618 for ( size_t i
= 0; i
< defines
.size (); i
++ )
620 Define
& define
= *defines
[i
];
621 if (parameters
.length () > 0)
624 parameters
+= define
.name
;
625 if (define
.value
.length () > 0)
628 parameters
+= define
.value
;
635 MingwModuleHandler::GenerateGccDefineParameters () const
637 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
638 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
639 if ( s
.length () > 0 )
648 MingwModuleHandler::ConcatenatePaths (
650 const string
& path2
) const
652 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
654 if ( path1
[path1
.length ()] == cSep
)
655 return path1
+ path2
;
657 return path1
+ cSep
+ path2
;
661 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
663 string parameters
, path_prefix
;
664 for ( size_t i
= 0; i
< includes
.size (); i
++ )
666 Include
& include
= *includes
[i
];
667 if ( parameters
.length () > 0 )
669 parameters
+= "-I" + backend
->GetFullPath ( *include
.directory
);;
675 MingwModuleHandler::GenerateGccIncludeParameters () const
677 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
678 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
679 if ( s
.length () > 0 )
688 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
691 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
693 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
694 if ( parameters
.length () > 0 )
696 parameters
+= compilerFlag
.flag
;
702 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
705 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
707 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
708 if ( parameters
.length () > 0 )
710 parameters
+= linkerFlag
.flag
;
716 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
717 const vector
<Library
*>& libraries
)
719 string
dependencies ( "" );
721 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
723 if ( wrap_count
++ == 5 )
724 dependencies
+= " \\\n\t\t", wrap_count
= 0;
725 else if ( dependencies
.size () > 0 )
727 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
733 MingwModuleHandler::GenerateLinkerParameters () const
735 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
739 MingwModuleHandler::GenerateMacro (
740 const char* assignmentOperation
,
742 const IfableData
& data
)
745 bool generateAssignment
;
747 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
748 if ( generateAssignment
)
753 assignmentOperation
);
756 if ( use_pch
&& module
.pch
!= NULL
)
760 backend
->GetFullPath ( *GetPrecompiledHeaderFilename () ).c_str () );
763 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
764 if ( compilerParameters
.size () > 0 )
769 compilerParameters
.c_str () );
772 for ( i
= 0; i
< data
.includes
.size(); i
++ )
774 const Include
& include
= *data
.includes
[i
];
775 const FileLocation
* includeDirectory
= include
.directory
;
779 backend
->GetFullPath ( *includeDirectory
).c_str() );
781 for ( i
= 0; i
< data
.defines
.size(); i
++ )
783 Define
& d
= *data
.defines
[i
];
788 if ( d
.value
.size() )
794 if ( generateAssignment
)
796 fprintf ( fMakefile
, "\n" );
801 MingwModuleHandler::GenerateMacros (
802 const char* assignmentOperation
,
803 const IfableData
& data
,
804 const vector
<LinkerFlag
*>* linkerFlags
)
808 GenerateMacro ( assignmentOperation
,
811 GenerateMacro ( assignmentOperation
,
815 if ( linkerFlags
!= NULL
)
817 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
818 if ( linkerParameters
.size () > 0 )
823 linkerflagsMacro
.c_str (),
825 linkerParameters
.c_str() );
829 if ( data
.libraries
.size () > 0 )
831 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
832 if ( deps
.size () > 0 )
843 const vector
<If
*>& ifs
= data
.ifs
;
844 for ( i
= 0; i
< ifs
.size(); i
++ )
847 if ( rIf
.data
.defines
.size()
848 || rIf
.data
.includes
.size()
849 || rIf
.data
.libraries
.size()
850 || rIf
.data
.compilationUnits
.size()
851 || rIf
.data
.compilerFlags
.size()
852 || rIf
.data
.ifs
.size() )
856 "%s (\"$(%s)\",\"%s\")\n",
857 rIf
.negated
? "ifneq" : "ifeq",
858 rIf
.property
.c_str(),
872 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
874 for (size_t i
= 0; i
< compilationUnits
.size (); i
++)
875 delete compilationUnits
[i
];
879 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
884 MingwModuleHandler::GenerateObjectMacros (
885 const char* assignmentOperation
,
886 const IfableData
& data
,
887 const vector
<LinkerFlag
*>* linkerFlags
)
891 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
892 vector
<const FileLocation
*> headers
;
893 if ( compilationUnits
.size () > 0 )
895 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
897 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
898 if ( compilationUnit
.IsFirstFile () )
902 objectsMacro
.c_str(),
903 backend
->GetFullName ( *GetObjectFilename ( compilationUnit
.GetFilename (), NULL
) ).c_str (),
904 objectsMacro
.c_str() );
910 objectsMacro
.c_str (),
911 assignmentOperation
);
912 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
914 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
915 if ( !compilationUnit
.IsFirstFile () )
917 const FileLocation
*objectFilename
= GetObjectFilename ( compilationUnit
.GetFilename (), NULL
);
918 if ( GetExtension ( *objectFilename
) == ".h" )
919 headers
.push_back ( objectFilename
);
924 ( i
%10 == 9 ? " \\\n\t" : " " ),
925 backend
->GetFullName ( *objectFilename
).c_str () );
928 fprintf ( fMakefile
, "\n" );
930 if ( headers
.size () > 0 )
935 module
.name
.c_str (),
936 assignmentOperation
);
937 for ( i
= 0; i
< headers
.size (); i
++ )
941 ( i
%10 == 9 ? " \\\n\t" : " " ),
942 backend
->GetFullName ( *headers
[i
] ).c_str () );
943 fprintf ( fMakefile
, "\n" );
946 const vector
<If
*>& ifs
= data
.ifs
;
947 for ( i
= 0; i
< ifs
.size(); i
++ )
950 if ( rIf
.data
.defines
.size()
951 || rIf
.data
.includes
.size()
952 || rIf
.data
.libraries
.size()
953 || rIf
.data
.compilationUnits
.size()
954 || rIf
.data
.compilerFlags
.size()
955 || rIf
.data
.ifs
.size() )
959 "%s (\"$(%s)\",\"%s\")\n",
960 rIf
.negated
? "ifneq" : "ifeq",
961 rIf
.property
.c_str(),
963 GenerateObjectMacros (
973 vector
<CompilationUnit
*> sourceCompilationUnits
;
974 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
975 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
980 objectsMacro
.c_str(),
981 backend
->GetFullName ( *GetObjectFilename ( sourceCompilationUnits
[i
]->GetFilename (), NULL
) ).c_str () );
983 CleanupCompilationUnitVector ( sourceCompilationUnits
);
987 MingwModuleHandler::GetPrecompiledHeaderFilename () const
989 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
990 return new FileLocation ( IntermediateDirectory
,
991 module
.pch
->file
.relative_path
,
996 MingwModuleHandler::GenerateGccCommand (
997 const FileLocation
* sourceFile
,
998 const string
& extraDependencies
,
1000 const string
& cflagsMacro
)
1002 string dependencies
= backend
->GetFullName ( *sourceFile
);
1003 if ( extraDependencies
!= "" )
1004 dependencies
+= " " + extraDependencies
;
1005 if ( module
.pch
&& use_pch
)
1006 dependencies
+= " " + backend
->GetFullName ( *GetPrecompiledHeaderFilename () );
1008 /* WIDL generated headers may be used */
1009 vector
<FileLocation
> rpcDependencies
;
1010 GetRpcHeaderDependencies ( rpcDependencies
);
1011 dependencies
+= " " + v2s ( backend
, rpcDependencies
, 5 );
1012 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1014 const FileLocation
*objectFilename
= GetObjectFilename (
1015 sourceFile
, &clean_files
);
1016 fprintf ( fMakefile
,
1018 backend
->GetFullName ( *objectFilename
).c_str (),
1019 dependencies
.c_str (),
1020 backend
->GetFullPath ( *objectFilename
).c_str () );
1021 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
1022 fprintf ( fMakefile
,
1023 "\t%s -c $< -o $@ %s\n",
1025 cflagsMacro
.c_str () );
1029 MingwModuleHandler::GenerateGccAssemblerCommand (
1030 const FileLocation
* sourceFile
,
1032 const string
& cflagsMacro
)
1034 string dependencies
= backend
->GetFullName ( *sourceFile
);
1035 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1037 const FileLocation
*objectFilename
= GetObjectFilename (
1038 sourceFile
, &clean_files
);
1039 fprintf ( fMakefile
,
1041 backend
->GetFullName ( *objectFilename
).c_str (),
1042 dependencies
.c_str (),
1043 backend
->GetFullPath ( *objectFilename
).c_str () );
1044 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
1045 fprintf ( fMakefile
,
1046 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
1048 cflagsMacro
.c_str () );
1052 MingwModuleHandler::GenerateNasmCommand (
1053 const FileLocation
* sourceFile
,
1054 const string
& nasmflagsMacro
)
1056 string dependencies
= backend
->GetFullName ( *sourceFile
);
1057 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1059 const FileLocation
*objectFilename
= GetObjectFilename (
1060 sourceFile
, &clean_files
);
1061 fprintf ( fMakefile
,
1063 backend
->GetFullName ( *objectFilename
).c_str (),
1064 dependencies
.c_str (),
1065 backend
->GetFullPath ( *objectFilename
).c_str () );
1066 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1067 fprintf ( fMakefile
,
1068 "\t%s -f win32 $< -o $@ %s\n",
1070 nasmflagsMacro
.c_str () );
1074 MingwModuleHandler::GenerateWindresCommand (
1075 const FileLocation
* sourceFile
,
1076 const string
& windresflagsMacro
)
1078 string dependencies
= backend
->GetFullName ( *sourceFile
);
1079 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1081 const FileLocation
*objectFilename
= GetObjectFilename ( sourceFile
, &clean_files
);
1083 if ( module
.useWRC
)
1085 string sourceFilenamePart
= module
.name
+ "." + ReplaceExtension ( sourceFile
->name
, "" );
1086 FileLocation
rciFilename ( TemporaryDirectory
,
1088 sourceFilenamePart
+ ".rci.tmp" );
1089 FileLocation
resFilename ( TemporaryDirectory
,
1091 sourceFilenamePart
+ ".res.tmp" );
1093 fprintf ( fMakefile
,
1094 "%s: %s $(WRC_TARGET) | %s\n",
1095 backend
->GetFullName ( *objectFilename
).c_str (),
1096 dependencies
.c_str (),
1097 backend
->GetFullPath ( *objectFilename
).c_str () );
1098 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1099 fprintf ( fMakefile
,
1100 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1101 windresflagsMacro
.c_str (),
1102 backend
->GetFullName ( *sourceFile
).c_str (),
1103 backend
->GetFullName ( rciFilename
).c_str () );
1104 fprintf ( fMakefile
,
1105 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1106 windresflagsMacro
.c_str (),
1107 backend
->GetFullName ( rciFilename
).c_str (),
1108 backend
->GetFullName ( resFilename
).c_str () );
1109 fprintf ( fMakefile
,
1110 "\t-@${rm} %s 2>$(NUL)\n",
1111 backend
->GetFullName ( rciFilename
).c_str () );
1112 fprintf ( fMakefile
,
1113 "\t${windres} %s -o $@\n",
1114 backend
->GetFullName ( resFilename
).c_str () );
1115 fprintf ( fMakefile
,
1116 "\t-@${rm} %s 2>$(NUL)\n",
1117 backend
->GetFullName ( resFilename
).c_str () );
1121 fprintf ( fMakefile
,
1122 "%s: %s $(WRC_TARGET) | %s\n",
1123 backend
->GetFullName ( *objectFilename
).c_str (),
1124 dependencies
.c_str (),
1125 backend
->GetFullPath ( *objectFilename
).c_str () );
1126 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1127 fprintf ( fMakefile
,
1128 "\t${windres} $(%s) %s -o $@\n",
1129 windresflagsMacro
.c_str (),
1130 backend
->GetFullName ( *sourceFile
).c_str () );
1135 MingwModuleHandler::GenerateWinebuildCommands (
1136 const FileLocation
* sourceFile
)
1138 string dependencies
= backend
->GetFullName ( *sourceFile
);
1139 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1141 string basename
= GetBasename ( sourceFile
->name
);
1142 FileLocation
def_file ( IntermediateDirectory
,
1143 sourceFile
->relative_path
,
1144 basename
+ ".spec.def" );
1145 CLEAN_FILE ( def_file
);
1147 FileLocation
stub_file ( IntermediateDirectory
,
1148 sourceFile
->relative_path
,
1149 basename
+ ".stubs.c" );
1150 CLEAN_FILE ( stub_file
);
1152 fprintf ( fMakefile
,
1153 "%s: %s $(WINEBUILD_TARGET) | %s\n",
1154 backend
->GetFullName ( def_file
).c_str (),
1155 dependencies
.c_str (),
1156 backend
->GetFullPath ( def_file
).c_str () );
1157 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1158 fprintf ( fMakefile
,
1159 "\t%s -o %s --def -E %s\n",
1160 "$(Q)$(WINEBUILD_TARGET)",
1161 backend
->GetFullName ( def_file
).c_str (),
1162 backend
->GetFullName ( *sourceFile
).c_str () );
1163 fprintf ( fMakefile
,
1164 "%s: %s $(WINEBUILD_TARGET)\n",
1165 backend
->GetFullName ( stub_file
).c_str (),
1166 backend
->GetFullName ( *sourceFile
).c_str () );
1167 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1168 fprintf ( fMakefile
,
1169 "\t%s -o %s --pedll %s\n",
1170 "$(Q)$(WINEBUILD_TARGET)",
1171 backend
->GetFullName ( stub_file
).c_str (),
1172 backend
->GetFullName ( *sourceFile
).c_str () );
1176 MingwModuleHandler::GetWidlFlags ( const CompilationUnit
& compilationUnit
)
1178 return compilationUnit
.GetSwitches ();
1182 MingwModuleHandler::GetPropertyValue ( const Module
& module
, const std::string
& name
)
1184 for ( size_t i
= 0; i
< module
.project
.non_if_data
.properties
.size (); i
++ )
1186 const Property
& property
= *module
.project
.non_if_data
.properties
[i
];
1187 if ( property
.name
== name
)
1188 return property
.value
;
1190 return string ( "" );
1194 MingwModuleHandler::GetRpcServerHeaderFilename ( const FileLocation
*base
) const
1196 string newname
= GetBasename ( base
->name
) + "_s.h";
1197 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1201 MingwModuleHandler::GenerateWidlCommandsServer (
1202 const CompilationUnit
& compilationUnit
,
1203 const string
& widlflagsMacro
)
1205 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1206 string dependencies
= backend
->GetFullName ( *sourceFile
);
1207 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1209 string basename
= GetBasename ( sourceFile
->name
);
1211 const FileLocation
*generatedHeaderFilename
= GetRpcServerHeaderFilename ( sourceFile
);
1212 CLEAN_FILE ( *generatedHeaderFilename
);
1214 FileLocation
generatedServerFilename ( IntermediateDirectory
,
1215 sourceFile
->relative_path
,
1216 basename
+ "_s.c" );
1217 CLEAN_FILE ( generatedServerFilename
);
1219 fprintf ( fMakefile
,
1220 "%s %s: %s $(WIDL_TARGET) | %s\n",
1221 backend
->GetFullName ( generatedServerFilename
).c_str (),
1222 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1223 dependencies
.c_str (),
1224 backend
->GetFullPath ( generatedServerFilename
).c_str () );
1225 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1226 fprintf ( fMakefile
,
1227 "\t%s %s %s -h -H %s -s -S %s %s\n",
1228 "$(Q)$(WIDL_TARGET)",
1229 GetWidlFlags ( compilationUnit
).c_str (),
1230 widlflagsMacro
.c_str (),
1231 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1232 backend
->GetFullName ( generatedServerFilename
).c_str (),
1233 backend
->GetFullName ( *sourceFile
).c_str () );
1237 MingwModuleHandler::GetRpcClientHeaderFilename ( const FileLocation
*base
) const
1239 string newname
= GetBasename ( base
->name
) + "_c.h";
1240 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1244 MingwModuleHandler::GetIdlHeaderFilename ( const FileLocation
*base
) const
1246 string newname
= GetBasename ( base
->name
) + ".h";
1247 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1251 MingwModuleHandler::GenerateWidlCommandsEmbeddedTypeLib (
1252 const CompilationUnit
& compilationUnit
,
1253 const string
& widlflagsMacro
)
1255 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1256 string dependencies
= backend
->GetFullName ( *sourceFile
);
1257 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1259 string basename
= GetBasename ( sourceFile
->name
);
1261 FileLocation
EmbeddedTypeLibFilename ( IntermediateDirectory
,
1262 sourceFile
->relative_path
,
1263 basename
+ ".tlb" );
1265 fprintf ( fMakefile
,
1266 "%s: %s $(WIDL_TARGET) | %s\n",
1267 GetTargetMacro ( module
).c_str (),
1268 dependencies
.c_str (),
1269 backend
->GetFullPath ( EmbeddedTypeLibFilename
).c_str () );
1270 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1271 fprintf ( fMakefile
,
1272 "\t%s %s %s -t -T %s %s\n",
1273 "$(Q)$(WIDL_TARGET)",
1274 GetWidlFlags ( compilationUnit
).c_str (),
1275 widlflagsMacro
.c_str (),
1276 backend
->GetFullName ( EmbeddedTypeLibFilename
).c_str(),
1277 backend
->GetFullName ( *sourceFile
).c_str () );
1281 MingwModuleHandler::GenerateWidlCommandsClient (
1282 const CompilationUnit
& compilationUnit
,
1283 const string
& widlflagsMacro
)
1285 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1286 string dependencies
= backend
->GetFullName ( *sourceFile
);
1287 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1289 string basename
= GetBasename ( sourceFile
->name
);
1291 const FileLocation
*generatedHeaderFilename
= GetRpcClientHeaderFilename ( sourceFile
);
1292 CLEAN_FILE ( *generatedHeaderFilename
);
1294 FileLocation
generatedClientFilename ( IntermediateDirectory
,
1295 sourceFile
->relative_path
,
1296 basename
+ "_c.c" );
1297 CLEAN_FILE ( generatedClientFilename
);
1299 fprintf ( fMakefile
,
1300 "%s %s: %s $(WIDL_TARGET) | %s\n",
1301 backend
->GetFullName ( generatedClientFilename
).c_str (),
1302 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1303 dependencies
.c_str (),
1304 backend
->GetFullPath ( generatedClientFilename
).c_str () );
1305 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1306 fprintf ( fMakefile
,
1307 "\t%s %s %s -h -H %s -c -C %s %s\n",
1308 "$(Q)$(WIDL_TARGET)",
1309 GetWidlFlags ( compilationUnit
).c_str (),
1310 widlflagsMacro
.c_str (),
1311 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1312 backend
->GetFullName ( generatedClientFilename
).c_str (),
1313 backend
->GetFullName ( *sourceFile
).c_str () );
1317 MingwModuleHandler::GenerateWidlCommandsIdlHeader (
1318 const CompilationUnit
& compilationUnit
,
1319 const string
& widlflagsMacro
)
1321 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1322 string dependencies
= backend
->GetFullName ( *sourceFile
);
1323 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1325 string basename
= GetBasename ( sourceFile
->name
);
1327 const FileLocation
*generatedHeader
= GetIdlHeaderFilename ( sourceFile
);
1328 CLEAN_FILE ( *generatedHeader
);
1330 fprintf ( fMakefile
,
1331 "%s: %s $(WIDL_TARGET) | %s\n",
1332 backend
->GetFullName( *generatedHeader
).c_str (),
1333 dependencies
.c_str (),
1334 backend
->GetFullPath ( *generatedHeader
).c_str () );
1335 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1336 fprintf ( fMakefile
,
1337 "\t%s %s %s -h -H %s %s\n",
1338 "$(Q)$(WIDL_TARGET)",
1339 GetWidlFlags ( compilationUnit
).c_str (),
1340 widlflagsMacro
.c_str (),
1341 backend
->GetFullName ( *generatedHeader
).c_str (),
1342 backend
->GetFullName ( *sourceFile
).c_str () );
1346 MingwModuleHandler::GenerateWidlCommands (
1347 const CompilationUnit
& compilationUnit
,
1348 const string
& widlflagsMacro
)
1350 if ( module
.type
== RpcServer
)
1351 GenerateWidlCommandsServer ( compilationUnit
,
1353 else if ( module
.type
== RpcClient
)
1354 GenerateWidlCommandsClient ( compilationUnit
,
1356 else if ( module
.type
== EmbeddedTypeLib
)
1357 GenerateWidlCommandsEmbeddedTypeLib ( compilationUnit
,
1359 else // applies also for other module.types which include idl files
1360 GenerateWidlCommandsIdlHeader ( compilationUnit
,
1365 MingwModuleHandler::GenerateCommands (
1366 const CompilationUnit
& compilationUnit
,
1367 const string
& extraDependencies
,
1370 const string
& cflagsMacro
,
1371 const string
& nasmflagsMacro
,
1372 const string
& windresflagsMacro
,
1373 const string
& widlflagsMacro
)
1375 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1376 string extension
= GetExtension ( *sourceFile
);
1377 if ( extension
== ".c" || extension
== ".C" )
1379 GenerateGccCommand ( sourceFile
,
1380 GetCompilationUnitDependencies ( compilationUnit
) + extraDependencies
,
1385 else if ( extension
== ".cc" || extension
== ".CC" ||
1386 extension
== ".cpp" || extension
== ".CPP" ||
1387 extension
== ".cxx" || extension
== ".CXX" )
1389 GenerateGccCommand ( sourceFile
,
1390 GetCompilationUnitDependencies ( compilationUnit
) + extraDependencies
,
1395 else if ( extension
== ".s" || extension
== ".S" )
1397 GenerateGccAssemblerCommand ( sourceFile
,
1402 else if ( extension
== ".asm" || extension
== ".ASM" )
1404 GenerateNasmCommand ( sourceFile
,
1408 else if ( extension
== ".rc" || extension
== ".RC" )
1410 GenerateWindresCommand ( sourceFile
,
1411 windresflagsMacro
);
1414 else if ( extension
== ".spec" || extension
== ".SPEC" )
1416 GenerateWinebuildCommands ( sourceFile
);
1417 GenerateGccCommand ( GetActualSourceFilename ( sourceFile
),
1423 else if ( extension
== ".idl" || extension
== ".IDL" )
1425 GenerateWidlCommands ( compilationUnit
,
1427 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
1429 GenerateGccCommand ( GetActualSourceFilename ( sourceFile
),
1430 GetExtraDependencies ( sourceFile
),
1437 throw InvalidOperationException ( __FILE__
,
1439 "Unsupported filename extension '%s' in file '%s'",
1441 backend
->GetFullName ( *sourceFile
).c_str () );
1445 MingwModuleHandler::GenerateBuildMapCode ( const FileLocation
*mapTarget
)
1447 fprintf ( fMakefile
,
1448 "ifeq ($(ROS_BUILDMAP),full)\n" );
1450 FileLocation
mapFilename ( OutputDirectory
,
1451 module
.output
->relative_path
,
1452 GetBasename ( module
.output
->name
) + ".map" );
1453 CLEAN_FILE ( mapFilename
);
1455 fprintf ( fMakefile
,
1456 "\t$(ECHO_OBJDUMP)\n" );
1457 fprintf ( fMakefile
,
1458 "\t$(Q)${objdump} -d -S %s > %s\n",
1459 mapTarget
? backend
->GetFullName ( *mapTarget
).c_str () : "$@",
1460 backend
->GetFullName ( mapFilename
).c_str () );
1462 fprintf ( fMakefile
,
1464 fprintf ( fMakefile
,
1465 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1467 fprintf ( fMakefile
,
1469 fprintf ( fMakefile
,
1470 "\t$(Q)${nm} --numeric-sort %s > %s\n",
1471 mapTarget
? backend
->GetFullName ( *mapTarget
).c_str () : "$@",
1472 backend
->GetFullName ( mapFilename
).c_str () );
1474 fprintf ( fMakefile
,
1477 fprintf ( fMakefile
,
1482 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1484 fprintf ( fMakefile
,
1485 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1487 FileLocation
nostripFilename ( OutputDirectory
,
1488 module
.output
->relative_path
,
1489 GetBasename ( module
.output
->name
) + ".nostrip" + GetExtension ( *module
.output
) );
1490 CLEAN_FILE ( nostripFilename
);
1492 OutputCopyCommand ( *module
.output
, nostripFilename
);
1494 fprintf ( fMakefile
,
1499 MergeStringVector ( const Backend
* backend
,
1500 const vector
<FileLocation
>& input
,
1501 vector
<string
>& output
)
1505 int wrap_count
= -1;
1506 for ( size_t i
= 0; i
< input
.size (); i
++ )
1508 if ( wrap_count
++ == wrap_at
)
1510 output
.push_back ( s
);
1514 else if ( s
.size () > 0)
1516 s
+= backend
->GetFullName ( input
[i
] );
1518 if ( s
.length () > 0 )
1519 output
.push_back ( s
);
1523 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1524 vector
<FileLocation
>& objectFiles
) const
1526 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1528 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1529 objectFiles
.push_back ( *GetObjectFilename ( compilationUnit
.GetFilename (), NULL
) );
1534 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1536 if ( backend
->configuration
.CleanAsYouGo
)
1538 vector
<FileLocation
> objectFiles
;
1539 GetObjectsVector ( module
.non_if_data
,
1541 vector
<string
> lines
;
1542 MergeStringVector ( backend
,
1545 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1547 fprintf ( fMakefile
,
1548 "\t-@${rm} %s 2>$(NUL)\n",
1549 lines
[i
].c_str () );
1555 MingwModuleHandler::GenerateRunRsymCode () const
1557 fprintf ( fMakefile
,
1558 "\t$(ECHO_RSYM)\n" );
1559 fprintf ( fMakefile
,
1560 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1564 MingwModuleHandler::GenerateRunStripCode () const
1566 fprintf ( fMakefile
,
1567 "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" );
1568 fprintf ( fMakefile
,
1569 "\t$(ECHO_STRIP)\n" );
1570 fprintf ( fMakefile
,
1571 "\t${strip} -s -x -X $@\n\n" );
1572 fprintf ( fMakefile
,
1577 MingwModuleHandler::GenerateLinkerCommand (
1578 const string
& dependencies
,
1579 const string
& linker
,
1580 const string
& linkerParameters
,
1581 const string
& objectsMacro
,
1582 const string
& libsMacro
,
1583 const string
& pefixupParameters
)
1585 string
target ( GetTargetMacro ( module
) );
1586 string
target_folder ( backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ) );
1587 const FileLocation
*definitionFilename
= GetDefinitionFilename ();
1589 string linkerScriptArgument
;
1590 if ( module
.linkerScript
!= NULL
)
1591 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", module
.linkerScript
->directory
.c_str () );
1593 linkerScriptArgument
= "";
1595 fprintf ( fMakefile
,
1596 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1598 backend
->GetFullName ( *definitionFilename
).c_str (),
1599 dependencies
.c_str (),
1600 target_folder
.c_str () );
1601 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1602 string
targetName ( module
.output
->name
);
1604 if ( !module
.IsDLL () )
1606 fprintf ( fMakefile
,
1607 "\t%s %s %s -o %s %s %s %s\n",
1609 linkerParameters
.c_str (),
1610 linkerScriptArgument
.c_str (),
1612 objectsMacro
.c_str (),
1614 GetLinkerMacro ().c_str () );
1616 else if ( module
.HasImportLibrary () )
1618 FileLocation
temp_exp ( TemporaryDirectory
,
1620 module
.name
+ ".temp.exp" );
1621 CLEAN_FILE ( temp_exp
);
1623 fprintf ( fMakefile
,
1624 "\t${dlltool} --dllname %s --def %s --output-exp %s %s %s\n",
1625 targetName
.c_str (),
1626 backend
->GetFullName ( *definitionFilename
).c_str (),
1627 backend
->GetFullName ( temp_exp
).c_str (),
1628 module
.mangledSymbols
? "" : "--kill-at",
1629 module
.underscoreSymbols
? "--add-underscore" : "" );
1631 fprintf ( fMakefile
,
1632 "\t%s %s %s %s -o %s %s %s %s\n",
1634 linkerParameters
.c_str (),
1635 linkerScriptArgument
.c_str (),
1636 backend
->GetFullName ( temp_exp
).c_str (),
1638 objectsMacro
.c_str (),
1640 GetLinkerMacro ().c_str () );
1642 fprintf ( fMakefile
,
1643 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1645 pefixupParameters
.c_str() );
1647 fprintf ( fMakefile
,
1648 "\t-@${rm} %s 2>$(NUL)\n",
1649 backend
->GetFullName ( temp_exp
).c_str () );
1653 /* XXX: need to workaround binutils bug, which exports
1654 * all functions in a dll if no .def file or an empty
1655 * one has been provided... */
1657 //printf ( "%s will have all its functions exported\n",
1658 // module.target->name.c_str () );
1659 fprintf ( fMakefile
,
1660 "\t%s %s %s -o %s %s %s %s\n",
1662 linkerParameters
.c_str (),
1663 linkerScriptArgument
.c_str (),
1665 objectsMacro
.c_str (),
1667 GetLinkerMacro ().c_str () );
1670 GenerateBuildMapCode ();
1671 GenerateBuildNonSymbolStrippedCode ();
1672 GenerateRunRsymCode ();
1673 GenerateRunStripCode ();
1674 GenerateCleanObjectsAsYouGoCode ();
1678 MingwModuleHandler::GeneratePhonyTarget() const
1680 string
targetMacro ( GetTargetMacro ( module
) );
1681 fprintf ( fMakefile
,
1683 targetMacro
.c_str ());
1684 fprintf ( fMakefile
, "%s: | %s\n",
1685 targetMacro
.c_str (),
1686 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
1690 MingwModuleHandler::GenerateObjectFileTargets (
1691 const IfableData
& data
,
1694 const string
& cflagsMacro
,
1695 const string
& nasmflagsMacro
,
1696 const string
& windresflagsMacro
,
1697 const string
& widlflagsMacro
)
1700 string moduleDependencies
;
1702 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1703 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1705 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1706 const FileLocation
*objectFilename
= GetObjectFilename ( compilationUnit
.GetFilename (), NULL
);
1707 if ( GetExtension ( *objectFilename
) == ".h" )
1709 moduleDependencies
= ssprintf ( " $(%s_HEADERS)", module
.name
.c_str () );
1714 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1716 GenerateCommands ( *compilationUnits
[i
],
1724 fprintf ( fMakefile
,
1728 const vector
<If
*>& ifs
= data
.ifs
;
1729 for ( i
= 0; i
< ifs
.size(); i
++ )
1731 GenerateObjectFileTargets ( ifs
[i
]->data
,
1740 vector
<CompilationUnit
*> sourceCompilationUnits
;
1741 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1742 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1744 GenerateCommands ( *sourceCompilationUnits
[i
],
1753 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1757 MingwModuleHandler::GenerateObjectFileTargets (
1760 const string
& cflagsMacro
,
1761 const string
& nasmflagsMacro
,
1762 const string
& windresflagsMacro
,
1763 const string
& widlflagsMacro
)
1765 if ( module
.pch
&& use_pch
)
1767 const FileLocation
& baseHeaderFile
= module
.pch
->file
;
1768 const FileLocation
*pchFilename
= GetPrecompiledHeaderFilename ();
1769 CLEAN_FILE ( *pchFilename
);
1770 string dependencies
= backend
->GetFullName ( baseHeaderFile
);
1771 /* WIDL generated headers may be used */
1772 vector
<FileLocation
> rpcDependencies
;
1773 GetRpcHeaderDependencies ( rpcDependencies
);
1774 dependencies
+= " " + v2s ( backend
, rpcDependencies
, 5 );
1775 fprintf ( fMakefile
,
1777 backend
->GetFullName ( *pchFilename
).c_str(),
1778 dependencies
.c_str(),
1779 backend
->GetFullPath ( *pchFilename
).c_str() );
1780 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1781 fprintf ( fMakefile
,
1782 "\t%s -o %s %s -g %s\n\n",
1783 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1784 backend
->GetFullName ( *pchFilename
).c_str(),
1785 cflagsMacro
.c_str(),
1786 backend
->GetFullName ( baseHeaderFile
).c_str() );
1789 GenerateObjectFileTargets ( module
.non_if_data
,
1796 fprintf ( fMakefile
, "\n" );
1800 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1801 const string
& objs_macro
) const
1803 const FileLocation
*archiveFilename
= GetModuleArchiveFilename ();
1805 fprintf ( fMakefile
,
1807 backend
->GetFullName ( *archiveFilename
).c_str (),
1808 objs_macro
.c_str (),
1809 backend
->GetFullPath ( *archiveFilename
).c_str() );
1811 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
1813 const FileLocation
*definitionFilename ( GetDefinitionFilename () );
1815 fprintf ( fMakefile
,
1816 "\t${dlltool} --dllname %s --def %s --output-lib $@ %s %s\n",
1817 module
.importLibrary
->dllname
.c_str (),
1818 backend
->GetFullName ( *definitionFilename
).c_str (),
1819 module
.mangledSymbols
? "" : "--kill-at",
1820 module
.underscoreSymbols
? "--add-underscore" : "" );
1823 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1825 fprintf ( fMakefile
,
1828 objs_macro
.c_str ());
1830 GenerateCleanObjectsAsYouGoCode ();
1832 fprintf ( fMakefile
, "\n" );
1834 return archiveFilename
;
1838 MingwModuleHandler::GetCFlagsMacro () const
1840 return ssprintf ( "$(%s_CFLAGS)",
1841 module
.name
.c_str () );
1845 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1847 return ssprintf ( "$(%s_OBJS)",
1848 module
.name
.c_str () );
1852 MingwModuleHandler::GetLinkingDependenciesMacro () const
1854 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1858 MingwModuleHandler::GetLibsMacro () const
1860 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1864 MingwModuleHandler::GetLinkerMacro () const
1866 return ssprintf ( "$(%s_LFLAGS)",
1867 module
.name
.c_str () );
1871 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1873 if ( ReferenceObjects ( module
) )
1874 return GetObjectsMacro ( module
);
1876 return backend
->GetFullName ( *GetTargetFilename ( module
, NULL
) ).c_str ();
1880 MingwModuleHandler::GenerateObjectMacro ()
1882 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1884 GenerateObjectMacros (
1887 &module
.linkerFlags
);
1889 // future references to the macro will be to get its values
1890 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1894 MingwModuleHandler::GenerateTargetMacro ()
1896 fprintf ( fMakefile
,
1898 GetTargetMacro ( module
, false ).c_str (),
1899 GetModuleTargets ( module
).c_str () );
1903 MingwModuleHandler::GetRpcHeaderDependencies (
1904 vector
<FileLocation
>& dependencies
) const
1906 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1908 Library
& library
= *module
.non_if_data
.libraries
[i
];
1909 if ( library
.importedModule
->type
== RpcServer
||
1910 library
.importedModule
->type
== RpcClient
||
1911 library
.importedModule
->type
== IdlHeader
)
1913 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
1915 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
1916 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1917 string extension
= GetExtension ( *sourceFile
);
1918 if ( extension
== ".idl" || extension
== ".IDL" )
1920 string basename
= GetBasename ( sourceFile
->name
);
1921 if ( library
.importedModule
->type
== RpcServer
)
1922 dependencies
.push_back ( *GetRpcServerHeaderFilename ( sourceFile
) );
1923 if ( library
.importedModule
->type
== RpcClient
)
1924 dependencies
.push_back ( *GetRpcClientHeaderFilename ( sourceFile
) );
1925 if ( library
.importedModule
->type
== IdlHeader
)
1926 dependencies
.push_back ( *GetIdlHeaderFilename ( sourceFile
) );
1934 MingwModuleHandler::GenerateOtherMacros ()
1936 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1937 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1938 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1939 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1940 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1941 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1942 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1947 &module
.linkerFlags
);
1949 vector
<FileLocation
> s
;
1950 if ( module
.importLibrary
)
1952 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
1953 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
1955 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1956 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1957 string extension
= GetExtension ( *sourceFile
);
1958 if ( extension
== ".spec" || extension
== ".SPEC" )
1959 GetSpecObjectDependencies ( s
, sourceFile
);
1962 if ( s
.size () > 0 )
1967 linkDepsMacro
.c_str() );
1968 for ( size_t i
= 0; i
< s
.size(); i
++ )
1969 fprintf ( fMakefile
,
1971 backend
->GetFullName ( s
[i
] ).c_str () );
1972 fprintf ( fMakefile
, "\n" );
1975 string globalCflags
= "-g";
1976 if ( backend
->usePipe
)
1977 globalCflags
+= " -pipe";
1978 if ( !module
.allowWarnings
)
1979 globalCflags
+= " -Werror";
1980 if ( module
.host
== HostTrue
)
1982 if ( module
.cplusplus
)
1983 globalCflags
+= " $(HOST_CPPFLAGS)";
1985 globalCflags
+= " $(HOST_CFLAGS)";
1989 if ( module
.cplusplus
)
1991 // HACK: use host headers when building C++
1992 globalCflags
+= " $(HOST_CPPFLAGS)";
1995 globalCflags
+= " -nostdinc";
1998 // Always force disabling of sibling calls optimisation for GCC
1999 // (TODO: Move to version-specific once this bug is fixed in GCC)
2000 globalCflags
+= " -fno-optimize-sibling-calls";
2004 "%s += $(PROJECT_CFLAGS) %s\n",
2005 cflagsMacro
.c_str (),
2006 globalCflags
.c_str () );
2010 "%s += $(PROJECT_RCFLAGS)\n",
2011 windresflagsMacro
.c_str () );
2015 "%s += $(PROJECT_WIDLFLAGS) -I%s\n",
2016 widlflagsMacro
.c_str (),
2017 module
.output
->relative_path
.c_str () );
2021 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
2022 module
.name
.c_str () );
2027 linkDepsMacro
.c_str (),
2028 libsMacro
.c_str () );
2030 string cflags
= TypeSpecificCFlags();
2031 if ( cflags
.size() > 0 )
2033 fprintf ( fMakefile
,
2035 cflagsMacro
.c_str (),
2039 string nasmflags
= TypeSpecificNasmFlags();
2040 if ( nasmflags
.size () > 0 )
2042 fprintf ( fMakefile
,
2044 nasmflagsMacro
.c_str (),
2045 nasmflags
.c_str () );
2048 string linkerflags
= TypeSpecificLinkerFlags();
2049 if ( linkerflags
.size() > 0 )
2051 fprintf ( fMakefile
,
2053 linkerflagsMacro
.c_str (),
2054 linkerflags
.c_str () );
2057 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
2059 fprintf ( fMakefile
,
2060 "%s += -Wno-main\n\n",
2061 cflagsMacro
.c_str () );
2064 fprintf ( fMakefile
, "\n\n" );
2066 // future references to the macros will be to get their values
2067 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
2068 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
2069 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
2073 MingwModuleHandler::GenerateRules ()
2075 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
2076 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
2077 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
2079 if ( module
.name
!= "zlib" ) /* Avoid make warning */
2081 FileLocation
proxyMakefile ( OutputDirectory
,
2082 module
.output
->relative_path
,
2084 CLEAN_FILE ( proxyMakefile
);
2087 string targetMacro
= GetTargetMacro ( module
);
2088 //CLEAN_FILE ( targetMacro );
2089 CLEAN_FILE ( FileLocation ( SourceDirectory
, "", targetMacro
) );
2091 // generate phony target for module name
2092 fprintf ( fMakefile
, ".PHONY: %s\n",
2093 module
.name
.c_str () );
2094 string dependencies
= GetTargetMacro ( module
);
2095 if ( module
.type
== Test
)
2096 dependencies
+= " $(REGTESTS_RUN_TARGET)";
2097 fprintf ( fMakefile
, "%s: %s\n\n",
2098 module
.name
.c_str (),
2099 dependencies
.c_str () );
2100 if ( module
.type
== Test
)
2102 fprintf ( fMakefile
,
2104 targetMacro
.c_str ());
2107 if ( !ReferenceObjects ( module
) )
2109 const FileLocation
* ar_target
= GenerateArchiveTarget ( ar
, objectsMacro
);
2110 CLEAN_FILE ( *ar_target
);
2113 GenerateObjectFileTargets ( cc
,
2122 MingwModuleHandler::GetInvocationDependencies (
2123 const Module
& module
,
2124 string_list
& dependencies
)
2126 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
2128 Invoke
& invoke
= *module
.invocations
[i
];
2129 if ( invoke
.invokeModule
== &module
)
2130 /* Protect against circular dependencies */
2132 invoke
.GetTargets ( dependencies
);
2137 MingwModuleHandler::GenerateInvocations () const
2139 if ( module
.invocations
.size () == 0 )
2142 size_t iend
= module
.invocations
.size ();
2143 for ( size_t i
= 0; i
< iend
; i
++ )
2145 const Invoke
& invoke
= *module
.invocations
[i
];
2147 if ( invoke
.invokeModule
->type
!= BuildTool
)
2149 throw XMLInvalidBuildFileException (
2150 module
.node
.location
,
2151 "Only modules of type buildtool can be invoked." );
2154 string invokeTarget
= module
.GetInvocationTarget ( i
);
2155 string_list invoke_targets
;
2156 assert ( invoke_targets
.size() );
2157 invoke
.GetTargets ( invoke_targets
);
2158 fprintf ( fMakefile
,
2160 invokeTarget
.c_str () );
2161 fprintf ( fMakefile
,
2163 invokeTarget
.c_str () );
2164 size_t j
, jend
= invoke_targets
.size();
2165 for ( j
= 0; j
< jend
; j
++ )
2167 fprintf ( fMakefile
,
2169 invoke_targets
[i
].c_str () );
2171 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
2172 for ( j
= 1; j
< jend
; j
++ )
2173 fprintf ( fMakefile
,
2175 invoke_targets
[i
].c_str () );
2176 fprintf ( fMakefile
,
2178 NormalizeFilename ( backend
->GetFullName ( *invoke
.invokeModule
->output
) ).c_str () );
2179 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
2180 fprintf ( fMakefile
,
2182 NormalizeFilename ( backend
->GetFullName ( *invoke
.invokeModule
->output
) ).c_str (),
2183 invoke
.GetParameters ().c_str () );
2188 MingwModuleHandler::GetPreconditionDependenciesName () const
2190 return module
.name
+ "_precondition";
2194 MingwModuleHandler::GetDefaultDependencies (
2195 string_list
& dependencies
) const
2197 /* Avoid circular dependency */
2198 if ( module
.type
!= BuildTool
2199 && module
.name
!= "zlib"
2200 && module
.name
!= "hostzlib" )
2202 dependencies
.push_back ( "$(INIT)" );
2204 if ( module
.type
!= BuildTool
2205 && module
.name
!= "psdk" )
2207 dependencies
.push_back ( "$(PSDK_TARGET) $(psdk_HEADERS)" );
2211 MingwModuleHandler::GeneratePreconditionDependencies ()
2213 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2214 vector
<FileLocation
> sourceFilenames
;
2215 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
2216 string_list dependencies
;
2217 GetDefaultDependencies ( dependencies
);
2218 GetModuleDependencies ( dependencies
);
2220 GetInvocationDependencies ( module
, dependencies
);
2222 if ( dependencies
.size() )
2224 fprintf ( fMakefile
,
2226 preconditionDependenciesName
.c_str () );
2227 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2228 fprintf ( fMakefile
,
2230 dependencies
[i
].c_str () );
2231 fprintf ( fMakefile
, "\n\n" );
2234 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
2236 fprintf ( fMakefile
,
2238 backend
->GetFullName ( sourceFilenames
[i
] ).c_str (),
2239 preconditionDependenciesName
.c_str ());
2241 fprintf ( fMakefile
, "\n" );
2245 MingwModuleHandler::IsWineModule () const
2247 if ( module
.importLibrary
== NULL
)
2250 size_t index
= module
.importLibrary
->source
->name
.rfind ( ".spec.def" );
2251 return ( index
!= string::npos
);
2255 MingwModuleHandler::GetDefinitionFilename () const
2257 if ( module
.importLibrary
!= NULL
)
2259 DirectoryLocation directory
;
2260 if ( IsWineModule () )
2261 directory
= IntermediateDirectory
;
2263 directory
= SourceDirectory
;
2265 return new FileLocation ( directory
,
2266 module
.importLibrary
->source
->relative_path
,
2267 module
.importLibrary
->source
->name
);
2270 return new FileLocation ( SourceDirectory
, "tools" + sSep
+ "rbuild", "empty.def" );
2274 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2276 if ( module
.importLibrary
!= NULL
)
2278 const FileLocation
*library_target
= GetImportLibraryFilename ( module
, &clean_files
);
2279 const FileLocation
*defFilename
= GetDefinitionFilename ();
2281 vector
<FileLocation
> deps
;
2282 GetDefinitionDependencies ( deps
);
2284 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2286 fprintf ( fMakefile
, "%s: %s",
2287 backend
->GetFullName ( *library_target
).c_str (),
2288 backend
->GetFullName ( *defFilename
).c_str () );
2290 size_t i
, iend
= deps
.size();
2291 for ( i
= 0; i
< iend
; i
++ )
2292 fprintf ( fMakefile
, " %s",
2293 backend
->GetFullName ( deps
[i
] ).c_str () );
2295 fprintf ( fMakefile
, " | %s\n",
2296 backend
->GetFullPath ( *GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2298 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2300 fprintf ( fMakefile
,
2301 "\t${dlltool} --dllname %s --def %s --output-lib %s %s %s\n\n",
2302 module
.output
->name
.c_str (),
2303 backend
->GetFullName ( *defFilename
).c_str (),
2304 backend
->GetFullName ( *library_target
).c_str (),
2305 module
.mangledSymbols
? "" : "--kill-at",
2306 module
.underscoreSymbols
? "--add-underscore" : "" );
2311 MingwModuleHandler::GetSpecObjectDependencies (
2312 vector
<FileLocation
>& dependencies
,
2313 const FileLocation
*file
) const
2315 string basename
= GetBasename ( file
->name
);
2317 FileLocation
defDependency ( IntermediateDirectory
,
2318 file
->relative_path
,
2319 basename
+ ".spec.def" );
2320 dependencies
.push_back ( defDependency
);
2322 FileLocation
stubsDependency ( IntermediateDirectory
,
2323 file
->relative_path
,
2324 basename
+ ".stubs.c" );
2325 dependencies
.push_back ( stubsDependency
);
2329 MingwModuleHandler::GetWidlObjectDependencies (
2330 vector
<FileLocation
>& dependencies
,
2331 const FileLocation
*file
) const
2333 string basename
= GetBasename ( file
->name
);
2335 FileLocation
serverSourceDependency ( IntermediateDirectory
,
2336 file
->relative_path
,
2337 basename
+ "_s.c" );
2338 dependencies
.push_back ( serverSourceDependency
);
2339 dependencies
.push_back ( *GetRpcServerHeaderFilename ( file
) );
2343 MingwModuleHandler::GetDefinitionDependencies (
2344 vector
<FileLocation
>& dependencies
) const
2346 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2347 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2349 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2350 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
2351 string extension
= GetExtension ( *sourceFile
);
2352 if ( extension
== ".spec" || extension
== ".SPEC" )
2353 GetSpecObjectDependencies ( dependencies
, sourceFile
);
2354 if ( extension
== ".idl" || extension
== ".IDL" )
2356 if ( ( module
.type
== RpcServer
) || ( module
.type
== RpcClient
) )
2357 GetWidlObjectDependencies ( dependencies
, sourceFile
);
2362 enum DebugSupportType
2369 MingwAddDebugSupportLibraries ( Module
& module
, DebugSupportType type
)
2375 case DebugKernelMode
:
2376 pLibrary
= new Library ( module
, "debugsup_ntoskrnl" );
2380 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2387 module
.non_if_data
.libraries
.push_back(pLibrary
);
2390 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2391 : MingwModuleHandler ( module_
)
2396 MingwBuildToolModuleHandler::Process ()
2398 GenerateBuildToolModuleTarget ();
2402 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2404 string
targetMacro ( GetTargetMacro (module
) );
2405 string objectsMacro
= GetObjectsMacro ( module
);
2406 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2407 string libsMacro
= GetLibsMacro ();
2412 if ( module
.cplusplus
)
2413 linker
= "${host_gpp}";
2415 linker
= "${host_gcc}";
2417 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2418 targetMacro
.c_str (),
2419 objectsMacro
.c_str (),
2420 linkDepsMacro
.c_str (),
2421 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
2422 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2423 fprintf ( fMakefile
,
2424 "\t%s %s -o $@ %s %s\n\n",
2426 GetLinkerMacro ().c_str (),
2427 objectsMacro
.c_str (),
2428 libsMacro
.c_str () );
2432 MingwKernelModuleHandler::MingwKernelModuleHandler (
2433 const Module
& module_
)
2435 : MingwModuleHandler ( module_
)
2440 MingwKernelModuleHandler::Process ()
2442 GenerateKernelModuleTarget ();
2446 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2448 string
targetMacro ( GetTargetMacro ( module
) );
2449 string workingDirectory
= GetWorkingDirectory ( );
2450 string objectsMacro
= GetObjectsMacro ( module
);
2451 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2452 string libsMacro
= GetLibsMacro ();
2454 GenerateImportLibraryTargetIfNeeded ();
2456 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2460 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2462 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",
2463 module
.output
->relative_path
.c_str (),
2465 module
.GetEntryPoint(true).c_str (),
2466 module
.baseaddress
.c_str () );
2467 GenerateLinkerCommand ( dependencies
,
2476 GeneratePhonyTarget();
2481 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2482 const Module
& module_
)
2484 : MingwModuleHandler ( module_
)
2489 MingwStaticLibraryModuleHandler::Process ()
2491 GenerateStaticLibraryModuleTarget ();
2495 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2501 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2502 const Module
& module_
)
2504 : MingwModuleHandler ( module_
)
2509 MingwObjectLibraryModuleHandler::Process ()
2511 GenerateObjectLibraryModuleTarget ();
2515 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2521 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2522 const Module
& module_
)
2524 : MingwModuleHandler ( module_
)
2528 MingwEmbeddedTypeLibModuleHandler::MingwEmbeddedTypeLibModuleHandler (
2529 const Module
& module_
)
2531 : MingwModuleHandler ( module_
)
2536 MingwEmbeddedTypeLibModuleHandler::Process ()
2543 MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2545 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2549 MingwKernelModeDLLModuleHandler::Process ()
2551 GenerateKernelModeDLLModuleTarget ();
2555 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2557 string
targetMacro ( GetTargetMacro ( module
) );
2558 string workingDirectory
= GetWorkingDirectory ( );
2559 string objectsMacro
= GetObjectsMacro ( module
);
2560 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2561 string libsMacro
= GetLibsMacro ();
2563 GenerateImportLibraryTargetIfNeeded ();
2565 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2569 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2571 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2572 module
.GetEntryPoint(true).c_str (),
2573 module
.baseaddress
.c_str () );
2574 GenerateLinkerCommand ( dependencies
,
2583 GeneratePhonyTarget();
2588 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2589 const Module
& module_
)
2591 : MingwModuleHandler ( module_
)
2596 MingwKernelModeDriverModuleHandler::AddImplicitLibraries ( Module
& module
)
2598 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2602 MingwKernelModeDriverModuleHandler::Process ()
2604 GenerateKernelModeDriverModuleTarget ();
2609 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2611 string
targetMacro ( GetTargetMacro (module
) );
2612 string workingDirectory
= GetWorkingDirectory ();
2613 string objectsMacro
= GetObjectsMacro ( module
);
2614 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2615 string libsMacro
= GetLibsMacro ();
2617 GenerateImportLibraryTargetIfNeeded ();
2619 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2623 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2625 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2626 module
.GetEntryPoint(true).c_str (),
2627 module
.baseaddress
.c_str () );
2628 GenerateLinkerCommand ( dependencies
,
2637 GeneratePhonyTarget();
2642 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2643 const Module
& module_
)
2645 : MingwModuleHandler ( module_
)
2650 MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2652 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2656 MingwNativeDLLModuleHandler::Process ()
2658 GenerateNativeDLLModuleTarget ();
2662 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2664 string
targetMacro ( GetTargetMacro (module
) );
2665 string workingDirectory
= GetWorkingDirectory ( );
2666 string objectsMacro
= GetObjectsMacro ( module
);
2667 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2668 string libsMacro
= GetLibsMacro ();
2670 GenerateImportLibraryTargetIfNeeded ();
2672 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2676 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2678 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2679 module
.GetEntryPoint(true).c_str (),
2680 module
.baseaddress
.c_str () );
2681 GenerateLinkerCommand ( dependencies
,
2690 GeneratePhonyTarget();
2695 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2696 const Module
& module_
)
2698 : MingwModuleHandler ( module_
)
2703 MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2705 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2709 MingwNativeCUIModuleHandler::Process ()
2711 GenerateNativeCUIModuleTarget ();
2715 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2717 string
targetMacro ( GetTargetMacro (module
) );
2718 string workingDirectory
= GetWorkingDirectory ( );
2719 string objectsMacro
= GetObjectsMacro ( module
);
2720 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2721 string libsMacro
= GetLibsMacro ();
2723 GenerateImportLibraryTargetIfNeeded ();
2725 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2729 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2731 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2732 module
.GetEntryPoint(true).c_str (),
2733 module
.baseaddress
.c_str () );
2734 GenerateLinkerCommand ( dependencies
,
2743 GeneratePhonyTarget();
2748 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2749 const Module
& module_
)
2751 : MingwModuleHandler ( module_
)
2755 MingwWin32OCXModuleHandler::MingwWin32OCXModuleHandler (
2756 const Module
& module_
)
2758 : MingwModuleHandler ( module_
)
2763 MingwAddImplicitLibraries( Module
&module
)
2767 if ( !module
.isDefaultEntryPoint
)
2769 if ( module
.GetEntryPoint(false) == "0" )
2771 pLibrary
= new Library ( module
, "mingw_common" );
2772 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() , pLibrary
);
2773 pLibrary
= new Library ( module
, "msvcrt" );
2774 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2779 if ( module
.IsDLL () )
2781 //pLibrary = new Library ( module, "__mingw_dllmain" );
2782 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
2786 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
2787 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
2790 pLibrary
= new Library ( module
, "mingw_common" );
2791 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
2793 if ( module
.name
!= "msvcrt" )
2795 // always link in msvcrt to get the basic routines
2796 pLibrary
= new Library ( module
, "msvcrt" );
2797 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2802 MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2804 MingwAddImplicitLibraries ( module
);
2805 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2809 MingwWin32DLLModuleHandler::Process ()
2811 GenerateWin32DLLModuleTarget ();
2815 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2817 string
targetMacro ( GetTargetMacro (module
) );
2818 string workingDirectory
= GetWorkingDirectory ( );
2819 string objectsMacro
= GetObjectsMacro ( module
);
2820 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2821 string libsMacro
= GetLibsMacro ();
2823 GenerateImportLibraryTargetIfNeeded ();
2825 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2829 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2832 if ( module
.cplusplus
)
2837 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2838 module
.GetEntryPoint(true).c_str (),
2839 module
.baseaddress
.c_str () );
2840 GenerateLinkerCommand ( dependencies
,
2849 GeneratePhonyTarget();
2855 MingwWin32OCXModuleHandler::AddImplicitLibraries ( Module
& module
)
2857 MingwAddImplicitLibraries ( module
);
2858 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2862 MingwWin32OCXModuleHandler::Process ()
2864 GenerateWin32OCXModuleTarget ();
2868 MingwWin32OCXModuleHandler::GenerateWin32OCXModuleTarget ()
2870 string
targetMacro ( GetTargetMacro (module
) );
2871 string workingDirectory
= GetWorkingDirectory ( );
2872 string objectsMacro
= GetObjectsMacro ( module
);
2873 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2874 string libsMacro
= GetLibsMacro ();
2876 GenerateImportLibraryTargetIfNeeded ();
2878 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2882 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2885 if ( module
.cplusplus
)
2890 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2891 module
.GetEntryPoint(true).c_str (),
2892 module
.baseaddress
.c_str () );
2893 GenerateLinkerCommand ( dependencies
,
2902 GeneratePhonyTarget();
2907 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2908 const Module
& module_
)
2910 : MingwModuleHandler ( module_
)
2915 MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2917 MingwAddImplicitLibraries ( module
);
2918 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2922 MingwWin32CUIModuleHandler::Process ()
2924 GenerateWin32CUIModuleTarget ();
2928 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2930 string
targetMacro ( GetTargetMacro (module
) );
2931 string workingDirectory
= GetWorkingDirectory ( );
2932 string objectsMacro
= GetObjectsMacro ( module
);
2933 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2934 string libsMacro
= GetLibsMacro ();
2936 GenerateImportLibraryTargetIfNeeded ();
2938 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2942 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2945 if ( module
.cplusplus
)
2950 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2951 module
.GetEntryPoint(true).c_str (),
2952 module
.baseaddress
.c_str () );
2953 GenerateLinkerCommand ( dependencies
,
2962 GeneratePhonyTarget();
2967 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2968 const Module
& module_
)
2970 : MingwModuleHandler ( module_
)
2975 MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2977 MingwAddImplicitLibraries ( module
);
2978 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2982 MingwWin32GUIModuleHandler::Process ()
2984 GenerateWin32GUIModuleTarget ();
2988 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2990 string
targetMacro ( GetTargetMacro (module
) );
2991 string workingDirectory
= GetWorkingDirectory ( );
2992 string objectsMacro
= GetObjectsMacro ( module
);
2993 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2994 string libsMacro
= GetLibsMacro ();
2996 GenerateImportLibraryTargetIfNeeded ();
2998 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3002 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3005 if ( module
.cplusplus
)
3010 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3011 module
.GetEntryPoint(true).c_str (),
3012 module
.baseaddress
.c_str () );
3013 GenerateLinkerCommand ( dependencies
,
3022 GeneratePhonyTarget();
3027 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
3028 const Module
& module_
)
3030 : MingwModuleHandler ( module_
)
3035 MingwBootLoaderModuleHandler::Process ()
3037 GenerateBootLoaderModuleTarget ();
3041 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
3043 string
targetName ( module
.output
->name
);
3044 string
targetMacro ( GetTargetMacro (module
) );
3045 string workingDirectory
= GetWorkingDirectory ();
3046 FileLocation
junk_tmp ( TemporaryDirectory
,
3048 module
.name
+ ".junk.tmp" );
3049 CLEAN_FILE ( junk_tmp
);
3050 string objectsMacro
= GetObjectsMacro ( module
);
3051 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3052 string libsMacro
= GetLibsMacro ();
3056 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3057 targetMacro
.c_str (),
3058 objectsMacro
.c_str (),
3059 linkDepsMacro
.c_str (),
3060 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
3062 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
3064 fprintf ( fMakefile
,
3065 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
3066 GetLinkerMacro ().c_str (),
3067 backend
->GetFullName ( junk_tmp
).c_str (),
3068 objectsMacro
.c_str (),
3069 linkDepsMacro
.c_str () );
3070 fprintf ( fMakefile
,
3071 "\t${objcopy} -O binary %s $@\n",
3072 backend
->GetFullName ( junk_tmp
).c_str () );
3073 GenerateBuildMapCode ( &junk_tmp
);
3074 fprintf ( fMakefile
,
3075 "\t-@${rm} %s 2>$(NUL)\n",
3076 backend
->GetFullName ( junk_tmp
).c_str () );
3080 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
3081 const Module
& module_
)
3083 : MingwModuleHandler ( module_
)
3088 MingwBootSectorModuleHandler::Process ()
3090 GenerateBootSectorModuleTarget ();
3094 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
3096 string objectsMacro
= GetObjectsMacro ( module
);
3100 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3101 module
.name
.c_str ());
3102 fprintf ( fMakefile
,
3104 module
.name
.c_str (),
3105 objectsMacro
.c_str () );
3109 MingwBootProgramModuleHandler::MingwBootProgramModuleHandler (
3110 const Module
& module_
)
3111 : MingwModuleHandler ( module_
)
3116 MingwBootProgramModuleHandler::Process ()
3118 GenerateBootProgramModuleTarget ();
3122 MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
3124 string
targetName ( module
.output
->name
);
3125 string
targetMacro ( GetTargetMacro (module
) );
3126 string workingDirectory
= GetWorkingDirectory ();
3127 FileLocation
junk_tmp ( TemporaryDirectory
,
3129 module
.name
+ ".junk.tmp" );
3130 FileLocation
junk_elf ( TemporaryDirectory
,
3132 module
.name
+ ".junk.elf" );
3133 FileLocation
junk_cpy ( TemporaryDirectory
,
3135 module
.name
+ ".junk.elf" );
3136 CLEAN_FILE ( junk_tmp
);
3137 CLEAN_FILE ( junk_elf
);
3138 CLEAN_FILE ( junk_cpy
);
3139 string objectsMacro
= GetObjectsMacro ( module
);
3140 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3141 string libsMacro
= GetLibsMacro ();
3142 const Module
*payload
= module
.project
.LocateModule ( module
.payload
);
3146 fprintf ( fMakefile
, "%s: %s %s %s | %s\n",
3147 targetMacro
.c_str (),
3148 objectsMacro
.c_str (),
3149 linkDepsMacro
.c_str (),
3150 payload
->name
.c_str (),
3151 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
3153 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3155 fprintf ( fMakefile
, "\t$(%s_PREPARE) $(OUTPUT)$(SEP)%s %s\n",
3156 module
.buildtype
.c_str (),
3157 NormalizeFilename( backend
->GetFullName ( *payload
->output
) ).c_str (),
3158 backend
->GetFullName ( junk_cpy
).c_str () );
3160 fprintf ( fMakefile
, "\t${objcopy} $(%s_FLATFORMAT) %s %s\n",
3161 module
.buildtype
.c_str (),
3162 backend
->GetFullName ( junk_cpy
).c_str (),
3163 backend
->GetFullName ( junk_tmp
).c_str () );
3165 fprintf ( fMakefile
, "\t${ld} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3166 module
.buildtype
.c_str (),
3167 linkDepsMacro
.c_str (),
3168 backend
->GetFullName ( junk_tmp
).c_str (),
3169 backend
->GetFullName ( junk_elf
).c_str () );
3171 fprintf ( fMakefile
, "\t${objcopy} $(%s_COPYFORMAT) %s $(INTERMEDIATE)$(SEP)%s\n",
3172 module
.buildtype
.c_str (),
3173 backend
->GetFullName ( junk_elf
).c_str (),
3174 backend
->GetFullName ( *module
.output
) .c_str () );
3176 fprintf ( fMakefile
,
3177 "\t-@${rm} %s %s %s 2>$(NUL)\n",
3178 backend
->GetFullName ( junk_tmp
).c_str (),
3179 backend
->GetFullName ( junk_elf
).c_str (),
3180 backend
->GetFullName ( junk_cpy
).c_str () );
3184 MingwIsoModuleHandler::MingwIsoModuleHandler (
3185 const Module
& module_
)
3187 : MingwModuleHandler ( module_
)
3192 MingwIsoModuleHandler::Process ()
3194 GenerateIsoModuleTarget ();
3198 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
3199 const string
& bootcdDirectory
)
3201 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3203 const Module
& m
= *module
.project
.modules
[i
];
3206 if ( m
.bootstrap
!= NULL
)
3208 FileLocation
targetFile ( OutputDirectory
,
3209 bootcdDirectory
+ sSep
+ m
.bootstrap
->base
,
3210 m
.bootstrap
->nameoncd
);
3211 OutputCopyCommand ( *m
.output
, targetFile
);
3217 MingwIsoModuleHandler::OutputCdfileCopyCommands (
3218 const string
& bootcdDirectory
)
3220 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3222 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3223 FileLocation
targetFile ( OutputDirectory
,
3224 cdfile
.target
->relative_path
.length () > 0
3225 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3227 cdfile
.target
->name
);
3228 OutputCopyCommand ( *cdfile
.source
, targetFile
);
3233 MingwIsoModuleHandler::GetBootstrapCdDirectories ( vector
<FileLocation
>& out
,
3234 const string
& bootcdDirectory
)
3236 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3238 const Module
& m
= *module
.project
.modules
[i
];
3241 if ( m
.bootstrap
!= NULL
)
3243 FileLocation
targetDirectory ( OutputDirectory
,
3244 bootcdDirectory
+ sSep
+ m
.bootstrap
->base
,
3246 out
.push_back ( targetDirectory
);
3252 MingwIsoModuleHandler::GetNonModuleCdDirectories ( vector
<FileLocation
>& out
,
3253 const string
& bootcdDirectory
)
3255 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3257 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3258 FileLocation
targetDirectory ( OutputDirectory
,
3259 cdfile
.target
->relative_path
.length () > 0
3260 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3263 out
.push_back( targetDirectory
);
3268 MingwIsoModuleHandler::GetCdDirectories ( vector
<FileLocation
>& out
,
3269 const string
& bootcdDirectory
)
3271 GetBootstrapCdDirectories ( out
, bootcdDirectory
);
3272 GetNonModuleCdDirectories ( out
, bootcdDirectory
);
3276 MingwIsoModuleHandler::GetBootstrapCdFiles (
3277 vector
<FileLocation
>& out
) const
3279 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3281 const Module
& m
= *module
.project
.modules
[i
];
3284 if ( m
.bootstrap
!= NULL
)
3286 out
.push_back ( *m
.output
);
3292 MingwIsoModuleHandler::GetNonModuleCdFiles (
3293 vector
<FileLocation
>& out
) const
3295 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3297 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3298 out
.push_back ( *cdfile
.source
);
3303 MingwIsoModuleHandler::GetCdFiles (
3304 vector
<FileLocation
>& out
) const
3306 GetBootstrapCdFiles ( out
);
3307 GetNonModuleCdFiles ( out
);
3311 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
3313 string bootcdDirectory
= "cd";
3314 FileLocation
bootcd ( OutputDirectory
,
3317 FileLocation
bootcdReactos ( OutputDirectory
,
3318 bootcdDirectory
+ sSep
+ Environment::GetCdOutputPath (),
3320 vector
<FileLocation
> vSourceFiles
, vCdFiles
;
3321 vector
<FileLocation
> vCdDirectories
;
3324 FileLocation
srcunattend ( SourceDirectory
,
3325 "boot" + sSep
+ "bootdata" + sSep
+ "bootcdregtest",
3327 FileLocation
tarunattend ( bootcdReactos
.directory
,
3328 bootcdReactos
.relative_path
,
3330 if (module
.type
== IsoRegTest
)
3331 vSourceFiles
.push_back ( srcunattend
);
3334 FileLocation
isoboot ( OutputDirectory
,
3335 "boot" + sSep
+ "freeldr" + sSep
+ "bootsect",
3336 module
.type
== IsoRegTest
3339 vSourceFiles
.push_back ( isoboot
);
3341 // prepare reactos.dff and reactos.inf
3342 FileLocation
reactosDff ( SourceDirectory
,
3343 "boot" + sSep
+ "bootdata" + sSep
+ "packages",
3345 FileLocation
reactosInf ( bootcdReactos
.directory
,
3346 bootcdReactos
.relative_path
,
3348 vSourceFiles
.push_back ( reactosDff
);
3352 if (module
.type
== IsoRegTest
)
3353 IsoName
= "ReactOS-RegTest.iso";
3355 IsoName
= "ReactOS.iso";
3358 string sourceFiles
= v2s ( backend
, vSourceFiles
, 5 );
3361 GetCdDirectories ( vCdDirectories
, bootcdDirectory
);
3362 GetCdFiles ( vCdFiles
);
3363 string cdDirectories
= "";//v2s ( vCdDirectories, 5 );
3364 string cdFiles
= v2s ( backend
, vCdFiles
, 5 );
3366 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3367 module
.name
.c_str ());
3368 fprintf ( fMakefile
,
3369 "%s: all %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET) %s\n",
3370 module
.name
.c_str (),
3371 backend
->GetFullName ( isoboot
).c_str (),
3372 sourceFiles
.c_str (),
3374 cdDirectories
.c_str () );
3375 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
3376 fprintf ( fMakefile
,
3377 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
3378 backend
->GetFullName ( reactosDff
).c_str (),
3379 backend
->GetFullPath ( bootcdReactos
).c_str () );
3380 fprintf ( fMakefile
,
3381 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
3382 backend
->GetFullName ( reactosDff
).c_str (),
3383 backend
->GetFullName ( reactosInf
).c_str (),
3384 backend
->GetFullPath ( bootcdReactos
).c_str ());
3385 fprintf ( fMakefile
,
3386 "\t-@${rm} %s 2>$(NUL)\n",
3387 backend
->GetFullName ( reactosInf
).c_str () );
3388 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
3389 OutputCdfileCopyCommands ( bootcdDirectory
);
3391 if (module
.type
== IsoRegTest
)
3392 OutputCopyCommand ( srcunattend
, tarunattend
);
3394 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3395 fprintf ( fMakefile
,
3396 "\t$(Q)$(CDMAKE_TARGET) -v -j -m -b %s %s REACTOS %s\n",
3397 backend
->GetFullName ( isoboot
).c_str (),
3398 backend
->GetFullPath ( bootcd
).c_str (),
3400 fprintf ( fMakefile
,
3405 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
3406 const Module
& module_
)
3408 : MingwModuleHandler ( module_
)
3413 MingwLiveIsoModuleHandler::Process ()
3415 GenerateLiveIsoModuleTarget ();
3419 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
3421 FileLocation
dir ( OutputDirectory
,
3424 MingwModuleHandler::PassThruCacheDirectory ( &dir
);
3428 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
3429 string
& reactosDirectory
)
3431 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3433 const Module
& m
= *module
.project
.modules
[i
];
3438 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
3439 FileLocation
destination ( OutputDirectory
,
3440 m
.install
->relative_path
.length () > 0
3441 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.install
->relative_path
3442 : livecdDirectory
+ sSep
+ reactosDirectory
,
3444 OutputCopyCommand ( *aliasedModule
.output
,
3451 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
3452 string
& reactosDirectory
)
3454 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
3456 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
3457 FileLocation
target ( OutputDirectory
,
3458 installfile
.target
->relative_path
.length () > 0
3459 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.target
->relative_path
3460 : livecdDirectory
+ sSep
+ reactosDirectory
,
3461 installfile
.target
->name
);
3462 OutputCopyCommand ( *installfile
.source
, target
);
3467 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
3469 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
3470 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
3471 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
3472 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
3473 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
3474 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
3476 FileLocation
livecdIni ( SourceDirectory
,
3477 "boot" + sSep
+ "bootdata",
3479 FileLocation
destination ( OutputDirectory
,
3482 OutputCopyCommand ( livecdIni
,
3487 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3489 FileLocation
freeldr ( OutputDirectory
,
3490 "boot" + sSep
+ "freeldr" + sSep
+ "freeldr",
3492 FileLocation
destination ( OutputDirectory
,
3493 livecdDirectory
+ sSep
+ "loader",
3495 OutputCopyCommand ( freeldr
,
3500 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3502 FileLocation
reactosSystem32ConfigDirectory ( OutputDirectory
,
3503 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config",
3505 fprintf ( fMakefile
,
3506 "\t$(ECHO_MKHIVE)\n" );
3507 fprintf ( fMakefile
,
3508 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%clivecd.inf boot%cbootdata%chiveinst.inf\n",
3509 cSep
, backend
->GetFullPath ( reactosSystem32ConfigDirectory
).c_str (),
3510 cSep
, cSep
, cSep
, cSep
);
3514 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
3516 string livecdDirectory
= module
.name
;
3517 FileLocation
livecd ( OutputDirectory
, livecdDirectory
, "" );
3522 if (module
.name
== "livecdregtest")
3524 bootloader
= "isobtrt.o";
3525 IsoName
= "ReactOS-LiveCD-RegTest.iso";
3529 bootloader
= "isoboot.o";
3530 IsoName
= "ReactOS-LiveCD.iso";
3533 FileLocation
isoboot ( OutputDirectory
, "boot" + sSep
+ "freeldr" + sSep
+ "bootsect", bootloader
);
3535 string reactosDirectory
= "reactos";
3536 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3537 FileLocation
livecdReactos ( OutputDirectory
,
3538 livecdReactosNoFixup
,
3540 CLEAN_FILE ( livecdReactos
);
3542 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3543 module
.name
.c_str ());
3544 fprintf ( fMakefile
,
3545 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3546 module
.name
.c_str (),
3547 backend
->GetFullName ( isoboot
) .c_str (),
3548 backend
->GetFullPath ( livecdReactos
).c_str () );
3549 OutputModuleCopyCommands ( livecdDirectory
,
3551 OutputNonModuleCopyCommands ( livecdDirectory
,
3553 OutputProfilesDirectoryCommands ( livecdDirectory
);
3554 OutputLoaderCommands ( livecdDirectory
);
3555 OutputRegistryCommands ( livecdDirectory
);
3556 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3557 fprintf ( fMakefile
,
3558 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS %s\n",
3559 backend
->GetFullName( isoboot
).c_str (),
3560 backend
->GetFullPath ( livecd
).c_str (),
3562 fprintf ( fMakefile
,
3567 MingwTestModuleHandler::MingwTestModuleHandler (
3568 const Module
& module_
)
3570 : MingwModuleHandler ( module_
)
3575 MingwTestModuleHandler::Process ()
3577 GenerateTestModuleTarget ();
3581 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
3583 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_hooks.c", false, "", false ) ) );
3584 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_stubs.S", false, "", false ) ) );
3585 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_startup.c", false, "", false ) ) );
3589 MingwTestModuleHandler::GenerateTestModuleTarget ()
3591 string
targetMacro ( GetTargetMacro ( module
) );
3592 string workingDirectory
= GetWorkingDirectory ( );
3593 string objectsMacro
= GetObjectsMacro ( module
);
3594 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3595 string libsMacro
= GetLibsMacro ();
3597 GenerateImportLibraryTargetIfNeeded ();
3599 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3603 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3606 if ( module
.cplusplus
)
3611 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3612 module
.GetEntryPoint(true).c_str (),
3613 module
.baseaddress
.c_str () );
3614 GenerateLinkerCommand ( dependencies
,
3623 GeneratePhonyTarget();
3628 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3629 const Module
& module_
)
3631 : MingwModuleHandler ( module_
)
3636 MingwRpcServerModuleHandler::Process ()
3642 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3643 const Module
& module_
)
3645 : MingwModuleHandler ( module_
)
3650 MingwRpcClientModuleHandler::Process ()
3656 MingwAliasModuleHandler::MingwAliasModuleHandler (
3657 const Module
& module_
)
3659 : MingwModuleHandler ( module_
)
3664 MingwAliasModuleHandler::Process ()
3668 MingwIdlHeaderModuleHandler::MingwIdlHeaderModuleHandler (
3669 const Module
& module_
)
3671 : MingwModuleHandler ( module_
)
3676 MingwIdlHeaderModuleHandler::Process ()
3681 MingwElfExecutableModuleHandler::MingwElfExecutableModuleHandler (
3682 const Module
& module_
)
3684 : MingwModuleHandler ( module_
)
3689 MingwElfExecutableModuleHandler::Process ()
3691 string
targetName ( module
.output
->name
);
3692 string
targetMacro ( GetTargetMacro (module
) );
3693 string workingDirectory
= GetWorkingDirectory ();
3694 string objectsMacro
= GetObjectsMacro ( module
);
3695 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3696 string libsMacro
= GetLibsMacro ();
3700 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3701 targetMacro
.c_str (),
3702 objectsMacro
.c_str (),
3703 linkDepsMacro
.c_str (),
3704 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
3706 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3708 fprintf ( fMakefile
, "\t${ld} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3709 module
.buildtype
.c_str(),
3710 objectsMacro
.c_str(),
3712 targetMacro
.c_str () );