2 * Copyright (C) 2005 Casper S. Hornstrup
3 * 2007-2008 Hervé Poussineau
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include "../../pch.h"
22 #include "../../rbuild.h"
24 #include "modulehandler.h"
30 #define CLEAN_FILE(f) clean_files.push_back ( (f).name.length () > 0 ? backend->GetFullName ( f ) : backend->GetFullPath ( f ) );
33 MingwModuleHandler::backend
= NULL
;
35 MingwModuleHandler::fMakefile
= NULL
;
39 const string
& filename
,
40 const string
& prefix
)
42 if ( !prefix
.length() )
45 const char* pfilename
= filename
.c_str();
46 const char* p1
= strrchr ( pfilename
, '/' );
47 const char* p2
= strrchr ( pfilename
, '\\' );
52 out
+= string(pfilename
,p1
-pfilename
) + cSep
;
55 out
+= prefix
+ pfilename
;
60 GetTargetMacro ( const Module
& module
, bool with_dollar
)
62 string
s ( module
.name
);
66 return ssprintf ( "$(%s)", s
.c_str() );
70 MingwModuleHandler::MingwModuleHandler (
71 const Module
& module_
)
78 MingwModuleHandler::~MingwModuleHandler()
83 MingwModuleHandler::SetBackend ( MingwBackend
* backend_
)
89 MingwModuleHandler::SetMakefile ( FILE* f
)
95 MingwModuleHandler::EnablePreCompiledHeaderSupport ()
100 /*static*/ const FileLocation
*
101 MingwModuleHandler::PassThruCacheDirectory (const FileLocation
* file
)
103 switch ( file
->directory
)
105 case SourceDirectory
:
107 case IntermediateDirectory
:
108 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->intermediateDirectory
);
110 case OutputDirectory
:
111 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->outputDirectory
);
113 case InstallDirectory
:
114 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->installDirectory
);
117 throw InvalidOperationException ( __FILE__
,
119 "Invalid directory %d.",
126 /* caller needs to delete the returned object */
128 MingwModuleHandler::GetTargetFilename (
129 const Module
& module
,
130 string_list
* pclean_files
)
132 FileLocation
*target
= new FileLocation ( *module
.output
);
135 string_list
& clean_files
= *pclean_files
;
136 CLEAN_FILE ( *target
);
141 /* caller needs to delete the returned object */
143 MingwModuleHandler::GetImportLibraryFilename (
144 const Module
& module
,
145 string_list
* pclean_files
)
147 FileLocation
*target
= new FileLocation ( *module
.dependency
);
150 string_list
& clean_files
= *pclean_files
;
151 CLEAN_FILE ( *target
);
156 /* caller needs to delete the returned object */
158 MingwModuleHandler::InstanciateHandler (
159 const Module
& module
,
160 MingwBackend
* backend
)
162 MingwModuleHandler
* handler
;
163 switch ( module
.type
)
166 handler
= new MingwBuildToolModuleHandler ( module
);
169 handler
= new MingwStaticLibraryModuleHandler ( module
);
172 handler
= new MingwObjectLibraryModuleHandler ( module
);
175 handler
= new MingwKernelModuleHandler ( module
);
178 handler
= new MingwNativeCUIModuleHandler ( module
);
181 handler
= new MingwWin32CUIModuleHandler ( module
);
185 handler
= new MingwWin32GUIModuleHandler ( module
);
188 handler
= new MingwKernelModeDLLModuleHandler ( module
);
191 handler
= new MingwNativeDLLModuleHandler ( module
);
194 handler
= new MingwWin32DLLModuleHandler ( module
);
197 handler
= new MingwWin32OCXModuleHandler ( module
);
199 case KernelModeDriver
:
200 handler
= new MingwKernelModeDriverModuleHandler ( module
);
203 handler
= new MingwBootLoaderModuleHandler ( module
);
206 handler
= new MingwBootSectorModuleHandler ( module
);
209 handler
= new MingwBootProgramModuleHandler ( module
);
212 handler
= new MingwIsoModuleHandler ( module
);
215 handler
= new MingwLiveIsoModuleHandler ( module
);
218 handler
= new MingwIsoModuleHandler ( module
);
221 handler
= new MingwLiveIsoModuleHandler ( module
);
224 handler
= new MingwTestModuleHandler ( module
);
227 handler
= new MingwRpcServerModuleHandler ( module
);
230 handler
= new MingwRpcClientModuleHandler ( module
);
233 handler
= new MingwRpcProxyModuleHandler ( module
);
236 handler
= new MingwAliasModuleHandler ( module
);
239 handler
= new MingwIdlHeaderModuleHandler ( module
);
241 case EmbeddedTypeLib
:
242 handler
= new MingwEmbeddedTypeLibModuleHandler ( module
);
245 handler
= new MingwElfExecutableModuleHandler ( module
);
248 throw UnknownModuleTypeException (
249 module
.node
.location
,
257 MingwModuleHandler::GetWorkingDirectory () const
263 MingwModuleHandler::GetBasename ( const string
& filename
) const
265 size_t index
= filename
.find_last_of ( '.' );
266 if ( index
!= string::npos
)
267 return filename
.substr ( 0, index
);
271 /* caller needs to delete the returned object */
273 MingwModuleHandler::GetActualSourceFilename (
274 const FileLocation
* file
) const
276 string filename
= file
->name
;
278 string extension
= GetExtension ( *file
);
279 if ( extension
== ".spec" || extension
== ".SPEC" )
281 const FileLocation
*objectFile
= GetObjectFilename ( file
, module
, NULL
);
282 FileLocation
*sourceFile
= new FileLocation (
283 objectFile
->directory
,
284 objectFile
->relative_path
,
285 ReplaceExtension ( objectFile
->name
, ".c" ) );
289 else if ( ( extension
== ".idl" || extension
== ".IDL" ) &&
290 ( module
.type
== RpcServer
|| module
.type
== RpcClient
|| module
.type
== RpcProxy
) )
292 const FileLocation
*objectFile
= GetObjectFilename ( file
, module
, NULL
);
293 FileLocation
*sourceFile
= new FileLocation (
294 objectFile
->directory
,
295 objectFile
->relative_path
,
296 ReplaceExtension ( objectFile
->name
, ".c" ) );
300 else if ( extension
== ".mc" || extension
== ".MC" )
302 const FileLocation
*objectFile
= GetObjectFilename ( file
, module
, NULL
);
303 FileLocation
*sourceFile
= new FileLocation (
304 objectFile
->directory
,
305 objectFile
->relative_path
,
306 ReplaceExtension ( objectFile
->name
, ".rc" ) );
311 return new FileLocation ( *file
);
315 MingwModuleHandler::GetExtraDependencies (
316 const FileLocation
*file
) const
318 string extension
= GetExtension ( *file
);
319 if ( extension
== ".idl" || extension
== ".IDL" )
321 const FileLocation
*header
;
322 switch ( module
.type
)
324 case RpcServer
: header
= GetRpcServerHeaderFilename ( file
); break;
325 case RpcClient
: header
= GetRpcClientHeaderFilename ( file
); break;
326 case RpcProxy
: header
= GetRpcProxyHeaderFilename ( file
); break;
327 case IdlHeader
: header
= GetIdlHeaderFilename ( file
); break;
328 default: header
= NULL
; break;
333 string dependencies
= backend
->GetFullName ( *header
);
342 MingwModuleHandler::GetCompilationUnitDependencies (
343 const CompilationUnit
& compilationUnit
) const
345 if ( compilationUnit
.GetFiles ().size () <= 1 )
347 vector
<string
> sourceFiles
;
348 for ( size_t i
= 0; i
< compilationUnit
.GetFiles ().size (); i
++ )
350 const File
& file
= *compilationUnit
.GetFiles ()[i
];
351 sourceFiles
.push_back ( backend
->GetFullName ( file
.file
) );
353 return v2s ( sourceFiles
, 10 );
356 /* caller needs to delete the returned object */
358 MingwModuleHandler::GetModuleArchiveFilename () const
360 if ( module
.type
== StaticLibrary
)
361 return GetTargetFilename ( module
, NULL
);
362 return new FileLocation ( IntermediateDirectory
,
363 module
.output
->relative_path
,
364 ReplaceExtension ( module
.name
, ".temp.a" ) );
368 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
370 string extension
= GetExtension ( file
.file
);
371 return ( extension
== ".spec" || extension
== ".SPEC" );
375 MingwModuleHandler::ReferenceObjects (
376 const Module
& module
)
378 if ( module
.type
== ObjectLibrary
)
380 if ( module
.type
== RpcServer
)
382 if ( module
.type
== RpcClient
)
384 if ( module
.type
== RpcProxy
)
386 if ( module
.type
== IdlHeader
)
392 MingwModuleHandler::OutputCopyCommand ( const FileLocation
& source
,
393 const FileLocation
& destination
)
398 "\t${cp} %s %s 1>$(NUL)\n",
399 backend
->GetFullName ( source
).c_str (),
400 backend
->GetFullName ( *PassThruCacheDirectory ( &destination
) ).c_str () );
404 MingwModuleHandler::GetImportLibraryDependency (
405 const Module
& importedModule
)
408 if ( ReferenceObjects ( importedModule
) )
410 const vector
<CompilationUnit
*>& compilationUnits
= importedModule
.non_if_data
.compilationUnits
;
413 dep
= GetTargetMacro ( importedModule
);
414 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
416 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
417 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
418 const FileLocation
*objectFilename
= GetObjectFilename ( &compilationName
, importedModule
, NULL
);
419 if ( GetExtension ( *objectFilename
) == ".h" )
420 dep
+= ssprintf ( " $(%s_HEADERS)", importedModule
.name
.c_str () );
421 else if ( GetExtension ( *objectFilename
) == ".rc" )
422 dep
+= ssprintf ( " $(%s_MCHEADERS)", importedModule
.name
.c_str () );
427 const FileLocation
*library_target
= GetImportLibraryFilename ( importedModule
, NULL
);
428 dep
= backend
->GetFullName ( *library_target
);
429 delete library_target
;
435 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
436 string_list
& targets
)
438 if ( dependencyModule
.invocations
.size () > 0 )
440 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
442 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
443 invoke
.GetTargets ( targets
);
447 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
451 MingwModuleHandler::GetModuleDependencies (
452 string_list
& dependencies
)
454 size_t iend
= module
.dependencies
.size ();
459 for ( size_t i
= 0; i
< iend
; i
++ )
461 const Dependency
& dependency
= *module
.dependencies
[i
];
462 const Module
& dependencyModule
= *dependency
.dependencyModule
;
463 GetTargets ( dependencyModule
,
466 vector
<FileLocation
> v
;
467 GetDefinitionDependencies ( v
);
469 for ( size_t i
= 0; i
< v
.size (); i
++ )
471 const FileLocation
& file
= v
[i
];
472 dependencies
.push_back ( backend
->GetFullName ( file
) );
477 MingwModuleHandler::GetSourceFilenames ( vector
<FileLocation
>& list
,
478 bool includeGeneratedFiles
) const
482 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
483 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
485 if ( includeGeneratedFiles
|| !compilationUnits
[i
]->IsGeneratedFile () )
487 const FileLocation
& compilationName
= compilationUnits
[i
]->GetFilename ();
488 const FileLocation
* sourceFileLocation
= GetActualSourceFilename ( &compilationName
);
489 list
.push_back ( *sourceFileLocation
);
490 delete sourceFileLocation
;
493 // intentionally make a copy so that we can append more work in
494 // the middle of processing without having to go recursive
495 vector
<If
*> v
= module
.non_if_data
.ifs
;
496 for ( i
= 0; i
< v
.size (); i
++ )
500 // check for sub-ifs to add to list
501 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
502 for ( j
= 0; j
< ifs
.size (); j
++ )
503 v
.push_back ( ifs
[j
] );
504 const vector
<CompilationUnit
*>& compilationUnits
= rIf
.data
.compilationUnits
;
505 for ( j
= 0; j
< compilationUnits
.size (); j
++ )
507 CompilationUnit
& compilationUnit
= *compilationUnits
[j
];
508 if ( includeGeneratedFiles
|| !compilationUnit
.IsGeneratedFile () )
510 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
511 const FileLocation
* sourceFileLocation
= GetActualSourceFilename ( &compilationName
);
512 list
.push_back ( *sourceFileLocation
);
513 delete sourceFileLocation
;
520 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
521 vector
<FileLocation
>& list
) const
523 GetSourceFilenames ( list
, false );
526 /* caller needs to delete the returned object */
528 MingwModuleHandler::GetObjectFilename (
529 const FileLocation
* sourceFile
,
530 const Module
& module
,
531 string_list
* pclean_files
) const
533 DirectoryLocation destination_directory
;
535 string extension
= GetExtension ( *sourceFile
);
537 if ( module
.type
== BootSector
)
538 return new FileLocation ( *module
.output
);
539 else if ( extension
== ".rc" || extension
== ".RC" )
540 newExtension
= "_" + module
.name
+ ".coff";
541 else if ( extension
== ".mc" || extension
== ".MC" )
542 newExtension
= ".rc";
543 else if ( extension
== ".spec" || extension
== ".SPEC" )
544 newExtension
= ".stubs.o";
545 else if ( extension
== ".idl" || extension
== ".IDL" )
547 if ( module
.type
== RpcServer
)
548 newExtension
= "_s.o";
549 else if ( module
.type
== RpcClient
)
550 newExtension
= "_c.o";
551 else if ( module
.type
== RpcProxy
)
552 newExtension
= "_p.o";
557 newExtension
= "_" + module
.name
+ ".o";
559 if ( module
.type
== BootSector
)
560 destination_directory
= OutputDirectory
;
562 destination_directory
= IntermediateDirectory
;
564 const FileLocation
*obj_file
= new FileLocation(
565 destination_directory
,
566 sourceFile
->relative_path
,
567 ReplaceExtension ( sourceFile
->name
, newExtension
) );
571 string_list
& clean_files
= *pclean_files
;
572 CLEAN_FILE ( *obj_file
);
578 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
580 return module
.name
+ "_clean";
584 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
586 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
588 Library
& library
= *module
.non_if_data
.libraries
[i
];
589 if ( library
.importedModule
->type
== ObjectLibrary
)
590 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
595 MingwModuleHandler::GenerateCleanTarget () const
597 if ( module
.type
== Alias
)
601 ".PHONY: %s_clean\n",
602 module
.name
.c_str() );
603 vector
<string
> referencedModuleNames
;
604 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
607 GetModuleCleanTarget ( module
).c_str(),
608 v2s ( referencedModuleNames
, 10 ).c_str () );
609 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
611 if ( ( i
+ 1 ) % 10 == 9 )
612 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
613 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
615 fprintf ( fMakefile
, " 2>$(NUL)\n" );
617 if ( module
.name
!= "zlib" ) /* Avoid make warning */
619 DirectoryLocation root
;
620 if ( backend
->configuration
.GenerateProxyMakefilesInSourceTree
)
621 root
= SourceDirectory
;
623 root
= OutputDirectory
;
624 FileLocation
proxyMakefile ( root
,
625 module
.output
->relative_path
,
627 fprintf ( fMakefile
, "\t-@${rm} %s 2>$(NUL)\n",
628 backend
->GetFullName ( proxyMakefile
).c_str () );
631 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
635 MingwModuleHandler::GenerateInstallTarget () const
637 if ( !module
.install
)
639 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
642 module
.name
.c_str (),
643 backend
->GetFullName ( *module
.install
).c_str () );
647 MingwModuleHandler::GenerateDependsTarget () const
650 ".PHONY: %s_depends\n",
651 module
.name
.c_str() );
653 "%s_depends: $(RBUILD_TARGET)\n",
654 module
.name
.c_str () );
656 "\t$(ECHO_RBUILD)\n" );
658 "\t$(Q)$(RBUILD_TARGET) $(RBUILD_FLAGS) -dm%s mingw\n",
659 module
.name
.c_str () );
663 MingwModuleHandler::GetObjectFilenames ()
665 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
666 if ( compilationUnits
.size () == 0 )
669 string
objectFilenames ( "" );
670 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
672 if ( objectFilenames
.size () > 0 )
673 objectFilenames
+= " ";
674 const FileLocation
& compilationName
= compilationUnits
[i
]->GetFilename ();
675 const FileLocation
*object_file
= GetObjectFilename ( &compilationName
, module
, NULL
);
676 objectFilenames
+= backend
->GetFullName ( *object_file
);
679 return objectFilenames
;
683 MingwModuleHandler::GenerateGccDefineParametersFromVector (
684 const vector
<Define
*>& defines
,
685 set
<string
>& used_defs
)
689 for ( size_t i
= 0; i
< defines
.size (); i
++ )
691 Define
& define
= *defines
[i
];
692 if (used_defs
.find(define
.name
) != used_defs
.end())
694 if (parameters
.length () > 0)
696 if (define
.name
.find('(') != string::npos
)
697 parameters
+= "$(QT)";
699 parameters
+= define
.name
;
700 if (define
.value
.length () > 0)
703 parameters
+= define
.value
;
705 if (define
.name
.find('(') != string::npos
)
706 parameters
+= "$(QT)";
707 used_defs
.insert(used_defs
.begin(),define
.name
);
713 MingwModuleHandler::GenerateGccDefineParameters () const
715 set
<string
> used_defs
;
716 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
, used_defs
);
717 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
, used_defs
);
718 if ( s
.length () > 0 )
727 MingwModuleHandler::ConcatenatePaths (
729 const string
& path2
) const
731 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
733 if ( path1
[path1
.length ()] == cSep
)
734 return path1
+ path2
;
736 return path1
+ cSep
+ path2
;
740 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
742 string parameters
, path_prefix
;
743 for ( size_t i
= 0; i
< includes
.size (); i
++ )
745 Include
& include
= *includes
[i
];
746 if ( parameters
.length () > 0 )
748 parameters
+= "-I" + backend
->GetFullPath ( *include
.directory
);;
754 MingwModuleHandler::GenerateGccIncludeParameters () const
756 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
757 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
758 if ( s
.length () > 0 )
767 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
, const CompilerType type
) const
770 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
772 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
773 if ( compilerFlag
.compiler
== type
)
775 if ( parameters
.length () > 0 )
777 parameters
+= compilerFlag
.flag
;
784 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
787 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
789 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
790 if ( parameters
.length () > 0 )
792 parameters
+= linkerFlag
.flag
;
798 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
799 const vector
<Library
*>& libraries
)
801 string
dependencies ( "" );
803 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
805 if ( wrap_count
++ == 5 )
806 dependencies
+= " \\\n\t\t", wrap_count
= 0;
807 else if ( dependencies
.size () > 0 )
809 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
815 MingwModuleHandler::GenerateLinkerParameters () const
817 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
821 MingwModuleHandler::GenerateMacro (
822 const char* assignmentOperation
,
824 const IfableData
& data
,
825 set
<const Define
*> *used_defs
,
826 bool generatingCompilerMacro
)
829 bool generateAssignment
;
831 if ( generatingCompilerMacro
)
832 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
834 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0;
835 if ( generateAssignment
)
840 assignmentOperation
);
843 const FileLocation
*pchFilename
= GetPrecompiledHeaderFilename ();
848 backend
->GetFullPath ( *pchFilename
).c_str () );
852 if ( generatingCompilerMacro
)
854 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
, CompilerTypeDontCare
);
855 if ( compilerParameters
.size () > 0 )
860 compilerParameters
.c_str () );
863 for ( i
= 0; i
< data
.includes
.size(); i
++ )
865 const Include
& include
= *data
.includes
[i
];
866 const FileLocation
* includeDirectory
= include
.directory
;
870 backend
->GetFullPath ( *includeDirectory
).c_str() );
872 for ( i
= 0; i
< data
.defines
.size(); i
++ )
874 const Define
& define
= *data
.defines
[i
];
877 set
<const Define
*>::const_iterator last_define
;
878 for (last_define
= used_defs
->begin ();
879 last_define
!= used_defs
->end ();
882 if ( (*last_define
)->name
!= define
.name
)
884 if ( !define
.overridable
)
886 throw InvalidOperationException ( (*last_define
)->node
->location
.c_str (),
888 "Invalid override of define '%s', already defined at %s",
889 define
.name
.c_str (),
890 define
.node
->location
.c_str () );
892 if ( backend
->configuration
.Verbose
)
893 printf("%s: Overriding '%s' already defined at %s\n",
894 (*last_define
)->node
->location
.c_str (), define
.name
.c_str (),
895 define
.node
->location
.c_str () );
898 if ( last_define
!= used_defs
->end () )
904 define
.name
.c_str() );
905 if (define
.value
.length () > 0)
909 define
.value
.c_str() );
911 used_defs
->insert( used_defs
->begin (), &define
);
913 if ( generateAssignment
)
915 fprintf ( fMakefile
, "\n" );
920 MingwModuleHandler::GenerateMacros (
921 const char* assignmentOperation
,
922 const IfableData
& data
,
923 const vector
<LinkerFlag
*>* linkerFlags
,
924 set
<const Define
*>& used_defs
)
928 GenerateMacro ( assignmentOperation
,
933 GenerateMacro ( assignmentOperation
,
939 if ( linkerFlags
!= NULL
)
941 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
942 if ( linkerParameters
.size () > 0 )
947 linkerflagsMacro
.c_str (),
949 linkerParameters
.c_str() );
953 if ( data
.libraries
.size () > 0 )
955 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
956 if ( deps
.size () > 0 )
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(),
997 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
999 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
1000 delete compilationUnits
[i
];
1004 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
1009 MingwModuleHandler::GenerateSourceMacros (
1010 const char* assignmentOperation
,
1011 const IfableData
& data
)
1015 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1016 vector
<const FileLocation
*> headers
;
1017 if ( compilationUnits
.size () > 0 )
1022 sourcesMacro
.c_str (),
1023 assignmentOperation
);
1024 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
1026 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1027 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
1031 ( i
%10 == 9 ? " \\\n\t" : " " ),
1032 backend
->GetFullName ( compilationName
).c_str () );
1034 fprintf ( fMakefile
, "\n" );
1037 const vector
<If
*>& ifs
= data
.ifs
;
1038 for ( i
= 0; i
< ifs
.size(); i
++ )
1041 if ( rIf
.data
.defines
.size()
1042 || rIf
.data
.includes
.size()
1043 || rIf
.data
.libraries
.size()
1044 || rIf
.data
.compilationUnits
.size()
1045 || rIf
.data
.compilerFlags
.size()
1046 || rIf
.data
.ifs
.size() )
1050 "%s (\"$(%s)\",\"%s\")\n",
1051 rIf
.negated
? "ifneq" : "ifeq",
1052 rIf
.property
.c_str(),
1053 rIf
.value
.c_str() );
1054 GenerateSourceMacros (
1063 vector
<CompilationUnit
*> sourceCompilationUnits
;
1064 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1065 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1067 const FileLocation
& compilationName
= sourceCompilationUnits
[i
]->GetFilename ();
1071 sourcesMacro
.c_str(),
1072 backend
->GetFullName ( compilationName
).c_str () );
1074 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1078 MingwModuleHandler::GenerateObjectMacros (
1079 const char* assignmentOperation
,
1080 const IfableData
& data
)
1084 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1085 vector
<const FileLocation
*> headers
;
1086 vector
<const FileLocation
*> mcheaders
;
1087 vector
<const FileLocation
*> mcresources
;
1088 if ( compilationUnits
.size () > 0 )
1090 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1092 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1093 if ( compilationUnit
.IsFirstFile () )
1095 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
1096 const FileLocation
*object_file
= GetObjectFilename ( &compilationName
, module
, NULL
);
1097 fprintf ( fMakefile
,
1099 objectsMacro
.c_str(),
1100 backend
->GetFullName ( *object_file
).c_str (),
1101 objectsMacro
.c_str() );
1108 objectsMacro
.c_str (),
1109 assignmentOperation
);
1110 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
1112 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1113 if ( !compilationUnit
.IsFirstFile () )
1115 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
1116 const FileLocation
*objectFilename
= GetObjectFilename ( &compilationName
, module
, NULL
);
1117 if ( GetExtension ( *objectFilename
) == ".h" )
1118 headers
.push_back ( objectFilename
);
1119 else if ( GetExtension ( *objectFilename
) == ".rc" )
1121 const FileLocation
*headerFilename
= GetMcHeaderFilename ( &compilationUnit
.GetFilename () );
1122 mcheaders
.push_back ( headerFilename
);
1123 mcresources
.push_back ( objectFilename
);
1130 ( i
%10 == 9 ? " \\\n\t" : " " ),
1131 backend
->GetFullName ( *objectFilename
).c_str () );
1132 delete objectFilename
;
1136 fprintf ( fMakefile
, "\n" );
1138 if ( headers
.size () > 0 )
1143 module
.name
.c_str (),
1144 assignmentOperation
);
1145 for ( i
= 0; i
< headers
.size (); i
++ )
1150 ( i
%10 == 9 ? " \\\n\t" : " " ),
1151 backend
->GetFullName ( *headers
[i
] ).c_str () );
1154 fprintf ( fMakefile
, "\n" );
1157 if ( mcheaders
.size () > 0 )
1162 module
.name
.c_str (),
1163 assignmentOperation
);
1164 for ( i
= 0; i
< mcheaders
.size (); i
++ )
1169 ( i
%10 == 9 ? " \\\n\t" : " " ),
1170 backend
->GetFullName ( *mcheaders
[i
] ).c_str () );
1171 delete mcheaders
[i
];
1173 fprintf ( fMakefile
, "\n" );
1176 if ( mcresources
.size () > 0 )
1181 module
.name
.c_str (),
1182 assignmentOperation
);
1183 for ( i
= 0; i
< mcresources
.size (); i
++ )
1188 ( i
%10 == 9 ? " \\\n\t" : " " ),
1189 backend
->GetFullName ( *mcresources
[i
] ).c_str () );
1190 delete mcresources
[i
];
1192 fprintf ( fMakefile
, "\n" );
1195 const vector
<If
*>& ifs
= data
.ifs
;
1196 for ( i
= 0; i
< ifs
.size(); i
++ )
1199 if ( rIf
.data
.defines
.size()
1200 || rIf
.data
.includes
.size()
1201 || rIf
.data
.libraries
.size()
1202 || rIf
.data
.compilationUnits
.size()
1203 || rIf
.data
.compilerFlags
.size()
1204 || rIf
.data
.ifs
.size() )
1208 "%s (\"$(%s)\",\"%s\")\n",
1209 rIf
.negated
? "ifneq" : "ifeq",
1210 rIf
.property
.c_str(),
1211 rIf
.value
.c_str() );
1212 GenerateObjectMacros (
1221 vector
<CompilationUnit
*> sourceCompilationUnits
;
1222 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1223 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1225 const FileLocation
& compilationName
= sourceCompilationUnits
[i
]->GetFilename ();
1226 const FileLocation
*object_file
= GetObjectFilename ( &compilationName
, module
, NULL
);
1230 objectsMacro
.c_str(),
1231 backend
->GetFullName ( *object_file
).c_str () );
1234 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1237 /* caller needs to delete the returned object */
1239 MingwModuleHandler::GetPrecompiledHeaderFilename () const
1241 if ( !module
.pch
|| !use_pch
)
1243 return new FileLocation ( IntermediateDirectory
,
1244 module
.pch
->file
.relative_path
,
1245 ReplaceExtension ( module
.pch
->file
.name
, "_" + module
.name
+ ".gch" ) );
1249 MingwModuleHandler::GenerateGccCommand (
1250 const FileLocation
* sourceFile
,
1251 const string
& extraDependencies
,
1253 const string
& cflagsMacro
)
1255 const FileLocation
*generatedSourceFileName
= GetActualSourceFilename ( sourceFile
);
1256 const FileLocation
*pchFilename
= GetPrecompiledHeaderFilename ();
1257 string dependencies
= backend
->GetFullName ( *generatedSourceFileName
);
1259 if ( extraDependencies
!= "" )
1260 dependencies
+= " " + extraDependencies
;
1262 dependencies
+= " " + backend
->GetFullName ( *pchFilename
);
1264 /* WIDL generated headers may be used */
1265 vector
<FileLocation
> rpcDependencies
;
1266 GetRpcHeaderDependencies ( rpcDependencies
);
1267 dependencies
+= " " + v2s ( backend
, rpcDependencies
, 5 );
1268 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1270 const FileLocation
*objectFilename
= GetObjectFilename (
1271 sourceFile
, module
, &clean_files
);
1272 fprintf ( fMakefile
,
1274 backend
->GetFullName ( *objectFilename
).c_str (),
1275 dependencies
.c_str (),
1276 backend
->GetFullPath ( *objectFilename
).c_str () );
1277 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
1278 fprintf ( fMakefile
,
1279 "\t%s -c $< -o $@ %s\n",
1281 cflagsMacro
.c_str () );
1283 delete objectFilename
;
1284 delete generatedSourceFileName
;
1290 MingwModuleHandler::GenerateGccAssemblerCommand (
1291 const FileLocation
* sourceFile
,
1293 const string
& cflagsMacro
)
1295 string dependencies
= backend
->GetFullName ( *sourceFile
);
1296 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1298 const FileLocation
*objectFilename
= GetObjectFilename (
1299 sourceFile
, module
, &clean_files
);
1300 fprintf ( fMakefile
,
1302 backend
->GetFullName ( *objectFilename
).c_str (),
1303 dependencies
.c_str (),
1304 backend
->GetFullPath ( *objectFilename
).c_str () );
1305 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
1306 fprintf ( fMakefile
,
1307 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
1309 cflagsMacro
.c_str () );
1311 delete objectFilename
;
1315 MingwModuleHandler::GenerateNasmCommand (
1316 const FileLocation
* sourceFile
,
1317 const string
& nasmflagsMacro
)
1319 string dependencies
= backend
->GetFullName ( *sourceFile
);
1320 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1322 const FileLocation
*objectFilename
= GetObjectFilename (
1323 sourceFile
, module
, &clean_files
);
1324 fprintf ( fMakefile
,
1326 backend
->GetFullName ( *objectFilename
).c_str (),
1327 dependencies
.c_str (),
1328 backend
->GetFullPath ( *objectFilename
).c_str () );
1329 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1330 fprintf ( fMakefile
,
1331 "\t%s -f win32 $< -o $@ %s\n",
1333 nasmflagsMacro
.c_str () );
1335 delete objectFilename
;
1339 MingwModuleHandler::GenerateWindresCommand (
1340 const FileLocation
* sourceFile
,
1341 const string
& windresflagsMacro
)
1343 string dependencies
= backend
->GetFullName ( *sourceFile
);
1344 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1346 const FileLocation
*objectFilename
= GetObjectFilename ( sourceFile
, module
, &clean_files
);
1348 string sourceFilenamePart
= module
.name
+ "." + ReplaceExtension ( sourceFile
->name
, "" );
1349 FileLocation
rciFilename ( TemporaryDirectory
,
1351 sourceFilenamePart
+ ".rci.tmp" );
1352 FileLocation
resFilename ( TemporaryDirectory
,
1354 sourceFilenamePart
+ ".res.tmp" );
1356 fprintf ( fMakefile
,
1357 "%s: %s $(WRC_TARGET) | %s\n",
1358 backend
->GetFullName ( *objectFilename
).c_str (),
1359 dependencies
.c_str (),
1360 backend
->GetFullPath ( *objectFilename
).c_str () );
1361 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1362 fprintf ( fMakefile
,
1363 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1364 windresflagsMacro
.c_str (),
1365 backend
->GetFullName ( *sourceFile
).c_str (),
1366 backend
->GetFullName ( rciFilename
).c_str () );
1367 fprintf ( fMakefile
,
1368 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1369 windresflagsMacro
.c_str (),
1370 backend
->GetFullName ( rciFilename
).c_str (),
1371 backend
->GetFullName ( resFilename
).c_str () );
1372 fprintf ( fMakefile
,
1373 "\t-@${rm} %s 2>$(NUL)\n",
1374 backend
->GetFullName ( rciFilename
).c_str () );
1375 fprintf ( fMakefile
,
1376 "\t${windres} %s -o $@\n",
1377 backend
->GetFullName ( resFilename
).c_str () );
1378 fprintf ( fMakefile
,
1379 "\t-@${rm} %s 2>$(NUL)\n",
1380 backend
->GetFullName ( resFilename
).c_str () );
1382 delete objectFilename
;
1386 MingwModuleHandler::GenerateWinebuildCommands (
1387 const FileLocation
* sourceFile
)
1389 string dependencies
= backend
->GetFullName ( *sourceFile
);
1390 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1392 string basename
= GetBasename ( sourceFile
->name
);
1393 FileLocation
def_file ( IntermediateDirectory
,
1394 sourceFile
->relative_path
,
1395 basename
+ ".spec.def" );
1396 CLEAN_FILE ( def_file
);
1398 const FileLocation
*stub_file
= GetActualSourceFilename ( sourceFile
);
1399 CLEAN_FILE ( *stub_file
);
1401 fprintf ( fMakefile
,
1402 "%s: %s $(WINEBUILD_TARGET) | %s\n",
1403 backend
->GetFullName ( def_file
).c_str (),
1404 dependencies
.c_str (),
1405 backend
->GetFullPath ( def_file
).c_str () );
1406 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1407 fprintf ( fMakefile
,
1408 "\t%s -o %s --def -E %s\n",
1409 "$(Q)$(WINEBUILD_TARGET)",
1410 backend
->GetFullName ( def_file
).c_str (),
1411 backend
->GetFullName ( *sourceFile
).c_str () );
1412 fprintf ( fMakefile
,
1413 "%s: %s $(WINEBUILD_TARGET)\n",
1414 backend
->GetFullName ( *stub_file
).c_str (),
1415 backend
->GetFullName ( *sourceFile
).c_str () );
1416 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1417 fprintf ( fMakefile
,
1418 "\t%s -o %s --pedll %s\n",
1419 "$(Q)$(WINEBUILD_TARGET)",
1420 backend
->GetFullName ( *stub_file
).c_str (),
1421 backend
->GetFullName ( *sourceFile
).c_str () );
1427 MingwModuleHandler::GenerateWmcCommands (
1428 const FileLocation
* sourceFile
)
1430 string dependencies
= backend
->GetFullName ( *sourceFile
);
1431 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1433 string basename
= GetBasename ( sourceFile
->name
);
1434 FileLocation
rc_file ( IntermediateDirectory
,
1435 sourceFile
->relative_path
,
1437 FileLocation
h_file ( IntermediateDirectory
,
1440 CLEAN_FILE ( rc_file
);
1441 CLEAN_FILE ( h_file
);
1443 fprintf ( fMakefile
,
1444 "%s %s: $(WMC_TARGET) %s\n",
1445 backend
->GetFullName ( rc_file
).c_str (),
1446 backend
->GetFullName ( h_file
).c_str (),
1447 backend
->GetFullName ( *sourceFile
).c_str () );
1448 fprintf ( fMakefile
, "\t$(ECHO_WMC)\n" );
1449 fprintf ( fMakefile
,
1450 "\t%s -i -H %s -o %s %s\n",
1451 "$(Q)$(WMC_TARGET)",
1452 backend
->GetFullName ( h_file
).c_str (),
1453 backend
->GetFullName ( rc_file
).c_str (),
1454 backend
->GetFullName ( *sourceFile
).c_str () );
1458 MingwModuleHandler::GetWidlFlags ( const CompilationUnit
& compilationUnit
)
1460 return compilationUnit
.GetSwitches ();
1464 MingwModuleHandler::GetPropertyValue ( const Module
& module
, const std::string
& name
)
1466 for ( size_t i
= 0; i
< module
.project
.non_if_data
.properties
.size (); i
++ )
1468 const Property
& property
= *module
.project
.non_if_data
.properties
[i
];
1469 if ( property
.name
== name
)
1470 return property
.value
;
1472 return string ( "" );
1475 /* caller needs to delete the returned object */
1477 MingwModuleHandler::GetRpcServerHeaderFilename ( const FileLocation
*base
) const
1479 string newname
= GetBasename ( base
->name
) + "_s.h";
1480 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1484 MingwModuleHandler::GenerateWidlCommandsServer (
1485 const CompilationUnit
& compilationUnit
,
1486 const string
& widlflagsMacro
)
1488 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
1489 string dependencies
= backend
->GetFullName ( sourceFile
);
1490 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1492 string basename
= GetBasename ( sourceFile
.name
);
1494 const FileLocation
*generatedHeaderFilename
= GetRpcServerHeaderFilename ( &sourceFile
);
1495 CLEAN_FILE ( *generatedHeaderFilename
);
1497 FileLocation
generatedServerFilename ( IntermediateDirectory
,
1498 sourceFile
.relative_path
,
1499 basename
+ "_s.c" );
1500 CLEAN_FILE ( generatedServerFilename
);
1502 fprintf ( fMakefile
,
1503 "%s %s: %s $(WIDL_TARGET) | %s\n",
1504 backend
->GetFullName ( generatedServerFilename
).c_str (),
1505 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1506 dependencies
.c_str (),
1507 backend
->GetFullPath ( generatedServerFilename
).c_str () );
1508 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1509 fprintf ( fMakefile
,
1510 "\t%s %s %s -h -H %s -s -S %s %s\n",
1511 "$(Q)$(WIDL_TARGET)",
1512 GetWidlFlags ( compilationUnit
).c_str (),
1513 widlflagsMacro
.c_str (),
1514 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1515 backend
->GetFullName ( generatedServerFilename
).c_str (),
1516 backend
->GetFullName ( sourceFile
).c_str () );
1518 delete generatedHeaderFilename
;
1521 /* caller needs to delete the returned object */
1523 MingwModuleHandler::GetRpcClientHeaderFilename ( const FileLocation
*base
) const
1525 string newname
= GetBasename ( base
->name
) + "_c.h";
1526 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1529 /* caller needs to delete the returned object */
1531 MingwModuleHandler::GetRpcProxyHeaderFilename ( const FileLocation
*base
) const
1533 string newname
= GetBasename ( base
->name
) + "_p.h";
1534 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1537 /* caller needs to delete the returned object */
1539 MingwModuleHandler::GetIdlHeaderFilename ( const FileLocation
*base
) const
1541 string newname
= GetBasename ( base
->name
) + ".h";
1542 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1545 /* caller needs to delete the returned object */
1547 MingwModuleHandler::GetMcHeaderFilename ( const FileLocation
*base
) const
1549 string newname
= GetBasename ( base
->name
) + ".h";
1550 return new FileLocation ( IntermediateDirectory
, "include/reactos" , newname
);
1554 MingwModuleHandler::GenerateWidlCommandsEmbeddedTypeLib (
1555 const CompilationUnit
& compilationUnit
,
1556 const string
& widlflagsMacro
)
1558 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
1559 string dependencies
= backend
->GetFullName ( sourceFile
);
1560 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1562 string basename
= GetBasename ( sourceFile
.name
);
1564 FileLocation
EmbeddedTypeLibFilename ( IntermediateDirectory
,
1565 sourceFile
.relative_path
,
1566 basename
+ ".tlb" );
1568 fprintf ( fMakefile
,
1569 "%s: %s $(WIDL_TARGET) | %s\n",
1570 GetTargetMacro ( module
).c_str (),
1571 dependencies
.c_str (),
1572 backend
->GetFullPath ( EmbeddedTypeLibFilename
).c_str () );
1573 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1574 fprintf ( fMakefile
,
1575 "\t%s %s %s -t -T %s %s\n",
1576 "$(Q)$(WIDL_TARGET)",
1577 GetWidlFlags ( compilationUnit
).c_str (),
1578 widlflagsMacro
.c_str (),
1579 backend
->GetFullName ( EmbeddedTypeLibFilename
).c_str(),
1580 backend
->GetFullName ( sourceFile
).c_str () );
1584 MingwModuleHandler::GenerateWidlCommandsClient (
1585 const CompilationUnit
& compilationUnit
,
1586 const string
& widlflagsMacro
)
1588 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
1589 string dependencies
= backend
->GetFullName ( sourceFile
);
1590 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1592 string basename
= GetBasename ( sourceFile
.name
);
1594 const FileLocation
*generatedHeaderFilename
= GetRpcClientHeaderFilename ( &sourceFile
);
1595 CLEAN_FILE ( *generatedHeaderFilename
);
1597 FileLocation
generatedClientFilename ( IntermediateDirectory
,
1598 sourceFile
.relative_path
,
1599 basename
+ "_c.c" );
1600 CLEAN_FILE ( generatedClientFilename
);
1602 fprintf ( fMakefile
,
1603 "%s %s: %s $(WIDL_TARGET) | %s\n",
1604 backend
->GetFullName ( generatedClientFilename
).c_str (),
1605 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1606 dependencies
.c_str (),
1607 backend
->GetFullPath ( generatedClientFilename
).c_str () );
1608 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1609 fprintf ( fMakefile
,
1610 "\t%s %s %s -h -H %s -c -C %s %s\n",
1611 "$(Q)$(WIDL_TARGET)",
1612 GetWidlFlags ( compilationUnit
).c_str (),
1613 widlflagsMacro
.c_str (),
1614 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1615 backend
->GetFullName ( generatedClientFilename
).c_str (),
1616 backend
->GetFullName ( sourceFile
).c_str () );
1618 delete generatedHeaderFilename
;
1622 MingwModuleHandler::GenerateWidlCommandsProxy (
1623 const CompilationUnit
& compilationUnit
,
1624 const string
& widlflagsMacro
)
1626 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
1627 string dependencies
= backend
->GetFullName ( sourceFile
);
1628 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1630 string basename
= GetBasename ( sourceFile
.name
);
1632 const FileLocation
*generatedHeaderFilename
= GetRpcProxyHeaderFilename ( &sourceFile
);
1633 CLEAN_FILE ( *generatedHeaderFilename
);
1635 FileLocation
generatedProxyFilename ( IntermediateDirectory
,
1636 sourceFile
.relative_path
,
1637 basename
+ "_p.c" );
1638 CLEAN_FILE ( generatedProxyFilename
);
1640 fprintf ( fMakefile
,
1641 "%s %s: %s $(WIDL_TARGET) | %s\n",
1642 backend
->GetFullName ( generatedProxyFilename
).c_str (),
1643 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1644 dependencies
.c_str (),
1645 backend
->GetFullPath ( generatedProxyFilename
).c_str () );
1646 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1647 fprintf ( fMakefile
,
1648 "\t%s %s %s -h -H %s -p -P %s %s\n",
1649 "$(Q)$(WIDL_TARGET)",
1650 GetWidlFlags ( compilationUnit
).c_str (),
1651 widlflagsMacro
.c_str (),
1652 backend
->GetFullName ( *generatedHeaderFilename
).c_str (),
1653 backend
->GetFullName ( generatedProxyFilename
).c_str (),
1654 backend
->GetFullName ( sourceFile
).c_str () );
1656 delete generatedHeaderFilename
;
1660 MingwModuleHandler::GenerateWidlCommandsIdlHeader (
1661 const CompilationUnit
& compilationUnit
,
1662 const string
& widlflagsMacro
)
1664 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
1665 string dependencies
= backend
->GetFullName ( sourceFile
);
1666 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1668 string basename
= GetBasename ( sourceFile
.name
);
1670 const FileLocation
*generatedHeader
= GetIdlHeaderFilename ( &sourceFile
);
1671 CLEAN_FILE ( *generatedHeader
);
1673 fprintf ( fMakefile
,
1674 "%s: %s $(WIDL_TARGET) | %s\n",
1675 backend
->GetFullName( *generatedHeader
).c_str (),
1676 dependencies
.c_str (),
1677 backend
->GetFullPath ( *generatedHeader
).c_str () );
1678 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1679 fprintf ( fMakefile
,
1680 "\t%s %s %s -h -H %s %s\n",
1681 "$(Q)$(WIDL_TARGET)",
1682 GetWidlFlags ( compilationUnit
).c_str (),
1683 widlflagsMacro
.c_str (),
1684 backend
->GetFullName ( *generatedHeader
).c_str (),
1685 backend
->GetFullName ( sourceFile
).c_str () );
1687 delete generatedHeader
;
1691 MingwModuleHandler::GenerateWidlCommands (
1692 const CompilationUnit
& compilationUnit
,
1693 const string
& widlflagsMacro
)
1695 if ( module
.type
== RpcServer
)
1696 GenerateWidlCommandsServer ( compilationUnit
,
1698 else if ( module
.type
== RpcClient
)
1699 GenerateWidlCommandsClient ( compilationUnit
,
1701 else if ( module
.type
== RpcProxy
)
1702 GenerateWidlCommandsProxy ( compilationUnit
,
1704 else if ( module
.type
== EmbeddedTypeLib
)
1705 GenerateWidlCommandsEmbeddedTypeLib ( compilationUnit
,
1707 else // applies also for other module.types which include idl files
1708 GenerateWidlCommandsIdlHeader ( compilationUnit
,
1713 MingwModuleHandler::GenerateCommands (
1714 const CompilationUnit
& compilationUnit
,
1715 const string
& extraDependencies
,
1718 const string
& cflagsMacro
,
1719 const string
& nasmflagsMacro
,
1720 const string
& windresflagsMacro
,
1721 const string
& widlflagsMacro
)
1723 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
1724 string extension
= GetExtension ( sourceFile
);
1725 string flags
= cflagsMacro
;
1727 if ( extension
== ".c" || extension
== ".C" )
1729 flags
+= GenerateCompilerParametersFromVector ( module
.non_if_data
.compilerFlags
, CompilerTypeCC
);
1730 GenerateGccCommand ( &sourceFile
,
1731 GetCompilationUnitDependencies ( compilationUnit
) + extraDependencies
,
1735 else if ( extension
== ".cc" || extension
== ".CC" ||
1736 extension
== ".cpp" || extension
== ".CPP" ||
1737 extension
== ".cxx" || extension
== ".CXX" )
1739 flags
+= GenerateCompilerParametersFromVector ( module
.non_if_data
.compilerFlags
, CompilerTypeCPP
);
1740 GenerateGccCommand ( &sourceFile
,
1741 GetCompilationUnitDependencies ( compilationUnit
) + extraDependencies
,
1745 else if ( extension
== ".s" || extension
== ".S" )
1747 GenerateGccAssemblerCommand ( &sourceFile
,
1751 else if ( extension
== ".asm" || extension
== ".ASM" )
1753 GenerateNasmCommand ( &sourceFile
,
1756 else if ( extension
== ".rc" || extension
== ".RC" )
1758 GenerateWindresCommand ( &sourceFile
,
1759 windresflagsMacro
);
1761 else if ( extension
== ".mc" || extension
== ".MC" )
1763 GenerateWmcCommands ( &sourceFile
);
1765 else if ( extension
== ".spec" || extension
== ".SPEC" )
1767 GenerateWinebuildCommands ( &sourceFile
);
1768 GenerateGccCommand ( &sourceFile
,
1773 else if ( extension
== ".idl" || extension
== ".IDL" )
1775 GenerateWidlCommands ( compilationUnit
,
1777 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) || (module
.type
== RpcProxy
) )
1779 GenerateGccCommand ( &sourceFile
,
1780 GetExtraDependencies ( &sourceFile
),
1787 throw InvalidOperationException ( __FILE__
,
1789 "Unsupported filename extension '%s' in file '%s'",
1791 backend
->GetFullName ( sourceFile
).c_str () );
1796 MingwModuleHandler::GenerateBuildMapCode ( const FileLocation
*mapTarget
)
1798 fprintf ( fMakefile
,
1799 "ifeq ($(ROS_BUILDMAP),full)\n" );
1801 FileLocation
mapFilename ( OutputDirectory
,
1802 module
.output
->relative_path
,
1803 GetBasename ( module
.output
->name
) + ".map" );
1804 CLEAN_FILE ( mapFilename
);
1806 fprintf ( fMakefile
,
1807 "\t$(ECHO_OBJDUMP)\n" );
1808 fprintf ( fMakefile
,
1809 "\t$(Q)${objdump} -d -S %s > %s\n",
1810 mapTarget
? backend
->GetFullName ( *mapTarget
).c_str () : "$@",
1811 backend
->GetFullName ( mapFilename
).c_str () );
1813 fprintf ( fMakefile
,
1815 fprintf ( fMakefile
,
1816 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1818 fprintf ( fMakefile
,
1820 fprintf ( fMakefile
,
1821 "\t$(Q)${nm} --numeric-sort %s > %s\n",
1822 mapTarget
? backend
->GetFullName ( *mapTarget
).c_str () : "$@",
1823 backend
->GetFullName ( mapFilename
).c_str () );
1825 fprintf ( fMakefile
,
1828 fprintf ( fMakefile
,
1833 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1835 fprintf ( fMakefile
,
1836 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1838 FileLocation
nostripFilename ( OutputDirectory
,
1839 module
.output
->relative_path
,
1840 GetBasename ( module
.output
->name
) + ".nostrip" + GetExtension ( *module
.output
) );
1841 CLEAN_FILE ( nostripFilename
);
1843 OutputCopyCommand ( *module
.output
, nostripFilename
);
1845 fprintf ( fMakefile
,
1850 MergeStringVector ( const Backend
* backend
,
1851 const vector
<FileLocation
>& input
,
1852 vector
<string
>& output
)
1856 int wrap_count
= -1;
1857 for ( size_t i
= 0; i
< input
.size (); i
++ )
1859 if ( wrap_count
++ == wrap_at
)
1861 output
.push_back ( s
);
1865 else if ( s
.size () > 0)
1867 s
+= backend
->GetFullName ( input
[i
] );
1869 if ( s
.length () > 0 )
1870 output
.push_back ( s
);
1874 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1875 vector
<FileLocation
>& objectFiles
) const
1877 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1879 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1880 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
1881 const FileLocation
*object_file
= GetObjectFilename ( &compilationName
, module
, NULL
);
1882 objectFiles
.push_back ( *object_file
);
1888 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1890 if ( backend
->configuration
.CleanAsYouGo
)
1892 vector
<FileLocation
> objectFiles
;
1893 GetObjectsVector ( module
.non_if_data
,
1895 vector
<string
> lines
;
1896 MergeStringVector ( backend
,
1899 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1901 fprintf ( fMakefile
,
1902 "\t-@${rm} %s 2>$(NUL)\n",
1903 lines
[i
].c_str () );
1909 MingwModuleHandler::GenerateRunRsymCode () const
1911 fprintf ( fMakefile
,
1912 "\t$(ECHO_RSYM)\n" );
1913 fprintf ( fMakefile
,
1914 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1918 MingwModuleHandler::GenerateRunStripCode () const
1920 fprintf ( fMakefile
,
1921 "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" );
1922 fprintf ( fMakefile
,
1923 "\t$(ECHO_STRIP)\n" );
1924 fprintf ( fMakefile
,
1925 "\t${strip} -s -x -X $@\n\n" );
1926 fprintf ( fMakefile
,
1931 MingwModuleHandler::GenerateLinkerCommand (
1932 const string
& dependencies
,
1933 const string
& linker
,
1934 const string
& linkerParameters
,
1935 const string
& objectsMacro
,
1936 const string
& libsMacro
,
1937 const string
& pefixupParameters
)
1939 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
1940 const FileLocation
*definitionFilename
= GetDefinitionFilename ();
1942 string
target_macro ( GetTargetMacro ( module
) );
1943 string
target_folder ( backend
->GetFullPath ( *target_file
) );
1945 string linkerScriptArgument
;
1946 if ( module
.linkerScript
!= NULL
)
1947 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", backend
->GetFullName ( module
.linkerScript
->file
).c_str () );
1949 linkerScriptArgument
= "";
1951 fprintf ( fMakefile
,
1952 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1953 target_macro
.c_str (),
1954 backend
->GetFullName ( *definitionFilename
).c_str (),
1955 dependencies
.c_str (),
1956 target_folder
.c_str () );
1957 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1958 string
targetName ( module
.output
->name
);
1960 if ( !module
.IsDLL () )
1962 fprintf ( fMakefile
,
1963 "\t%s %s %s -o %s %s %s %s\n",
1965 linkerParameters
.c_str (),
1966 linkerScriptArgument
.c_str (),
1967 target_macro
.c_str (),
1968 objectsMacro
.c_str (),
1970 GetLinkerMacro ().c_str () );
1972 else if ( module
.HasImportLibrary () )
1974 FileLocation
temp_exp ( TemporaryDirectory
,
1976 module
.name
+ ".temp.exp" );
1977 CLEAN_FILE ( temp_exp
);
1979 fprintf ( fMakefile
,
1980 "\t${dlltool} --dllname %s --def %s --output-exp %s %s %s\n",
1981 targetName
.c_str (),
1982 backend
->GetFullName ( *definitionFilename
).c_str (),
1983 backend
->GetFullName ( temp_exp
).c_str (),
1984 module
.mangledSymbols
? "" : "--kill-at",
1985 module
.underscoreSymbols
? "--add-underscore" : "" );
1987 fprintf ( fMakefile
,
1988 "\t%s %s %s %s -o %s %s %s %s\n",
1990 linkerParameters
.c_str (),
1991 linkerScriptArgument
.c_str (),
1992 backend
->GetFullName ( temp_exp
).c_str (),
1993 target_macro
.c_str (),
1994 objectsMacro
.c_str (),
1996 GetLinkerMacro ().c_str () );
1998 fprintf ( fMakefile
,
1999 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
2000 target_macro
.c_str (),
2001 pefixupParameters
.c_str() );
2003 fprintf ( fMakefile
,
2004 "\t-@${rm} %s 2>$(NUL)\n",
2005 backend
->GetFullName ( temp_exp
).c_str () );
2009 /* XXX: need to workaround binutils bug, which exports
2010 * all functions in a dll if no .def file or an empty
2011 * one has been provided... */
2013 //printf ( "%s will have all its functions exported\n",
2014 // module.target->name.c_str () );
2015 fprintf ( fMakefile
,
2016 "\t%s %s %s -o %s %s %s %s\n",
2018 linkerParameters
.c_str (),
2019 linkerScriptArgument
.c_str (),
2020 target_macro
.c_str (),
2021 objectsMacro
.c_str (),
2023 GetLinkerMacro ().c_str () );
2026 GenerateBuildMapCode ();
2027 GenerateBuildNonSymbolStrippedCode ();
2028 GenerateRunRsymCode ();
2029 GenerateRunStripCode ();
2030 GenerateCleanObjectsAsYouGoCode ();
2032 delete definitionFilename
;
2037 MingwModuleHandler::GeneratePhonyTarget() const
2039 string
targetMacro ( GetTargetMacro ( module
) );
2040 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
2042 fprintf ( fMakefile
,
2044 targetMacro
.c_str ());
2045 fprintf ( fMakefile
, "%s: | %s\n",
2046 targetMacro
.c_str (),
2047 backend
->GetFullPath ( *target_file
).c_str () );
2053 MingwModuleHandler::GenerateObjectFileTargets (
2054 const IfableData
& data
,
2057 const string
& cflagsMacro
,
2058 const string
& nasmflagsMacro
,
2059 const string
& windresflagsMacro
,
2060 const string
& widlflagsMacro
)
2063 string moduleDependencies
;
2065 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
2066 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
2068 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2069 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
2070 const FileLocation
*objectFilename
= GetObjectFilename ( &compilationName
, module
, NULL
);
2071 if ( GetExtension ( *objectFilename
) == ".h" )
2072 moduleDependencies
+= ssprintf ( " $(%s_HEADERS)", module
.name
.c_str () );
2073 else if ( GetExtension ( *objectFilename
) == ".rc" )
2074 moduleDependencies
+= ssprintf ( " $(%s_RESOURCES)", module
.name
.c_str () );
2075 delete objectFilename
;
2078 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
2080 GenerateCommands ( *compilationUnits
[i
],
2088 fprintf ( fMakefile
,
2092 const vector
<If
*>& ifs
= data
.ifs
;
2093 for ( i
= 0; i
< ifs
.size(); i
++ )
2095 GenerateObjectFileTargets ( ifs
[i
]->data
,
2104 vector
<CompilationUnit
*> sourceCompilationUnits
;
2105 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
2106 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
2108 GenerateCommands ( *sourceCompilationUnits
[i
],
2117 CleanupCompilationUnitVector ( sourceCompilationUnits
);
2121 MingwModuleHandler::GenerateObjectFileTargets (
2124 const string
& cflagsMacro
,
2125 const string
& nasmflagsMacro
,
2126 const string
& windresflagsMacro
,
2127 const string
& widlflagsMacro
)
2129 const FileLocation
*pchFilename
= GetPrecompiledHeaderFilename ();
2133 const FileLocation
& baseHeaderFile
= module
.pch
->file
;
2134 CLEAN_FILE ( *pchFilename
);
2135 string dependencies
= backend
->GetFullName ( baseHeaderFile
);
2136 /* WIDL generated headers may be used */
2137 vector
<FileLocation
> rpcDependencies
;
2138 GetRpcHeaderDependencies ( rpcDependencies
);
2139 dependencies
+= " " + v2s ( backend
, rpcDependencies
, 5 );
2140 fprintf ( fMakefile
,
2142 backend
->GetFullName ( *pchFilename
).c_str(),
2143 dependencies
.c_str(),
2144 backend
->GetFullPath ( *pchFilename
).c_str() );
2145 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
2146 fprintf ( fMakefile
,
2147 "\t%s -o %s %s -g %s\n\n",
2148 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
2149 backend
->GetFullName ( *pchFilename
).c_str(),
2150 cflagsMacro
.c_str(),
2151 backend
->GetFullName ( baseHeaderFile
).c_str() );
2155 GenerateObjectFileTargets ( module
.non_if_data
,
2162 fprintf ( fMakefile
, "\n" );
2165 /* caller needs to delete the returned object */
2167 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
2168 const string
& objs_macro
) const
2170 const FileLocation
*archiveFilename
= GetModuleArchiveFilename ();
2172 fprintf ( fMakefile
,
2174 backend
->GetFullName ( *archiveFilename
).c_str (),
2175 objs_macro
.c_str (),
2176 backend
->GetFullPath ( *archiveFilename
).c_str() );
2178 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
2180 const FileLocation
*definitionFilename
= GetDefinitionFilename ();
2182 fprintf ( fMakefile
,
2183 "\t${dlltool} --dllname %s --def %s --output-lib $@ %s %s\n",
2184 module
.importLibrary
->dllname
.c_str (),
2185 backend
->GetFullName ( *definitionFilename
).c_str (),
2186 module
.mangledSymbols
? "" : "--kill-at",
2187 module
.underscoreSymbols
? "--add-underscore" : "" );
2189 delete definitionFilename
;
2192 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
2194 fprintf ( fMakefile
,
2197 objs_macro
.c_str ());
2199 GenerateCleanObjectsAsYouGoCode ();
2201 fprintf ( fMakefile
, "\n" );
2203 return archiveFilename
;
2207 MingwModuleHandler::GetCFlagsMacro () const
2209 return ssprintf ( "$(%s_CFLAGS)",
2210 module
.name
.c_str () );
2214 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
2216 return ssprintf ( "$(%s_OBJS)",
2217 module
.name
.c_str () );
2221 MingwModuleHandler::GetLinkingDependenciesMacro () const
2223 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
2227 MingwModuleHandler::GetLibsMacro () const
2229 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
2233 MingwModuleHandler::GetLinkerMacro () const
2235 return ssprintf ( "$(%s_LFLAGS)",
2236 module
.name
.c_str () );
2240 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
2242 if ( ReferenceObjects ( module
) )
2243 return GetObjectsMacro ( module
);
2246 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
2247 string target
= backend
->GetFullName ( *target_file
).c_str ();
2254 MingwModuleHandler::GenerateSourceMacro ()
2256 sourcesMacro
= ssprintf ( "%s_SOURCES", module
.name
.c_str ());
2258 GenerateSourceMacros (
2260 module
.non_if_data
);
2262 // future references to the macro will be to get its values
2263 sourcesMacro
= ssprintf ("$(%s)", sourcesMacro
.c_str ());
2267 MingwModuleHandler::GenerateObjectMacro ()
2269 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
2271 GenerateObjectMacros (
2273 module
.non_if_data
);
2275 // future references to the macro will be to get its values
2276 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
2280 MingwModuleHandler::GenerateTargetMacro ()
2282 fprintf ( fMakefile
,
2284 GetTargetMacro ( module
, false ).c_str (),
2285 GetModuleTargets ( module
).c_str () );
2289 MingwModuleHandler::GetRpcHeaderDependencies (
2290 vector
<FileLocation
>& dependencies
) const
2292 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
2294 Library
& library
= *module
.non_if_data
.libraries
[i
];
2295 if ( library
.importedModule
->type
== RpcServer
||
2296 library
.importedModule
->type
== RpcClient
||
2297 library
.importedModule
->type
== RpcProxy
||
2298 library
.importedModule
->type
== IdlHeader
)
2300 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
2302 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
2303 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
2304 string extension
= GetExtension ( sourceFile
);
2305 if ( extension
== ".idl" || extension
== ".IDL" )
2307 string basename
= GetBasename ( sourceFile
.name
);
2308 if ( library
.importedModule
->type
== RpcServer
)
2310 const FileLocation
*header
= GetRpcServerHeaderFilename ( &sourceFile
);
2311 dependencies
.push_back ( *header
);
2314 if ( library
.importedModule
->type
== RpcClient
)
2316 const FileLocation
*header
= GetRpcClientHeaderFilename ( &sourceFile
);
2317 dependencies
.push_back ( *header
);
2320 if ( library
.importedModule
->type
== RpcProxy
)
2322 const FileLocation
*header
= GetRpcProxyHeaderFilename ( &sourceFile
);
2323 dependencies
.push_back ( *header
);
2326 if ( library
.importedModule
->type
== IdlHeader
)
2328 const FileLocation
*header
= GetIdlHeaderFilename ( &sourceFile
);
2329 dependencies
.push_back ( *header
);
2339 MingwModuleHandler::GenerateOtherMacros ()
2341 set
<const Define
*> used_defs
;
2343 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
2344 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
2345 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
2346 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
2347 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
2348 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
2349 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
2354 &module
.linkerFlags
,
2359 module
.project
.non_if_data
,
2363 vector
<FileLocation
> s
;
2364 if ( module
.importLibrary
)
2366 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2367 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2369 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2370 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
2371 string extension
= GetExtension ( sourceFile
);
2372 if ( extension
== ".spec" || extension
== ".SPEC" )
2373 GetSpecObjectDependencies ( s
, &sourceFile
);
2376 if ( s
.size () > 0 )
2381 linkDepsMacro
.c_str() );
2382 for ( size_t i
= 0; i
< s
.size(); i
++ )
2383 fprintf ( fMakefile
,
2385 backend
->GetFullName ( s
[i
] ).c_str () );
2386 fprintf ( fMakefile
, "\n" );
2389 string globalCflags
= "-g";
2390 if ( backend
->usePipe
)
2391 globalCflags
+= " -pipe";
2392 if ( !module
.allowWarnings
)
2393 globalCflags
+= " -Werror";
2394 if ( module
.host
== HostTrue
)
2396 if ( module
.cplusplus
)
2397 globalCflags
+= " $(HOST_CPPFLAGS)";
2399 globalCflags
+= " $(HOST_CFLAGS)";
2403 if ( module
.cplusplus
)
2405 // HACK: use host headers when building C++
2406 globalCflags
+= " $(HOST_CPPFLAGS)";
2409 globalCflags
+= " -nostdinc";
2412 // Always force disabling of sibling calls optimisation for GCC
2413 // (TODO: Move to version-specific once this bug is fixed in GCC)
2414 globalCflags
+= " -fno-optimize-sibling-calls";
2418 "%s += $(PROJECT_CFLAGS) %s\n",
2419 cflagsMacro
.c_str (),
2420 globalCflags
.c_str () );
2424 "%s += $(PROJECT_RCFLAGS)\n",
2425 windresflagsMacro
.c_str () );
2429 "%s += $(PROJECT_WIDLFLAGS) -I%s\n",
2430 widlflagsMacro
.c_str (),
2431 module
.output
->relative_path
.c_str () );
2435 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
2436 module
.name
.c_str () );
2441 linkDepsMacro
.c_str (),
2442 libsMacro
.c_str () );
2444 string cflags
= TypeSpecificCFlags();
2445 if ( cflags
.size() > 0 )
2447 fprintf ( fMakefile
,
2449 cflagsMacro
.c_str (),
2453 string nasmflags
= TypeSpecificNasmFlags();
2454 if ( nasmflags
.size () > 0 )
2456 fprintf ( fMakefile
,
2458 nasmflagsMacro
.c_str (),
2459 nasmflags
.c_str () );
2462 string linkerflags
= TypeSpecificLinkerFlags();
2463 if ( linkerflags
.size() > 0 )
2465 fprintf ( fMakefile
,
2467 linkerflagsMacro
.c_str (),
2468 linkerflags
.c_str () );
2471 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
2473 fprintf ( fMakefile
,
2474 "%s += -Wno-main\n\n",
2475 cflagsMacro
.c_str () );
2478 fprintf ( fMakefile
, "\n\n" );
2480 // future references to the macros will be to get their values
2481 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
2482 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
2483 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
2487 MingwModuleHandler::GenerateRules ()
2489 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
2490 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
2491 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
2493 string targetMacro
= GetTargetMacro ( module
);
2494 //CLEAN_FILE ( targetMacro );
2495 CLEAN_FILE ( FileLocation ( SourceDirectory
, "", targetMacro
) );
2497 // generate phony target for module name
2498 fprintf ( fMakefile
, ".PHONY: %s\n",
2499 module
.name
.c_str () );
2500 string dependencies
= GetTargetMacro ( module
);
2501 if ( module
.type
== Test
)
2502 dependencies
+= " $(REGTESTS_RUN_TARGET)";
2503 fprintf ( fMakefile
, "%s: %s\n\n",
2504 module
.name
.c_str (),
2505 dependencies
.c_str () );
2506 if ( module
.type
== Test
)
2508 fprintf ( fMakefile
,
2510 targetMacro
.c_str ());
2513 if ( !ReferenceObjects ( module
) )
2515 const FileLocation
* ar_target
= GenerateArchiveTarget ( ar
, objectsMacro
);
2516 CLEAN_FILE ( *ar_target
);
2520 GenerateObjectFileTargets ( cc
,
2529 MingwModuleHandler::GetInvocationDependencies (
2530 const Module
& module
,
2531 string_list
& dependencies
)
2533 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
2535 Invoke
& invoke
= *module
.invocations
[i
];
2536 if ( invoke
.invokeModule
== &module
)
2537 /* Protect against circular dependencies */
2539 invoke
.GetTargets ( dependencies
);
2544 MingwModuleHandler::GenerateInvocations () const
2546 if ( module
.invocations
.size () == 0 )
2549 size_t iend
= module
.invocations
.size ();
2550 for ( size_t i
= 0; i
< iend
; i
++ )
2552 const Invoke
& invoke
= *module
.invocations
[i
];
2554 if ( invoke
.invokeModule
->type
!= BuildTool
)
2556 throw XMLInvalidBuildFileException (
2557 module
.node
.location
,
2558 "Only modules of type buildtool can be invoked." );
2561 string invokeTarget
= module
.GetInvocationTarget ( i
);
2562 string_list invoke_targets
;
2563 assert ( invoke_targets
.size() );
2564 invoke
.GetTargets ( invoke_targets
);
2565 fprintf ( fMakefile
,
2567 invokeTarget
.c_str () );
2568 fprintf ( fMakefile
,
2570 invokeTarget
.c_str () );
2571 size_t j
, jend
= invoke_targets
.size();
2572 for ( j
= 0; j
< jend
; j
++ )
2574 fprintf ( fMakefile
,
2576 invoke_targets
[i
].c_str () );
2578 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
2579 for ( j
= 1; j
< jend
; j
++ )
2580 fprintf ( fMakefile
,
2582 invoke_targets
[i
].c_str () );
2583 fprintf ( fMakefile
,
2585 NormalizeFilename ( backend
->GetFullName ( *invoke
.invokeModule
->output
) ).c_str () );
2586 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
2587 fprintf ( fMakefile
,
2589 NormalizeFilename ( backend
->GetFullName ( *invoke
.invokeModule
->output
) ).c_str (),
2590 invoke
.GetParameters ().c_str () );
2595 MingwModuleHandler::GetPreconditionDependenciesName () const
2597 return module
.name
+ "_precondition";
2601 MingwModuleHandler::GetDefaultDependencies (
2602 string_list
& dependencies
) const
2604 /* Avoid circular dependency */
2605 if ( module
.type
!= BuildTool
2606 && module
.name
!= "zlib"
2607 && module
.name
!= "hostzlib" )
2609 dependencies
.push_back ( "$(INIT)" );
2611 if ( module
.type
!= BuildTool
2612 && module
.name
!= "psdk" )
2614 dependencies
.push_back ( "$(PSDK_TARGET) $(psdk_HEADERS)" );
2616 /* Check if any dependent library relays on the generated headers */
2617 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2619 const Module
& m
= *module
.project
.modules
[i
];
2620 for ( size_t j
= 0; j
< m
.non_if_data
.compilationUnits
.size (); j
++ )
2622 CompilationUnit
& compilationUnit
= *m
.non_if_data
.compilationUnits
[j
];
2623 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
2624 string extension
= GetExtension ( sourceFile
);
2625 if (extension
== ".mc" || extension
== ".MC" )
2627 string dependency
= ssprintf ( " $(%s_MCHEADERS)", m
.name
.c_str () );
2628 dependencies
.push_back ( dependency
);
2635 MingwModuleHandler::GeneratePreconditionDependencies ()
2637 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2638 vector
<FileLocation
> sourceFilenames
;
2639 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
2640 string_list dependencies
;
2641 GetDefaultDependencies ( dependencies
);
2642 GetModuleDependencies ( dependencies
);
2644 GetInvocationDependencies ( module
, dependencies
);
2646 if ( dependencies
.size() )
2648 fprintf ( fMakefile
,
2650 preconditionDependenciesName
.c_str () );
2651 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2652 fprintf ( fMakefile
,
2654 dependencies
[i
].c_str () );
2655 fprintf ( fMakefile
, "\n\n" );
2658 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
2660 fprintf ( fMakefile
,
2662 backend
->GetFullName ( sourceFilenames
[i
] ).c_str (),
2663 preconditionDependenciesName
.c_str ());
2665 fprintf ( fMakefile
, "\n" );
2669 MingwModuleHandler::IsWineModule () const
2671 if ( module
.importLibrary
== NULL
)
2674 size_t index
= module
.importLibrary
->source
->name
.rfind ( ".spec.def" );
2675 return ( index
!= string::npos
);
2678 /* caller needs to delete the returned object */
2680 MingwModuleHandler::GetDefinitionFilename () const
2682 if ( module
.importLibrary
!= NULL
)
2684 DirectoryLocation directory
;
2685 if ( IsWineModule () )
2686 directory
= IntermediateDirectory
;
2688 directory
= SourceDirectory
;
2690 return new FileLocation ( directory
,
2691 module
.importLibrary
->source
->relative_path
,
2692 module
.importLibrary
->source
->name
);
2695 return new FileLocation ( SourceDirectory
, "tools" + sSep
+ "rbuild", "empty.def" );
2699 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2701 if ( module
.importLibrary
!= NULL
)
2703 const FileLocation
*library_target
= GetImportLibraryFilename ( module
, &clean_files
);
2704 const FileLocation
*defFilename
= GetDefinitionFilename ();
2706 vector
<FileLocation
> deps
;
2707 GetDefinitionDependencies ( deps
);
2709 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2711 fprintf ( fMakefile
, "%s: %s",
2712 backend
->GetFullName ( *library_target
).c_str (),
2713 backend
->GetFullName ( *defFilename
).c_str () );
2715 size_t i
, iend
= deps
.size();
2716 for ( i
= 0; i
< iend
; i
++ )
2717 fprintf ( fMakefile
, " %s",
2718 backend
->GetFullName ( deps
[i
] ).c_str () );
2720 fprintf ( fMakefile
, " | %s\n",
2721 backend
->GetFullPath ( *library_target
).c_str () );
2723 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2725 fprintf ( fMakefile
,
2726 "\t${dlltool} --dllname %s --def %s --output-lib %s %s %s\n\n",
2727 module
.output
->name
.c_str (),
2728 backend
->GetFullName ( *defFilename
).c_str (),
2729 backend
->GetFullName ( *library_target
).c_str (),
2730 module
.mangledSymbols
? "" : "--kill-at",
2731 module
.underscoreSymbols
? "--add-underscore" : "" );
2734 delete library_target
;
2739 MingwModuleHandler::GetSpecObjectDependencies (
2740 vector
<FileLocation
>& dependencies
,
2741 const FileLocation
*file
) const
2743 string basename
= GetBasename ( file
->name
);
2745 FileLocation
defDependency ( IntermediateDirectory
,
2746 file
->relative_path
,
2747 basename
+ ".spec.def" );
2748 dependencies
.push_back ( defDependency
);
2750 FileLocation
stubsDependency ( IntermediateDirectory
,
2751 file
->relative_path
,
2752 basename
+ ".stubs.c" );
2753 dependencies
.push_back ( stubsDependency
);
2757 MingwModuleHandler::GetMcObjectDependencies (
2758 vector
<FileLocation
>& dependencies
,
2759 const FileLocation
*file
) const
2761 string basename
= GetBasename ( file
->name
);
2763 FileLocation
defDependency ( IntermediateDirectory
,
2766 dependencies
.push_back ( defDependency
);
2768 FileLocation
stubsDependency ( IntermediateDirectory
,
2769 file
->relative_path
,
2771 dependencies
.push_back ( stubsDependency
);
2775 MingwModuleHandler::GetWidlObjectDependencies (
2776 vector
<FileLocation
>& dependencies
,
2777 const FileLocation
*file
) const
2779 string basename
= GetBasename ( file
->name
);
2780 const FileLocation
*generatedHeaderFilename
= GetRpcServerHeaderFilename ( file
);
2782 FileLocation
serverSourceDependency ( IntermediateDirectory
,
2783 file
->relative_path
,
2784 basename
+ "_s.c" );
2785 dependencies
.push_back ( serverSourceDependency
);
2786 dependencies
.push_back ( *generatedHeaderFilename
);
2788 delete generatedHeaderFilename
;
2792 MingwModuleHandler::GetDefinitionDependencies (
2793 vector
<FileLocation
>& dependencies
) const
2795 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2796 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2798 const CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2799 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
2800 string extension
= GetExtension ( sourceFile
);
2801 if ( extension
== ".spec" || extension
== ".SPEC" )
2802 GetSpecObjectDependencies ( dependencies
, &sourceFile
);
2803 if ( extension
== ".idl" || extension
== ".IDL" )
2805 if ( ( module
.type
== RpcServer
) || ( module
.type
== RpcClient
) || ( module
.type
== RpcProxy
) )
2806 GetWidlObjectDependencies ( dependencies
, &sourceFile
);
2811 enum DebugSupportType
2818 MingwAddDebugSupportLibraries ( Module
& module
, DebugSupportType type
)
2824 case DebugKernelMode
:
2825 pLibrary
= new Library ( module
, "debugsup_ntoskrnl" );
2829 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2836 module
.non_if_data
.libraries
.push_back(pLibrary
);
2839 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2840 : MingwModuleHandler ( module_
)
2845 MingwBuildToolModuleHandler::Process ()
2847 GenerateBuildToolModuleTarget ();
2851 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2853 string
targetMacro ( GetTargetMacro (module
) );
2854 string objectsMacro
= GetObjectsMacro ( module
);
2855 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2856 string libsMacro
= GetLibsMacro ();
2861 if ( module
.cplusplus
)
2862 linker
= "${host_gpp}";
2864 linker
= "${host_gcc}";
2866 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
2867 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2868 targetMacro
.c_str (),
2869 objectsMacro
.c_str (),
2870 linkDepsMacro
.c_str (),
2871 backend
->GetFullPath ( *target_file
).c_str () );
2872 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2873 fprintf ( fMakefile
,
2874 "\t%s %s -o $@ %s %s\n\n",
2876 GetLinkerMacro ().c_str (),
2877 objectsMacro
.c_str (),
2878 libsMacro
.c_str () );
2884 MingwKernelModuleHandler::MingwKernelModuleHandler (
2885 const Module
& module_
)
2887 : MingwModuleHandler ( module_
)
2892 MingwKernelModuleHandler::Process ()
2894 GenerateKernelModuleTarget ();
2898 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2900 string
targetMacro ( GetTargetMacro ( module
) );
2901 string workingDirectory
= GetWorkingDirectory ( );
2902 string objectsMacro
= GetObjectsMacro ( module
);
2903 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2904 string libsMacro
= GetLibsMacro ();
2906 GenerateImportLibraryTargetIfNeeded ();
2908 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2912 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2914 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s",
2915 module
.GetEntryPoint(true).c_str (),
2916 module
.baseaddress
.c_str () );
2917 GenerateLinkerCommand ( dependencies
,
2919 linkerParameters
+ " $(NTOSKRNL_SHARED)",
2926 GeneratePhonyTarget();
2931 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2932 const Module
& module_
)
2934 : MingwModuleHandler ( module_
)
2939 MingwStaticLibraryModuleHandler::Process ()
2941 GenerateStaticLibraryModuleTarget ();
2945 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2951 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2952 const Module
& module_
)
2954 : MingwModuleHandler ( module_
)
2959 MingwObjectLibraryModuleHandler::Process ()
2961 GenerateObjectLibraryModuleTarget ();
2965 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2971 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2972 const Module
& module_
)
2974 : MingwModuleHandler ( module_
)
2978 MingwEmbeddedTypeLibModuleHandler::MingwEmbeddedTypeLibModuleHandler (
2979 const Module
& module_
)
2981 : MingwModuleHandler ( module_
)
2986 MingwEmbeddedTypeLibModuleHandler::Process ()
2993 MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2995 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2999 MingwKernelModeDLLModuleHandler::Process ()
3001 GenerateKernelModeDLLModuleTarget ();
3005 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
3007 string
targetMacro ( GetTargetMacro ( module
) );
3008 string workingDirectory
= GetWorkingDirectory ( );
3009 string objectsMacro
= GetObjectsMacro ( module
);
3010 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3011 string libsMacro
= GetLibsMacro ();
3013 GenerateImportLibraryTargetIfNeeded ();
3015 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3019 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3021 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
3022 module
.GetEntryPoint(true).c_str (),
3023 module
.baseaddress
.c_str () );
3024 GenerateLinkerCommand ( dependencies
,
3033 GeneratePhonyTarget();
3038 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
3039 const Module
& module_
)
3041 : MingwModuleHandler ( module_
)
3046 MingwKernelModeDriverModuleHandler::AddImplicitLibraries ( Module
& module
)
3048 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
3052 MingwKernelModeDriverModuleHandler::Process ()
3054 GenerateKernelModeDriverModuleTarget ();
3059 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
3061 string
targetMacro ( GetTargetMacro (module
) );
3062 string workingDirectory
= GetWorkingDirectory ();
3063 string objectsMacro
= GetObjectsMacro ( module
);
3064 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3065 string libsMacro
= GetLibsMacro ();
3067 GenerateImportLibraryTargetIfNeeded ();
3069 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3073 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3075 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
3076 module
.GetEntryPoint(true).c_str (),
3077 module
.baseaddress
.c_str () );
3078 GenerateLinkerCommand ( dependencies
,
3087 GeneratePhonyTarget();
3092 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
3093 const Module
& module_
)
3095 : MingwModuleHandler ( module_
)
3100 MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
3102 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3106 MingwNativeDLLModuleHandler::Process ()
3108 GenerateNativeDLLModuleTarget ();
3112 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
3114 string
targetMacro ( GetTargetMacro (module
) );
3115 string workingDirectory
= GetWorkingDirectory ( );
3116 string objectsMacro
= GetObjectsMacro ( module
);
3117 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3118 string libsMacro
= GetLibsMacro ();
3120 GenerateImportLibraryTargetIfNeeded ();
3122 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3126 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3128 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
3129 module
.GetEntryPoint(true).c_str (),
3130 module
.baseaddress
.c_str () );
3131 GenerateLinkerCommand ( dependencies
,
3140 GeneratePhonyTarget();
3145 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
3146 const Module
& module_
)
3148 : MingwModuleHandler ( module_
)
3153 MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module
& module
)
3155 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3159 MingwNativeCUIModuleHandler::Process ()
3161 GenerateNativeCUIModuleTarget ();
3165 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
3167 string
targetMacro ( GetTargetMacro (module
) );
3168 string workingDirectory
= GetWorkingDirectory ( );
3169 string objectsMacro
= GetObjectsMacro ( module
);
3170 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3171 string libsMacro
= GetLibsMacro ();
3173 GenerateImportLibraryTargetIfNeeded ();
3175 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3179 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3181 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
3182 module
.GetEntryPoint(true).c_str (),
3183 module
.baseaddress
.c_str () );
3184 GenerateLinkerCommand ( dependencies
,
3193 GeneratePhonyTarget();
3198 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
3199 const Module
& module_
)
3201 : MingwModuleHandler ( module_
)
3205 MingwWin32OCXModuleHandler::MingwWin32OCXModuleHandler (
3206 const Module
& module_
)
3208 : MingwModuleHandler ( module_
)
3213 LinksToCrt( Module
&module
)
3215 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
3217 Library
& library
= *module
.non_if_data
.libraries
[i
];
3218 if ( library
.name
== "libcntpr" || library
.name
== "crt" )
3225 MingwAddImplicitLibraries( Module
&module
)
3230 if ( module
.type
!= Win32DLL
3231 && module
.type
!= Win32OCX
3232 && module
.type
!= Win32CUI
3233 && module
.type
!= Win32GUI
3234 && module
.type
!= Win32SCR
)
3236 // no implicit libraries
3240 links_to_crt
= LinksToCrt ( module
);
3242 if ( !module
.isDefaultEntryPoint
)
3244 if ( module
.GetEntryPoint(false) == "0" )
3246 if ( !links_to_crt
)
3248 pLibrary
= new Library ( module
, "mingw_common" );
3249 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() , pLibrary
);
3251 pLibrary
= new Library ( module
, "msvcrt" );
3252 module
.non_if_data
.libraries
.push_back ( pLibrary
);
3253 links_to_crt
= true;
3259 if ( module
.IsDLL () )
3261 //pLibrary = new Library ( module, "__mingw_dllmain" );
3262 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
3266 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
3267 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
3270 pLibrary
= new Library ( module
, "mingw_common" );
3271 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
3273 if ( !links_to_crt
)
3275 // always link in msvcrt to get the basic routines
3276 pLibrary
= new Library ( module
, "msvcrt" );
3277 module
.non_if_data
.libraries
.push_back ( pLibrary
);
3282 MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module
& module
)
3284 MingwAddImplicitLibraries ( module
);
3285 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3289 MingwWin32DLLModuleHandler::Process ()
3291 GenerateWin32DLLModuleTarget ();
3295 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
3297 string
targetMacro ( GetTargetMacro (module
) );
3298 string workingDirectory
= GetWorkingDirectory ( );
3299 string objectsMacro
= GetObjectsMacro ( module
);
3300 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3301 string libsMacro
= GetLibsMacro ();
3303 GenerateImportLibraryTargetIfNeeded ();
3305 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3309 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3312 if ( module
.cplusplus
)
3317 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
3318 module
.GetEntryPoint(true).c_str (),
3319 module
.baseaddress
.c_str () );
3320 GenerateLinkerCommand ( dependencies
,
3329 GeneratePhonyTarget();
3335 MingwWin32OCXModuleHandler::AddImplicitLibraries ( Module
& module
)
3337 MingwAddImplicitLibraries ( module
);
3338 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3342 MingwWin32OCXModuleHandler::Process ()
3344 GenerateWin32OCXModuleTarget ();
3348 MingwWin32OCXModuleHandler::GenerateWin32OCXModuleTarget ()
3350 string
targetMacro ( GetTargetMacro (module
) );
3351 string workingDirectory
= GetWorkingDirectory ( );
3352 string objectsMacro
= GetObjectsMacro ( module
);
3353 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3354 string libsMacro
= GetLibsMacro ();
3356 GenerateImportLibraryTargetIfNeeded ();
3358 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3362 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3365 if ( module
.cplusplus
)
3370 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
3371 module
.GetEntryPoint(true).c_str (),
3372 module
.baseaddress
.c_str () );
3373 GenerateLinkerCommand ( dependencies
,
3382 GeneratePhonyTarget();
3387 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
3388 const Module
& module_
)
3390 : MingwModuleHandler ( module_
)
3395 MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module
& module
)
3397 MingwAddImplicitLibraries ( module
);
3398 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3402 MingwWin32CUIModuleHandler::Process ()
3404 GenerateWin32CUIModuleTarget ();
3408 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
3410 string
targetMacro ( GetTargetMacro (module
) );
3411 string workingDirectory
= GetWorkingDirectory ( );
3412 string objectsMacro
= GetObjectsMacro ( module
);
3413 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3414 string libsMacro
= GetLibsMacro ();
3416 GenerateImportLibraryTargetIfNeeded ();
3418 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3422 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3425 if ( module
.cplusplus
)
3430 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3431 module
.GetEntryPoint(true).c_str (),
3432 module
.baseaddress
.c_str () );
3433 GenerateLinkerCommand ( dependencies
,
3442 GeneratePhonyTarget();
3447 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
3448 const Module
& module_
)
3450 : MingwModuleHandler ( module_
)
3455 MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module
& module
)
3457 MingwAddImplicitLibraries ( module
);
3458 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
3462 MingwWin32GUIModuleHandler::Process ()
3464 GenerateWin32GUIModuleTarget ();
3468 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
3470 string
targetMacro ( GetTargetMacro (module
) );
3471 string workingDirectory
= GetWorkingDirectory ( );
3472 string objectsMacro
= GetObjectsMacro ( module
);
3473 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3474 string libsMacro
= GetLibsMacro ();
3476 GenerateImportLibraryTargetIfNeeded ();
3478 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3482 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3485 if ( module
.cplusplus
)
3490 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3491 module
.GetEntryPoint(true).c_str (),
3492 module
.baseaddress
.c_str () );
3493 GenerateLinkerCommand ( dependencies
,
3502 GeneratePhonyTarget();
3507 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
3508 const Module
& module_
)
3510 : MingwModuleHandler ( module_
)
3515 MingwBootLoaderModuleHandler::Process ()
3517 GenerateBootLoaderModuleTarget ();
3521 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
3523 string
targetName ( module
.output
->name
);
3524 string
targetMacro ( GetTargetMacro (module
) );
3525 string workingDirectory
= GetWorkingDirectory ();
3526 FileLocation
junk_tmp ( TemporaryDirectory
,
3528 module
.name
+ ".junk.tmp" );
3529 CLEAN_FILE ( junk_tmp
);
3530 string objectsMacro
= GetObjectsMacro ( module
);
3531 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3532 string libsMacro
= GetLibsMacro ();
3536 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
3537 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3538 targetMacro
.c_str (),
3539 objectsMacro
.c_str (),
3540 linkDepsMacro
.c_str (),
3541 backend
->GetFullPath ( *target_file
).c_str () );
3543 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
3545 fprintf ( fMakefile
,
3546 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
3547 GetLinkerMacro ().c_str (),
3548 backend
->GetFullName ( junk_tmp
).c_str (),
3549 objectsMacro
.c_str (),
3550 linkDepsMacro
.c_str () );
3551 fprintf ( fMakefile
,
3552 "\t${objcopy} -O binary %s $@\n",
3553 backend
->GetFullName ( junk_tmp
).c_str () );
3554 GenerateBuildMapCode ( &junk_tmp
);
3555 fprintf ( fMakefile
,
3556 "\t-@${rm} %s 2>$(NUL)\n",
3557 backend
->GetFullName ( junk_tmp
).c_str () );
3563 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
3564 const Module
& module_
)
3566 : MingwModuleHandler ( module_
)
3571 MingwBootSectorModuleHandler::Process ()
3573 GenerateBootSectorModuleTarget ();
3577 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
3579 string objectsMacro
= GetObjectsMacro ( module
);
3583 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3584 module
.name
.c_str ());
3585 fprintf ( fMakefile
,
3587 module
.name
.c_str (),
3588 objectsMacro
.c_str () );
3592 MingwBootProgramModuleHandler::MingwBootProgramModuleHandler (
3593 const Module
& module_
)
3594 : MingwModuleHandler ( module_
)
3599 MingwBootProgramModuleHandler::Process ()
3601 GenerateBootProgramModuleTarget ();
3605 MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
3607 string
targetName ( module
.output
->name
);
3608 string
targetMacro ( GetTargetMacro (module
) );
3609 string workingDirectory
= GetWorkingDirectory ();
3610 FileLocation
junk_tmp ( TemporaryDirectory
,
3612 module
.name
+ ".junk.tmp" );
3613 FileLocation
junk_elf ( TemporaryDirectory
,
3615 module
.name
+ ".junk.elf" );
3616 FileLocation
junk_cpy ( TemporaryDirectory
,
3618 module
.name
+ ".junk.elf" );
3619 CLEAN_FILE ( junk_tmp
);
3620 CLEAN_FILE ( junk_elf
);
3621 CLEAN_FILE ( junk_cpy
);
3622 string objectsMacro
= GetObjectsMacro ( module
);
3623 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3624 string libsMacro
= GetLibsMacro ();
3625 const Module
*payload
= module
.project
.LocateModule ( module
.payload
);
3629 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
3630 fprintf ( fMakefile
, "%s: %s %s %s | %s\n",
3631 targetMacro
.c_str (),
3632 objectsMacro
.c_str (),
3633 linkDepsMacro
.c_str (),
3634 payload
->name
.c_str (),
3635 backend
->GetFullPath ( *target_file
).c_str () );
3637 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3639 fprintf ( fMakefile
, "\t$(%s_PREPARE) $(OUTPUT)$(SEP)%s %s\n",
3640 module
.buildtype
.c_str (),
3641 NormalizeFilename( backend
->GetFullName ( *payload
->output
) ).c_str (),
3642 backend
->GetFullName ( junk_cpy
).c_str () );
3644 fprintf ( fMakefile
, "\t${objcopy} $(%s_FLATFORMAT) %s %s\n",
3645 module
.buildtype
.c_str (),
3646 backend
->GetFullName ( junk_cpy
).c_str (),
3647 backend
->GetFullName ( junk_tmp
).c_str () );
3649 fprintf ( fMakefile
, "\t${ld} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3650 module
.buildtype
.c_str (),
3651 linkDepsMacro
.c_str (),
3652 backend
->GetFullName ( junk_tmp
).c_str (),
3653 backend
->GetFullName ( junk_elf
).c_str () );
3655 fprintf ( fMakefile
, "\t${objcopy} $(%s_COPYFORMAT) %s $(INTERMEDIATE)$(SEP)%s\n",
3656 module
.buildtype
.c_str (),
3657 backend
->GetFullName ( junk_elf
).c_str (),
3658 backend
->GetFullName ( *module
.output
) .c_str () );
3660 fprintf ( fMakefile
,
3661 "\t-@${rm} %s %s %s 2>$(NUL)\n",
3662 backend
->GetFullName ( junk_tmp
).c_str (),
3663 backend
->GetFullName ( junk_elf
).c_str (),
3664 backend
->GetFullName ( junk_cpy
).c_str () );
3670 MingwIsoModuleHandler::MingwIsoModuleHandler (
3671 const Module
& module_
)
3673 : MingwModuleHandler ( module_
)
3678 MingwIsoModuleHandler::Process ()
3680 GenerateIsoModuleTarget ();
3684 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
3685 const string
& bootcdDirectory
)
3687 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3689 const Module
& m
= *module
.project
.modules
[i
];
3692 if ( m
.bootstrap
!= NULL
)
3694 FileLocation
targetFile ( OutputDirectory
,
3695 m
.bootstrap
->base
.length () > 0
3696 ? bootcdDirectory
+ sSep
+ m
.bootstrap
->base
3698 m
.bootstrap
->nameoncd
);
3699 OutputCopyCommand ( *m
.output
, targetFile
);
3705 MingwIsoModuleHandler::OutputCdfileCopyCommands (
3706 const string
& bootcdDirectory
)
3708 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3710 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3711 FileLocation
targetFile ( OutputDirectory
,
3712 cdfile
.target
->relative_path
.length () > 0
3713 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3715 cdfile
.target
->name
);
3716 OutputCopyCommand ( *cdfile
.source
, targetFile
);
3721 MingwIsoModuleHandler::GetBootstrapCdDirectories ( vector
<FileLocation
>& out
,
3722 const string
& bootcdDirectory
)
3724 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3726 const Module
& m
= *module
.project
.modules
[i
];
3729 if ( m
.bootstrap
!= NULL
)
3731 FileLocation
targetDirectory ( OutputDirectory
,
3732 m
.bootstrap
->base
.length () > 0
3733 ? bootcdDirectory
+ sSep
+ m
.bootstrap
->base
3736 out
.push_back ( targetDirectory
);
3742 MingwIsoModuleHandler::GetNonModuleCdDirectories ( vector
<FileLocation
>& out
,
3743 const string
& bootcdDirectory
)
3745 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3747 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3748 FileLocation
targetDirectory ( OutputDirectory
,
3749 cdfile
.target
->relative_path
.length () > 0
3750 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3753 out
.push_back( targetDirectory
);
3758 MingwIsoModuleHandler::GetCdDirectories ( vector
<FileLocation
>& out
,
3759 const string
& bootcdDirectory
)
3761 GetBootstrapCdDirectories ( out
, bootcdDirectory
);
3762 GetNonModuleCdDirectories ( out
, bootcdDirectory
);
3766 MingwIsoModuleHandler::GetBootstrapCdFiles (
3767 vector
<FileLocation
>& out
) const
3769 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3771 const Module
& m
= *module
.project
.modules
[i
];
3774 if ( m
.bootstrap
!= NULL
)
3776 out
.push_back ( *m
.output
);
3782 MingwIsoModuleHandler::GetNonModuleCdFiles (
3783 vector
<FileLocation
>& out
) const
3785 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3787 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3788 out
.push_back ( *cdfile
.source
);
3793 MingwIsoModuleHandler::GetCdFiles (
3794 vector
<FileLocation
>& out
) const
3796 GetBootstrapCdFiles ( out
);
3797 GetNonModuleCdFiles ( out
);
3801 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
3803 string bootcdDirectory
= "cd";
3804 FileLocation
bootcd ( OutputDirectory
,
3807 FileLocation
bootcdReactos ( OutputDirectory
,
3808 bootcdDirectory
+ sSep
+ Environment::GetCdOutputPath (),
3810 vector
<FileLocation
> vSourceFiles
, vCdFiles
;
3811 vector
<FileLocation
> vCdDirectories
;
3814 FileLocation
srcunattend ( SourceDirectory
,
3815 "boot" + sSep
+ "bootdata" + sSep
+ "bootcdregtest",
3817 FileLocation
tarunattend ( bootcdReactos
.directory
,
3818 bootcdReactos
.relative_path
,
3820 if (module
.type
== IsoRegTest
)
3821 vSourceFiles
.push_back ( srcunattend
);
3824 const Module
* bootModule
;
3825 bootModule
= module
.project
.LocateModule ( module
.type
== IsoRegTest
3828 const FileLocation
*isoboot
= bootModule
->output
;
3829 vSourceFiles
.push_back ( *isoboot
);
3831 // prepare reactos.dff and reactos.inf
3832 FileLocation
reactosDff ( SourceDirectory
,
3833 "boot" + sSep
+ "bootdata" + sSep
+ "packages",
3835 FileLocation
reactosInf ( bootcdReactos
.directory
,
3836 bootcdReactos
.relative_path
,
3838 vSourceFiles
.push_back ( reactosDff
);
3842 if (module
.type
== IsoRegTest
)
3843 IsoName
= "ReactOS-RegTest.iso";
3845 IsoName
= "ReactOS.iso";
3848 string sourceFiles
= v2s ( backend
, vSourceFiles
, 5 );
3851 GetCdDirectories ( vCdDirectories
, bootcdDirectory
);
3852 GetCdFiles ( vCdFiles
);
3853 string cdDirectories
= "";//v2s ( vCdDirectories, 5 );
3854 string cdFiles
= v2s ( backend
, vCdFiles
, 5 );
3856 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3857 module
.name
.c_str ());
3858 fprintf ( fMakefile
,
3859 "%s: all %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET) %s\n",
3860 module
.name
.c_str (),
3861 backend
->GetFullName ( *isoboot
).c_str (),
3862 sourceFiles
.c_str (),
3864 cdDirectories
.c_str () );
3865 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
3866 fprintf ( fMakefile
,
3867 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
3868 backend
->GetFullName ( reactosDff
).c_str (),
3869 backend
->GetFullPath ( bootcdReactos
).c_str () );
3870 fprintf ( fMakefile
,
3871 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
3872 backend
->GetFullName ( reactosDff
).c_str (),
3873 backend
->GetFullName ( reactosInf
).c_str (),
3874 backend
->GetFullPath ( bootcdReactos
).c_str ());
3875 fprintf ( fMakefile
,
3876 "\t-@${rm} %s 2>$(NUL)\n",
3877 backend
->GetFullName ( reactosInf
).c_str () );
3878 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
3879 OutputCdfileCopyCommands ( bootcdDirectory
);
3881 if (module
.type
== IsoRegTest
)
3882 OutputCopyCommand ( srcunattend
, tarunattend
);
3884 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3885 fprintf ( fMakefile
,
3886 "\t$(Q)$(CDMAKE_TARGET) -v -j -m -b %s %s REACTOS %s\n",
3887 backend
->GetFullName ( *isoboot
).c_str (),
3888 backend
->GetFullPath ( bootcd
).c_str (),
3890 fprintf ( fMakefile
,
3895 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
3896 const Module
& module_
)
3898 : MingwModuleHandler ( module_
)
3903 MingwLiveIsoModuleHandler::Process ()
3905 GenerateLiveIsoModuleTarget ();
3909 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
3911 FileLocation
dir ( OutputDirectory
,
3914 MingwModuleHandler::PassThruCacheDirectory ( &dir
);
3918 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
3919 string
& reactosDirectory
)
3921 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3923 const Module
& m
= *module
.project
.modules
[i
];
3928 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
3929 FileLocation
destination ( OutputDirectory
,
3930 m
.install
->relative_path
.length () > 0
3931 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.install
->relative_path
3932 : livecdDirectory
+ sSep
+ reactosDirectory
,
3934 OutputCopyCommand ( *aliasedModule
.output
,
3941 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
3942 string
& reactosDirectory
)
3944 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
3946 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
3947 FileLocation
target ( OutputDirectory
,
3948 installfile
.target
->relative_path
.length () > 0
3949 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.target
->relative_path
3950 : livecdDirectory
+ sSep
+ reactosDirectory
,
3951 installfile
.target
->name
);
3952 OutputCopyCommand ( *installfile
.source
, target
);
3957 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
3959 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
3960 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
3961 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
3962 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
3963 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
3964 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
3966 FileLocation
livecdIni ( SourceDirectory
,
3967 "boot" + sSep
+ "bootdata",
3969 FileLocation
destination ( OutputDirectory
,
3972 OutputCopyCommand ( livecdIni
,
3977 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3979 FileLocation
freeldr ( OutputDirectory
,
3980 "boot" + sSep
+ "freeldr" + sSep
+ "freeldr",
3982 FileLocation
destination ( OutputDirectory
,
3983 livecdDirectory
+ sSep
+ "loader",
3985 OutputCopyCommand ( freeldr
,
3990 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3992 FileLocation
reactosSystem32ConfigDirectory ( OutputDirectory
,
3993 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config",
3995 fprintf ( fMakefile
,
3996 "\t$(ECHO_MKHIVE)\n" );
3997 fprintf ( fMakefile
,
3998 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%clivecd.inf boot%cbootdata%chiveinst.inf\n",
3999 cSep
, backend
->GetFullPath ( reactosSystem32ConfigDirectory
).c_str (),
4000 cSep
, cSep
, cSep
, cSep
);
4004 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
4006 string livecdDirectory
= module
.name
;
4007 FileLocation
livecd ( OutputDirectory
, livecdDirectory
, "" );
4011 const Module
* bootModule
;
4012 bootModule
= module
.project
.LocateModule ( module
.name
== "livecdregtest"
4015 const FileLocation
*isoboot
= bootModule
->output
;
4016 if (module
.name
== "livecdregtest")
4017 IsoName
= "ReactOS-LiveCD-RegTest.iso";
4019 IsoName
= "ReactOS-LiveCD.iso";
4021 string reactosDirectory
= "reactos";
4022 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
4023 FileLocation
livecdReactos ( OutputDirectory
,
4024 livecdReactosNoFixup
,
4026 CLEAN_FILE ( livecdReactos
);
4028 fprintf ( fMakefile
, ".PHONY: %s\n\n",
4029 module
.name
.c_str ());
4030 fprintf ( fMakefile
,
4031 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
4032 module
.name
.c_str (),
4033 backend
->GetFullName ( *isoboot
) .c_str (),
4034 backend
->GetFullPath ( livecdReactos
).c_str () );
4035 OutputModuleCopyCommands ( livecdDirectory
,
4037 OutputNonModuleCopyCommands ( livecdDirectory
,
4039 OutputProfilesDirectoryCommands ( livecdDirectory
);
4040 OutputLoaderCommands ( livecdDirectory
);
4041 OutputRegistryCommands ( livecdDirectory
);
4042 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
4043 fprintf ( fMakefile
,
4044 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS %s\n",
4045 backend
->GetFullName( *isoboot
).c_str (),
4046 backend
->GetFullPath ( livecd
).c_str (),
4048 fprintf ( fMakefile
,
4053 MingwTestModuleHandler::MingwTestModuleHandler (
4054 const Module
& module_
)
4056 : MingwModuleHandler ( module_
)
4061 MingwTestModuleHandler::Process ()
4063 GenerateTestModuleTarget ();
4066 /* caller needs to delete the returned object */
4068 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
4070 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_hooks.c", false, "", false ) ) );
4071 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_stubs.S", false, "", false ) ) );
4072 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_startup.c", false, "", false ) ) );
4076 MingwTestModuleHandler::GenerateTestModuleTarget ()
4078 string
targetMacro ( GetTargetMacro ( module
) );
4079 string workingDirectory
= GetWorkingDirectory ( );
4080 string objectsMacro
= GetObjectsMacro ( module
);
4081 string linkDepsMacro
= GetLinkingDependenciesMacro ();
4082 string libsMacro
= GetLibsMacro ();
4084 GenerateImportLibraryTargetIfNeeded ();
4086 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
4090 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
4093 if ( module
.cplusplus
)
4098 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
4099 module
.GetEntryPoint(true).c_str (),
4100 module
.baseaddress
.c_str () );
4101 GenerateLinkerCommand ( dependencies
,
4110 GeneratePhonyTarget();
4115 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
4116 const Module
& module_
)
4118 : MingwModuleHandler ( module_
)
4123 MingwRpcServerModuleHandler::Process ()
4129 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
4130 const Module
& module_
)
4132 : MingwModuleHandler ( module_
)
4137 MingwRpcClientModuleHandler::Process ()
4143 MingwRpcProxyModuleHandler::MingwRpcProxyModuleHandler (
4144 const Module
& module_
)
4146 : MingwModuleHandler ( module_
)
4151 MingwRpcProxyModuleHandler::Process ()
4157 MingwAliasModuleHandler::MingwAliasModuleHandler (
4158 const Module
& module_
)
4160 : MingwModuleHandler ( module_
)
4165 MingwAliasModuleHandler::Process ()
4169 MingwIdlHeaderModuleHandler::MingwIdlHeaderModuleHandler (
4170 const Module
& module_
)
4172 : MingwModuleHandler ( module_
)
4177 MingwIdlHeaderModuleHandler::Process ()
4182 MingwElfExecutableModuleHandler::MingwElfExecutableModuleHandler (
4183 const Module
& module_
)
4185 : MingwModuleHandler ( module_
)
4190 MingwElfExecutableModuleHandler::Process ()
4192 string
targetName ( module
.output
->name
);
4193 string
targetMacro ( GetTargetMacro (module
) );
4194 string workingDirectory
= GetWorkingDirectory ();
4195 string objectsMacro
= GetObjectsMacro ( module
);
4196 string linkDepsMacro
= GetLinkingDependenciesMacro ();
4197 string libsMacro
= GetLibsMacro ();
4201 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
4202 fprintf ( fMakefile
, "%s: %s %s | %s\n",
4203 targetMacro
.c_str (),
4204 objectsMacro
.c_str (),
4205 linkDepsMacro
.c_str (),
4206 backend
->GetFullPath ( *target_file
).c_str () );
4208 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
4210 fprintf ( fMakefile
, "\t${gcc} $(%s_LINKFORMAT) %s %s -g -o %s\n",
4211 module
.buildtype
.c_str(),
4212 objectsMacro
.c_str(),
4214 targetMacro
.c_str () );