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 (), 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 string_list
* pclean_files
) const
505 DirectoryLocation destination_directory
;
507 string extension
= GetExtension ( *sourceFile
);
508 if ( extension
== ".rc" || extension
== ".RC" )
509 newExtension
= ".coff";
510 else if ( extension
== ".spec" || extension
== ".SPEC" )
511 newExtension
= ".stubs.o";
512 else if ( extension
== ".idl" || extension
== ".IDL" )
514 if ( module
.type
== RpcServer
)
515 newExtension
= "_s.o";
516 else if ( module
.type
== RpcClient
)
517 newExtension
= "_c.o";
524 if ( module
.type
== BootSector
)
525 destination_directory
= OutputDirectory
;
527 destination_directory
= IntermediateDirectory
;
529 const FileLocation
*obj_file
= new FileLocation(
530 destination_directory
,
531 sourceFile
->relative_path
,
532 ReplaceExtension ( sourceFile
->name
, newExtension
) );
536 string_list
& clean_files
= *pclean_files
;
537 CLEAN_FILE ( *obj_file
);
543 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
545 return module
.name
+ "_clean";
549 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
551 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
553 Library
& library
= *module
.non_if_data
.libraries
[i
];
554 if ( library
.importedModule
->type
== ObjectLibrary
)
555 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
560 MingwModuleHandler::GenerateCleanTarget () const
562 if ( module
.type
== Alias
)
566 ".PHONY: %s_clean\n",
567 module
.name
.c_str() );
568 vector
<string
> referencedModuleNames
;
569 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
572 GetModuleCleanTarget ( module
).c_str(),
573 v2s ( referencedModuleNames
, 10 ).c_str () );
574 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
576 if ( ( i
+ 1 ) % 10 == 9 )
577 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
578 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
580 fprintf ( fMakefile
, " 2>$(NUL)\n" );
581 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
585 MingwModuleHandler::GenerateInstallTarget () const
587 if ( !module
.install
)
589 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
592 module
.name
.c_str (),
593 backend
->GetFullName ( *module
.install
).c_str () );
597 MingwModuleHandler::GenerateDependsTarget () const
600 ".PHONY: %s_depends\n",
601 module
.name
.c_str() );
603 "%s_depends: $(RBUILD_TARGET)\n",
604 module
.name
.c_str () );
606 "\t$(ECHO_RBUILD)\n" );
608 "\t$(Q)$(RBUILD_TARGET) $(RBUILD_FLAGS) -dm%s mingw\n",
609 module
.name
.c_str () );
613 MingwModuleHandler::GetObjectFilenames ()
615 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
616 if ( compilationUnits
.size () == 0 )
619 string
objectFilenames ( "" );
620 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
622 if ( objectFilenames
.size () > 0 )
623 objectFilenames
+= " ";
624 objectFilenames
+= backend
->GetFullName ( *GetObjectFilename ( compilationUnits
[i
]->GetFilename (), NULL
) );
626 return objectFilenames
;
630 MingwModuleHandler::GenerateGccDefineParametersFromVector (
631 const vector
<Define
*>& defines
,
632 set
<string
>& used_defs
)
636 for ( size_t i
= 0; i
< defines
.size (); i
++ )
638 Define
& define
= *defines
[i
];
639 if (used_defs
.find(define
.name
) != used_defs
.end())
641 if (parameters
.length () > 0)
643 if (define
.name
.find('(') != string::npos
)
644 parameters
+= "$(QT)";
646 parameters
+= define
.name
;
647 if (define
.value
.length () > 0)
650 parameters
+= define
.value
;
652 if (define
.name
.find('(') != string::npos
)
653 parameters
+= "$(QT)";
654 used_defs
.insert(used_defs
.begin(),define
.name
);
660 MingwModuleHandler::GenerateGccDefineParameters () const
662 set
<string
> used_defs
;
663 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
, used_defs
);
664 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
, used_defs
);
665 if ( s
.length () > 0 )
674 MingwModuleHandler::ConcatenatePaths (
676 const string
& path2
) const
678 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
680 if ( path1
[path1
.length ()] == cSep
)
681 return path1
+ path2
;
683 return path1
+ cSep
+ path2
;
687 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
689 string parameters
, path_prefix
;
690 for ( size_t i
= 0; i
< includes
.size (); i
++ )
692 Include
& include
= *includes
[i
];
693 if ( parameters
.length () > 0 )
695 parameters
+= "-I" + backend
->GetFullPath ( *include
.directory
);;
701 MingwModuleHandler::GenerateGccIncludeParameters () const
703 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
704 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
705 if ( s
.length () > 0 )
714 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
717 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
719 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
720 if ( parameters
.length () > 0 )
722 parameters
+= compilerFlag
.flag
;
728 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
731 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
733 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
734 if ( parameters
.length () > 0 )
736 parameters
+= linkerFlag
.flag
;
742 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
743 const vector
<Library
*>& libraries
)
745 string
dependencies ( "" );
747 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
749 if ( wrap_count
++ == 5 )
750 dependencies
+= " \\\n\t\t", wrap_count
= 0;
751 else if ( dependencies
.size () > 0 )
753 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
759 MingwModuleHandler::GenerateLinkerParameters () const
761 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
765 MingwModuleHandler::GenerateMacro (
766 const char* assignmentOperation
,
768 const IfableData
& data
,
769 set
<string
> *used_defs
,
770 bool generatingCompilerMacro
)
773 bool generateAssignment
;
775 if ( generatingCompilerMacro
)
776 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
778 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0;
779 if ( generateAssignment
)
784 assignmentOperation
);
787 if ( use_pch
&& module
.pch
!= NULL
)
791 backend
->GetFullPath ( *GetPrecompiledHeaderFilename () ).c_str () );
794 if ( generatingCompilerMacro
)
796 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
797 if ( compilerParameters
.size () > 0 )
802 compilerParameters
.c_str () );
805 for ( i
= 0; i
< data
.includes
.size(); i
++ )
807 const Include
& include
= *data
.includes
[i
];
808 const FileLocation
* includeDirectory
= include
.directory
;
812 backend
->GetFullPath ( *includeDirectory
).c_str() );
814 for ( i
= 0; i
< data
.defines
.size(); i
++ )
816 const Define
& define
= *data
.defines
[i
];
817 if ( used_defs
&& used_defs
->find ( define
.name
) != used_defs
->end () )
819 if ( !define
.overridable
)
821 throw InvalidOperationException ( __FILE__
,
823 "Invalid override of define '%s' in module '%s'",
824 define
.name
.c_str (),
825 module
.name
.c_str () );
827 if ( backend
->configuration
.Verbose
)
828 printf("Define '%s' overridden in module '%s'\n",
829 define
.name
.c_str (), module
.name
.c_str () );
835 define
.name
.c_str() );
836 if ( define
.value
.size() )
840 define
.value
.c_str() );
842 used_defs
->insert(used_defs
->begin(), define
.name
);
844 if ( generateAssignment
)
846 fprintf ( fMakefile
, "\n" );
851 MingwModuleHandler::GenerateMacros (
852 const char* assignmentOperation
,
853 const IfableData
& data
,
854 const vector
<LinkerFlag
*>* linkerFlags
,
855 set
<string
>& used_defs
)
859 GenerateMacro ( assignmentOperation
,
864 GenerateMacro ( assignmentOperation
,
870 if ( linkerFlags
!= NULL
)
872 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
873 if ( linkerParameters
.size () > 0 )
878 linkerflagsMacro
.c_str (),
880 linkerParameters
.c_str() );
884 if ( data
.libraries
.size () > 0 )
886 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
887 if ( deps
.size () > 0 )
898 const vector
<If
*>& ifs
= data
.ifs
;
899 for ( i
= 0; i
< ifs
.size(); i
++ )
902 if ( rIf
.data
.defines
.size()
903 || rIf
.data
.includes
.size()
904 || rIf
.data
.libraries
.size()
905 || rIf
.data
.compilationUnits
.size()
906 || rIf
.data
.compilerFlags
.size()
907 || rIf
.data
.ifs
.size() )
911 "%s (\"$(%s)\",\"%s\")\n",
912 rIf
.negated
? "ifneq" : "ifeq",
913 rIf
.property
.c_str(),
928 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
930 for (size_t i
= 0; i
< compilationUnits
.size (); i
++)
931 delete compilationUnits
[i
];
935 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
940 MingwModuleHandler::GenerateSourceMacros (
941 const char* assignmentOperation
,
942 const IfableData
& data
)
946 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
947 vector
<const FileLocation
*> headers
;
948 if ( compilationUnits
.size () > 0 )
953 sourcesMacro
.c_str (),
954 assignmentOperation
);
955 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
957 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
961 ( i
%10 == 9 ? " \\\n\t" : " " ),
962 backend
->GetFullName ( *compilationUnit
.GetFilename () ).c_str () );
964 fprintf ( fMakefile
, "\n" );
967 const vector
<If
*>& ifs
= data
.ifs
;
968 for ( i
= 0; i
< ifs
.size(); i
++ )
971 if ( rIf
.data
.defines
.size()
972 || rIf
.data
.includes
.size()
973 || rIf
.data
.libraries
.size()
974 || rIf
.data
.compilationUnits
.size()
975 || rIf
.data
.compilerFlags
.size()
976 || rIf
.data
.ifs
.size() )
980 "%s (\"$(%s)\",\"%s\")\n",
981 rIf
.negated
? "ifneq" : "ifeq",
982 rIf
.property
.c_str(),
984 GenerateSourceMacros (
993 vector
<CompilationUnit
*> sourceCompilationUnits
;
994 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
995 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1000 sourcesMacro
.c_str(),
1001 backend
->GetFullName ( *sourceCompilationUnits
[i
]->GetFilename () ).c_str () );
1003 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1007 MingwModuleHandler::GenerateObjectMacros (
1008 const char* assignmentOperation
,
1009 const IfableData
& data
)
1013 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1014 vector
<const FileLocation
*> headers
;
1015 if ( compilationUnits
.size () > 0 )
1017 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1019 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1020 if ( compilationUnit
.IsFirstFile () )
1022 fprintf ( fMakefile
,
1024 objectsMacro
.c_str(),
1025 backend
->GetFullName ( *GetObjectFilename ( compilationUnit
.GetFilename (), NULL
) ).c_str (),
1026 objectsMacro
.c_str() );
1032 objectsMacro
.c_str (),
1033 assignmentOperation
);
1034 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
1036 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1037 if ( !compilationUnit
.IsFirstFile () )
1039 const FileLocation
*objectFilename
= GetObjectFilename ( compilationUnit
.GetFilename (), NULL
);
1040 if ( GetExtension ( *objectFilename
) == ".h" )
1041 headers
.push_back ( objectFilename
);
1046 ( i
%10 == 9 ? " \\\n\t" : " " ),
1047 backend
->GetFullName ( *objectFilename
).c_str () );
1050 fprintf ( fMakefile
, "\n" );
1052 if ( headers
.size () > 0 )
1057 module
.name
.c_str (),
1058 assignmentOperation
);
1059 for ( i
= 0; i
< headers
.size (); i
++ )
1063 ( i
%10 == 9 ? " \\\n\t" : " " ),
1064 backend
->GetFullName ( *headers
[i
] ).c_str () );
1065 fprintf ( fMakefile
, "\n" );
1068 const vector
<If
*>& ifs
= data
.ifs
;
1069 for ( i
= 0; i
< ifs
.size(); i
++ )
1072 if ( rIf
.data
.defines
.size()
1073 || rIf
.data
.includes
.size()
1074 || rIf
.data
.libraries
.size()
1075 || rIf
.data
.compilationUnits
.size()
1076 || rIf
.data
.compilerFlags
.size()
1077 || rIf
.data
.ifs
.size() )
1081 "%s (\"$(%s)\",\"%s\")\n",
1082 rIf
.negated
? "ifneq" : "ifeq",
1083 rIf
.property
.c_str(),
1084 rIf
.value
.c_str() );
1085 GenerateObjectMacros (
1094 vector
<CompilationUnit
*> sourceCompilationUnits
;
1095 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1096 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1101 objectsMacro
.c_str(),
1102 backend
->GetFullName ( *GetObjectFilename ( sourceCompilationUnits
[i
]->GetFilename (), NULL
) ).c_str () );
1104 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1108 MingwModuleHandler::GetPrecompiledHeaderFilename () const
1110 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
1111 return new FileLocation ( IntermediateDirectory
,
1112 module
.pch
->file
.relative_path
,
1117 MingwModuleHandler::GenerateGccCommand (
1118 const FileLocation
* sourceFile
,
1119 const string
& extraDependencies
,
1121 const string
& cflagsMacro
)
1123 string dependencies
= backend
->GetFullName ( *sourceFile
);
1124 if ( extraDependencies
!= "" )
1125 dependencies
+= " " + extraDependencies
;
1126 if ( module
.pch
&& use_pch
)
1127 dependencies
+= " " + backend
->GetFullName ( *GetPrecompiledHeaderFilename () );
1129 /* WIDL generated headers may be used */
1130 vector
<FileLocation
> rpcDependencies
;
1131 GetRpcHeaderDependencies ( rpcDependencies
);
1132 dependencies
+= " " + v2s ( backend
, rpcDependencies
, 5 );
1133 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1135 const FileLocation
*objectFilename
= GetObjectFilename (
1136 sourceFile
, &clean_files
);
1137 fprintf ( fMakefile
,
1139 backend
->GetFullName ( *objectFilename
).c_str (),
1140 dependencies
.c_str (),
1141 backend
->GetFullPath ( *objectFilename
).c_str () );
1142 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
1143 fprintf ( fMakefile
,
1144 "\t%s -c $< -o $@ %s\n",
1146 cflagsMacro
.c_str () );
1150 MingwModuleHandler::GenerateGccAssemblerCommand (
1151 const FileLocation
* sourceFile
,
1153 const string
& cflagsMacro
)
1155 string dependencies
= backend
->GetFullName ( *sourceFile
);
1156 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1158 const FileLocation
*objectFilename
= GetObjectFilename (
1159 sourceFile
, &clean_files
);
1160 fprintf ( fMakefile
,
1162 backend
->GetFullName ( *objectFilename
).c_str (),
1163 dependencies
.c_str (),
1164 backend
->GetFullPath ( *objectFilename
).c_str () );
1165 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
1166 fprintf ( fMakefile
,
1167 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
1169 cflagsMacro
.c_str () );
1173 MingwModuleHandler::GenerateNasmCommand (
1174 const FileLocation
* sourceFile
,
1175 const string
& nasmflagsMacro
)
1177 string dependencies
= backend
->GetFullName ( *sourceFile
);
1178 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1180 const FileLocation
*objectFilename
= GetObjectFilename (
1181 sourceFile
, &clean_files
);
1182 fprintf ( fMakefile
,
1184 backend
->GetFullName ( *objectFilename
).c_str (),
1185 dependencies
.c_str (),
1186 backend
->GetFullPath ( *objectFilename
).c_str () );
1187 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1188 fprintf ( fMakefile
,
1189 "\t%s -f win32 $< -o $@ %s\n",
1191 nasmflagsMacro
.c_str () );
1195 MingwModuleHandler::GenerateWindresCommand (
1196 const FileLocation
* sourceFile
,
1197 const string
& windresflagsMacro
)
1199 string dependencies
= backend
->GetFullName ( *sourceFile
);
1200 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1202 const FileLocation
*objectFilename
= GetObjectFilename ( sourceFile
, &clean_files
);
1204 string sourceFilenamePart
= module
.name
+ "." + ReplaceExtension ( sourceFile
->name
, "" );
1205 FileLocation
rciFilename ( TemporaryDirectory
,
1207 sourceFilenamePart
+ ".rci.tmp" );
1208 FileLocation
resFilename ( TemporaryDirectory
,
1210 sourceFilenamePart
+ ".res.tmp" );
1212 fprintf ( fMakefile
,
1213 "%s: %s $(WRC_TARGET) | %s\n",
1214 backend
->GetFullName ( *objectFilename
).c_str (),
1215 dependencies
.c_str (),
1216 backend
->GetFullPath ( *objectFilename
).c_str () );
1217 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1218 fprintf ( fMakefile
,
1219 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1220 windresflagsMacro
.c_str (),
1221 backend
->GetFullName ( *sourceFile
).c_str (),
1222 backend
->GetFullName ( rciFilename
).c_str () );
1223 fprintf ( fMakefile
,
1224 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1225 windresflagsMacro
.c_str (),
1226 backend
->GetFullName ( rciFilename
).c_str (),
1227 backend
->GetFullName ( resFilename
).c_str () );
1228 fprintf ( fMakefile
,
1229 "\t-@${rm} %s 2>$(NUL)\n",
1230 backend
->GetFullName ( rciFilename
).c_str () );
1231 fprintf ( fMakefile
,
1232 "\t${windres} %s -o $@\n",
1233 backend
->GetFullName ( resFilename
).c_str () );
1234 fprintf ( fMakefile
,
1235 "\t-@${rm} %s 2>$(NUL)\n",
1236 backend
->GetFullName ( resFilename
).c_str () );
1240 MingwModuleHandler::GenerateWinebuildCommands (
1241 const FileLocation
* sourceFile
)
1243 string dependencies
= backend
->GetFullName ( *sourceFile
);
1244 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1246 string basename
= GetBasename ( sourceFile
->name
);
1247 FileLocation
def_file ( IntermediateDirectory
,
1248 sourceFile
->relative_path
,
1249 basename
+ ".spec.def" );
1250 CLEAN_FILE ( def_file
);
1252 FileLocation
stub_file ( IntermediateDirectory
,
1253 sourceFile
->relative_path
,
1254 basename
+ ".stubs.c" );
1255 CLEAN_FILE ( stub_file
);
1257 fprintf ( fMakefile
,
1258 "%s: %s $(WINEBUILD_TARGET) | %s\n",
1259 backend
->GetFullName ( def_file
).c_str (),
1260 dependencies
.c_str (),
1261 backend
->GetFullPath ( def_file
).c_str () );
1262 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1263 fprintf ( fMakefile
,
1264 "\t%s -o %s --def -E %s\n",
1265 "$(Q)$(WINEBUILD_TARGET)",
1266 backend
->GetFullName ( def_file
).c_str (),
1267 backend
->GetFullName ( *sourceFile
).c_str () );
1268 fprintf ( fMakefile
,
1269 "%s: %s $(WINEBUILD_TARGET)\n",
1270 backend
->GetFullName ( stub_file
).c_str (),
1271 backend
->GetFullName ( *sourceFile
).c_str () );
1272 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1273 fprintf ( fMakefile
,
1274 "\t%s -o %s --pedll %s\n",
1275 "$(Q)$(WINEBUILD_TARGET)",
1276 backend
->GetFullName ( stub_file
).c_str (),
1277 backend
->GetFullName ( *sourceFile
).c_str () );
1281 MingwModuleHandler::GetWidlFlags ( const CompilationUnit
& compilationUnit
)
1283 return compilationUnit
.GetSwitches ();
1287 MingwModuleHandler::GetPropertyValue ( const Module
& module
, const std::string
& name
)
1289 for ( size_t i
= 0; i
< module
.project
.non_if_data
.properties
.size (); i
++ )
1291 const Property
& property
= *module
.project
.non_if_data
.properties
[i
];
1292 if ( property
.name
== name
)
1293 return property
.value
;
1295 return string ( "" );
1299 MingwModuleHandler::GetRpcServerHeaderFilename ( const FileLocation
*base
) const
1301 string newname
= GetBasename ( base
->name
) + "_s.h";
1302 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1306 MingwModuleHandler::GenerateWidlCommandsServer (
1307 const CompilationUnit
& compilationUnit
,
1308 const string
& widlflagsMacro
)
1310 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1311 string dependencies
= backend
->GetFullName ( *sourceFile
);
1312 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1314 string basename
= GetBasename ( sourceFile
->name
);
1316 const FileLocation
*generatedHeaderFilename
= GetRpcServerHeaderFilename ( sourceFile
);
1317 CLEAN_FILE ( *generatedHeaderFilename
);
1319 FileLocation
generatedServerFilename ( IntermediateDirectory
,
1320 sourceFile
->relative_path
,
1321 basename
+ "_s.c" );
1322 CLEAN_FILE ( generatedServerFilename
);
1324 fprintf ( fMakefile
,
1325 "%s %s: %s $(WIDL_TARGET) | %s\n",
1326 backend
->GetFullName ( generatedServerFilename
).c_str (),
1327 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1328 dependencies
.c_str (),
1329 backend
->GetFullPath ( generatedServerFilename
).c_str () );
1330 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1331 fprintf ( fMakefile
,
1332 "\t%s %s %s -h -H %s -s -S %s %s\n",
1333 "$(Q)$(WIDL_TARGET)",
1334 GetWidlFlags ( compilationUnit
).c_str (),
1335 widlflagsMacro
.c_str (),
1336 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1337 backend
->GetFullName ( generatedServerFilename
).c_str (),
1338 backend
->GetFullName ( *sourceFile
).c_str () );
1342 MingwModuleHandler::GetRpcClientHeaderFilename ( const FileLocation
*base
) const
1344 string newname
= GetBasename ( base
->name
) + "_c.h";
1345 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1349 MingwModuleHandler::GetIdlHeaderFilename ( const FileLocation
*base
) const
1351 string newname
= GetBasename ( base
->name
) + ".h";
1352 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1356 MingwModuleHandler::GenerateWidlCommandsEmbeddedTypeLib (
1357 const CompilationUnit
& compilationUnit
,
1358 const string
& widlflagsMacro
)
1360 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1361 string dependencies
= backend
->GetFullName ( *sourceFile
);
1362 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1364 string basename
= GetBasename ( sourceFile
->name
);
1366 FileLocation
EmbeddedTypeLibFilename ( IntermediateDirectory
,
1367 sourceFile
->relative_path
,
1368 basename
+ ".tlb" );
1370 fprintf ( fMakefile
,
1371 "%s: %s $(WIDL_TARGET) | %s\n",
1372 GetTargetMacro ( module
).c_str (),
1373 dependencies
.c_str (),
1374 backend
->GetFullPath ( EmbeddedTypeLibFilename
).c_str () );
1375 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1376 fprintf ( fMakefile
,
1377 "\t%s %s %s -t -T %s %s\n",
1378 "$(Q)$(WIDL_TARGET)",
1379 GetWidlFlags ( compilationUnit
).c_str (),
1380 widlflagsMacro
.c_str (),
1381 backend
->GetFullName ( EmbeddedTypeLibFilename
).c_str(),
1382 backend
->GetFullName ( *sourceFile
).c_str () );
1386 MingwModuleHandler::GenerateWidlCommandsClient (
1387 const CompilationUnit
& compilationUnit
,
1388 const string
& widlflagsMacro
)
1390 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1391 string dependencies
= backend
->GetFullName ( *sourceFile
);
1392 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1394 string basename
= GetBasename ( sourceFile
->name
);
1396 const FileLocation
*generatedHeaderFilename
= GetRpcClientHeaderFilename ( sourceFile
);
1397 CLEAN_FILE ( *generatedHeaderFilename
);
1399 FileLocation
generatedClientFilename ( IntermediateDirectory
,
1400 sourceFile
->relative_path
,
1401 basename
+ "_c.c" );
1402 CLEAN_FILE ( generatedClientFilename
);
1404 fprintf ( fMakefile
,
1405 "%s %s: %s $(WIDL_TARGET) | %s\n",
1406 backend
->GetFullName ( generatedClientFilename
).c_str (),
1407 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1408 dependencies
.c_str (),
1409 backend
->GetFullPath ( generatedClientFilename
).c_str () );
1410 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1411 fprintf ( fMakefile
,
1412 "\t%s %s %s -h -H %s -c -C %s %s\n",
1413 "$(Q)$(WIDL_TARGET)",
1414 GetWidlFlags ( compilationUnit
).c_str (),
1415 widlflagsMacro
.c_str (),
1416 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1417 backend
->GetFullName ( generatedClientFilename
).c_str (),
1418 backend
->GetFullName ( *sourceFile
).c_str () );
1422 MingwModuleHandler::GenerateWidlCommandsIdlHeader (
1423 const CompilationUnit
& compilationUnit
,
1424 const string
& widlflagsMacro
)
1426 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1427 string dependencies
= backend
->GetFullName ( *sourceFile
);
1428 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1430 string basename
= GetBasename ( sourceFile
->name
);
1432 const FileLocation
*generatedHeader
= GetIdlHeaderFilename ( sourceFile
);
1433 CLEAN_FILE ( *generatedHeader
);
1435 fprintf ( fMakefile
,
1436 "%s: %s $(WIDL_TARGET) | %s\n",
1437 backend
->GetFullName( *generatedHeader
).c_str (),
1438 dependencies
.c_str (),
1439 backend
->GetFullPath ( *generatedHeader
).c_str () );
1440 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1441 fprintf ( fMakefile
,
1442 "\t%s %s %s -h -H %s %s\n",
1443 "$(Q)$(WIDL_TARGET)",
1444 GetWidlFlags ( compilationUnit
).c_str (),
1445 widlflagsMacro
.c_str (),
1446 backend
->GetFullName ( *generatedHeader
).c_str (),
1447 backend
->GetFullName ( *sourceFile
).c_str () );
1451 MingwModuleHandler::GenerateWidlCommands (
1452 const CompilationUnit
& compilationUnit
,
1453 const string
& widlflagsMacro
)
1455 if ( module
.type
== RpcServer
)
1456 GenerateWidlCommandsServer ( compilationUnit
,
1458 else if ( module
.type
== RpcClient
)
1459 GenerateWidlCommandsClient ( compilationUnit
,
1461 else if ( module
.type
== EmbeddedTypeLib
)
1462 GenerateWidlCommandsEmbeddedTypeLib ( compilationUnit
,
1464 else // applies also for other module.types which include idl files
1465 GenerateWidlCommandsIdlHeader ( compilationUnit
,
1470 MingwModuleHandler::GenerateCommands (
1471 const CompilationUnit
& compilationUnit
,
1472 const string
& extraDependencies
,
1475 const string
& cflagsMacro
,
1476 const string
& nasmflagsMacro
,
1477 const string
& windresflagsMacro
,
1478 const string
& widlflagsMacro
)
1480 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
1481 string extension
= GetExtension ( *sourceFile
);
1482 if ( extension
== ".c" || extension
== ".C" )
1484 GenerateGccCommand ( sourceFile
,
1485 GetCompilationUnitDependencies ( compilationUnit
) + extraDependencies
,
1490 else if ( extension
== ".cc" || extension
== ".CC" ||
1491 extension
== ".cpp" || extension
== ".CPP" ||
1492 extension
== ".cxx" || extension
== ".CXX" )
1494 GenerateGccCommand ( sourceFile
,
1495 GetCompilationUnitDependencies ( compilationUnit
) + extraDependencies
,
1500 else if ( extension
== ".s" || extension
== ".S" )
1502 GenerateGccAssemblerCommand ( sourceFile
,
1507 else if ( extension
== ".asm" || extension
== ".ASM" )
1509 GenerateNasmCommand ( sourceFile
,
1513 else if ( extension
== ".rc" || extension
== ".RC" )
1515 GenerateWindresCommand ( sourceFile
,
1516 windresflagsMacro
);
1519 else if ( extension
== ".spec" || extension
== ".SPEC" )
1521 GenerateWinebuildCommands ( sourceFile
);
1522 GenerateGccCommand ( GetActualSourceFilename ( sourceFile
),
1528 else if ( extension
== ".idl" || extension
== ".IDL" )
1530 GenerateWidlCommands ( compilationUnit
,
1532 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
1534 GenerateGccCommand ( GetActualSourceFilename ( sourceFile
),
1535 GetExtraDependencies ( sourceFile
),
1542 throw InvalidOperationException ( __FILE__
,
1544 "Unsupported filename extension '%s' in file '%s'",
1546 backend
->GetFullName ( *sourceFile
).c_str () );
1550 MingwModuleHandler::GenerateBuildMapCode ( const FileLocation
*mapTarget
)
1552 fprintf ( fMakefile
,
1553 "ifeq ($(ROS_BUILDMAP),full)\n" );
1555 FileLocation
mapFilename ( OutputDirectory
,
1556 module
.output
->relative_path
,
1557 GetBasename ( module
.output
->name
) + ".map" );
1558 CLEAN_FILE ( mapFilename
);
1560 fprintf ( fMakefile
,
1561 "\t$(ECHO_OBJDUMP)\n" );
1562 fprintf ( fMakefile
,
1563 "\t$(Q)${objdump} -d -S %s > %s\n",
1564 mapTarget
? backend
->GetFullName ( *mapTarget
).c_str () : "$@",
1565 backend
->GetFullName ( mapFilename
).c_str () );
1567 fprintf ( fMakefile
,
1569 fprintf ( fMakefile
,
1570 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1572 fprintf ( fMakefile
,
1574 fprintf ( fMakefile
,
1575 "\t$(Q)${nm} --numeric-sort %s > %s\n",
1576 mapTarget
? backend
->GetFullName ( *mapTarget
).c_str () : "$@",
1577 backend
->GetFullName ( mapFilename
).c_str () );
1579 fprintf ( fMakefile
,
1582 fprintf ( fMakefile
,
1587 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1589 fprintf ( fMakefile
,
1590 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1592 FileLocation
nostripFilename ( OutputDirectory
,
1593 module
.output
->relative_path
,
1594 GetBasename ( module
.output
->name
) + ".nostrip" + GetExtension ( *module
.output
) );
1595 CLEAN_FILE ( nostripFilename
);
1597 OutputCopyCommand ( *module
.output
, nostripFilename
);
1599 fprintf ( fMakefile
,
1604 MergeStringVector ( const Backend
* backend
,
1605 const vector
<FileLocation
>& input
,
1606 vector
<string
>& output
)
1610 int wrap_count
= -1;
1611 for ( size_t i
= 0; i
< input
.size (); i
++ )
1613 if ( wrap_count
++ == wrap_at
)
1615 output
.push_back ( s
);
1619 else if ( s
.size () > 0)
1621 s
+= backend
->GetFullName ( input
[i
] );
1623 if ( s
.length () > 0 )
1624 output
.push_back ( s
);
1628 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1629 vector
<FileLocation
>& objectFiles
) const
1631 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1633 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1634 objectFiles
.push_back ( *GetObjectFilename ( compilationUnit
.GetFilename (), NULL
) );
1639 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1641 if ( backend
->configuration
.CleanAsYouGo
)
1643 vector
<FileLocation
> objectFiles
;
1644 GetObjectsVector ( module
.non_if_data
,
1646 vector
<string
> lines
;
1647 MergeStringVector ( backend
,
1650 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1652 fprintf ( fMakefile
,
1653 "\t-@${rm} %s 2>$(NUL)\n",
1654 lines
[i
].c_str () );
1660 MingwModuleHandler::GenerateRunRsymCode () const
1662 fprintf ( fMakefile
,
1663 "\t$(ECHO_RSYM)\n" );
1664 fprintf ( fMakefile
,
1665 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1669 MingwModuleHandler::GenerateRunStripCode () const
1671 fprintf ( fMakefile
,
1672 "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" );
1673 fprintf ( fMakefile
,
1674 "\t$(ECHO_STRIP)\n" );
1675 fprintf ( fMakefile
,
1676 "\t${strip} -s -x -X $@\n\n" );
1677 fprintf ( fMakefile
,
1682 MingwModuleHandler::GenerateLinkerCommand (
1683 const string
& dependencies
,
1684 const string
& linker
,
1685 const string
& linkerParameters
,
1686 const string
& objectsMacro
,
1687 const string
& libsMacro
,
1688 const string
& pefixupParameters
)
1690 string
target ( GetTargetMacro ( module
) );
1691 string
target_folder ( backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ) );
1692 const FileLocation
*definitionFilename
= GetDefinitionFilename ();
1694 string linkerScriptArgument
;
1695 if ( module
.linkerScript
!= NULL
)
1696 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", backend
->GetFullName ( module
.linkerScript
->file
).c_str () );
1698 linkerScriptArgument
= "";
1700 fprintf ( fMakefile
,
1701 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1703 backend
->GetFullName ( *definitionFilename
).c_str (),
1704 dependencies
.c_str (),
1705 target_folder
.c_str () );
1706 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1707 string
targetName ( module
.output
->name
);
1709 if ( !module
.IsDLL () )
1711 fprintf ( fMakefile
,
1712 "\t%s %s %s -o %s %s %s %s\n",
1714 linkerParameters
.c_str (),
1715 linkerScriptArgument
.c_str (),
1717 objectsMacro
.c_str (),
1719 GetLinkerMacro ().c_str () );
1721 else if ( module
.HasImportLibrary () )
1723 FileLocation
temp_exp ( TemporaryDirectory
,
1725 module
.name
+ ".temp.exp" );
1726 CLEAN_FILE ( temp_exp
);
1728 fprintf ( fMakefile
,
1729 "\t${dlltool} --dllname %s --def %s --output-exp %s %s %s\n",
1730 targetName
.c_str (),
1731 backend
->GetFullName ( *definitionFilename
).c_str (),
1732 backend
->GetFullName ( temp_exp
).c_str (),
1733 module
.mangledSymbols
? "" : "--kill-at",
1734 module
.underscoreSymbols
? "--add-underscore" : "" );
1736 fprintf ( fMakefile
,
1737 "\t%s %s %s %s -o %s %s %s %s\n",
1739 linkerParameters
.c_str (),
1740 linkerScriptArgument
.c_str (),
1741 backend
->GetFullName ( temp_exp
).c_str (),
1743 objectsMacro
.c_str (),
1745 GetLinkerMacro ().c_str () );
1747 fprintf ( fMakefile
,
1748 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1750 pefixupParameters
.c_str() );
1752 fprintf ( fMakefile
,
1753 "\t-@${rm} %s 2>$(NUL)\n",
1754 backend
->GetFullName ( temp_exp
).c_str () );
1758 /* XXX: need to workaround binutils bug, which exports
1759 * all functions in a dll if no .def file or an empty
1760 * one has been provided... */
1762 //printf ( "%s will have all its functions exported\n",
1763 // module.target->name.c_str () );
1764 fprintf ( fMakefile
,
1765 "\t%s %s %s -o %s %s %s %s\n",
1767 linkerParameters
.c_str (),
1768 linkerScriptArgument
.c_str (),
1770 objectsMacro
.c_str (),
1772 GetLinkerMacro ().c_str () );
1775 GenerateBuildMapCode ();
1776 GenerateBuildNonSymbolStrippedCode ();
1777 GenerateRunRsymCode ();
1778 GenerateRunStripCode ();
1779 GenerateCleanObjectsAsYouGoCode ();
1783 MingwModuleHandler::GeneratePhonyTarget() const
1785 string
targetMacro ( GetTargetMacro ( module
) );
1786 fprintf ( fMakefile
,
1788 targetMacro
.c_str ());
1789 fprintf ( fMakefile
, "%s: | %s\n",
1790 targetMacro
.c_str (),
1791 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
1795 MingwModuleHandler::GenerateObjectFileTargets (
1796 const IfableData
& data
,
1799 const string
& cflagsMacro
,
1800 const string
& nasmflagsMacro
,
1801 const string
& windresflagsMacro
,
1802 const string
& widlflagsMacro
)
1805 string moduleDependencies
;
1807 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1808 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1810 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1811 const FileLocation
*objectFilename
= GetObjectFilename ( compilationUnit
.GetFilename (), NULL
);
1812 if ( GetExtension ( *objectFilename
) == ".h" )
1814 moduleDependencies
= ssprintf ( " $(%s_HEADERS)", module
.name
.c_str () );
1819 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1821 GenerateCommands ( *compilationUnits
[i
],
1829 fprintf ( fMakefile
,
1833 const vector
<If
*>& ifs
= data
.ifs
;
1834 for ( i
= 0; i
< ifs
.size(); i
++ )
1836 GenerateObjectFileTargets ( ifs
[i
]->data
,
1845 vector
<CompilationUnit
*> sourceCompilationUnits
;
1846 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1847 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1849 GenerateCommands ( *sourceCompilationUnits
[i
],
1858 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1862 MingwModuleHandler::GenerateObjectFileTargets (
1865 const string
& cflagsMacro
,
1866 const string
& nasmflagsMacro
,
1867 const string
& windresflagsMacro
,
1868 const string
& widlflagsMacro
)
1870 if ( module
.pch
&& use_pch
)
1872 const FileLocation
& baseHeaderFile
= module
.pch
->file
;
1873 const FileLocation
*pchFilename
= GetPrecompiledHeaderFilename ();
1874 CLEAN_FILE ( *pchFilename
);
1875 string dependencies
= backend
->GetFullName ( baseHeaderFile
);
1876 /* WIDL generated headers may be used */
1877 vector
<FileLocation
> rpcDependencies
;
1878 GetRpcHeaderDependencies ( rpcDependencies
);
1879 dependencies
+= " " + v2s ( backend
, rpcDependencies
, 5 );
1880 fprintf ( fMakefile
,
1882 backend
->GetFullName ( *pchFilename
).c_str(),
1883 dependencies
.c_str(),
1884 backend
->GetFullPath ( *pchFilename
).c_str() );
1885 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1886 fprintf ( fMakefile
,
1887 "\t%s -o %s %s -g %s\n\n",
1888 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1889 backend
->GetFullName ( *pchFilename
).c_str(),
1890 cflagsMacro
.c_str(),
1891 backend
->GetFullName ( baseHeaderFile
).c_str() );
1894 GenerateObjectFileTargets ( module
.non_if_data
,
1901 fprintf ( fMakefile
, "\n" );
1905 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1906 const string
& objs_macro
) const
1908 const FileLocation
*archiveFilename
= GetModuleArchiveFilename ();
1910 fprintf ( fMakefile
,
1912 backend
->GetFullName ( *archiveFilename
).c_str (),
1913 objs_macro
.c_str (),
1914 backend
->GetFullPath ( *archiveFilename
).c_str() );
1916 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
1918 const FileLocation
*definitionFilename ( GetDefinitionFilename () );
1920 fprintf ( fMakefile
,
1921 "\t${dlltool} --dllname %s --def %s --output-lib $@ %s %s\n",
1922 module
.importLibrary
->dllname
.c_str (),
1923 backend
->GetFullName ( *definitionFilename
).c_str (),
1924 module
.mangledSymbols
? "" : "--kill-at",
1925 module
.underscoreSymbols
? "--add-underscore" : "" );
1928 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1930 fprintf ( fMakefile
,
1933 objs_macro
.c_str ());
1935 GenerateCleanObjectsAsYouGoCode ();
1937 fprintf ( fMakefile
, "\n" );
1939 return archiveFilename
;
1943 MingwModuleHandler::GetCFlagsMacro () const
1945 return ssprintf ( "$(%s_CFLAGS)",
1946 module
.name
.c_str () );
1950 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1952 return ssprintf ( "$(%s_OBJS)",
1953 module
.name
.c_str () );
1957 MingwModuleHandler::GetLinkingDependenciesMacro () const
1959 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1963 MingwModuleHandler::GetLibsMacro () const
1965 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1969 MingwModuleHandler::GetLinkerMacro () const
1971 return ssprintf ( "$(%s_LFLAGS)",
1972 module
.name
.c_str () );
1976 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1978 if ( ReferenceObjects ( module
) )
1979 return GetObjectsMacro ( module
);
1981 return backend
->GetFullName ( *GetTargetFilename ( module
, NULL
) ).c_str ();
1985 MingwModuleHandler::GenerateSourceMacro ()
1987 sourcesMacro
= ssprintf ( "%s_SOURCES", module
.name
.c_str ());
1989 GenerateSourceMacros (
1991 module
.non_if_data
);
1993 // future references to the macro will be to get its values
1994 sourcesMacro
= ssprintf ("$(%s)", sourcesMacro
.c_str ());
1998 MingwModuleHandler::GenerateObjectMacro ()
2000 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
2002 GenerateObjectMacros (
2004 module
.non_if_data
);
2006 // future references to the macro will be to get its values
2007 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
2011 MingwModuleHandler::GenerateTargetMacro ()
2013 fprintf ( fMakefile
,
2015 GetTargetMacro ( module
, false ).c_str (),
2016 GetModuleTargets ( module
).c_str () );
2020 MingwModuleHandler::GetRpcHeaderDependencies (
2021 vector
<FileLocation
>& dependencies
) const
2023 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
2025 Library
& library
= *module
.non_if_data
.libraries
[i
];
2026 if ( library
.importedModule
->type
== RpcServer
||
2027 library
.importedModule
->type
== RpcClient
||
2028 library
.importedModule
->type
== IdlHeader
)
2030 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
2032 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
2033 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
2034 string extension
= GetExtension ( *sourceFile
);
2035 if ( extension
== ".idl" || extension
== ".IDL" )
2037 string basename
= GetBasename ( sourceFile
->name
);
2038 if ( library
.importedModule
->type
== RpcServer
)
2039 dependencies
.push_back ( *GetRpcServerHeaderFilename ( sourceFile
) );
2040 if ( library
.importedModule
->type
== RpcClient
)
2041 dependencies
.push_back ( *GetRpcClientHeaderFilename ( sourceFile
) );
2042 if ( library
.importedModule
->type
== IdlHeader
)
2043 dependencies
.push_back ( *GetIdlHeaderFilename ( sourceFile
) );
2051 MingwModuleHandler::GenerateOtherMacros ()
2053 set
<string
> used_defs
;
2055 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
2056 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
2057 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
2058 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
2059 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
2060 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
2061 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
2066 &module
.linkerFlags
,
2071 module
.project
.non_if_data
,
2075 vector
<FileLocation
> s
;
2076 if ( module
.importLibrary
)
2078 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2079 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2081 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2082 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
2083 string extension
= GetExtension ( *sourceFile
);
2084 if ( extension
== ".spec" || extension
== ".SPEC" )
2085 GetSpecObjectDependencies ( s
, sourceFile
);
2088 if ( s
.size () > 0 )
2093 linkDepsMacro
.c_str() );
2094 for ( size_t i
= 0; i
< s
.size(); i
++ )
2095 fprintf ( fMakefile
,
2097 backend
->GetFullName ( s
[i
] ).c_str () );
2098 fprintf ( fMakefile
, "\n" );
2101 string globalCflags
= "-g";
2102 if ( backend
->usePipe
)
2103 globalCflags
+= " -pipe";
2104 if ( !module
.allowWarnings
)
2105 globalCflags
+= " -Werror";
2106 if ( module
.host
== HostTrue
)
2108 if ( module
.cplusplus
)
2109 globalCflags
+= " $(HOST_CPPFLAGS)";
2111 globalCflags
+= " $(HOST_CFLAGS)";
2115 if ( module
.cplusplus
)
2117 // HACK: use host headers when building C++
2118 globalCflags
+= " $(HOST_CPPFLAGS)";
2121 globalCflags
+= " -nostdinc";
2124 // Always force disabling of sibling calls optimisation for GCC
2125 // (TODO: Move to version-specific once this bug is fixed in GCC)
2126 globalCflags
+= " -fno-optimize-sibling-calls";
2130 "%s += $(PROJECT_CFLAGS) %s\n",
2131 cflagsMacro
.c_str (),
2132 globalCflags
.c_str () );
2136 "%s += $(PROJECT_RCFLAGS)\n",
2137 windresflagsMacro
.c_str () );
2141 "%s += $(PROJECT_WIDLFLAGS) -I%s\n",
2142 widlflagsMacro
.c_str (),
2143 module
.output
->relative_path
.c_str () );
2147 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
2148 module
.name
.c_str () );
2153 linkDepsMacro
.c_str (),
2154 libsMacro
.c_str () );
2156 string cflags
= TypeSpecificCFlags();
2157 if ( cflags
.size() > 0 )
2159 fprintf ( fMakefile
,
2161 cflagsMacro
.c_str (),
2165 string nasmflags
= TypeSpecificNasmFlags();
2166 if ( nasmflags
.size () > 0 )
2168 fprintf ( fMakefile
,
2170 nasmflagsMacro
.c_str (),
2171 nasmflags
.c_str () );
2174 string linkerflags
= TypeSpecificLinkerFlags();
2175 if ( linkerflags
.size() > 0 )
2177 fprintf ( fMakefile
,
2179 linkerflagsMacro
.c_str (),
2180 linkerflags
.c_str () );
2183 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
2185 fprintf ( fMakefile
,
2186 "%s += -Wno-main\n\n",
2187 cflagsMacro
.c_str () );
2190 fprintf ( fMakefile
, "\n\n" );
2192 // future references to the macros will be to get their values
2193 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
2194 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
2195 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
2199 MingwModuleHandler::GenerateRules ()
2201 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
2202 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
2203 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
2205 if ( module
.name
!= "zlib" ) /* Avoid make warning */
2207 FileLocation
proxyMakefile ( OutputDirectory
,
2208 module
.output
->relative_path
,
2210 CLEAN_FILE ( proxyMakefile
);
2213 string targetMacro
= GetTargetMacro ( module
);
2214 //CLEAN_FILE ( targetMacro );
2215 CLEAN_FILE ( FileLocation ( SourceDirectory
, "", targetMacro
) );
2217 // generate phony target for module name
2218 fprintf ( fMakefile
, ".PHONY: %s\n",
2219 module
.name
.c_str () );
2220 string dependencies
= GetTargetMacro ( module
);
2221 if ( module
.type
== Test
)
2222 dependencies
+= " $(REGTESTS_RUN_TARGET)";
2223 fprintf ( fMakefile
, "%s: %s\n\n",
2224 module
.name
.c_str (),
2225 dependencies
.c_str () );
2226 if ( module
.type
== Test
)
2228 fprintf ( fMakefile
,
2230 targetMacro
.c_str ());
2233 if ( !ReferenceObjects ( module
) )
2235 const FileLocation
* ar_target
= GenerateArchiveTarget ( ar
, objectsMacro
);
2236 CLEAN_FILE ( *ar_target
);
2239 GenerateObjectFileTargets ( cc
,
2248 MingwModuleHandler::GetInvocationDependencies (
2249 const Module
& module
,
2250 string_list
& dependencies
)
2252 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
2254 Invoke
& invoke
= *module
.invocations
[i
];
2255 if ( invoke
.invokeModule
== &module
)
2256 /* Protect against circular dependencies */
2258 invoke
.GetTargets ( dependencies
);
2263 MingwModuleHandler::GenerateInvocations () const
2265 if ( module
.invocations
.size () == 0 )
2268 size_t iend
= module
.invocations
.size ();
2269 for ( size_t i
= 0; i
< iend
; i
++ )
2271 const Invoke
& invoke
= *module
.invocations
[i
];
2273 if ( invoke
.invokeModule
->type
!= BuildTool
)
2275 throw XMLInvalidBuildFileException (
2276 module
.node
.location
,
2277 "Only modules of type buildtool can be invoked." );
2280 string invokeTarget
= module
.GetInvocationTarget ( i
);
2281 string_list invoke_targets
;
2282 assert ( invoke_targets
.size() );
2283 invoke
.GetTargets ( invoke_targets
);
2284 fprintf ( fMakefile
,
2286 invokeTarget
.c_str () );
2287 fprintf ( fMakefile
,
2289 invokeTarget
.c_str () );
2290 size_t j
, jend
= invoke_targets
.size();
2291 for ( j
= 0; j
< jend
; j
++ )
2293 fprintf ( fMakefile
,
2295 invoke_targets
[i
].c_str () );
2297 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
2298 for ( j
= 1; j
< jend
; j
++ )
2299 fprintf ( fMakefile
,
2301 invoke_targets
[i
].c_str () );
2302 fprintf ( fMakefile
,
2304 NormalizeFilename ( backend
->GetFullName ( *invoke
.invokeModule
->output
) ).c_str () );
2305 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
2306 fprintf ( fMakefile
,
2308 NormalizeFilename ( backend
->GetFullName ( *invoke
.invokeModule
->output
) ).c_str (),
2309 invoke
.GetParameters ().c_str () );
2314 MingwModuleHandler::GetPreconditionDependenciesName () const
2316 return module
.name
+ "_precondition";
2320 MingwModuleHandler::GetDefaultDependencies (
2321 string_list
& dependencies
) const
2323 /* Avoid circular dependency */
2324 if ( module
.type
!= BuildTool
2325 && module
.name
!= "zlib"
2326 && module
.name
!= "hostzlib" )
2328 dependencies
.push_back ( "$(INIT)" );
2330 if ( module
.type
!= BuildTool
2331 && module
.name
!= "psdk" )
2333 dependencies
.push_back ( "$(PSDK_TARGET) $(psdk_HEADERS)" );
2337 MingwModuleHandler::GeneratePreconditionDependencies ()
2339 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2340 vector
<FileLocation
> sourceFilenames
;
2341 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
2342 string_list dependencies
;
2343 GetDefaultDependencies ( dependencies
);
2344 GetModuleDependencies ( dependencies
);
2346 GetInvocationDependencies ( module
, dependencies
);
2348 if ( dependencies
.size() )
2350 fprintf ( fMakefile
,
2352 preconditionDependenciesName
.c_str () );
2353 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2354 fprintf ( fMakefile
,
2356 dependencies
[i
].c_str () );
2357 fprintf ( fMakefile
, "\n\n" );
2360 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
2362 fprintf ( fMakefile
,
2364 backend
->GetFullName ( sourceFilenames
[i
] ).c_str (),
2365 preconditionDependenciesName
.c_str ());
2367 fprintf ( fMakefile
, "\n" );
2371 MingwModuleHandler::IsWineModule () const
2373 if ( module
.importLibrary
== NULL
)
2376 size_t index
= module
.importLibrary
->source
->name
.rfind ( ".spec.def" );
2377 return ( index
!= string::npos
);
2381 MingwModuleHandler::GetDefinitionFilename () const
2383 if ( module
.importLibrary
!= NULL
)
2385 DirectoryLocation directory
;
2386 if ( IsWineModule () )
2387 directory
= IntermediateDirectory
;
2389 directory
= SourceDirectory
;
2391 return new FileLocation ( directory
,
2392 module
.importLibrary
->source
->relative_path
,
2393 module
.importLibrary
->source
->name
);
2396 return new FileLocation ( SourceDirectory
, "tools" + sSep
+ "rbuild", "empty.def" );
2400 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2402 if ( module
.importLibrary
!= NULL
)
2404 const FileLocation
*library_target
= GetImportLibraryFilename ( module
, &clean_files
);
2405 const FileLocation
*defFilename
= GetDefinitionFilename ();
2407 vector
<FileLocation
> deps
;
2408 GetDefinitionDependencies ( deps
);
2410 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2412 fprintf ( fMakefile
, "%s: %s",
2413 backend
->GetFullName ( *library_target
).c_str (),
2414 backend
->GetFullName ( *defFilename
).c_str () );
2416 size_t i
, iend
= deps
.size();
2417 for ( i
= 0; i
< iend
; i
++ )
2418 fprintf ( fMakefile
, " %s",
2419 backend
->GetFullName ( deps
[i
] ).c_str () );
2421 fprintf ( fMakefile
, " | %s\n",
2422 backend
->GetFullPath ( *GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2424 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2426 fprintf ( fMakefile
,
2427 "\t${dlltool} --dllname %s --def %s --output-lib %s %s %s\n\n",
2428 module
.output
->name
.c_str (),
2429 backend
->GetFullName ( *defFilename
).c_str (),
2430 backend
->GetFullName ( *library_target
).c_str (),
2431 module
.mangledSymbols
? "" : "--kill-at",
2432 module
.underscoreSymbols
? "--add-underscore" : "" );
2437 MingwModuleHandler::GetSpecObjectDependencies (
2438 vector
<FileLocation
>& dependencies
,
2439 const FileLocation
*file
) const
2441 string basename
= GetBasename ( file
->name
);
2443 FileLocation
defDependency ( IntermediateDirectory
,
2444 file
->relative_path
,
2445 basename
+ ".spec.def" );
2446 dependencies
.push_back ( defDependency
);
2448 FileLocation
stubsDependency ( IntermediateDirectory
,
2449 file
->relative_path
,
2450 basename
+ ".stubs.c" );
2451 dependencies
.push_back ( stubsDependency
);
2455 MingwModuleHandler::GetWidlObjectDependencies (
2456 vector
<FileLocation
>& dependencies
,
2457 const FileLocation
*file
) const
2459 string basename
= GetBasename ( file
->name
);
2461 FileLocation
serverSourceDependency ( IntermediateDirectory
,
2462 file
->relative_path
,
2463 basename
+ "_s.c" );
2464 dependencies
.push_back ( serverSourceDependency
);
2465 dependencies
.push_back ( *GetRpcServerHeaderFilename ( file
) );
2469 MingwModuleHandler::GetDefinitionDependencies (
2470 vector
<FileLocation
>& dependencies
) const
2472 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2473 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2475 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2476 const FileLocation
* sourceFile
= compilationUnit
.GetFilename ();
2477 string extension
= GetExtension ( *sourceFile
);
2478 if ( extension
== ".spec" || extension
== ".SPEC" )
2479 GetSpecObjectDependencies ( dependencies
, sourceFile
);
2480 if ( extension
== ".idl" || extension
== ".IDL" )
2482 if ( ( module
.type
== RpcServer
) || ( module
.type
== RpcClient
) )
2483 GetWidlObjectDependencies ( dependencies
, sourceFile
);
2488 enum DebugSupportType
2495 MingwAddDebugSupportLibraries ( Module
& module
, DebugSupportType type
)
2501 case DebugKernelMode
:
2502 pLibrary
= new Library ( module
, "debugsup_ntoskrnl" );
2506 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2513 module
.non_if_data
.libraries
.push_back(pLibrary
);
2516 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2517 : MingwModuleHandler ( module_
)
2522 MingwBuildToolModuleHandler::Process ()
2524 GenerateBuildToolModuleTarget ();
2528 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2530 string
targetMacro ( GetTargetMacro (module
) );
2531 string objectsMacro
= GetObjectsMacro ( module
);
2532 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2533 string libsMacro
= GetLibsMacro ();
2538 if ( module
.cplusplus
)
2539 linker
= "${host_gpp}";
2541 linker
= "${host_gcc}";
2543 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2544 targetMacro
.c_str (),
2545 objectsMacro
.c_str (),
2546 linkDepsMacro
.c_str (),
2547 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
2548 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2549 fprintf ( fMakefile
,
2550 "\t%s %s -o $@ %s %s\n\n",
2552 GetLinkerMacro ().c_str (),
2553 objectsMacro
.c_str (),
2554 libsMacro
.c_str () );
2558 MingwKernelModuleHandler::MingwKernelModuleHandler (
2559 const Module
& module_
)
2561 : MingwModuleHandler ( module_
)
2566 MingwKernelModuleHandler::Process ()
2568 GenerateKernelModuleTarget ();
2572 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2574 string
targetMacro ( GetTargetMacro ( module
) );
2575 string workingDirectory
= GetWorkingDirectory ( );
2576 string objectsMacro
= GetObjectsMacro ( module
);
2577 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2578 string libsMacro
= GetLibsMacro ();
2580 GenerateImportLibraryTargetIfNeeded ();
2582 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2586 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2588 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s",
2589 module
.GetEntryPoint(true).c_str (),
2590 module
.baseaddress
.c_str () );
2591 GenerateLinkerCommand ( dependencies
,
2593 linkerParameters
+ " $(NTOSKRNL_SHARED)",
2600 GeneratePhonyTarget();
2605 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2606 const Module
& module_
)
2608 : MingwModuleHandler ( module_
)
2613 MingwStaticLibraryModuleHandler::Process ()
2615 GenerateStaticLibraryModuleTarget ();
2619 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2625 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2626 const Module
& module_
)
2628 : MingwModuleHandler ( module_
)
2633 MingwObjectLibraryModuleHandler::Process ()
2635 GenerateObjectLibraryModuleTarget ();
2639 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2645 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2646 const Module
& module_
)
2648 : MingwModuleHandler ( module_
)
2652 MingwEmbeddedTypeLibModuleHandler::MingwEmbeddedTypeLibModuleHandler (
2653 const Module
& module_
)
2655 : MingwModuleHandler ( module_
)
2660 MingwEmbeddedTypeLibModuleHandler::Process ()
2667 MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2669 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2673 MingwKernelModeDLLModuleHandler::Process ()
2675 GenerateKernelModeDLLModuleTarget ();
2679 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2681 string
targetMacro ( GetTargetMacro ( module
) );
2682 string workingDirectory
= GetWorkingDirectory ( );
2683 string objectsMacro
= GetObjectsMacro ( module
);
2684 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2685 string libsMacro
= GetLibsMacro ();
2687 GenerateImportLibraryTargetIfNeeded ();
2689 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2693 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2695 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2696 module
.GetEntryPoint(true).c_str (),
2697 module
.baseaddress
.c_str () );
2698 GenerateLinkerCommand ( dependencies
,
2707 GeneratePhonyTarget();
2712 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2713 const Module
& module_
)
2715 : MingwModuleHandler ( module_
)
2720 MingwKernelModeDriverModuleHandler::AddImplicitLibraries ( Module
& module
)
2722 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2726 MingwKernelModeDriverModuleHandler::Process ()
2728 GenerateKernelModeDriverModuleTarget ();
2733 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2735 string
targetMacro ( GetTargetMacro (module
) );
2736 string workingDirectory
= GetWorkingDirectory ();
2737 string objectsMacro
= GetObjectsMacro ( module
);
2738 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2739 string libsMacro
= GetLibsMacro ();
2741 GenerateImportLibraryTargetIfNeeded ();
2743 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2747 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2749 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2750 module
.GetEntryPoint(true).c_str (),
2751 module
.baseaddress
.c_str () );
2752 GenerateLinkerCommand ( dependencies
,
2761 GeneratePhonyTarget();
2766 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2767 const Module
& module_
)
2769 : MingwModuleHandler ( module_
)
2774 MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2776 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2780 MingwNativeDLLModuleHandler::Process ()
2782 GenerateNativeDLLModuleTarget ();
2786 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2788 string
targetMacro ( GetTargetMacro (module
) );
2789 string workingDirectory
= GetWorkingDirectory ( );
2790 string objectsMacro
= GetObjectsMacro ( module
);
2791 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2792 string libsMacro
= GetLibsMacro ();
2794 GenerateImportLibraryTargetIfNeeded ();
2796 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2800 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2802 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2803 module
.GetEntryPoint(true).c_str (),
2804 module
.baseaddress
.c_str () );
2805 GenerateLinkerCommand ( dependencies
,
2814 GeneratePhonyTarget();
2819 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2820 const Module
& module_
)
2822 : MingwModuleHandler ( module_
)
2827 MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2829 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2833 MingwNativeCUIModuleHandler::Process ()
2835 GenerateNativeCUIModuleTarget ();
2839 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2841 string
targetMacro ( GetTargetMacro (module
) );
2842 string workingDirectory
= GetWorkingDirectory ( );
2843 string objectsMacro
= GetObjectsMacro ( module
);
2844 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2845 string libsMacro
= GetLibsMacro ();
2847 GenerateImportLibraryTargetIfNeeded ();
2849 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2853 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2855 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2856 module
.GetEntryPoint(true).c_str (),
2857 module
.baseaddress
.c_str () );
2858 GenerateLinkerCommand ( dependencies
,
2867 GeneratePhonyTarget();
2872 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2873 const Module
& module_
)
2875 : MingwModuleHandler ( module_
)
2879 MingwWin32OCXModuleHandler::MingwWin32OCXModuleHandler (
2880 const Module
& module_
)
2882 : MingwModuleHandler ( module_
)
2887 MingwAddImplicitLibraries( Module
&module
)
2891 if ( module
.type
!= Win32DLL
2892 && module
.type
!= Win32OCX
2893 && module
.type
!= Win32CUI
2894 && module
.type
!= Win32GUI
2895 && module
.type
!= Win32SCR
)
2897 // no implicit libraries
2901 if ( !module
.isDefaultEntryPoint
)
2903 if ( module
.GetEntryPoint(false) == "0" )
2905 pLibrary
= new Library ( module
, "mingw_common" );
2906 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() , pLibrary
);
2907 pLibrary
= new Library ( module
, "msvcrt" );
2908 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2913 if ( module
.IsDLL () )
2915 //pLibrary = new Library ( module, "__mingw_dllmain" );
2916 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
2920 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
2921 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
2924 pLibrary
= new Library ( module
, "mingw_common" );
2925 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
2927 if ( module
.name
!= "msvcrt" )
2929 // always link in msvcrt to get the basic routines
2930 pLibrary
= new Library ( module
, "msvcrt" );
2931 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2936 MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2938 MingwAddImplicitLibraries ( module
);
2939 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2943 MingwWin32DLLModuleHandler::Process ()
2945 GenerateWin32DLLModuleTarget ();
2949 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2951 string
targetMacro ( GetTargetMacro (module
) );
2952 string workingDirectory
= GetWorkingDirectory ( );
2953 string objectsMacro
= GetObjectsMacro ( module
);
2954 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2955 string libsMacro
= GetLibsMacro ();
2957 GenerateImportLibraryTargetIfNeeded ();
2959 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2963 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2966 if ( module
.cplusplus
)
2971 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2972 module
.GetEntryPoint(true).c_str (),
2973 module
.baseaddress
.c_str () );
2974 GenerateLinkerCommand ( dependencies
,
2983 GeneratePhonyTarget();
2989 MingwWin32OCXModuleHandler::AddImplicitLibraries ( Module
& module
)
2991 MingwAddImplicitLibraries ( module
);
2992 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2996 MingwWin32OCXModuleHandler::Process ()
2998 GenerateWin32OCXModuleTarget ();
3002 MingwWin32OCXModuleHandler::GenerateWin32OCXModuleTarget ()
3004 string
targetMacro ( GetTargetMacro (module
) );
3005 string workingDirectory
= GetWorkingDirectory ( );
3006 string objectsMacro
= GetObjectsMacro ( module
);
3007 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3008 string libsMacro
= GetLibsMacro ();
3010 GenerateImportLibraryTargetIfNeeded ();
3012 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3016 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3019 if ( module
.cplusplus
)
3024 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
3025 module
.GetEntryPoint(true).c_str (),
3026 module
.baseaddress
.c_str () );
3027 GenerateLinkerCommand ( dependencies
,
3036 GeneratePhonyTarget();
3041 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
3042 const Module
& module_
)
3044 : MingwModuleHandler ( module_
)
3049 MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module
& module
)
3051 MingwAddImplicitLibraries ( module
);
3052 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3056 MingwWin32CUIModuleHandler::Process ()
3058 GenerateWin32CUIModuleTarget ();
3062 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
3064 string
targetMacro ( GetTargetMacro (module
) );
3065 string workingDirectory
= GetWorkingDirectory ( );
3066 string objectsMacro
= GetObjectsMacro ( module
);
3067 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3068 string libsMacro
= GetLibsMacro ();
3070 GenerateImportLibraryTargetIfNeeded ();
3072 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3076 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3079 if ( module
.cplusplus
)
3084 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3085 module
.GetEntryPoint(true).c_str (),
3086 module
.baseaddress
.c_str () );
3087 GenerateLinkerCommand ( dependencies
,
3096 GeneratePhonyTarget();
3101 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
3102 const Module
& module_
)
3104 : MingwModuleHandler ( module_
)
3109 MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module
& module
)
3111 MingwAddImplicitLibraries ( module
);
3112 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3116 MingwWin32GUIModuleHandler::Process ()
3118 GenerateWin32GUIModuleTarget ();
3122 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
3124 string
targetMacro ( GetTargetMacro (module
) );
3125 string workingDirectory
= GetWorkingDirectory ( );
3126 string objectsMacro
= GetObjectsMacro ( module
);
3127 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3128 string libsMacro
= GetLibsMacro ();
3130 GenerateImportLibraryTargetIfNeeded ();
3132 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3136 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3139 if ( module
.cplusplus
)
3144 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3145 module
.GetEntryPoint(true).c_str (),
3146 module
.baseaddress
.c_str () );
3147 GenerateLinkerCommand ( dependencies
,
3156 GeneratePhonyTarget();
3161 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
3162 const Module
& module_
)
3164 : MingwModuleHandler ( module_
)
3169 MingwBootLoaderModuleHandler::Process ()
3171 GenerateBootLoaderModuleTarget ();
3175 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
3177 string
targetName ( module
.output
->name
);
3178 string
targetMacro ( GetTargetMacro (module
) );
3179 string workingDirectory
= GetWorkingDirectory ();
3180 FileLocation
junk_tmp ( TemporaryDirectory
,
3182 module
.name
+ ".junk.tmp" );
3183 CLEAN_FILE ( junk_tmp
);
3184 string objectsMacro
= GetObjectsMacro ( module
);
3185 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3186 string libsMacro
= GetLibsMacro ();
3190 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3191 targetMacro
.c_str (),
3192 objectsMacro
.c_str (),
3193 linkDepsMacro
.c_str (),
3194 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
3196 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
3198 fprintf ( fMakefile
,
3199 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
3200 GetLinkerMacro ().c_str (),
3201 backend
->GetFullName ( junk_tmp
).c_str (),
3202 objectsMacro
.c_str (),
3203 linkDepsMacro
.c_str () );
3204 fprintf ( fMakefile
,
3205 "\t${objcopy} -O binary %s $@\n",
3206 backend
->GetFullName ( junk_tmp
).c_str () );
3207 GenerateBuildMapCode ( &junk_tmp
);
3208 fprintf ( fMakefile
,
3209 "\t-@${rm} %s 2>$(NUL)\n",
3210 backend
->GetFullName ( junk_tmp
).c_str () );
3214 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
3215 const Module
& module_
)
3217 : MingwModuleHandler ( module_
)
3222 MingwBootSectorModuleHandler::Process ()
3224 GenerateBootSectorModuleTarget ();
3228 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
3230 string objectsMacro
= GetObjectsMacro ( module
);
3234 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3235 module
.name
.c_str ());
3236 fprintf ( fMakefile
,
3238 module
.name
.c_str (),
3239 objectsMacro
.c_str () );
3243 MingwBootProgramModuleHandler::MingwBootProgramModuleHandler (
3244 const Module
& module_
)
3245 : MingwModuleHandler ( module_
)
3250 MingwBootProgramModuleHandler::Process ()
3252 GenerateBootProgramModuleTarget ();
3256 MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
3258 string
targetName ( module
.output
->name
);
3259 string
targetMacro ( GetTargetMacro (module
) );
3260 string workingDirectory
= GetWorkingDirectory ();
3261 FileLocation
junk_tmp ( TemporaryDirectory
,
3263 module
.name
+ ".junk.tmp" );
3264 FileLocation
junk_elf ( TemporaryDirectory
,
3266 module
.name
+ ".junk.elf" );
3267 FileLocation
junk_cpy ( TemporaryDirectory
,
3269 module
.name
+ ".junk.elf" );
3270 CLEAN_FILE ( junk_tmp
);
3271 CLEAN_FILE ( junk_elf
);
3272 CLEAN_FILE ( junk_cpy
);
3273 string objectsMacro
= GetObjectsMacro ( module
);
3274 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3275 string libsMacro
= GetLibsMacro ();
3276 const Module
*payload
= module
.project
.LocateModule ( module
.payload
);
3280 fprintf ( fMakefile
, "%s: %s %s %s | %s\n",
3281 targetMacro
.c_str (),
3282 objectsMacro
.c_str (),
3283 linkDepsMacro
.c_str (),
3284 payload
->name
.c_str (),
3285 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
3287 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3289 fprintf ( fMakefile
, "\t$(%s_PREPARE) $(OUTPUT)$(SEP)%s %s\n",
3290 module
.buildtype
.c_str (),
3291 NormalizeFilename( backend
->GetFullName ( *payload
->output
) ).c_str (),
3292 backend
->GetFullName ( junk_cpy
).c_str () );
3294 fprintf ( fMakefile
, "\t${objcopy} $(%s_FLATFORMAT) %s %s\n",
3295 module
.buildtype
.c_str (),
3296 backend
->GetFullName ( junk_cpy
).c_str (),
3297 backend
->GetFullName ( junk_tmp
).c_str () );
3299 fprintf ( fMakefile
, "\t${ld} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3300 module
.buildtype
.c_str (),
3301 linkDepsMacro
.c_str (),
3302 backend
->GetFullName ( junk_tmp
).c_str (),
3303 backend
->GetFullName ( junk_elf
).c_str () );
3305 fprintf ( fMakefile
, "\t${objcopy} $(%s_COPYFORMAT) %s $(INTERMEDIATE)$(SEP)%s\n",
3306 module
.buildtype
.c_str (),
3307 backend
->GetFullName ( junk_elf
).c_str (),
3308 backend
->GetFullName ( *module
.output
) .c_str () );
3310 fprintf ( fMakefile
,
3311 "\t-@${rm} %s %s %s 2>$(NUL)\n",
3312 backend
->GetFullName ( junk_tmp
).c_str (),
3313 backend
->GetFullName ( junk_elf
).c_str (),
3314 backend
->GetFullName ( junk_cpy
).c_str () );
3318 MingwIsoModuleHandler::MingwIsoModuleHandler (
3319 const Module
& module_
)
3321 : MingwModuleHandler ( module_
)
3326 MingwIsoModuleHandler::Process ()
3328 GenerateIsoModuleTarget ();
3332 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
3333 const string
& bootcdDirectory
)
3335 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3337 const Module
& m
= *module
.project
.modules
[i
];
3340 if ( m
.bootstrap
!= NULL
)
3342 FileLocation
targetFile ( OutputDirectory
,
3343 m
.bootstrap
->base
.length () > 0
3344 ? bootcdDirectory
+ sSep
+ m
.bootstrap
->base
3346 m
.bootstrap
->nameoncd
);
3347 OutputCopyCommand ( *m
.output
, targetFile
);
3353 MingwIsoModuleHandler::OutputCdfileCopyCommands (
3354 const string
& bootcdDirectory
)
3356 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3358 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3359 FileLocation
targetFile ( OutputDirectory
,
3360 cdfile
.target
->relative_path
.length () > 0
3361 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3363 cdfile
.target
->name
);
3364 OutputCopyCommand ( *cdfile
.source
, targetFile
);
3369 MingwIsoModuleHandler::GetBootstrapCdDirectories ( vector
<FileLocation
>& out
,
3370 const string
& bootcdDirectory
)
3372 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3374 const Module
& m
= *module
.project
.modules
[i
];
3377 if ( m
.bootstrap
!= NULL
)
3379 FileLocation
targetDirectory ( OutputDirectory
,
3380 m
.bootstrap
->base
.length () > 0
3381 ? bootcdDirectory
+ sSep
+ m
.bootstrap
->base
3384 out
.push_back ( targetDirectory
);
3390 MingwIsoModuleHandler::GetNonModuleCdDirectories ( vector
<FileLocation
>& out
,
3391 const string
& bootcdDirectory
)
3393 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3395 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3396 FileLocation
targetDirectory ( OutputDirectory
,
3397 cdfile
.target
->relative_path
.length () > 0
3398 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3401 out
.push_back( targetDirectory
);
3406 MingwIsoModuleHandler::GetCdDirectories ( vector
<FileLocation
>& out
,
3407 const string
& bootcdDirectory
)
3409 GetBootstrapCdDirectories ( out
, bootcdDirectory
);
3410 GetNonModuleCdDirectories ( out
, bootcdDirectory
);
3414 MingwIsoModuleHandler::GetBootstrapCdFiles (
3415 vector
<FileLocation
>& out
) const
3417 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3419 const Module
& m
= *module
.project
.modules
[i
];
3422 if ( m
.bootstrap
!= NULL
)
3424 out
.push_back ( *m
.output
);
3430 MingwIsoModuleHandler::GetNonModuleCdFiles (
3431 vector
<FileLocation
>& out
) const
3433 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3435 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3436 out
.push_back ( *cdfile
.source
);
3441 MingwIsoModuleHandler::GetCdFiles (
3442 vector
<FileLocation
>& out
) const
3444 GetBootstrapCdFiles ( out
);
3445 GetNonModuleCdFiles ( out
);
3449 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
3451 string bootcdDirectory
= "cd";
3452 FileLocation
bootcd ( OutputDirectory
,
3455 FileLocation
bootcdReactos ( OutputDirectory
,
3456 bootcdDirectory
+ sSep
+ Environment::GetCdOutputPath (),
3458 vector
<FileLocation
> vSourceFiles
, vCdFiles
;
3459 vector
<FileLocation
> vCdDirectories
;
3462 FileLocation
srcunattend ( SourceDirectory
,
3463 "boot" + sSep
+ "bootdata" + sSep
+ "bootcdregtest",
3465 FileLocation
tarunattend ( bootcdReactos
.directory
,
3466 bootcdReactos
.relative_path
,
3468 if (module
.type
== IsoRegTest
)
3469 vSourceFiles
.push_back ( srcunattend
);
3472 FileLocation
isoboot ( OutputDirectory
,
3473 "boot" + sSep
+ "freeldr" + sSep
+ "bootsect",
3474 module
.type
== IsoRegTest
3477 vSourceFiles
.push_back ( isoboot
);
3479 // prepare reactos.dff and reactos.inf
3480 FileLocation
reactosDff ( SourceDirectory
,
3481 "boot" + sSep
+ "bootdata" + sSep
+ "packages",
3483 FileLocation
reactosInf ( bootcdReactos
.directory
,
3484 bootcdReactos
.relative_path
,
3486 vSourceFiles
.push_back ( reactosDff
);
3490 if (module
.type
== IsoRegTest
)
3491 IsoName
= "ReactOS-RegTest.iso";
3493 IsoName
= "ReactOS.iso";
3496 string sourceFiles
= v2s ( backend
, vSourceFiles
, 5 );
3499 GetCdDirectories ( vCdDirectories
, bootcdDirectory
);
3500 GetCdFiles ( vCdFiles
);
3501 string cdDirectories
= "";//v2s ( vCdDirectories, 5 );
3502 string cdFiles
= v2s ( backend
, vCdFiles
, 5 );
3504 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3505 module
.name
.c_str ());
3506 fprintf ( fMakefile
,
3507 "%s: all %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET) %s\n",
3508 module
.name
.c_str (),
3509 backend
->GetFullName ( isoboot
).c_str (),
3510 sourceFiles
.c_str (),
3512 cdDirectories
.c_str () );
3513 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
3514 fprintf ( fMakefile
,
3515 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
3516 backend
->GetFullName ( reactosDff
).c_str (),
3517 backend
->GetFullPath ( bootcdReactos
).c_str () );
3518 fprintf ( fMakefile
,
3519 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
3520 backend
->GetFullName ( reactosDff
).c_str (),
3521 backend
->GetFullName ( reactosInf
).c_str (),
3522 backend
->GetFullPath ( bootcdReactos
).c_str ());
3523 fprintf ( fMakefile
,
3524 "\t-@${rm} %s 2>$(NUL)\n",
3525 backend
->GetFullName ( reactosInf
).c_str () );
3526 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
3527 OutputCdfileCopyCommands ( bootcdDirectory
);
3529 if (module
.type
== IsoRegTest
)
3530 OutputCopyCommand ( srcunattend
, tarunattend
);
3532 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3533 fprintf ( fMakefile
,
3534 "\t$(Q)$(CDMAKE_TARGET) -v -j -m -b %s %s REACTOS %s\n",
3535 backend
->GetFullName ( isoboot
).c_str (),
3536 backend
->GetFullPath ( bootcd
).c_str (),
3538 fprintf ( fMakefile
,
3543 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
3544 const Module
& module_
)
3546 : MingwModuleHandler ( module_
)
3551 MingwLiveIsoModuleHandler::Process ()
3553 GenerateLiveIsoModuleTarget ();
3557 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
3559 FileLocation
dir ( OutputDirectory
,
3562 MingwModuleHandler::PassThruCacheDirectory ( &dir
);
3566 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
3567 string
& reactosDirectory
)
3569 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3571 const Module
& m
= *module
.project
.modules
[i
];
3576 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
3577 FileLocation
destination ( OutputDirectory
,
3578 m
.install
->relative_path
.length () > 0
3579 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.install
->relative_path
3580 : livecdDirectory
+ sSep
+ reactosDirectory
,
3582 OutputCopyCommand ( *aliasedModule
.output
,
3589 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
3590 string
& reactosDirectory
)
3592 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
3594 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
3595 FileLocation
target ( OutputDirectory
,
3596 installfile
.target
->relative_path
.length () > 0
3597 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.target
->relative_path
3598 : livecdDirectory
+ sSep
+ reactosDirectory
,
3599 installfile
.target
->name
);
3600 OutputCopyCommand ( *installfile
.source
, target
);
3605 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
3607 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
3608 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
3609 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
3610 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
3611 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
3612 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
3614 FileLocation
livecdIni ( SourceDirectory
,
3615 "boot" + sSep
+ "bootdata",
3617 FileLocation
destination ( OutputDirectory
,
3620 OutputCopyCommand ( livecdIni
,
3625 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3627 FileLocation
freeldr ( OutputDirectory
,
3628 "boot" + sSep
+ "freeldr" + sSep
+ "freeldr",
3630 FileLocation
destination ( OutputDirectory
,
3631 livecdDirectory
+ sSep
+ "loader",
3633 OutputCopyCommand ( freeldr
,
3638 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3640 FileLocation
reactosSystem32ConfigDirectory ( OutputDirectory
,
3641 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config",
3643 fprintf ( fMakefile
,
3644 "\t$(ECHO_MKHIVE)\n" );
3645 fprintf ( fMakefile
,
3646 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%clivecd.inf boot%cbootdata%chiveinst.inf\n",
3647 cSep
, backend
->GetFullPath ( reactosSystem32ConfigDirectory
).c_str (),
3648 cSep
, cSep
, cSep
, cSep
);
3652 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
3654 string livecdDirectory
= module
.name
;
3655 FileLocation
livecd ( OutputDirectory
, livecdDirectory
, "" );
3660 if (module
.name
== "livecdregtest")
3662 bootloader
= "isobtrt.o";
3663 IsoName
= "ReactOS-LiveCD-RegTest.iso";
3667 bootloader
= "isoboot.o";
3668 IsoName
= "ReactOS-LiveCD.iso";
3671 FileLocation
isoboot ( OutputDirectory
, "boot" + sSep
+ "freeldr" + sSep
+ "bootsect", bootloader
);
3673 string reactosDirectory
= "reactos";
3674 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3675 FileLocation
livecdReactos ( OutputDirectory
,
3676 livecdReactosNoFixup
,
3678 CLEAN_FILE ( livecdReactos
);
3680 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3681 module
.name
.c_str ());
3682 fprintf ( fMakefile
,
3683 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3684 module
.name
.c_str (),
3685 backend
->GetFullName ( isoboot
) .c_str (),
3686 backend
->GetFullPath ( livecdReactos
).c_str () );
3687 OutputModuleCopyCommands ( livecdDirectory
,
3689 OutputNonModuleCopyCommands ( livecdDirectory
,
3691 OutputProfilesDirectoryCommands ( livecdDirectory
);
3692 OutputLoaderCommands ( livecdDirectory
);
3693 OutputRegistryCommands ( livecdDirectory
);
3694 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3695 fprintf ( fMakefile
,
3696 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS %s\n",
3697 backend
->GetFullName( isoboot
).c_str (),
3698 backend
->GetFullPath ( livecd
).c_str (),
3700 fprintf ( fMakefile
,
3705 MingwTestModuleHandler::MingwTestModuleHandler (
3706 const Module
& module_
)
3708 : MingwModuleHandler ( module_
)
3713 MingwTestModuleHandler::Process ()
3715 GenerateTestModuleTarget ();
3719 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
3721 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_hooks.c", false, "", false ) ) );
3722 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_stubs.S", false, "", false ) ) );
3723 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_startup.c", false, "", false ) ) );
3727 MingwTestModuleHandler::GenerateTestModuleTarget ()
3729 string
targetMacro ( GetTargetMacro ( module
) );
3730 string workingDirectory
= GetWorkingDirectory ( );
3731 string objectsMacro
= GetObjectsMacro ( module
);
3732 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3733 string libsMacro
= GetLibsMacro ();
3735 GenerateImportLibraryTargetIfNeeded ();
3737 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3741 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3744 if ( module
.cplusplus
)
3749 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3750 module
.GetEntryPoint(true).c_str (),
3751 module
.baseaddress
.c_str () );
3752 GenerateLinkerCommand ( dependencies
,
3761 GeneratePhonyTarget();
3766 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3767 const Module
& module_
)
3769 : MingwModuleHandler ( module_
)
3774 MingwRpcServerModuleHandler::Process ()
3780 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3781 const Module
& module_
)
3783 : MingwModuleHandler ( module_
)
3788 MingwRpcClientModuleHandler::Process ()
3794 MingwAliasModuleHandler::MingwAliasModuleHandler (
3795 const Module
& module_
)
3797 : MingwModuleHandler ( module_
)
3802 MingwAliasModuleHandler::Process ()
3806 MingwIdlHeaderModuleHandler::MingwIdlHeaderModuleHandler (
3807 const Module
& module_
)
3809 : MingwModuleHandler ( module_
)
3814 MingwIdlHeaderModuleHandler::Process ()
3819 MingwElfExecutableModuleHandler::MingwElfExecutableModuleHandler (
3820 const Module
& module_
)
3822 : MingwModuleHandler ( module_
)
3827 MingwElfExecutableModuleHandler::Process ()
3829 string
targetName ( module
.output
->name
);
3830 string
targetMacro ( GetTargetMacro (module
) );
3831 string workingDirectory
= GetWorkingDirectory ();
3832 string objectsMacro
= GetObjectsMacro ( module
);
3833 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3834 string libsMacro
= GetLibsMacro ();
3838 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3839 targetMacro
.c_str (),
3840 objectsMacro
.c_str (),
3841 linkDepsMacro
.c_str (),
3842 backend
->GetFullPath ( *GetTargetFilename ( module
, NULL
) ).c_str () );
3844 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3846 fprintf ( fMakefile
, "\t${gcc} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3847 module
.buildtype
.c_str(),
3848 objectsMacro
.c_str(),
3850 targetMacro
.c_str () );