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"
29 #define CLEAN_FILE(f) clean_files.push_back ( (f).name.length () > 0 ? backend->GetFullName ( f ) : backend->GetFullPath ( f ) );
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 ()
99 /*static*/ const FileLocation
*
100 MingwModuleHandler::PassThruCacheDirectory (const FileLocation
* file
)
102 switch ( file
->directory
)
104 case SourceDirectory
:
106 case IntermediateDirectory
:
107 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->intermediateDirectory
);
109 case OutputDirectory
:
110 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->outputDirectory
);
112 case InstallDirectory
:
113 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->installDirectory
);
116 throw InvalidOperationException ( __FILE__
,
118 "Invalid directory %d.",
125 /*static*/ const FileLocation
*
126 MingwModuleHandler::GetTargetFilename (
127 const Module
& module
,
128 string_list
* pclean_files
)
130 FileLocation
*target
= new FileLocation ( *module
.output
);
133 string_list
& clean_files
= *pclean_files
;
134 CLEAN_FILE ( *target
);
139 /*static*/ const FileLocation
*
140 MingwModuleHandler::GetImportLibraryFilename (
141 const Module
& module
,
142 string_list
* pclean_files
)
144 FileLocation
*target
= new FileLocation ( *module
.dependency
);
147 string_list
& clean_files
= *pclean_files
;
148 CLEAN_FILE ( *target
);
153 /*static*/ MingwModuleHandler
*
154 MingwModuleHandler::InstanciateHandler (
155 const Module
& module
,
156 MingwBackend
* backend
)
158 MingwModuleHandler
* handler
;
159 switch ( module
.type
)
162 handler
= new MingwBuildToolModuleHandler ( module
);
165 handler
= new MingwStaticLibraryModuleHandler ( module
);
168 handler
= new MingwObjectLibraryModuleHandler ( module
);
171 handler
= new MingwKernelModuleHandler ( module
);
174 handler
= new MingwNativeCUIModuleHandler ( module
);
177 handler
= new MingwWin32CUIModuleHandler ( module
);
181 handler
= new MingwWin32GUIModuleHandler ( module
);
184 handler
= new MingwKernelModeDLLModuleHandler ( module
);
187 handler
= new MingwNativeDLLModuleHandler ( module
);
190 handler
= new MingwWin32DLLModuleHandler ( module
);
193 handler
= new MingwWin32OCXModuleHandler ( module
);
195 case KernelModeDriver
:
196 handler
= new MingwKernelModeDriverModuleHandler ( module
);
199 handler
= new MingwBootLoaderModuleHandler ( module
);
202 handler
= new MingwBootSectorModuleHandler ( module
);
205 handler
= new MingwBootProgramModuleHandler ( module
);
208 handler
= new MingwIsoModuleHandler ( module
);
211 handler
= new MingwLiveIsoModuleHandler ( module
);
214 handler
= new MingwIsoModuleHandler ( module
);
217 handler
= new MingwLiveIsoModuleHandler ( module
);
220 handler
= new MingwTestModuleHandler ( module
);
223 handler
= new MingwRpcServerModuleHandler ( module
);
226 handler
= new MingwRpcClientModuleHandler ( module
);
229 handler
= new MingwAliasModuleHandler ( module
);
232 handler
= new MingwIdlHeaderModuleHandler ( module
);
234 case EmbeddedTypeLib
:
235 handler
= new MingwEmbeddedTypeLibModuleHandler ( module
);
238 handler
= new MingwElfExecutableModuleHandler ( module
);
241 throw UnknownModuleTypeException (
242 module
.node
.location
,
250 MingwModuleHandler::GetWorkingDirectory () const
256 MingwModuleHandler::GetBasename ( const string
& filename
) const
258 size_t index
= filename
.find_last_of ( '.' );
259 if ( index
!= string::npos
)
260 return filename
.substr ( 0, index
);
265 MingwModuleHandler::GetActualSourceFilename (
266 const FileLocation
* file
) const
268 string filename
= file
->name
;
270 string extension
= GetExtension ( *file
);
271 if ( extension
== ".spec" || extension
== ".SPEC" )
273 string basename
= GetBasename ( filename
);
274 return new FileLocation (
275 IntermediateDirectory
,
277 basename
+ ".stubs.c" );
279 else if ( extension
== ".idl" || extension
== ".IDL" )
281 string basename
= GetBasename ( filename
);
282 if ( module
.type
== RpcServer
)
284 return new FileLocation (
285 IntermediateDirectory
,
289 else if ( module
.type
== RpcClient
)
291 return new FileLocation (
292 IntermediateDirectory
,
298 return new FileLocation ( *file
);
302 return new FileLocation ( *file
);
306 MingwModuleHandler::GetExtraDependencies (
307 const FileLocation
*file
) const
309 string extension
= GetExtension ( *file
);
310 if ( extension
== ".idl" || extension
== ".IDL" )
312 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
313 return backend
->GetFullName ( *GetRpcServerHeaderFilename ( file
) )
315 + backend
->GetFullName ( *GetRpcClientHeaderFilename ( file
) );
316 else if ( module
.type
== IdlHeader
)
317 return backend
->GetFullName ( *GetIdlHeaderFilename ( file
) );
326 MingwModuleHandler::GetCompilationUnitDependencies (
327 const CompilationUnit
& compilationUnit
) const
329 if ( compilationUnit
.files
.size () <= 1 )
331 vector
<string
> sourceFiles
;
332 for ( size_t i
= 0; i
< compilationUnit
.files
.size (); i
++ )
334 File
& file
= *compilationUnit
.files
[i
];
335 sourceFiles
.push_back ( backend
->GetFullName ( file
.file
) );
337 return v2s ( sourceFiles
, 10 );
341 MingwModuleHandler::GetModuleArchiveFilename () const
343 if ( module
.type
== StaticLibrary
)
344 return new FileLocation ( *GetTargetFilename ( module
, NULL
) );
345 return new FileLocation ( IntermediateDirectory
,
346 module
.output
->relative_path
,
347 ReplaceExtension ( module
.name
, ".temp.a" ) );
351 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
353 string extension
= GetExtension ( file
.file
);
354 return ( extension
== ".spec" || extension
== ".SPEC" );
358 MingwModuleHandler::ReferenceObjects (
359 const Module
& module
)
361 if ( module
.type
== ObjectLibrary
)
363 if ( module
.type
== RpcServer
)
365 if ( module
.type
== RpcClient
)
367 if ( module
.type
== IdlHeader
)
373 MingwModuleHandler::OutputCopyCommand ( const FileLocation
& source
,
374 const FileLocation
& destination
)
379 "\t${cp} %s %s 1>$(NUL)\n",
380 backend
->GetFullName ( source
).c_str (),
381 backend
->GetFullName ( *PassThruCacheDirectory ( &destination
) ).c_str () );
385 MingwModuleHandler::GetImportLibraryDependency (
386 const Module
& importedModule
)
389 if ( ReferenceObjects ( importedModule
) )
391 const vector
<CompilationUnit
*>& compilationUnits
= importedModule
.non_if_data
.compilationUnits
;
394 dep
= GetTargetMacro ( importedModule
);
395 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
397 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
398 const FileLocation
*objectFilename
= GetObjectFilename ( compilationUnit
.GetFilename (), importedModule
, NULL
);
399 if ( GetExtension ( *objectFilename
) == ".h" )
401 dep
+= ssprintf ( " $(%s_HEADERS)", importedModule
.name
.c_str () );
407 dep
= backend
->GetFullName ( *GetImportLibraryFilename ( importedModule
, NULL
) );
412 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
413 string_list
& targets
)
415 if ( dependencyModule
.invocations
.size () > 0 )
417 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
419 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
420 invoke
.GetTargets ( targets
);
424 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
428 MingwModuleHandler::GetModuleDependencies (
429 string_list
& dependencies
)
431 size_t iend
= module
.dependencies
.size ();
436 for ( size_t i
= 0; i
< iend
; i
++ )
438 const Dependency
& dependency
= *module
.dependencies
[i
];
439 const Module
& dependencyModule
= *dependency
.dependencyModule
;
440 GetTargets ( dependencyModule
,
443 vector
<FileLocation
> v
;
444 GetDefinitionDependencies ( v
);
445 for ( size_t i
= 0; i
< v
.size (); i
++ )
447 const FileLocation
& file
= v
[i
];
448 dependencies
.push_back ( backend
->GetFullName ( file
) );
453 MingwModuleHandler::GetSourceFilenames ( vector
<FileLocation
>& list
,
454 bool includeGeneratedFiles
) const
458 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
459 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
461 if ( includeGeneratedFiles
|| !compilationUnits
[i
]->IsGeneratedFile () )
463 const FileLocation
* sourceFileLocation
= GetActualSourceFilename (
464 compilationUnits
[i
]->GetFilename () );
465 list
.push_back ( *sourceFileLocation
);
468 // intentionally make a copy so that we can append more work in
469 // the middle of processing without having to go recursive
470 vector
<If
*> v
= module
.non_if_data
.ifs
;
471 for ( i
= 0; i
< v
.size (); i
++ )
475 // check for sub-ifs to add to list
476 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
477 for ( j
= 0; j
< ifs
.size (); j
++ )
478 v
.push_back ( ifs
[j
] );
479 const vector
<CompilationUnit
*>& compilationUnits
= rIf
.data
.compilationUnits
;
480 for ( j
= 0; j
< compilationUnits
.size (); j
++ )
482 CompilationUnit
& compilationUnit
= *compilationUnits
[j
];
483 if ( includeGeneratedFiles
|| !compilationUnit
.IsGeneratedFile () )
485 const FileLocation
* sourceFileLocation
= GetActualSourceFilename (
486 compilationUnit
.GetFilename () );
487 list
.push_back ( *sourceFileLocation
);
494 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
495 vector
<FileLocation
>& list
) const
497 GetSourceFilenames ( list
, false );
501 MingwModuleHandler::GetObjectFilename (
502 const FileLocation
* sourceFile
,
503 const Module
& module
,
504 string_list
* pclean_files
) const
506 DirectoryLocation destination_directory
;
508 string extension
= GetExtension ( *sourceFile
);
509 if ( extension
== ".rc" || extension
== ".RC" )
510 newExtension
= ".coff";
511 else if ( extension
== ".spec" || extension
== ".SPEC" )
512 newExtension
= ".stubs.o";
513 else if ( extension
== ".idl" || extension
== ".IDL" )
515 if ( module
.type
== RpcServer
)
516 newExtension
= "_s.o";
517 else if ( module
.type
== RpcClient
)
518 newExtension
= "_c.o";
525 if ( module
.type
== BootSector
)
526 destination_directory
= OutputDirectory
;
528 destination_directory
= IntermediateDirectory
;
530 const FileLocation
*obj_file
= new FileLocation(
531 destination_directory
,
532 sourceFile
->relative_path
,
533 ReplaceExtension ( sourceFile
->name
, newExtension
) );
537 string_list
& clean_files
= *pclean_files
;
538 CLEAN_FILE ( *obj_file
);
544 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
546 return module
.name
+ "_clean";
550 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
552 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
554 Library
& library
= *module
.non_if_data
.libraries
[i
];
555 if ( library
.importedModule
->type
== ObjectLibrary
)
556 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
561 MingwModuleHandler::GenerateCleanTarget () const
563 if ( module
.type
== Alias
)
567 ".PHONY: %s_clean\n",
568 module
.name
.c_str() );
569 vector
<string
> referencedModuleNames
;
570 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
573 GetModuleCleanTarget ( module
).c_str(),
574 v2s ( referencedModuleNames
, 10 ).c_str () );
575 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
577 if ( ( i
+ 1 ) % 10 == 9 )
578 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
579 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
581 fprintf ( fMakefile
, " 2>$(NUL)\n" );
582 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
586 MingwModuleHandler::GenerateInstallTarget () const
588 if ( !module
.install
)
590 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
593 module
.name
.c_str (),
594 backend
->GetFullName ( *module
.install
).c_str () );
598 MingwModuleHandler::GenerateDependsTarget () const
601 ".PHONY: %s_depends\n",
602 module
.name
.c_str() );
604 "%s_depends: $(RBUILD_TARGET)\n",
605 module
.name
.c_str () );
607 "\t$(ECHO_RBUILD)\n" );
609 "\t$(Q)$(RBUILD_TARGET) $(RBUILD_FLAGS) -dm%s mingw\n",
610 module
.name
.c_str () );
614 MingwModuleHandler::GetObjectFilenames ()
616 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
617 if ( compilationUnits
.size () == 0 )
620 string
objectFilenames ( "" );
621 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
623 if ( objectFilenames
.size () > 0 )
624 objectFilenames
+= " ";
625 objectFilenames
+= backend
->GetFullName ( *GetObjectFilename ( compilationUnits
[i
]->GetFilename (), module
, NULL
) );
627 return objectFilenames
;
631 MingwModuleHandler::GenerateGccDefineParametersFromVector (
632 const vector
<Define
*>& defines
,
633 set
<string
>& used_defs
)
637 for ( size_t i
= 0; i
< defines
.size (); i
++ )
639 Define
& define
= *defines
[i
];
640 if (used_defs
.find(define
.name
) != used_defs
.end())
642 if (parameters
.length () > 0)
644 if (define
.name
.find('(') != string::npos
)
645 parameters
+= "$(QT)";
647 parameters
+= define
.name
;
648 if (define
.value
.length () > 0)
651 parameters
+= define
.value
;
653 if (define
.name
.find('(') != string::npos
)
654 parameters
+= "$(QT)";
655 used_defs
.insert(used_defs
.begin(),define
.name
);
661 MingwModuleHandler::GenerateGccDefineParameters () const
663 set
<string
> used_defs
;
664 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
, used_defs
);
665 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
, used_defs
);
666 if ( s
.length () > 0 )
675 MingwModuleHandler::ConcatenatePaths (
677 const string
& path2
) const
679 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
681 if ( path1
[path1
.length ()] == cSep
)
682 return path1
+ path2
;
684 return path1
+ cSep
+ path2
;
688 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
690 string parameters
, path_prefix
;
691 for ( size_t i
= 0; i
< includes
.size (); i
++ )
693 Include
& include
= *includes
[i
];
694 if ( parameters
.length () > 0 )
696 parameters
+= "-I" + backend
->GetFullPath ( *include
.directory
);;
702 MingwModuleHandler::GenerateGccIncludeParameters () const
704 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
705 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
706 if ( s
.length () > 0 )
715 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
718 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
720 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
721 if ( parameters
.length () > 0 )
723 parameters
+= compilerFlag
.flag
;
729 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
732 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
734 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
735 if ( parameters
.length () > 0 )
737 parameters
+= linkerFlag
.flag
;
743 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
744 const vector
<Library
*>& libraries
)
746 string
dependencies ( "" );
748 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
750 if ( wrap_count
++ == 5 )
751 dependencies
+= " \\\n\t\t", wrap_count
= 0;
752 else if ( dependencies
.size () > 0 )
754 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
760 MingwModuleHandler::GenerateLinkerParameters () const
762 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
766 MingwModuleHandler::GenerateMacro (
767 const char* assignmentOperation
,
769 const IfableData
& data
,
770 set
<const Define
*> *used_defs
,
771 bool generatingCompilerMacro
)
774 bool generateAssignment
;
776 if ( generatingCompilerMacro
)
777 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
779 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0;
780 if ( generateAssignment
)
785 assignmentOperation
);
788 if ( use_pch
&& module
.pch
!= NULL
)
792 backend
->GetFullPath ( *GetPrecompiledHeaderFilename () ).c_str () );
795 if ( generatingCompilerMacro
)
797 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
798 if ( compilerParameters
.size () > 0 )
803 compilerParameters
.c_str () );
806 for ( i
= 0; i
< data
.includes
.size(); i
++ )
808 const Include
& include
= *data
.includes
[i
];
809 const FileLocation
* includeDirectory
= include
.directory
;
813 backend
->GetFullPath ( *includeDirectory
).c_str() );
815 for ( i
= 0; i
< data
.defines
.size(); i
++ )
817 const Define
& define
= *data
.defines
[i
];
820 set
<const Define
*>::const_iterator last_define
;
821 for (last_define
= used_defs
->begin ();
822 last_define
!= used_defs
->end ();
825 if ( (*last_define
)->name
!= define
.name
)
827 if ( !define
.overridable
)
829 throw InvalidOperationException ( (*last_define
)->node
->location
.c_str (),
831 "Invalid override of define '%s', already defined at %s",
832 define
.name
.c_str (),
833 define
.node
->location
.c_str () );
835 if ( backend
->configuration
.Verbose
)
836 printf("%s: Overriding '%s' already defined at %s\n",
837 (*last_define
)->node
->location
.c_str (), define
.name
.c_str (),
838 define
.node
->location
.c_str () );
841 if ( last_define
!= used_defs
->end () )
847 define
.name
.c_str() );
848 if (define
.value
.length () > 0)
852 define
.value
.c_str() );
854 used_defs
->insert( used_defs
->begin (), &define
);
856 if ( generateAssignment
)
858 fprintf ( fMakefile
, "\n" );
863 MingwModuleHandler::GenerateMacros (
864 const char* assignmentOperation
,
865 const IfableData
& data
,
866 const vector
<LinkerFlag
*>* linkerFlags
,
867 set
<const Define
*>& used_defs
)
871 GenerateMacro ( assignmentOperation
,
876 GenerateMacro ( assignmentOperation
,
882 if ( linkerFlags
!= NULL
)
884 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
885 if ( linkerParameters
.size () > 0 )
890 linkerflagsMacro
.c_str (),
892 linkerParameters
.c_str() );
896 if ( data
.libraries
.size () > 0 )
898 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
899 if ( deps
.size () > 0 )
910 const vector
<If
*>& ifs
= data
.ifs
;
911 for ( i
= 0; i
< ifs
.size(); i
++ )
914 if ( rIf
.data
.defines
.size()
915 || rIf
.data
.includes
.size()
916 || rIf
.data
.libraries
.size()
917 || rIf
.data
.compilationUnits
.size()
918 || rIf
.data
.compilerFlags
.size()
919 || rIf
.data
.ifs
.size() )
923 "%s (\"$(%s)\",\"%s\")\n",
924 rIf
.negated
? "ifneq" : "ifeq",
925 rIf
.property
.c_str(),
940 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
942 for (size_t i
= 0; i
< compilationUnits
.size (); i
++)
943 delete compilationUnits
[i
];
947 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
952 MingwModuleHandler::GenerateSourceMacros (
953 const char* assignmentOperation
,
954 const IfableData
& data
)
958 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
959 vector
<const FileLocation
*> headers
;
960 if ( compilationUnits
.size () > 0 )
965 sourcesMacro
.c_str (),
966 assignmentOperation
);
967 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
969 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
973 ( i
%10 == 9 ? " \\\n\t" : " " ),
974 backend
->GetFullName ( *compilationUnit
.GetFilename () ).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 GenerateSourceMacros (
1005 vector
<CompilationUnit
*> sourceCompilationUnits
;
1006 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1007 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1012 sourcesMacro
.c_str(),
1013 backend
->GetFullName ( *sourceCompilationUnits
[i
]->GetFilename () ).c_str () );
1015 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1019 MingwModuleHandler::GenerateObjectMacros (
1020 const char* assignmentOperation
,
1021 const IfableData
& data
)
1025 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1026 vector
<const FileLocation
*> headers
;
1027 if ( compilationUnits
.size () > 0 )
1029 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1031 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1032 if ( compilationUnit
.IsFirstFile () )
1034 fprintf ( fMakefile
,
1036 objectsMacro
.c_str(),
1037 backend
->GetFullName ( *GetObjectFilename ( compilationUnit
.GetFilename (), module
, NULL
) ).c_str (),
1038 objectsMacro
.c_str() );
1044 objectsMacro
.c_str (),
1045 assignmentOperation
);
1046 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
1048 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1049 if ( !compilationUnit
.IsFirstFile () )
1051 const FileLocation
*objectFilename
= GetObjectFilename ( compilationUnit
.GetFilename (), module
, NULL
);
1052 if ( GetExtension ( *objectFilename
) == ".h" )
1053 headers
.push_back ( objectFilename
);
1058 ( i
%10 == 9 ? " \\\n\t" : " " ),
1059 backend
->GetFullName ( *objectFilename
).c_str () );
1062 fprintf ( fMakefile
, "\n" );
1064 if ( headers
.size () > 0 )
1069 module
.name
.c_str (),
1070 assignmentOperation
);
1071 for ( i
= 0; i
< headers
.size (); i
++ )
1075 ( i
%10 == 9 ? " \\\n\t" : " " ),
1076 backend
->GetFullName ( *headers
[i
] ).c_str () );
1077 fprintf ( fMakefile
, "\n" );
1080 const vector
<If
*>& ifs
= data
.ifs
;
1081 for ( i
= 0; i
< ifs
.size(); i
++ )
1084 if ( rIf
.data
.defines
.size()
1085 || rIf
.data
.includes
.size()
1086 || rIf
.data
.libraries
.size()
1087 || rIf
.data
.compilationUnits
.size()
1088 || rIf
.data
.compilerFlags
.size()
1089 || rIf
.data
.ifs
.size() )
1093 "%s (\"$(%s)\",\"%s\")\n",
1094 rIf
.negated
? "ifneq" : "ifeq",
1095 rIf
.property
.c_str(),
1096 rIf
.value
.c_str() );
1097 GenerateObjectMacros (
1106 vector
<CompilationUnit
*> sourceCompilationUnits
;
1107 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1108 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1113 objectsMacro
.c_str(),
1114 backend
->GetFullName ( *GetObjectFilename ( sourceCompilationUnits
[i
]->GetFilename (), module
, NULL
) ).c_str () );
1116 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1120 MingwModuleHandler::GetPrecompiledHeaderFilename () const
1122 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
1123 return new FileLocation ( IntermediateDirectory
,
1124 module
.pch
->file
.relative_path
,
1129 MingwModuleHandler::GenerateGccCommand (
1130 const FileLocation
* sourceFile
,
1131 const string
& extraDependencies
,
1133 const string
& cflagsMacro
)
1135 string dependencies
= backend
->GetFullName ( *sourceFile
);
1136 if ( extraDependencies
!= "" )
1137 dependencies
+= " " + extraDependencies
;
1138 if ( module
.pch
&& use_pch
)
1139 dependencies
+= " " + backend
->GetFullName ( *GetPrecompiledHeaderFilename () );
1141 /* WIDL generated headers may be used */
1142 vector
<FileLocation
> rpcDependencies
;
1143 GetRpcHeaderDependencies ( rpcDependencies
);
1144 dependencies
+= " " + v2s ( backend
, rpcDependencies
, 5 );
1145 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1147 const FileLocation
*objectFilename
= GetObjectFilename (
1148 sourceFile
, module
, &clean_files
);
1149 fprintf ( fMakefile
,
1151 backend
->GetFullName ( *objectFilename
).c_str (),
1152 dependencies
.c_str (),
1153 backend
->GetFullPath ( *objectFilename
).c_str () );
1154 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
1155 fprintf ( fMakefile
,
1156 "\t%s -c $< -o $@ %s\n",
1158 cflagsMacro
.c_str () );
1162 MingwModuleHandler::GenerateGccAssemblerCommand (
1163 const FileLocation
* sourceFile
,
1165 const string
& cflagsMacro
)
1167 string dependencies
= backend
->GetFullName ( *sourceFile
);
1168 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1170 const FileLocation
*objectFilename
= GetObjectFilename (
1171 sourceFile
, module
, &clean_files
);
1172 fprintf ( fMakefile
,
1174 backend
->GetFullName ( *objectFilename
).c_str (),
1175 dependencies
.c_str (),
1176 backend
->GetFullPath ( *objectFilename
).c_str () );
1177 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
1178 fprintf ( fMakefile
,
1179 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
1181 cflagsMacro
.c_str () );
1185 MingwModuleHandler::GenerateNasmCommand (
1186 const FileLocation
* sourceFile
,
1187 const string
& nasmflagsMacro
)
1189 string dependencies
= backend
->GetFullName ( *sourceFile
);
1190 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1192 const FileLocation
*objectFilename
= GetObjectFilename (
1193 sourceFile
, module
, &clean_files
);
1194 fprintf ( fMakefile
,
1196 backend
->GetFullName ( *objectFilename
).c_str (),
1197 dependencies
.c_str (),
1198 backend
->GetFullPath ( *objectFilename
).c_str () );
1199 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1200 fprintf ( fMakefile
,
1201 "\t%s -f win32 $< -o $@ %s\n",
1203 nasmflagsMacro
.c_str () );
1207 MingwModuleHandler::GenerateWindresCommand (
1208 const FileLocation
* sourceFile
,
1209 const string
& windresflagsMacro
)
1211 string dependencies
= backend
->GetFullName ( *sourceFile
);
1212 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1214 const FileLocation
*objectFilename
= GetObjectFilename ( sourceFile
, module
, &clean_files
);
1216 string sourceFilenamePart
= module
.name
+ "." + ReplaceExtension ( sourceFile
->name
, "" );
1217 FileLocation
rciFilename ( TemporaryDirectory
,
1219 sourceFilenamePart
+ ".rci.tmp" );
1220 FileLocation
resFilename ( TemporaryDirectory
,
1222 sourceFilenamePart
+ ".res.tmp" );
1224 fprintf ( fMakefile
,
1225 "%s: %s $(WRC_TARGET) | %s\n",
1226 backend
->GetFullName ( *objectFilename
).c_str (),
1227 dependencies
.c_str (),
1228 backend
->GetFullPath ( *objectFilename
).c_str () );
1229 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1230 fprintf ( fMakefile
,
1231 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1232 windresflagsMacro
.c_str (),
1233 backend
->GetFullName ( *sourceFile
).c_str (),
1234 backend
->GetFullName ( rciFilename
).c_str () );
1235 fprintf ( fMakefile
,
1236 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1237 windresflagsMacro
.c_str (),
1238 backend
->GetFullName ( rciFilename
).c_str (),
1239 backend
->GetFullName ( resFilename
).c_str () );
1240 fprintf ( fMakefile
,
1241 "\t-@${rm} %s 2>$(NUL)\n",
1242 backend
->GetFullName ( rciFilename
).c_str () );
1243 fprintf ( fMakefile
,
1244 "\t${windres} %s -o $@\n",
1245 backend
->GetFullName ( resFilename
).c_str () );
1246 fprintf ( fMakefile
,
1247 "\t-@${rm} %s 2>$(NUL)\n",
1248 backend
->GetFullName ( resFilename
).c_str () );
1252 MingwModuleHandler::GenerateWinebuildCommands (
1253 const FileLocation
* sourceFile
)
1255 string dependencies
= backend
->GetFullName ( *sourceFile
);
1256 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1258 string basename
= GetBasename ( sourceFile
->name
);
1259 FileLocation
def_file ( IntermediateDirectory
,
1260 sourceFile
->relative_path
,
1261 basename
+ ".spec.def" );
1262 CLEAN_FILE ( def_file
);
1264 FileLocation
stub_file ( IntermediateDirectory
,
1265 sourceFile
->relative_path
,
1266 basename
+ ".stubs.c" );
1267 CLEAN_FILE ( stub_file
);
1269 fprintf ( fMakefile
,
1270 "%s: %s $(WINEBUILD_TARGET) | %s\n",
1271 backend
->GetFullName ( def_file
).c_str (),
1272 dependencies
.c_str (),
1273 backend
->GetFullPath ( def_file
).c_str () );
1274 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1275 fprintf ( fMakefile
,
1276 "\t%s -o %s --def -E %s\n",
1277 "$(Q)$(WINEBUILD_TARGET)",
1278 backend
->GetFullName ( def_file
).c_str (),
1279 backend
->GetFullName ( *sourceFile
).c_str () );
1280 fprintf ( fMakefile
,
1281 "%s: %s $(WINEBUILD_TARGET)\n",
1282 backend
->GetFullName ( stub_file
).c_str (),
1283 backend
->GetFullName ( *sourceFile
).c_str () );
1284 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1285 fprintf ( fMakefile
,
1286 "\t%s -o %s --pedll %s\n",
1287 "$(Q)$(WINEBUILD_TARGET)",
1288 backend
->GetFullName ( stub_file
).c_str (),
1289 backend
->GetFullName ( *sourceFile
).c_str () );
1293 MingwModuleHandler::GetWidlFlags ( const CompilationUnit
& compilationUnit
)
1295 return compilationUnit
.GetSwitches ();
1299 MingwModuleHandler::GetPropertyValue ( const Module
& module
, const std::string
& name
)
1301 for ( size_t i
= 0; i
< module
.project
.non_if_data
.properties
.size (); i
++ )
1303 const Property
& property
= *module
.project
.non_if_data
.properties
[i
];
1304 if ( property
.name
== name
)
1305 return property
.value
;
1307 return string ( "" );
1311 MingwModuleHandler::GetRpcServerHeaderFilename ( const FileLocation
*base
) const
1313 string newname
= GetBasename ( base
->name
) + "_s.h";
1314 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1318 MingwModuleHandler::GenerateWidlCommandsServer (
1319 const CompilationUnit
& compilationUnit
,
1320 const string
& widlflagsMacro
)
1322 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1323 string dependencies
= backend
->GetFullName ( *sourceFile
);
1324 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1326 string basename
= GetBasename ( sourceFile
->name
);
1328 const FileLocation
*generatedHeaderFilename
= GetRpcServerHeaderFilename ( sourceFile
);
1329 CLEAN_FILE ( *generatedHeaderFilename
);
1331 FileLocation
generatedServerFilename ( IntermediateDirectory
,
1332 sourceFile
->relative_path
,
1333 basename
+ "_s.c" );
1334 CLEAN_FILE ( generatedServerFilename
);
1336 fprintf ( fMakefile
,
1337 "%s %s: %s $(WIDL_TARGET) | %s\n",
1338 backend
->GetFullName ( generatedServerFilename
).c_str (),
1339 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1340 dependencies
.c_str (),
1341 backend
->GetFullPath ( generatedServerFilename
).c_str () );
1342 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1343 fprintf ( fMakefile
,
1344 "\t%s %s %s -h -H %s -s -S %s %s\n",
1345 "$(Q)$(WIDL_TARGET)",
1346 GetWidlFlags ( compilationUnit
).c_str (),
1347 widlflagsMacro
.c_str (),
1348 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1349 backend
->GetFullName ( generatedServerFilename
).c_str (),
1350 backend
->GetFullName ( *sourceFile
).c_str () );
1354 MingwModuleHandler::GetRpcClientHeaderFilename ( const FileLocation
*base
) const
1356 string newname
= GetBasename ( base
->name
) + "_c.h";
1357 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1361 MingwModuleHandler::GetIdlHeaderFilename ( const FileLocation
*base
) const
1363 string newname
= GetBasename ( base
->name
) + ".h";
1364 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1368 MingwModuleHandler::GenerateWidlCommandsEmbeddedTypeLib (
1369 const CompilationUnit
& compilationUnit
,
1370 const string
& widlflagsMacro
)
1372 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1373 string dependencies
= backend
->GetFullName ( *sourceFile
);
1374 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1376 string basename
= GetBasename ( sourceFile
->name
);
1378 FileLocation
EmbeddedTypeLibFilename ( IntermediateDirectory
,
1379 sourceFile
->relative_path
,
1380 basename
+ ".tlb" );
1382 fprintf ( fMakefile
,
1383 "%s: %s $(WIDL_TARGET) | %s\n",
1384 GetTargetMacro ( module
).c_str (),
1385 dependencies
.c_str (),
1386 backend
->GetFullPath ( EmbeddedTypeLibFilename
).c_str () );
1387 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1388 fprintf ( fMakefile
,
1389 "\t%s %s %s -t -T %s %s\n",
1390 "$(Q)$(WIDL_TARGET)",
1391 GetWidlFlags ( compilationUnit
).c_str (),
1392 widlflagsMacro
.c_str (),
1393 backend
->GetFullName ( EmbeddedTypeLibFilename
).c_str(),
1394 backend
->GetFullName ( *sourceFile
).c_str () );
1398 MingwModuleHandler::GenerateWidlCommandsClient (
1399 const CompilationUnit
& compilationUnit
,
1400 const string
& widlflagsMacro
)
1402 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1403 string dependencies
= backend
->GetFullName ( *sourceFile
);
1404 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1406 string basename
= GetBasename ( sourceFile
->name
);
1408 const FileLocation
*generatedHeaderFilename
= GetRpcClientHeaderFilename ( sourceFile
);
1409 CLEAN_FILE ( *generatedHeaderFilename
);
1411 FileLocation
generatedClientFilename ( IntermediateDirectory
,
1412 sourceFile
->relative_path
,
1413 basename
+ "_c.c" );
1414 CLEAN_FILE ( generatedClientFilename
);
1416 fprintf ( fMakefile
,
1417 "%s %s: %s $(WIDL_TARGET) | %s\n",
1418 backend
->GetFullName ( generatedClientFilename
).c_str (),
1419 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1420 dependencies
.c_str (),
1421 backend
->GetFullPath ( generatedClientFilename
).c_str () );
1422 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1423 fprintf ( fMakefile
,
1424 "\t%s %s %s -h -H %s -c -C %s %s\n",
1425 "$(Q)$(WIDL_TARGET)",
1426 GetWidlFlags ( compilationUnit
).c_str (),
1427 widlflagsMacro
.c_str (),
1428 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1429 backend
->GetFullName ( generatedClientFilename
).c_str (),
1430 backend
->GetFullName ( *sourceFile
).c_str () );
1434 MingwModuleHandler::GenerateWidlCommandsIdlHeader (
1435 const CompilationUnit
& compilationUnit
,
1436 const string
& widlflagsMacro
)
1438 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1439 string dependencies
= backend
->GetFullName ( *sourceFile
);
1440 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1442 string basename
= GetBasename ( sourceFile
->name
);
1444 const FileLocation
*generatedHeader
= GetIdlHeaderFilename ( sourceFile
);
1445 CLEAN_FILE ( *generatedHeader
);
1447 fprintf ( fMakefile
,
1448 "%s: %s $(WIDL_TARGET) | %s\n",
1449 backend
->GetFullName( *generatedHeader
).c_str (),
1450 dependencies
.c_str (),
1451 backend
->GetFullPath ( *generatedHeader
).c_str () );
1452 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1453 fprintf ( fMakefile
,
1454 "\t%s %s %s -h -H %s %s\n",
1455 "$(Q)$(WIDL_TARGET)",
1456 GetWidlFlags ( compilationUnit
).c_str (),
1457 widlflagsMacro
.c_str (),
1458 backend
->GetFullName ( *generatedHeader
).c_str (),
1459 backend
->GetFullName ( *sourceFile
).c_str () );
1463 MingwModuleHandler::GenerateWidlCommands (
1464 const CompilationUnit
& compilationUnit
,
1465 const string
& widlflagsMacro
)
1467 if ( module
.type
== RpcServer
)
1468 GenerateWidlCommandsServer ( compilationUnit
,
1470 else if ( module
.type
== RpcClient
)
1471 GenerateWidlCommandsClient ( compilationUnit
,
1473 else if ( module
.type
== EmbeddedTypeLib
)
1474 GenerateWidlCommandsEmbeddedTypeLib ( compilationUnit
,
1476 else // applies also for other module.types which include idl files
1477 GenerateWidlCommandsIdlHeader ( compilationUnit
,
1482 MingwModuleHandler::GenerateCommands (
1483 const CompilationUnit
& compilationUnit
,
1484 const string
& extraDependencies
,
1487 const string
& cflagsMacro
,
1488 const string
& nasmflagsMacro
,
1489 const string
& windresflagsMacro
,
1490 const string
& widlflagsMacro
)
1492 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1493 string extension
= GetExtension ( *sourceFile
);
1494 if ( extension
== ".c" || extension
== ".C" )
1496 GenerateGccCommand ( sourceFile
,
1497 GetCompilationUnitDependencies ( compilationUnit
) + extraDependencies
,
1502 else if ( extension
== ".cc" || extension
== ".CC" ||
1503 extension
== ".cpp" || extension
== ".CPP" ||
1504 extension
== ".cxx" || extension
== ".CXX" )
1506 GenerateGccCommand ( sourceFile
,
1507 GetCompilationUnitDependencies ( compilationUnit
) + extraDependencies
,
1512 else if ( extension
== ".s" || extension
== ".S" )
1514 GenerateGccAssemblerCommand ( sourceFile
,
1519 else if ( extension
== ".asm" || extension
== ".ASM" )
1521 GenerateNasmCommand ( sourceFile
,
1525 else if ( extension
== ".rc" || extension
== ".RC" )
1527 GenerateWindresCommand ( sourceFile
,
1528 windresflagsMacro
);
1531 else if ( extension
== ".spec" || extension
== ".SPEC" )
1533 GenerateWinebuildCommands ( sourceFile
);
1534 GenerateGccCommand ( GetActualSourceFilename ( sourceFile
),
1540 else if ( extension
== ".idl" || extension
== ".IDL" )
1542 GenerateWidlCommands ( compilationUnit
,
1544 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
1546 GenerateGccCommand ( GetActualSourceFilename ( sourceFile
),
1547 GetExtraDependencies ( sourceFile
),
1554 throw InvalidOperationException ( __FILE__
,
1556 "Unsupported filename extension '%s' in file '%s'",
1558 backend
->GetFullName ( *sourceFile
).c_str () );
1562 MingwModuleHandler::GenerateBuildMapCode ( const FileLocation
*mapTarget
)
1564 fprintf ( fMakefile
,
1565 "ifeq ($(ROS_BUILDMAP),full)\n" );
1567 FileLocation
mapFilename ( OutputDirectory
,
1568 module
.output
->relative_path
,
1569 GetBasename ( module
.output
->name
) + ".map" );
1570 CLEAN_FILE ( mapFilename
);
1572 fprintf ( fMakefile
,
1573 "\t$(ECHO_OBJDUMP)\n" );
1574 fprintf ( fMakefile
,
1575 "\t$(Q)${objdump} -d -S %s > %s\n",
1576 mapTarget
? backend
->GetFullName ( *mapTarget
).c_str () : "$@",
1577 backend
->GetFullName ( mapFilename
).c_str () );
1579 fprintf ( fMakefile
,
1581 fprintf ( fMakefile
,
1582 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1584 fprintf ( fMakefile
,
1586 fprintf ( fMakefile
,
1587 "\t$(Q)${nm} --numeric-sort %s > %s\n",
1588 mapTarget
? backend
->GetFullName ( *mapTarget
).c_str () : "$@",
1589 backend
->GetFullName ( mapFilename
).c_str () );
1591 fprintf ( fMakefile
,
1594 fprintf ( fMakefile
,
1599 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1601 fprintf ( fMakefile
,
1602 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1604 FileLocation
nostripFilename ( OutputDirectory
,
1605 module
.output
->relative_path
,
1606 GetBasename ( module
.output
->name
) + ".nostrip" + GetExtension ( *module
.output
) );
1607 CLEAN_FILE ( nostripFilename
);
1609 OutputCopyCommand ( *module
.output
, nostripFilename
);
1611 fprintf ( fMakefile
,
1616 MergeStringVector ( const Backend
* backend
,
1617 const vector
<FileLocation
>& input
,
1618 vector
<string
>& output
)
1622 int wrap_count
= -1;
1623 for ( size_t i
= 0; i
< input
.size (); i
++ )
1625 if ( wrap_count
++ == wrap_at
)
1627 output
.push_back ( s
);
1631 else if ( s
.size () > 0)
1633 s
+= backend
->GetFullName ( input
[i
] );
1635 if ( s
.length () > 0 )
1636 output
.push_back ( s
);
1640 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1641 vector
<FileLocation
>& objectFiles
) const
1643 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1645 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1646 objectFiles
.push_back ( *GetObjectFilename ( compilationUnit
.GetFilename (), module
, NULL
) );
1651 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1653 if ( backend
->configuration
.CleanAsYouGo
)
1655 vector
<FileLocation
> objectFiles
;
1656 GetObjectsVector ( module
.non_if_data
,
1658 vector
<string
> lines
;
1659 MergeStringVector ( backend
,
1662 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1664 fprintf ( fMakefile
,
1665 "\t-@${rm} %s 2>$(NUL)\n",
1666 lines
[i
].c_str () );
1672 MingwModuleHandler::GenerateRunRsymCode () const
1674 fprintf ( fMakefile
,
1675 "\t$(ECHO_RSYM)\n" );
1676 fprintf ( fMakefile
,
1677 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1681 MingwModuleHandler::GenerateRunStripCode () const
1683 fprintf ( fMakefile
,
1684 "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" );
1685 fprintf ( fMakefile
,
1686 "\t$(ECHO_STRIP)\n" );
1687 fprintf ( fMakefile
,
1688 "\t${strip} -s -x -X $@\n\n" );
1689 fprintf ( fMakefile
,
1694 MingwModuleHandler::GenerateLinkerCommand (
1695 const string
& dependencies
,
1696 const string
& linker
,
1697 const string
& linkerParameters
,
1698 const string
& objectsMacro
,
1699 const string
& libsMacro
,
1700 const string
& pefixupParameters
)
1702 string
target ( GetTargetMacro ( module
) );
1703 string
target_folder ( backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ) );
1704 const FileLocation
*definitionFilename
= GetDefinitionFilename ();
1706 string linkerScriptArgument
;
1707 if ( module
.linkerScript
!= NULL
)
1708 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", backend
->GetFullName ( module
.linkerScript
->file
).c_str () );
1710 linkerScriptArgument
= "";
1712 fprintf ( fMakefile
,
1713 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1715 backend
->GetFullName ( *definitionFilename
).c_str (),
1716 dependencies
.c_str (),
1717 target_folder
.c_str () );
1718 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1719 string
targetName ( module
.output
->name
);
1721 if ( !module
.IsDLL () )
1723 fprintf ( fMakefile
,
1724 "\t%s %s %s -o %s %s %s %s\n",
1726 linkerParameters
.c_str (),
1727 linkerScriptArgument
.c_str (),
1729 objectsMacro
.c_str (),
1731 GetLinkerMacro ().c_str () );
1733 else if ( module
.HasImportLibrary () )
1735 FileLocation
temp_exp ( TemporaryDirectory
,
1737 module
.name
+ ".temp.exp" );
1738 CLEAN_FILE ( temp_exp
);
1740 fprintf ( fMakefile
,
1741 "\t${dlltool} --dllname %s --def %s --output-exp %s %s %s\n",
1742 targetName
.c_str (),
1743 backend
->GetFullName ( *definitionFilename
).c_str (),
1744 backend
->GetFullName ( temp_exp
).c_str (),
1745 module
.mangledSymbols
? "" : "--kill-at",
1746 module
.underscoreSymbols
? "--add-underscore" : "" );
1748 fprintf ( fMakefile
,
1749 "\t%s %s %s %s -o %s %s %s %s\n",
1751 linkerParameters
.c_str (),
1752 linkerScriptArgument
.c_str (),
1753 backend
->GetFullName ( temp_exp
).c_str (),
1755 objectsMacro
.c_str (),
1757 GetLinkerMacro ().c_str () );
1759 fprintf ( fMakefile
,
1760 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1762 pefixupParameters
.c_str() );
1764 fprintf ( fMakefile
,
1765 "\t-@${rm} %s 2>$(NUL)\n",
1766 backend
->GetFullName ( temp_exp
).c_str () );
1770 /* XXX: need to workaround binutils bug, which exports
1771 * all functions in a dll if no .def file or an empty
1772 * one has been provided... */
1774 //printf ( "%s will have all its functions exported\n",
1775 // module.target->name.c_str () );
1776 fprintf ( fMakefile
,
1777 "\t%s %s %s -o %s %s %s %s\n",
1779 linkerParameters
.c_str (),
1780 linkerScriptArgument
.c_str (),
1782 objectsMacro
.c_str (),
1784 GetLinkerMacro ().c_str () );
1787 GenerateBuildMapCode ();
1788 GenerateBuildNonSymbolStrippedCode ();
1789 GenerateRunRsymCode ();
1790 GenerateRunStripCode ();
1791 GenerateCleanObjectsAsYouGoCode ();
1795 MingwModuleHandler::GeneratePhonyTarget() const
1797 string
targetMacro ( GetTargetMacro ( module
) );
1798 fprintf ( fMakefile
,
1800 targetMacro
.c_str ());
1801 fprintf ( fMakefile
, "%s: | %s\n",
1802 targetMacro
.c_str (),
1803 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
1807 MingwModuleHandler::GenerateObjectFileTargets (
1808 const IfableData
& data
,
1811 const string
& cflagsMacro
,
1812 const string
& nasmflagsMacro
,
1813 const string
& windresflagsMacro
,
1814 const string
& widlflagsMacro
)
1817 string moduleDependencies
;
1819 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1820 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1822 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1823 const FileLocation
*objectFilename
= GetObjectFilename ( compilationUnit
.GetFilename (), module
, NULL
);
1824 if ( GetExtension ( *objectFilename
) == ".h" )
1826 moduleDependencies
= ssprintf ( " $(%s_HEADERS)", module
.name
.c_str () );
1831 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1833 GenerateCommands ( *compilationUnits
[i
],
1841 fprintf ( fMakefile
,
1845 const vector
<If
*>& ifs
= data
.ifs
;
1846 for ( i
= 0; i
< ifs
.size(); i
++ )
1848 GenerateObjectFileTargets ( ifs
[i
]->data
,
1857 vector
<CompilationUnit
*> sourceCompilationUnits
;
1858 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1859 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1861 GenerateCommands ( *sourceCompilationUnits
[i
],
1870 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1874 MingwModuleHandler::GenerateObjectFileTargets (
1877 const string
& cflagsMacro
,
1878 const string
& nasmflagsMacro
,
1879 const string
& windresflagsMacro
,
1880 const string
& widlflagsMacro
)
1882 if ( module
.pch
&& use_pch
)
1884 const FileLocation
& baseHeaderFile
= module
.pch
->file
;
1885 const FileLocation
*pchFilename
= GetPrecompiledHeaderFilename ();
1886 CLEAN_FILE ( *pchFilename
);
1887 string dependencies
= backend
->GetFullName ( baseHeaderFile
);
1888 /* WIDL generated headers may be used */
1889 vector
<FileLocation
> rpcDependencies
;
1890 GetRpcHeaderDependencies ( rpcDependencies
);
1891 dependencies
+= " " + v2s ( backend
, rpcDependencies
, 5 );
1892 fprintf ( fMakefile
,
1894 backend
->GetFullName ( *pchFilename
).c_str(),
1895 dependencies
.c_str(),
1896 backend
->GetFullPath ( *pchFilename
).c_str() );
1897 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1898 fprintf ( fMakefile
,
1899 "\t%s -o %s %s -g %s\n\n",
1900 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1901 backend
->GetFullName ( *pchFilename
).c_str(),
1902 cflagsMacro
.c_str(),
1903 backend
->GetFullName ( baseHeaderFile
).c_str() );
1906 GenerateObjectFileTargets ( module
.non_if_data
,
1913 fprintf ( fMakefile
, "\n" );
1917 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1918 const string
& objs_macro
) const
1920 const FileLocation
*archiveFilename
= GetModuleArchiveFilename ();
1922 fprintf ( fMakefile
,
1924 backend
->GetFullName ( *archiveFilename
).c_str (),
1925 objs_macro
.c_str (),
1926 backend
->GetFullPath ( *archiveFilename
).c_str() );
1928 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
1930 const FileLocation
*definitionFilename ( GetDefinitionFilename () );
1932 fprintf ( fMakefile
,
1933 "\t${dlltool} --dllname %s --def %s --output-lib $@ %s %s\n",
1934 module
.importLibrary
->dllname
.c_str (),
1935 backend
->GetFullName ( *definitionFilename
).c_str (),
1936 module
.mangledSymbols
? "" : "--kill-at",
1937 module
.underscoreSymbols
? "--add-underscore" : "" );
1940 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1942 fprintf ( fMakefile
,
1945 objs_macro
.c_str ());
1947 GenerateCleanObjectsAsYouGoCode ();
1949 fprintf ( fMakefile
, "\n" );
1951 return archiveFilename
;
1955 MingwModuleHandler::GetCFlagsMacro () const
1957 return ssprintf ( "$(%s_CFLAGS)",
1958 module
.name
.c_str () );
1962 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1964 return ssprintf ( "$(%s_OBJS)",
1965 module
.name
.c_str () );
1969 MingwModuleHandler::GetLinkingDependenciesMacro () const
1971 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1975 MingwModuleHandler::GetLibsMacro () const
1977 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1981 MingwModuleHandler::GetLinkerMacro () const
1983 return ssprintf ( "$(%s_LFLAGS)",
1984 module
.name
.c_str () );
1988 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1990 if ( ReferenceObjects ( module
) )
1991 return GetObjectsMacro ( module
);
1993 return backend
->GetFullName ( *GetTargetFilename ( module
, NULL
) ).c_str ();
1997 MingwModuleHandler::GenerateSourceMacro ()
1999 sourcesMacro
= ssprintf ( "%s_SOURCES", module
.name
.c_str ());
2001 GenerateSourceMacros (
2003 module
.non_if_data
);
2005 // future references to the macro will be to get its values
2006 sourcesMacro
= ssprintf ("$(%s)", sourcesMacro
.c_str ());
2010 MingwModuleHandler::GenerateObjectMacro ()
2012 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
2014 GenerateObjectMacros (
2016 module
.non_if_data
);
2018 // future references to the macro will be to get its values
2019 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
2023 MingwModuleHandler::GenerateTargetMacro ()
2025 fprintf ( fMakefile
,
2027 GetTargetMacro ( module
, false ).c_str (),
2028 GetModuleTargets ( module
).c_str () );
2032 MingwModuleHandler::GetRpcHeaderDependencies (
2033 vector
<FileLocation
>& dependencies
) const
2035 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
2037 Library
& library
= *module
.non_if_data
.libraries
[i
];
2038 if ( library
.importedModule
->type
== RpcServer
||
2039 library
.importedModule
->type
== RpcClient
||
2040 library
.importedModule
->type
== IdlHeader
)
2042 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
2044 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
2045 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
2046 string extension
= GetExtension ( *sourceFile
);
2047 if ( extension
== ".idl" || extension
== ".IDL" )
2049 string basename
= GetBasename ( sourceFile
->name
);
2050 if ( library
.importedModule
->type
== RpcServer
)
2051 dependencies
.push_back ( *GetRpcServerHeaderFilename ( sourceFile
) );
2052 if ( library
.importedModule
->type
== RpcClient
)
2053 dependencies
.push_back ( *GetRpcClientHeaderFilename ( sourceFile
) );
2054 if ( library
.importedModule
->type
== IdlHeader
)
2055 dependencies
.push_back ( *GetIdlHeaderFilename ( sourceFile
) );
2063 MingwModuleHandler::GenerateOtherMacros ()
2065 set
<const Define
*> used_defs
;
2067 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
2068 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
2069 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
2070 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
2071 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
2072 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
2073 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
2078 &module
.linkerFlags
,
2083 module
.project
.non_if_data
,
2087 vector
<FileLocation
> s
;
2088 if ( module
.importLibrary
)
2090 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2091 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2093 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2094 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
2095 string extension
= GetExtension ( *sourceFile
);
2096 if ( extension
== ".spec" || extension
== ".SPEC" )
2097 GetSpecObjectDependencies ( s
, sourceFile
);
2100 if ( s
.size () > 0 )
2105 linkDepsMacro
.c_str() );
2106 for ( size_t i
= 0; i
< s
.size(); i
++ )
2107 fprintf ( fMakefile
,
2109 backend
->GetFullName ( s
[i
] ).c_str () );
2110 fprintf ( fMakefile
, "\n" );
2113 string globalCflags
= "-g";
2114 if ( backend
->usePipe
)
2115 globalCflags
+= " -pipe";
2116 if ( !module
.allowWarnings
)
2117 globalCflags
+= " -Werror";
2118 if ( module
.host
== HostTrue
)
2120 if ( module
.cplusplus
)
2121 globalCflags
+= " $(HOST_CPPFLAGS)";
2123 globalCflags
+= " $(HOST_CFLAGS)";
2127 if ( module
.cplusplus
)
2129 // HACK: use host headers when building C++
2130 globalCflags
+= " $(HOST_CPPFLAGS)";
2133 globalCflags
+= " -nostdinc";
2136 // Always force disabling of sibling calls optimisation for GCC
2137 // (TODO: Move to version-specific once this bug is fixed in GCC)
2138 globalCflags
+= " -fno-optimize-sibling-calls";
2142 "%s += $(PROJECT_CFLAGS) %s\n",
2143 cflagsMacro
.c_str (),
2144 globalCflags
.c_str () );
2148 "%s += $(PROJECT_RCFLAGS)\n",
2149 windresflagsMacro
.c_str () );
2153 "%s += $(PROJECT_WIDLFLAGS) -I%s\n",
2154 widlflagsMacro
.c_str (),
2155 module
.output
->relative_path
.c_str () );
2159 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
2160 module
.name
.c_str () );
2165 linkDepsMacro
.c_str (),
2166 libsMacro
.c_str () );
2168 string cflags
= TypeSpecificCFlags();
2169 if ( cflags
.size() > 0 )
2171 fprintf ( fMakefile
,
2173 cflagsMacro
.c_str (),
2177 string nasmflags
= TypeSpecificNasmFlags();
2178 if ( nasmflags
.size () > 0 )
2180 fprintf ( fMakefile
,
2182 nasmflagsMacro
.c_str (),
2183 nasmflags
.c_str () );
2186 string linkerflags
= TypeSpecificLinkerFlags();
2187 if ( linkerflags
.size() > 0 )
2189 fprintf ( fMakefile
,
2191 linkerflagsMacro
.c_str (),
2192 linkerflags
.c_str () );
2195 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
2197 fprintf ( fMakefile
,
2198 "%s += -Wno-main\n\n",
2199 cflagsMacro
.c_str () );
2202 fprintf ( fMakefile
, "\n\n" );
2204 // future references to the macros will be to get their values
2205 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
2206 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
2207 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
2211 MingwModuleHandler::GenerateRules ()
2213 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
2214 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
2215 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
2217 if ( module
.name
!= "zlib" ) /* Avoid make warning */
2219 FileLocation
proxyMakefile ( OutputDirectory
,
2220 module
.output
->relative_path
,
2222 CLEAN_FILE ( proxyMakefile
);
2225 string targetMacro
= GetTargetMacro ( module
);
2226 //CLEAN_FILE ( targetMacro );
2227 CLEAN_FILE ( FileLocation ( SourceDirectory
, "", targetMacro
) );
2229 // generate phony target for module name
2230 fprintf ( fMakefile
, ".PHONY: %s\n",
2231 module
.name
.c_str () );
2232 string dependencies
= GetTargetMacro ( module
);
2233 if ( module
.type
== Test
)
2234 dependencies
+= " $(REGTESTS_RUN_TARGET)";
2235 fprintf ( fMakefile
, "%s: %s\n\n",
2236 module
.name
.c_str (),
2237 dependencies
.c_str () );
2238 if ( module
.type
== Test
)
2240 fprintf ( fMakefile
,
2242 targetMacro
.c_str ());
2245 if ( !ReferenceObjects ( module
) )
2247 const FileLocation
* ar_target
= GenerateArchiveTarget ( ar
, objectsMacro
);
2248 CLEAN_FILE ( *ar_target
);
2251 GenerateObjectFileTargets ( cc
,
2260 MingwModuleHandler::GetInvocationDependencies (
2261 const Module
& module
,
2262 string_list
& dependencies
)
2264 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
2266 Invoke
& invoke
= *module
.invocations
[i
];
2267 if ( invoke
.invokeModule
== &module
)
2268 /* Protect against circular dependencies */
2270 invoke
.GetTargets ( dependencies
);
2275 MingwModuleHandler::GenerateInvocations () const
2277 if ( module
.invocations
.size () == 0 )
2280 size_t iend
= module
.invocations
.size ();
2281 for ( size_t i
= 0; i
< iend
; i
++ )
2283 const Invoke
& invoke
= *module
.invocations
[i
];
2285 if ( invoke
.invokeModule
->type
!= BuildTool
)
2287 throw XMLInvalidBuildFileException (
2288 module
.node
.location
,
2289 "Only modules of type buildtool can be invoked." );
2292 string invokeTarget
= module
.GetInvocationTarget ( i
);
2293 string_list invoke_targets
;
2294 assert ( invoke_targets
.size() );
2295 invoke
.GetTargets ( invoke_targets
);
2296 fprintf ( fMakefile
,
2298 invokeTarget
.c_str () );
2299 fprintf ( fMakefile
,
2301 invokeTarget
.c_str () );
2302 size_t j
, jend
= invoke_targets
.size();
2303 for ( j
= 0; j
< jend
; j
++ )
2305 fprintf ( fMakefile
,
2307 invoke_targets
[i
].c_str () );
2309 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
2310 for ( j
= 1; j
< jend
; j
++ )
2311 fprintf ( fMakefile
,
2313 invoke_targets
[i
].c_str () );
2314 fprintf ( fMakefile
,
2316 NormalizeFilename ( backend
->GetFullName ( *invoke
.invokeModule
->output
) ).c_str () );
2317 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
2318 fprintf ( fMakefile
,
2320 NormalizeFilename ( backend
->GetFullName ( *invoke
.invokeModule
->output
) ).c_str (),
2321 invoke
.GetParameters ().c_str () );
2326 MingwModuleHandler::GetPreconditionDependenciesName () const
2328 return module
.name
+ "_precondition";
2332 MingwModuleHandler::GetDefaultDependencies (
2333 string_list
& dependencies
) const
2335 /* Avoid circular dependency */
2336 if ( module
.type
!= BuildTool
2337 && module
.name
!= "zlib"
2338 && module
.name
!= "hostzlib" )
2340 dependencies
.push_back ( "$(INIT)" );
2342 if ( module
.type
!= BuildTool
2343 && module
.name
!= "psdk" )
2345 dependencies
.push_back ( "$(PSDK_TARGET) $(psdk_HEADERS)" );
2349 MingwModuleHandler::GeneratePreconditionDependencies ()
2351 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2352 vector
<FileLocation
> sourceFilenames
;
2353 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
2354 string_list dependencies
;
2355 GetDefaultDependencies ( dependencies
);
2356 GetModuleDependencies ( dependencies
);
2358 GetInvocationDependencies ( module
, dependencies
);
2360 if ( dependencies
.size() )
2362 fprintf ( fMakefile
,
2364 preconditionDependenciesName
.c_str () );
2365 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2366 fprintf ( fMakefile
,
2368 dependencies
[i
].c_str () );
2369 fprintf ( fMakefile
, "\n\n" );
2372 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
2374 fprintf ( fMakefile
,
2376 backend
->GetFullName ( sourceFilenames
[i
] ).c_str (),
2377 preconditionDependenciesName
.c_str ());
2379 fprintf ( fMakefile
, "\n" );
2383 MingwModuleHandler::IsWineModule () const
2385 if ( module
.importLibrary
== NULL
)
2388 size_t index
= module
.importLibrary
->source
->name
.rfind ( ".spec.def" );
2389 return ( index
!= string::npos
);
2393 MingwModuleHandler::GetDefinitionFilename () const
2395 if ( module
.importLibrary
!= NULL
)
2397 DirectoryLocation directory
;
2398 if ( IsWineModule () )
2399 directory
= IntermediateDirectory
;
2401 directory
= SourceDirectory
;
2403 return new FileLocation ( directory
,
2404 module
.importLibrary
->source
->relative_path
,
2405 module
.importLibrary
->source
->name
);
2408 return new FileLocation ( SourceDirectory
, "tools" + sSep
+ "rbuild", "empty.def" );
2412 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2414 if ( module
.importLibrary
!= NULL
)
2416 const FileLocation
*library_target
= GetImportLibraryFilename ( module
, &clean_files
);
2417 const FileLocation
*defFilename
= GetDefinitionFilename ();
2419 vector
<FileLocation
> deps
;
2420 GetDefinitionDependencies ( deps
);
2422 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2424 fprintf ( fMakefile
, "%s: %s",
2425 backend
->GetFullName ( *library_target
).c_str (),
2426 backend
->GetFullName ( *defFilename
).c_str () );
2428 size_t i
, iend
= deps
.size();
2429 for ( i
= 0; i
< iend
; i
++ )
2430 fprintf ( fMakefile
, " %s",
2431 backend
->GetFullName ( deps
[i
] ).c_str () );
2433 fprintf ( fMakefile
, " | %s\n",
2434 backend
->GetFullPath ( *GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2436 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2438 fprintf ( fMakefile
,
2439 "\t${dlltool} --dllname %s --def %s --output-lib %s %s %s\n\n",
2440 module
.output
->name
.c_str (),
2441 backend
->GetFullName ( *defFilename
).c_str (),
2442 backend
->GetFullName ( *library_target
).c_str (),
2443 module
.mangledSymbols
? "" : "--kill-at",
2444 module
.underscoreSymbols
? "--add-underscore" : "" );
2449 MingwModuleHandler::GetSpecObjectDependencies (
2450 vector
<FileLocation
>& dependencies
,
2451 const FileLocation
*file
) const
2453 string basename
= GetBasename ( file
->name
);
2455 FileLocation
defDependency ( IntermediateDirectory
,
2456 file
->relative_path
,
2457 basename
+ ".spec.def" );
2458 dependencies
.push_back ( defDependency
);
2460 FileLocation
stubsDependency ( IntermediateDirectory
,
2461 file
->relative_path
,
2462 basename
+ ".stubs.c" );
2463 dependencies
.push_back ( stubsDependency
);
2467 MingwModuleHandler::GetWidlObjectDependencies (
2468 vector
<FileLocation
>& dependencies
,
2469 const FileLocation
*file
) const
2471 string basename
= GetBasename ( file
->name
);
2473 FileLocation
serverSourceDependency ( IntermediateDirectory
,
2474 file
->relative_path
,
2475 basename
+ "_s.c" );
2476 dependencies
.push_back ( serverSourceDependency
);
2477 dependencies
.push_back ( *GetRpcServerHeaderFilename ( file
) );
2481 MingwModuleHandler::GetDefinitionDependencies (
2482 vector
<FileLocation
>& dependencies
) const
2484 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2485 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2487 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2488 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
2489 string extension
= GetExtension ( *sourceFile
);
2490 if ( extension
== ".spec" || extension
== ".SPEC" )
2491 GetSpecObjectDependencies ( dependencies
, sourceFile
);
2492 if ( extension
== ".idl" || extension
== ".IDL" )
2494 if ( ( module
.type
== RpcServer
) || ( module
.type
== RpcClient
) )
2495 GetWidlObjectDependencies ( dependencies
, sourceFile
);
2500 enum DebugSupportType
2507 MingwAddDebugSupportLibraries ( Module
& module
, DebugSupportType type
)
2513 case DebugKernelMode
:
2514 pLibrary
= new Library ( module
, "debugsup_ntoskrnl" );
2518 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2525 module
.non_if_data
.libraries
.push_back(pLibrary
);
2528 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2529 : MingwModuleHandler ( module_
)
2534 MingwBuildToolModuleHandler::Process ()
2536 GenerateBuildToolModuleTarget ();
2540 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2542 string
targetMacro ( GetTargetMacro (module
) );
2543 string objectsMacro
= GetObjectsMacro ( module
);
2544 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2545 string libsMacro
= GetLibsMacro ();
2550 if ( module
.cplusplus
)
2551 linker
= "${host_gpp}";
2553 linker
= "${host_gcc}";
2555 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2556 targetMacro
.c_str (),
2557 objectsMacro
.c_str (),
2558 linkDepsMacro
.c_str (),
2559 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
2560 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2561 fprintf ( fMakefile
,
2562 "\t%s %s -o $@ %s %s\n\n",
2564 GetLinkerMacro ().c_str (),
2565 objectsMacro
.c_str (),
2566 libsMacro
.c_str () );
2570 MingwKernelModuleHandler::MingwKernelModuleHandler (
2571 const Module
& module_
)
2573 : MingwModuleHandler ( module_
)
2578 MingwKernelModuleHandler::Process ()
2580 GenerateKernelModuleTarget ();
2584 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2586 string
targetMacro ( GetTargetMacro ( module
) );
2587 string workingDirectory
= GetWorkingDirectory ( );
2588 string objectsMacro
= GetObjectsMacro ( module
);
2589 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2590 string libsMacro
= GetLibsMacro ();
2592 GenerateImportLibraryTargetIfNeeded ();
2594 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2598 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2600 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s",
2601 module
.GetEntryPoint(true).c_str (),
2602 module
.baseaddress
.c_str () );
2603 GenerateLinkerCommand ( dependencies
,
2605 linkerParameters
+ " $(NTOSKRNL_SHARED)",
2612 GeneratePhonyTarget();
2617 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2618 const Module
& module_
)
2620 : MingwModuleHandler ( module_
)
2625 MingwStaticLibraryModuleHandler::Process ()
2627 GenerateStaticLibraryModuleTarget ();
2631 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2637 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2638 const Module
& module_
)
2640 : MingwModuleHandler ( module_
)
2645 MingwObjectLibraryModuleHandler::Process ()
2647 GenerateObjectLibraryModuleTarget ();
2651 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2657 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2658 const Module
& module_
)
2660 : MingwModuleHandler ( module_
)
2664 MingwEmbeddedTypeLibModuleHandler::MingwEmbeddedTypeLibModuleHandler (
2665 const Module
& module_
)
2667 : MingwModuleHandler ( module_
)
2672 MingwEmbeddedTypeLibModuleHandler::Process ()
2679 MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2681 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2685 MingwKernelModeDLLModuleHandler::Process ()
2687 GenerateKernelModeDLLModuleTarget ();
2691 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2693 string
targetMacro ( GetTargetMacro ( module
) );
2694 string workingDirectory
= GetWorkingDirectory ( );
2695 string objectsMacro
= GetObjectsMacro ( module
);
2696 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2697 string libsMacro
= GetLibsMacro ();
2699 GenerateImportLibraryTargetIfNeeded ();
2701 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2705 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2707 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2708 module
.GetEntryPoint(true).c_str (),
2709 module
.baseaddress
.c_str () );
2710 GenerateLinkerCommand ( dependencies
,
2719 GeneratePhonyTarget();
2724 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2725 const Module
& module_
)
2727 : MingwModuleHandler ( module_
)
2732 MingwKernelModeDriverModuleHandler::AddImplicitLibraries ( Module
& module
)
2734 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2738 MingwKernelModeDriverModuleHandler::Process ()
2740 GenerateKernelModeDriverModuleTarget ();
2745 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2747 string
targetMacro ( GetTargetMacro (module
) );
2748 string workingDirectory
= GetWorkingDirectory ();
2749 string objectsMacro
= GetObjectsMacro ( module
);
2750 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2751 string libsMacro
= GetLibsMacro ();
2753 GenerateImportLibraryTargetIfNeeded ();
2755 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2759 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2761 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2762 module
.GetEntryPoint(true).c_str (),
2763 module
.baseaddress
.c_str () );
2764 GenerateLinkerCommand ( dependencies
,
2773 GeneratePhonyTarget();
2778 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2779 const Module
& module_
)
2781 : MingwModuleHandler ( module_
)
2786 MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2788 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2792 MingwNativeDLLModuleHandler::Process ()
2794 GenerateNativeDLLModuleTarget ();
2798 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2800 string
targetMacro ( GetTargetMacro (module
) );
2801 string workingDirectory
= GetWorkingDirectory ( );
2802 string objectsMacro
= GetObjectsMacro ( module
);
2803 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2804 string libsMacro
= GetLibsMacro ();
2806 GenerateImportLibraryTargetIfNeeded ();
2808 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2812 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2814 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2815 module
.GetEntryPoint(true).c_str (),
2816 module
.baseaddress
.c_str () );
2817 GenerateLinkerCommand ( dependencies
,
2826 GeneratePhonyTarget();
2831 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2832 const Module
& module_
)
2834 : MingwModuleHandler ( module_
)
2839 MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2841 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2845 MingwNativeCUIModuleHandler::Process ()
2847 GenerateNativeCUIModuleTarget ();
2851 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2853 string
targetMacro ( GetTargetMacro (module
) );
2854 string workingDirectory
= GetWorkingDirectory ( );
2855 string objectsMacro
= GetObjectsMacro ( module
);
2856 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2857 string libsMacro
= GetLibsMacro ();
2859 GenerateImportLibraryTargetIfNeeded ();
2861 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2865 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2867 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2868 module
.GetEntryPoint(true).c_str (),
2869 module
.baseaddress
.c_str () );
2870 GenerateLinkerCommand ( dependencies
,
2879 GeneratePhonyTarget();
2884 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2885 const Module
& module_
)
2887 : MingwModuleHandler ( module_
)
2891 MingwWin32OCXModuleHandler::MingwWin32OCXModuleHandler (
2892 const Module
& module_
)
2894 : MingwModuleHandler ( module_
)
2899 MingwAddImplicitLibraries( Module
&module
)
2903 if ( module
.type
!= Win32DLL
2904 && module
.type
!= Win32OCX
2905 && module
.type
!= Win32CUI
2906 && module
.type
!= Win32GUI
2907 && module
.type
!= Win32SCR
)
2909 // no implicit libraries
2913 if ( !module
.isDefaultEntryPoint
)
2915 if ( module
.GetEntryPoint(false) == "0" )
2917 pLibrary
= new Library ( module
, "mingw_common" );
2918 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() , pLibrary
);
2919 pLibrary
= new Library ( module
, "msvcrt" );
2920 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2925 if ( module
.IsDLL () )
2927 //pLibrary = new Library ( module, "__mingw_dllmain" );
2928 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
2932 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
2933 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
2936 pLibrary
= new Library ( module
, "mingw_common" );
2937 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
2939 if ( module
.name
!= "msvcrt" )
2941 // always link in msvcrt to get the basic routines
2942 pLibrary
= new Library ( module
, "msvcrt" );
2943 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2948 MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2950 MingwAddImplicitLibraries ( module
);
2951 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2955 MingwWin32DLLModuleHandler::Process ()
2957 GenerateWin32DLLModuleTarget ();
2961 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2963 string
targetMacro ( GetTargetMacro (module
) );
2964 string workingDirectory
= GetWorkingDirectory ( );
2965 string objectsMacro
= GetObjectsMacro ( module
);
2966 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2967 string libsMacro
= GetLibsMacro ();
2969 GenerateImportLibraryTargetIfNeeded ();
2971 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2975 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2978 if ( module
.cplusplus
)
2983 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2984 module
.GetEntryPoint(true).c_str (),
2985 module
.baseaddress
.c_str () );
2986 GenerateLinkerCommand ( dependencies
,
2995 GeneratePhonyTarget();
3001 MingwWin32OCXModuleHandler::AddImplicitLibraries ( Module
& module
)
3003 MingwAddImplicitLibraries ( module
);
3004 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3008 MingwWin32OCXModuleHandler::Process ()
3010 GenerateWin32OCXModuleTarget ();
3014 MingwWin32OCXModuleHandler::GenerateWin32OCXModuleTarget ()
3016 string
targetMacro ( GetTargetMacro (module
) );
3017 string workingDirectory
= GetWorkingDirectory ( );
3018 string objectsMacro
= GetObjectsMacro ( module
);
3019 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3020 string libsMacro
= GetLibsMacro ();
3022 GenerateImportLibraryTargetIfNeeded ();
3024 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3028 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3031 if ( module
.cplusplus
)
3036 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
3037 module
.GetEntryPoint(true).c_str (),
3038 module
.baseaddress
.c_str () );
3039 GenerateLinkerCommand ( dependencies
,
3048 GeneratePhonyTarget();
3053 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
3054 const Module
& module_
)
3056 : MingwModuleHandler ( module_
)
3061 MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module
& module
)
3063 MingwAddImplicitLibraries ( module
);
3064 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3068 MingwWin32CUIModuleHandler::Process ()
3070 GenerateWin32CUIModuleTarget ();
3074 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
3076 string
targetMacro ( GetTargetMacro (module
) );
3077 string workingDirectory
= GetWorkingDirectory ( );
3078 string objectsMacro
= GetObjectsMacro ( module
);
3079 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3080 string libsMacro
= GetLibsMacro ();
3082 GenerateImportLibraryTargetIfNeeded ();
3084 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3088 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3091 if ( module
.cplusplus
)
3096 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3097 module
.GetEntryPoint(true).c_str (),
3098 module
.baseaddress
.c_str () );
3099 GenerateLinkerCommand ( dependencies
,
3108 GeneratePhonyTarget();
3113 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
3114 const Module
& module_
)
3116 : MingwModuleHandler ( module_
)
3121 MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module
& module
)
3123 MingwAddImplicitLibraries ( module
);
3124 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3128 MingwWin32GUIModuleHandler::Process ()
3130 GenerateWin32GUIModuleTarget ();
3134 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
3136 string
targetMacro ( GetTargetMacro (module
) );
3137 string workingDirectory
= GetWorkingDirectory ( );
3138 string objectsMacro
= GetObjectsMacro ( module
);
3139 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3140 string libsMacro
= GetLibsMacro ();
3142 GenerateImportLibraryTargetIfNeeded ();
3144 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3148 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3151 if ( module
.cplusplus
)
3156 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3157 module
.GetEntryPoint(true).c_str (),
3158 module
.baseaddress
.c_str () );
3159 GenerateLinkerCommand ( dependencies
,
3168 GeneratePhonyTarget();
3173 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
3174 const Module
& module_
)
3176 : MingwModuleHandler ( module_
)
3181 MingwBootLoaderModuleHandler::Process ()
3183 GenerateBootLoaderModuleTarget ();
3187 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
3189 string
targetName ( module
.output
->name
);
3190 string
targetMacro ( GetTargetMacro (module
) );
3191 string workingDirectory
= GetWorkingDirectory ();
3192 FileLocation
junk_tmp ( TemporaryDirectory
,
3194 module
.name
+ ".junk.tmp" );
3195 CLEAN_FILE ( junk_tmp
);
3196 string objectsMacro
= GetObjectsMacro ( module
);
3197 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3198 string libsMacro
= GetLibsMacro ();
3202 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3203 targetMacro
.c_str (),
3204 objectsMacro
.c_str (),
3205 linkDepsMacro
.c_str (),
3206 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
3208 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
3210 fprintf ( fMakefile
,
3211 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
3212 GetLinkerMacro ().c_str (),
3213 backend
->GetFullName ( junk_tmp
).c_str (),
3214 objectsMacro
.c_str (),
3215 linkDepsMacro
.c_str () );
3216 fprintf ( fMakefile
,
3217 "\t${objcopy} -O binary %s $@\n",
3218 backend
->GetFullName ( junk_tmp
).c_str () );
3219 GenerateBuildMapCode ( &junk_tmp
);
3220 fprintf ( fMakefile
,
3221 "\t-@${rm} %s 2>$(NUL)\n",
3222 backend
->GetFullName ( junk_tmp
).c_str () );
3226 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
3227 const Module
& module_
)
3229 : MingwModuleHandler ( module_
)
3234 MingwBootSectorModuleHandler::Process ()
3236 GenerateBootSectorModuleTarget ();
3240 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
3242 string objectsMacro
= GetObjectsMacro ( module
);
3246 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3247 module
.name
.c_str ());
3248 fprintf ( fMakefile
,
3250 module
.name
.c_str (),
3251 objectsMacro
.c_str () );
3255 MingwBootProgramModuleHandler::MingwBootProgramModuleHandler (
3256 const Module
& module_
)
3257 : MingwModuleHandler ( module_
)
3262 MingwBootProgramModuleHandler::Process ()
3264 GenerateBootProgramModuleTarget ();
3268 MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
3270 string
targetName ( module
.output
->name
);
3271 string
targetMacro ( GetTargetMacro (module
) );
3272 string workingDirectory
= GetWorkingDirectory ();
3273 FileLocation
junk_tmp ( TemporaryDirectory
,
3275 module
.name
+ ".junk.tmp" );
3276 FileLocation
junk_elf ( TemporaryDirectory
,
3278 module
.name
+ ".junk.elf" );
3279 FileLocation
junk_cpy ( TemporaryDirectory
,
3281 module
.name
+ ".junk.elf" );
3282 CLEAN_FILE ( junk_tmp
);
3283 CLEAN_FILE ( junk_elf
);
3284 CLEAN_FILE ( junk_cpy
);
3285 string objectsMacro
= GetObjectsMacro ( module
);
3286 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3287 string libsMacro
= GetLibsMacro ();
3288 const Module
*payload
= module
.project
.LocateModule ( module
.payload
);
3292 fprintf ( fMakefile
, "%s: %s %s %s | %s\n",
3293 targetMacro
.c_str (),
3294 objectsMacro
.c_str (),
3295 linkDepsMacro
.c_str (),
3296 payload
->name
.c_str (),
3297 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
3299 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3301 fprintf ( fMakefile
, "\t$(%s_PREPARE) $(OUTPUT)$(SEP)%s %s\n",
3302 module
.buildtype
.c_str (),
3303 NormalizeFilename( backend
->GetFullName ( *payload
->output
) ).c_str (),
3304 backend
->GetFullName ( junk_cpy
).c_str () );
3306 fprintf ( fMakefile
, "\t${objcopy} $(%s_FLATFORMAT) %s %s\n",
3307 module
.buildtype
.c_str (),
3308 backend
->GetFullName ( junk_cpy
).c_str (),
3309 backend
->GetFullName ( junk_tmp
).c_str () );
3311 fprintf ( fMakefile
, "\t${ld} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3312 module
.buildtype
.c_str (),
3313 linkDepsMacro
.c_str (),
3314 backend
->GetFullName ( junk_tmp
).c_str (),
3315 backend
->GetFullName ( junk_elf
).c_str () );
3317 fprintf ( fMakefile
, "\t${objcopy} $(%s_COPYFORMAT) %s $(INTERMEDIATE)$(SEP)%s\n",
3318 module
.buildtype
.c_str (),
3319 backend
->GetFullName ( junk_elf
).c_str (),
3320 backend
->GetFullName ( *module
.output
) .c_str () );
3322 fprintf ( fMakefile
,
3323 "\t-@${rm} %s %s %s 2>$(NUL)\n",
3324 backend
->GetFullName ( junk_tmp
).c_str (),
3325 backend
->GetFullName ( junk_elf
).c_str (),
3326 backend
->GetFullName ( junk_cpy
).c_str () );
3330 MingwIsoModuleHandler::MingwIsoModuleHandler (
3331 const Module
& module_
)
3333 : MingwModuleHandler ( module_
)
3338 MingwIsoModuleHandler::Process ()
3340 GenerateIsoModuleTarget ();
3344 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
3345 const string
& bootcdDirectory
)
3347 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3349 const Module
& m
= *module
.project
.modules
[i
];
3352 if ( m
.bootstrap
!= NULL
)
3354 FileLocation
targetFile ( OutputDirectory
,
3355 m
.bootstrap
->base
.length () > 0
3356 ? bootcdDirectory
+ sSep
+ m
.bootstrap
->base
3358 m
.bootstrap
->nameoncd
);
3359 OutputCopyCommand ( *m
.output
, targetFile
);
3365 MingwIsoModuleHandler::OutputCdfileCopyCommands (
3366 const string
& bootcdDirectory
)
3368 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3370 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3371 FileLocation
targetFile ( OutputDirectory
,
3372 cdfile
.target
->relative_path
.length () > 0
3373 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3375 cdfile
.target
->name
);
3376 OutputCopyCommand ( *cdfile
.source
, targetFile
);
3381 MingwIsoModuleHandler::GetBootstrapCdDirectories ( vector
<FileLocation
>& out
,
3382 const string
& bootcdDirectory
)
3384 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3386 const Module
& m
= *module
.project
.modules
[i
];
3389 if ( m
.bootstrap
!= NULL
)
3391 FileLocation
targetDirectory ( OutputDirectory
,
3392 m
.bootstrap
->base
.length () > 0
3393 ? bootcdDirectory
+ sSep
+ m
.bootstrap
->base
3396 out
.push_back ( targetDirectory
);
3402 MingwIsoModuleHandler::GetNonModuleCdDirectories ( vector
<FileLocation
>& out
,
3403 const string
& bootcdDirectory
)
3405 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3407 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3408 FileLocation
targetDirectory ( OutputDirectory
,
3409 cdfile
.target
->relative_path
.length () > 0
3410 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3413 out
.push_back( targetDirectory
);
3418 MingwIsoModuleHandler::GetCdDirectories ( vector
<FileLocation
>& out
,
3419 const string
& bootcdDirectory
)
3421 GetBootstrapCdDirectories ( out
, bootcdDirectory
);
3422 GetNonModuleCdDirectories ( out
, bootcdDirectory
);
3426 MingwIsoModuleHandler::GetBootstrapCdFiles (
3427 vector
<FileLocation
>& out
) const
3429 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3431 const Module
& m
= *module
.project
.modules
[i
];
3434 if ( m
.bootstrap
!= NULL
)
3436 out
.push_back ( *m
.output
);
3442 MingwIsoModuleHandler::GetNonModuleCdFiles (
3443 vector
<FileLocation
>& out
) const
3445 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3447 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3448 out
.push_back ( *cdfile
.source
);
3453 MingwIsoModuleHandler::GetCdFiles (
3454 vector
<FileLocation
>& out
) const
3456 GetBootstrapCdFiles ( out
);
3457 GetNonModuleCdFiles ( out
);
3461 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
3463 string bootcdDirectory
= "cd";
3464 FileLocation
bootcd ( OutputDirectory
,
3467 FileLocation
bootcdReactos ( OutputDirectory
,
3468 bootcdDirectory
+ sSep
+ Environment::GetCdOutputPath (),
3470 vector
<FileLocation
> vSourceFiles
, vCdFiles
;
3471 vector
<FileLocation
> vCdDirectories
;
3474 FileLocation
srcunattend ( SourceDirectory
,
3475 "boot" + sSep
+ "bootdata" + sSep
+ "bootcdregtest",
3477 FileLocation
tarunattend ( bootcdReactos
.directory
,
3478 bootcdReactos
.relative_path
,
3480 if (module
.type
== IsoRegTest
)
3481 vSourceFiles
.push_back ( srcunattend
);
3484 FileLocation
isoboot ( OutputDirectory
,
3485 "boot" + sSep
+ "freeldr" + sSep
+ "bootsect",
3486 module
.type
== IsoRegTest
3489 vSourceFiles
.push_back ( isoboot
);
3491 // prepare reactos.dff and reactos.inf
3492 FileLocation
reactosDff ( SourceDirectory
,
3493 "boot" + sSep
+ "bootdata" + sSep
+ "packages",
3495 FileLocation
reactosInf ( bootcdReactos
.directory
,
3496 bootcdReactos
.relative_path
,
3498 vSourceFiles
.push_back ( reactosDff
);
3502 if (module
.type
== IsoRegTest
)
3503 IsoName
= "ReactOS-RegTest.iso";
3505 IsoName
= "ReactOS.iso";
3508 string sourceFiles
= v2s ( backend
, vSourceFiles
, 5 );
3511 GetCdDirectories ( vCdDirectories
, bootcdDirectory
);
3512 GetCdFiles ( vCdFiles
);
3513 string cdDirectories
= "";//v2s ( vCdDirectories, 5 );
3514 string cdFiles
= v2s ( backend
, vCdFiles
, 5 );
3516 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3517 module
.name
.c_str ());
3518 fprintf ( fMakefile
,
3519 "%s: all %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET) %s\n",
3520 module
.name
.c_str (),
3521 backend
->GetFullName ( isoboot
).c_str (),
3522 sourceFiles
.c_str (),
3524 cdDirectories
.c_str () );
3525 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
3526 fprintf ( fMakefile
,
3527 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
3528 backend
->GetFullName ( reactosDff
).c_str (),
3529 backend
->GetFullPath ( bootcdReactos
).c_str () );
3530 fprintf ( fMakefile
,
3531 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
3532 backend
->GetFullName ( reactosDff
).c_str (),
3533 backend
->GetFullName ( reactosInf
).c_str (),
3534 backend
->GetFullPath ( bootcdReactos
).c_str ());
3535 fprintf ( fMakefile
,
3536 "\t-@${rm} %s 2>$(NUL)\n",
3537 backend
->GetFullName ( reactosInf
).c_str () );
3538 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
3539 OutputCdfileCopyCommands ( bootcdDirectory
);
3541 if (module
.type
== IsoRegTest
)
3542 OutputCopyCommand ( srcunattend
, tarunattend
);
3544 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3545 fprintf ( fMakefile
,
3546 "\t$(Q)$(CDMAKE_TARGET) -v -j -m -b %s %s REACTOS %s\n",
3547 backend
->GetFullName ( isoboot
).c_str (),
3548 backend
->GetFullPath ( bootcd
).c_str (),
3550 fprintf ( fMakefile
,
3555 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
3556 const Module
& module_
)
3558 : MingwModuleHandler ( module_
)
3563 MingwLiveIsoModuleHandler::Process ()
3565 GenerateLiveIsoModuleTarget ();
3569 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
3571 FileLocation
dir ( OutputDirectory
,
3574 MingwModuleHandler::PassThruCacheDirectory ( &dir
);
3578 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
3579 string
& reactosDirectory
)
3581 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3583 const Module
& m
= *module
.project
.modules
[i
];
3588 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
3589 FileLocation
destination ( OutputDirectory
,
3590 m
.install
->relative_path
.length () > 0
3591 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.install
->relative_path
3592 : livecdDirectory
+ sSep
+ reactosDirectory
,
3594 OutputCopyCommand ( *aliasedModule
.output
,
3601 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
3602 string
& reactosDirectory
)
3604 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
3606 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
3607 FileLocation
target ( OutputDirectory
,
3608 installfile
.target
->relative_path
.length () > 0
3609 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.target
->relative_path
3610 : livecdDirectory
+ sSep
+ reactosDirectory
,
3611 installfile
.target
->name
);
3612 OutputCopyCommand ( *installfile
.source
, target
);
3617 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
3619 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
3620 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
3621 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
3622 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
3623 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
3624 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
3626 FileLocation
livecdIni ( SourceDirectory
,
3627 "boot" + sSep
+ "bootdata",
3629 FileLocation
destination ( OutputDirectory
,
3632 OutputCopyCommand ( livecdIni
,
3637 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3639 FileLocation
freeldr ( OutputDirectory
,
3640 "boot" + sSep
+ "freeldr" + sSep
+ "freeldr",
3642 FileLocation
destination ( OutputDirectory
,
3643 livecdDirectory
+ sSep
+ "loader",
3645 OutputCopyCommand ( freeldr
,
3650 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3652 FileLocation
reactosSystem32ConfigDirectory ( OutputDirectory
,
3653 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config",
3655 fprintf ( fMakefile
,
3656 "\t$(ECHO_MKHIVE)\n" );
3657 fprintf ( fMakefile
,
3658 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%clivecd.inf boot%cbootdata%chiveinst.inf\n",
3659 cSep
, backend
->GetFullPath ( reactosSystem32ConfigDirectory
).c_str (),
3660 cSep
, cSep
, cSep
, cSep
);
3664 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
3666 string livecdDirectory
= module
.name
;
3667 FileLocation
livecd ( OutputDirectory
, livecdDirectory
, "" );
3672 if (module
.name
== "livecdregtest")
3674 bootloader
= "isobtrt.o";
3675 IsoName
= "ReactOS-LiveCD-RegTest.iso";
3679 bootloader
= "isoboot.o";
3680 IsoName
= "ReactOS-LiveCD.iso";
3683 FileLocation
isoboot ( OutputDirectory
, "boot" + sSep
+ "freeldr" + sSep
+ "bootsect", bootloader
);
3685 string reactosDirectory
= "reactos";
3686 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3687 FileLocation
livecdReactos ( OutputDirectory
,
3688 livecdReactosNoFixup
,
3690 CLEAN_FILE ( livecdReactos
);
3692 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3693 module
.name
.c_str ());
3694 fprintf ( fMakefile
,
3695 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3696 module
.name
.c_str (),
3697 backend
->GetFullName ( isoboot
) .c_str (),
3698 backend
->GetFullPath ( livecdReactos
).c_str () );
3699 OutputModuleCopyCommands ( livecdDirectory
,
3701 OutputNonModuleCopyCommands ( livecdDirectory
,
3703 OutputProfilesDirectoryCommands ( livecdDirectory
);
3704 OutputLoaderCommands ( livecdDirectory
);
3705 OutputRegistryCommands ( livecdDirectory
);
3706 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3707 fprintf ( fMakefile
,
3708 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS %s\n",
3709 backend
->GetFullName( isoboot
).c_str (),
3710 backend
->GetFullPath ( livecd
).c_str (),
3712 fprintf ( fMakefile
,
3717 MingwTestModuleHandler::MingwTestModuleHandler (
3718 const Module
& module_
)
3720 : MingwModuleHandler ( module_
)
3725 MingwTestModuleHandler::Process ()
3727 GenerateTestModuleTarget ();
3731 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
3733 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_hooks.c", false, "", false ) ) );
3734 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_stubs.S", false, "", false ) ) );
3735 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_startup.c", false, "", false ) ) );
3739 MingwTestModuleHandler::GenerateTestModuleTarget ()
3741 string
targetMacro ( GetTargetMacro ( module
) );
3742 string workingDirectory
= GetWorkingDirectory ( );
3743 string objectsMacro
= GetObjectsMacro ( module
);
3744 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3745 string libsMacro
= GetLibsMacro ();
3747 GenerateImportLibraryTargetIfNeeded ();
3749 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3753 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3756 if ( module
.cplusplus
)
3761 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3762 module
.GetEntryPoint(true).c_str (),
3763 module
.baseaddress
.c_str () );
3764 GenerateLinkerCommand ( dependencies
,
3773 GeneratePhonyTarget();
3778 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3779 const Module
& module_
)
3781 : MingwModuleHandler ( module_
)
3786 MingwRpcServerModuleHandler::Process ()
3792 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3793 const Module
& module_
)
3795 : MingwModuleHandler ( module_
)
3800 MingwRpcClientModuleHandler::Process ()
3806 MingwAliasModuleHandler::MingwAliasModuleHandler (
3807 const Module
& module_
)
3809 : MingwModuleHandler ( module_
)
3814 MingwAliasModuleHandler::Process ()
3818 MingwIdlHeaderModuleHandler::MingwIdlHeaderModuleHandler (
3819 const Module
& module_
)
3821 : MingwModuleHandler ( module_
)
3826 MingwIdlHeaderModuleHandler::Process ()
3831 MingwElfExecutableModuleHandler::MingwElfExecutableModuleHandler (
3832 const Module
& module_
)
3834 : MingwModuleHandler ( module_
)
3839 MingwElfExecutableModuleHandler::Process ()
3841 string
targetName ( module
.output
->name
);
3842 string
targetMacro ( GetTargetMacro (module
) );
3843 string workingDirectory
= GetWorkingDirectory ();
3844 string objectsMacro
= GetObjectsMacro ( module
);
3845 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3846 string libsMacro
= GetLibsMacro ();
3850 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3851 targetMacro
.c_str (),
3852 objectsMacro
.c_str (),
3853 linkDepsMacro
.c_str (),
3854 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
3856 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3858 fprintf ( fMakefile
, "\t${gcc} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3859 module
.buildtype
.c_str(),
3860 objectsMacro
.c_str(),
3862 targetMacro
.c_str () );