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"
23 #include "../../rbuild.h"
25 #include "modulehandler.h"
32 #define CLEAN_FILE(f) clean_files.push_back ( (f).name.length () > 0 ? backend->GetFullName ( f ) : backend->GetFullPath ( f ) );
33 #define IsStaticLibrary( module ) ( ( module.type == StaticLibrary ) || ( module.type == HostStaticLibrary ) )
36 MingwModuleHandler::backend
= NULL
;
38 MingwModuleHandler::fMakefile
= NULL
;
42 const string
& filename
,
43 const string
& prefix
)
45 if ( !prefix
.length() )
48 const char* pfilename
= filename
.c_str();
49 const char* p1
= strrchr ( pfilename
, '/' );
50 const char* p2
= strrchr ( pfilename
, '\\' );
55 out
+= string(pfilename
,p1
-pfilename
) + cSep
;
58 out
+= prefix
+ pfilename
;
63 GetTargetMacro ( const Module
& module
, bool with_dollar
)
65 string
s ( module
.name
);
69 return ssprintf ( "$(%s)", s
.c_str() );
73 MingwModuleHandler::MingwModuleHandler (
74 const Module
& module_
)
81 MingwModuleHandler::~MingwModuleHandler()
86 MingwModuleHandler::SetBackend ( MingwBackend
* backend_
)
92 MingwModuleHandler::SetMakefile ( FILE* f
)
98 MingwModuleHandler::EnablePreCompiledHeaderSupport ()
103 /*static*/ const FileLocation
*
104 MingwModuleHandler::PassThruCacheDirectory (const FileLocation
* file
)
106 switch ( file
->directory
)
108 case SourceDirectory
:
110 case IntermediateDirectory
:
111 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->intermediateDirectory
);
113 case OutputDirectory
:
114 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->outputDirectory
);
116 case InstallDirectory
:
117 backend
->AddDirectoryTarget ( file
->relative_path
, backend
->installDirectory
);
120 throw InvalidOperationException ( __FILE__
,
122 "Invalid directory %d.",
129 /* caller needs to delete the returned object */
131 MingwModuleHandler::GetTargetFilename (
132 const Module
& module
,
133 string_list
* pclean_files
)
135 FileLocation
*target
= new FileLocation ( *module
.output
);
138 string_list
& clean_files
= *pclean_files
;
139 CLEAN_FILE ( *target
);
144 /* caller needs to delete the returned object */
146 MingwModuleHandler::GetImportLibraryFilename (
147 const Module
& module
,
148 string_list
* pclean_files
)
150 FileLocation
*target
= new FileLocation ( *module
.dependency
);
153 string_list
& clean_files
= *pclean_files
;
154 CLEAN_FILE ( *target
);
159 /* caller needs to delete the returned object */
161 MingwModuleHandler::InstanciateHandler (
162 const Module
& module
,
163 MingwBackend
* backend
)
165 MingwModuleHandler
* handler
;
166 switch ( module
.type
)
169 case HostStaticLibrary
:
176 case EmbeddedTypeLib
:
178 handler
= new MingwModuleHandler( module
);
181 handler
= new MingwBuildToolModuleHandler ( module
);
184 handler
= new MingwKernelModuleHandler ( module
);
187 handler
= new MingwNativeCUIModuleHandler ( module
);
190 handler
= new MingwWin32CUIModuleHandler ( module
);
194 handler
= new MingwWin32GUIModuleHandler ( module
);
198 case KernelModeDriver
:
199 handler
= new MingwKernelModeDLLModuleHandler ( module
);
202 handler
= new MingwNativeDLLModuleHandler ( module
);
205 handler
= new MingwWin32DLLModuleHandler ( module
);
208 handler
= new MingwWin32OCXModuleHandler ( module
);
211 handler
= new MingwBootLoaderModuleHandler ( module
);
214 handler
= new MingwBootProgramModuleHandler ( module
);
217 handler
= new MingwIsoModuleHandler ( module
);
220 handler
= new MingwLiveIsoModuleHandler ( module
);
223 handler
= new MingwIsoModuleHandler ( module
);
226 handler
= new MingwLiveIsoModuleHandler ( module
);
229 handler
= new MingwTestModuleHandler ( module
);
232 handler
= new MingwAliasModuleHandler ( module
);
235 handler
= new MingwCabinetModuleHandler ( module
);
238 handler
= new MingwElfExecutableModuleHandler ( module
);
241 throw UnknownModuleTypeException (
242 module
.node
.location
,
250 MingwModuleHandler::GetWorkingDirectory () const
256 MingwModuleHandler::GetBasename ( const string
& filename
) const
258 size_t index
= filename
.find_last_of ( '.' );
259 if ( index
!= string::npos
)
260 return filename
.substr ( 0, index
);
265 MingwModuleHandler::GetCompilationUnitDependencies (
266 const CompilationUnit
& compilationUnit
) const
268 if ( compilationUnit
.GetFiles ().size () <= 1 )
270 vector
<string
> sourceFiles
;
271 for ( size_t i
= 0; i
< compilationUnit
.GetFiles ().size (); i
++ )
273 const File
& file
= *compilationUnit
.GetFiles ()[i
];
274 sourceFiles
.push_back ( backend
->GetFullName ( file
.file
) );
276 return string ( " " ) + v2s ( sourceFiles
, 10 );
279 /* caller needs to delete the returned object */
281 MingwModuleHandler::GetModuleArchiveFilename () const
283 if ( IsStaticLibrary ( module
) )
284 return GetTargetFilename ( module
, NULL
);
285 return new FileLocation ( IntermediateDirectory
,
286 module
.output
->relative_path
,
287 ReplaceExtension ( module
.name
, ".temp.a" ) );
291 MingwModuleHandler::ReferenceObjects (
292 const Module
& module
)
294 if ( module
.type
== ObjectLibrary
)
296 if ( module
.type
== RpcServer
)
298 if ( module
.type
== RpcClient
)
300 if ( module
.type
== RpcProxy
)
302 if ( module
.type
== IdlHeader
)
304 if ( module
.type
== MessageHeader
)
310 MingwModuleHandler::OutputCopyCommand ( const FileLocation
& source
,
311 const FileLocation
& destination
)
313 fprintf ( fMakefile
, "# OUTPUT COPY COMMAND\n" );
317 "\t${cp} %s %s 1>$(NUL)\n",
318 backend
->GetFullName ( source
).c_str (),
319 backend
->GetFullName ( *PassThruCacheDirectory ( &destination
) ).c_str () );
323 MingwModuleHandler::GetImportLibraryDependency (
324 const Module
& importedModule
)
327 if ( ReferenceObjects ( importedModule
) )
329 const vector
<CompilationUnit
*>& compilationUnits
= importedModule
.non_if_data
.compilationUnits
;
332 dep
= GetTargetMacro ( importedModule
);
333 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
335 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
336 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
337 const FileLocation
*objectFilename
= GetObjectFilename ( &compilationName
, importedModule
);
338 if ( GetExtension ( *objectFilename
) == ".h" )
339 dep
+= ssprintf ( " $(%s_HEADERS)", importedModule
.name
.c_str () );
340 else if ( GetExtension ( *objectFilename
) == ".rc" )
341 dep
+= ssprintf ( " $(%s_MCHEADERS)", importedModule
.name
.c_str () );
346 const FileLocation
*library_target
= GetImportLibraryFilename ( importedModule
, NULL
);
347 dep
= backend
->GetFullName ( *library_target
);
348 delete library_target
;
351 if ( IsStaticLibrary ( importedModule
) || importedModule
.type
== ObjectLibrary
)
353 const std::vector
<Library
*>& libraries
= importedModule
.non_if_data
.libraries
;
355 for ( size_t i
= 0; i
< libraries
.size (); ++ i
)
358 dep
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
366 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
367 string_list
& targets
)
369 if ( dependencyModule
.invocations
.size () > 0 )
371 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
373 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
374 invoke
.GetTargets ( targets
);
378 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
382 MingwModuleHandler::GetModuleDependencies (
383 string_list
& dependencies
)
385 size_t iend
= module
.dependencies
.size ();
390 for ( size_t i
= 0; i
< iend
; i
++ )
392 const Dependency
& dependency
= *module
.dependencies
[i
];
393 const Module
& dependencyModule
= *dependency
.dependencyModule
;
394 GetTargets ( dependencyModule
,
397 vector
<FileLocation
> v
;
398 GetDefinitionDependencies ( v
);
400 for ( size_t i
= 0; i
< v
.size (); i
++ )
402 const FileLocation
& file
= v
[i
];
403 dependencies
.push_back ( backend
->GetFullName ( file
) );
407 /* caller needs to delete the returned object */
409 MingwModuleHandler::GetObjectFilename (
410 const FileLocation
* sourceFile
,
411 const Module
& module
) const
413 DirectoryLocation destination_directory
;
415 string extension
= GetExtension ( *sourceFile
);
417 if ( module
.type
== BootSector
)
418 return new FileLocation ( *module
.output
);
419 else if (extension
== ".rc")
420 newExtension
= "_" + module
.name
+ ".coff";
421 else if (extension
== ".mc")
422 newExtension
= ".rc";
423 else if (extension
== ".spec" || extension
== ".pspec")
424 newExtension
= "_" + module
.name
+ ".stubs.o";
425 else if (extension
== ".idl")
427 if ( module
.type
== RpcServer
)
428 newExtension
= "_s.o";
429 else if ( module
.type
== RpcClient
)
430 newExtension
= "_c.o";
431 else if ( module
.type
== RpcProxy
)
432 newExtension
= "_p.o";
437 newExtension
= "_" + module
.name
+ ".o";
439 if ( module
.type
== BootSector
)
440 destination_directory
= OutputDirectory
;
442 destination_directory
= IntermediateDirectory
;
444 const FileLocation
*obj_file
= new FileLocation(
445 destination_directory
,
446 sourceFile
->relative_path
,
447 ReplaceExtension ( sourceFile
->name
, newExtension
) );
448 PassThruCacheDirectory ( obj_file
);
454 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
456 return module
.name
+ "_clean";
460 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
462 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
464 Library
& library
= *module
.non_if_data
.libraries
[i
];
465 if ( library
.importedModule
->type
== ObjectLibrary
)
466 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
471 MingwModuleHandler::GenerateCleanTarget () const
473 if ( module
.type
== Alias
)
476 fprintf ( fMakefile
, "# CLEAN TARGET\n" );
478 ".PHONY: %s_clean\n",
479 module
.name
.c_str() );
480 vector
<string
> referencedModuleNames
;
481 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
484 GetModuleCleanTarget ( module
).c_str(),
485 v2s ( referencedModuleNames
, 10 ).c_str () );
486 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
488 if ( ( i
+ 1 ) % 10 == 9 )
489 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
490 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
492 fprintf ( fMakefile
, " 2>$(NUL)\n" );
494 if( ProxyMakefile::GenerateProxyMakefile(module
) )
496 DirectoryLocation root
;
498 if ( backend
->configuration
.GenerateProxyMakefilesInSourceTree
)
499 root
= SourceDirectory
;
501 root
= OutputDirectory
;
503 FileLocation
proxyMakefile ( root
,
504 module
.output
->relative_path
,
506 fprintf ( fMakefile
, "\t-@${rm} %s 2>$(NUL)\n",
507 backend
->GetFullName ( proxyMakefile
).c_str () );
510 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
514 MingwModuleHandler::GenerateInstallTarget () const
516 if ( !module
.install
)
518 fprintf ( fMakefile
, "# INSTALL TARGET\n" );
519 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
522 module
.name
.c_str (),
523 backend
->GetFullName ( *module
.install
).c_str () );
527 MingwModuleHandler::GenerateDependsTarget () const
529 fprintf ( fMakefile
, "# DEPENDS TARGET\n" );
531 ".PHONY: %s_depends\n",
532 module
.name
.c_str() );
534 "%s_depends: $(RBUILD_TARGET)\n",
535 module
.name
.c_str () );
537 "\t$(ECHO_RBUILD)\n" );
539 "\t$(Q)$(RBUILD_TARGET) $(RBUILD_FLAGS) -dm%s mingw\n",
540 module
.name
.c_str () );
544 MingwModuleHandler::GetObjectFilenames ()
546 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
547 if ( compilationUnits
.size () == 0 )
550 string
objectFilenames ( "" );
551 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
553 if ( objectFilenames
.size () > 0 )
554 objectFilenames
+= " ";
555 const FileLocation
& compilationName
= compilationUnits
[i
]->GetFilename ();
556 const FileLocation
*object_file
= GetObjectFilename ( &compilationName
, module
);
557 objectFilenames
+= backend
->GetFullName ( *object_file
);
560 return objectFilenames
;
564 MingwModuleHandler::GenerateGccDefineParametersFromVector (
565 const vector
<Define
*>& defines
,
566 set
<string
>& used_defs
)
570 for ( size_t i
= 0; i
< defines
.size (); i
++ )
572 Define
& define
= *defines
[i
];
573 if (used_defs
.find(define
.name
) != used_defs
.end())
575 if (parameters
.length () > 0)
577 if (define
.name
.find('(') != string::npos
)
578 parameters
+= "$(QT)";
580 parameters
+= define
.name
;
581 if (define
.value
.length () > 0)
584 parameters
+= define
.value
;
586 if (define
.name
.find('(') != string::npos
)
587 parameters
+= "$(QT)";
588 used_defs
.insert(used_defs
.begin(),define
.name
);
594 MingwModuleHandler::ConcatenatePaths (
596 const string
& path2
) const
598 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
600 if ( path1
[path1
.length ()] == cSep
)
601 return path1
+ path2
;
603 return path1
+ cSep
+ path2
;
607 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
609 string parameters
, path_prefix
;
610 for ( size_t i
= 0; i
< includes
.size (); i
++ )
612 Include
& include
= *includes
[i
];
613 if ( parameters
.length () > 0 )
615 parameters
+= "-I" + backend
->GetFullPath ( *include
.directory
);;
621 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
, const CompilerType type
) const
624 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
626 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
627 if ( compilerFlag
.compiler
== type
)
628 parameters
+= " " + compilerFlag
.flag
;
634 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
637 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
639 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
640 if ( parameters
.length () > 0 )
642 parameters
+= linkerFlag
.flag
;
648 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
649 const vector
<Library
*>& libraries
)
651 string
dependencies ( "" );
653 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
655 if ( wrap_count
++ == 5 )
656 dependencies
+= " \\\n\t\t", wrap_count
= 0;
657 else if ( dependencies
.size () > 0 )
659 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
665 MingwModuleHandler::GenerateLinkerParameters () const
667 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
671 MingwModuleHandler::GenerateMacro (
672 const char* assignmentOperation
,
674 const IfableData
& data
,
675 set
<const Define
*> *used_defs
,
676 bool generatingCompilerMacro
)
679 bool generateAssignment
;
681 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0;
682 if ( generatingCompilerMacro
)
683 generateAssignment
|= data
.compilerFlags
.size () > 0;
684 if ( generateAssignment
)
689 assignmentOperation
);
692 const FileLocation
*pchFilename
= GetPrecompiledHeaderFilename ();
697 backend
->GetFullPath ( *pchFilename
).c_str () );
701 if ( generatingCompilerMacro
)
703 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
, CompilerTypeDontCare
);
704 if ( compilerParameters
.size () > 0 )
709 compilerParameters
.c_str () );
712 for ( i
= 0; i
< data
.includes
.size(); i
++ )
714 const Include
& include
= *data
.includes
[i
];
715 const FileLocation
* includeDirectory
= include
.directory
;
719 backend
->GetFullPath ( *includeDirectory
).c_str() );
721 for ( i
= 0; i
< data
.defines
.size(); i
++ )
723 const Define
& define
= *data
.defines
[i
];
726 set
<const Define
*>::const_iterator last_define
;
727 for (last_define
= used_defs
->begin ();
728 last_define
!= used_defs
->end ();
731 if ( (*last_define
)->name
!= define
.name
)
733 if ( !define
.overridable
)
735 throw InvalidOperationException ( (*last_define
)->node
->location
.c_str (),
737 "Invalid override of define '%s', already defined at %s",
738 define
.name
.c_str (),
739 define
.node
->location
.c_str () );
741 if ( backend
->configuration
.Verbose
)
742 printf("%s: Overriding '%s' already defined at %s\n",
743 (*last_define
)->node
->location
.c_str (), define
.name
.c_str (),
744 define
.node
->location
.c_str () );
747 if ( last_define
!= used_defs
->end () )
753 define
.name
.c_str() );
754 if (define
.value
.length () > 0)
758 define
.value
.c_str() );
760 used_defs
->insert( used_defs
->begin (), &define
);
762 if ( generateAssignment
)
764 fprintf ( fMakefile
, "\n" );
769 MingwModuleHandler::GenerateMacros (
770 const char* assignmentOperation
,
771 const IfableData
& data
,
772 const vector
<LinkerFlag
*>* linkerFlags
,
773 set
<const Define
*>& used_defs
)
775 fprintf ( fMakefile
, "# MACROS\n" );
776 GenerateMacro ( assignmentOperation
,
781 GenerateMacro ( assignmentOperation
,
787 if ( linkerFlags
!= NULL
)
789 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
790 if ( linkerParameters
.size () > 0 )
795 linkerflagsMacro
.c_str (),
797 linkerParameters
.c_str() );
801 if ( data
.libraries
.size () > 0 )
803 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
804 if ( deps
.size () > 0 )
817 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
819 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
820 delete compilationUnits
[i
];
824 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
829 MingwModuleHandler::GenerateSourceMacros (
830 const IfableData
& data
)
834 fprintf ( fMakefile
, "# SOURCE MACROS\n" );
835 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
836 vector
<const FileLocation
*> headers
;
837 if ( compilationUnits
.size () > 0 )
842 sourcesMacro
.c_str () );
843 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
845 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
846 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
850 ( i
%10 == 9 ? " \\\n\t" : " " ),
851 backend
->GetFullName ( compilationName
).c_str () );
853 fprintf ( fMakefile
, "\n" );
856 vector
<CompilationUnit
*> sourceCompilationUnits
;
857 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
858 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
860 const FileLocation
& compilationName
= sourceCompilationUnits
[i
]->GetFilename ();
864 sourcesMacro
.c_str(),
865 backend
->GetFullName ( compilationName
).c_str () );
867 CleanupCompilationUnitVector ( sourceCompilationUnits
);
871 MingwModuleHandler::GenerateObjectMacros (
872 const IfableData
& data
)
875 const char* assignmentOperation
= "=";
877 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
878 vector
<const FileLocation
*> headers
;
879 vector
<const FileLocation
*> mcheaders
;
880 vector
<const FileLocation
*> mcresources
;
881 fprintf ( fMakefile
, "# OBJECT MACROS\n" );
882 if ( compilationUnits
.size () > 0 )
884 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
886 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
887 if ( compilationUnit
.IsFirstFile () )
889 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
890 const FileLocation
*object_file
= GetObjectFilename ( &compilationName
, module
);
893 objectsMacro
.c_str(),
894 backend
->GetFullName ( *object_file
).c_str () );
896 assignmentOperation
= "+=";
903 objectsMacro
.c_str (),
904 assignmentOperation
);
905 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
907 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
908 if ( !compilationUnit
.IsFirstFile () )
910 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
911 const FileLocation
*objectFilename
= GetObjectFilename ( &compilationName
, module
);
912 if ( GetExtension ( *objectFilename
) == ".h" )
913 headers
.push_back ( objectFilename
);
914 else if ( GetExtension ( *objectFilename
) == ".rc" )
916 const FileLocation
*headerFilename
= GetMcHeaderFilename ( &compilationUnit
.GetFilename () );
917 mcheaders
.push_back ( headerFilename
);
918 mcresources
.push_back ( objectFilename
);
925 ( i
%10 == 9 ? " \\\n\t" : " " ),
926 backend
->GetFullName ( *objectFilename
).c_str () );
927 delete objectFilename
;
931 fprintf ( fMakefile
, "\n" );
933 if ( headers
.size () > 0 )
938 module
.name
.c_str (),
939 assignmentOperation
);
940 for ( i
= 0; i
< headers
.size (); i
++ )
945 ( i
%10 == 9 ? " \\\n\t" : " " ),
946 backend
->GetFullName ( *headers
[i
] ).c_str () );
949 fprintf ( fMakefile
, "\n" );
952 if ( mcheaders
.size () > 0 )
957 module
.name
.c_str (),
958 assignmentOperation
);
959 for ( i
= 0; i
< mcheaders
.size (); i
++ )
964 ( i
%10 == 9 ? " \\\n\t" : " " ),
965 backend
->GetFullName ( *mcheaders
[i
] ).c_str () );
968 fprintf ( fMakefile
, "\n" );
971 if ( mcresources
.size () > 0 )
976 module
.name
.c_str (),
977 assignmentOperation
);
978 for ( i
= 0; i
< mcresources
.size (); i
++ )
983 ( i
%10 == 9 ? " \\\n\t" : " " ),
984 backend
->GetFullName ( *mcresources
[i
] ).c_str () );
985 delete mcresources
[i
];
987 fprintf ( fMakefile
, "\n" );
990 vector
<CompilationUnit
*> sourceCompilationUnits
;
991 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
992 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
994 const FileLocation
& compilationName
= sourceCompilationUnits
[i
]->GetFilename ();
995 const FileLocation
*object_file
= GetObjectFilename ( &compilationName
, module
);
999 objectsMacro
.c_str(),
1000 backend
->GetFullName ( *object_file
).c_str () );
1003 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1006 /* caller needs to delete the returned object */
1008 MingwModuleHandler::GetPrecompiledHeaderFilename () const
1010 if ( !module
.pch
|| !use_pch
)
1012 return new FileLocation ( IntermediateDirectory
,
1013 module
.pch
->file
->relative_path
+ "/.gch_" + module
.name
,
1014 module
.pch
->file
->name
+ ".gch" );
1017 Rule
arRule1 ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).a: $($(module_name)_OBJS) $(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n",
1018 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).a",
1019 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1020 Rule
arRule2 ( "\t$(ECHO_AR)\n"
1021 "\t${ar} -rc $@ $($(module_name)_OBJS)\n",
1023 Rule
arHostRule2 ( "\t$(ECHO_AR)\n"
1024 "\t${host_ar} -rc $@ $($(module_name)_OBJS)\n",
1026 Rule
gasRule ( "$(source): ${$(module_name)_precondition}\n"
1027 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1029 "\t${gcc} -x assembler-with-cpp -o $@ -D__ASM__ $($(module_name)_CFLAGS) -c $<\n",
1030 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o",
1031 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1032 Rule
bootRule ( "$(source): ${$(module_name)_precondition}\n"
1033 "$(module_output): $(source)$(dependencies) | $(OUTPUT)$(SEP)$(source_dir)\n"
1035 "\t$(Q)${nasm} -f win32 $< -o $@ $($(module_name)_NASMFLAGS)\n",
1036 "$(OUTPUT)$(SEP)$(source_dir)$(SEP)", NULL
);
1037 Rule
nasmRule ( "$(source): ${$(module_name)_precondition}\n"
1038 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1040 "\t$(Q)${nasm} -f win32 $< -o $@ $($(module_name)_NASMFLAGS)\n",
1041 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o",
1042 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1043 Rule
windresRule ( "$(source): ${$(module_name)_precondition}\n"
1044 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).coff: $(source)$(dependencies) $(WRC_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir) $(TEMPORARY)\n"
1046 "\t${gcc} -xc -E -DRC_INVOKED ${$(module_name)_RCFLAGS} $(source) > $(TEMPORARY)$(SEP)$(module_name).$(source_name_noext).rci.tmp\n"
1047 "\t$(Q)$(WRC_TARGET) ${$(module_name)_RCFLAGS} $(TEMPORARY)$(SEP)$(module_name).$(source_name_noext).rci.tmp $(TEMPORARY)$(SEP)$(module_name).$(source_name_noext).res.tmp\n"
1048 "\t-@${rm} $(TEMPORARY)$(SEP)$(module_name).$(source_name_noext).rci.tmp 2>$(NUL)\n"
1049 "\t${windres} $(TEMPORARY)$(SEP)$(module_name).$(source_name_noext).res.tmp -o $@\n"
1050 "\t-@${rm} $(TEMPORARY)$(SEP)$(module_name).$(source_name_noext).res.tmp 2>$(NUL)\n",
1051 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).coff",
1052 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1053 Rule
wmcRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).rc $(INTERMEDIATE)$(SEP)include$(SEP)reactos$(SEP)$(source_name_noext).h: $(WMC_TARGET) $(source) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1055 "\t$(Q)$(WMC_TARGET) -i -H $(INTERMEDIATE)$(SEP)include$(SEP)reactos$(SEP)$(source_name_noext).h -o $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).rc $(source)\n",
1056 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).rc",
1057 "$(INTERMEDIATE)$(SEP)include$(SEP)reactos$(SEP)$(source_name_noext).h",
1058 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1059 Rule
winebuildPDefRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).auto.def: $(source)$(dependencies) $(WINEBUILD_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1060 "\t$(ECHO_WINEBLD)\n"
1061 "\t${gcc} -xc -E $(source) -I. > $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec\n"
1062 "\t$(Q)$(WINEBUILD_TARGET) $(WINEBUILD_FLAGS) -o $(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext)_$(module_name).auto.def --def -E $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec\n\n",
1063 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec",
1064 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).auto.def",
1065 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1066 Rule
winebuildPRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).stubs.c:\n"
1067 "\t${cp} $(NUL) $@ 1>$(NUL)\n"
1068 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).stubs.o: $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).stubs.c$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1070 "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
1071 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec",
1072 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).stubs.c",
1073 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).stubs.o",
1074 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1075 Rule
winebuildDefRule ( "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).auto.def: $(source)$(dependencies) $(WINEBUILD_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1076 "\t$(ECHO_WINEBLD)\n"
1077 "\t$(Q)$(WINEBUILD_TARGET) $(WINEBUILD_FLAGS) -o $(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext)_$(module_name).auto.def --def -E $(source)\n\n",
1078 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).spec",
1079 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).auto.def",
1080 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1081 Rule
winebuildRule ( "$(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext)_$(module_name).stubs.c: $(source_path)$(SEP)$(source_name_noext).spec $(WINEBUILD_TARGET)\n"
1082 "\t$(ECHO_WINEBLD)\n"
1083 "\t$(Q)$(WINEBUILD_TARGET) $(WINEBUILD_FLAGS) -o $(INTERMEDIATE)$(SEP)$(source_path)$(SEP)$(source_name_noext)_$(module_name).stubs.c --pedll $(source_path)$(SEP)$(source_name_noext).spec\n"
1084 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).stubs.o: $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).stubs.c$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1086 "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
1087 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).stubs.c",
1088 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).stubs.o",
1089 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1090 Rule
widlHeaderRule ( "$(source): ${$(module_name)_precondition}\n"
1091 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1093 "\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -h -H $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).h $(source)\n",
1094 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).h",
1095 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1096 Rule
widlServerRule ( "$(source): ${$(module_name)_precondition}\n"
1097 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1099 "\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -h -H $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.h -s -S $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.c $(source)\n"
1100 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.o: $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.h$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1102 "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
1103 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.h",
1104 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.c",
1105 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_s.o",
1106 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1107 Rule
widlClientRule ( "$(source): ${$(module_name)_precondition}\n"
1108 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1110 "\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -h -H $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.h -c -C $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.c $(source)\n"
1111 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.o: $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.h$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1113 "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
1114 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.h",
1115 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.c",
1116 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_c.o",
1117 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1118 Rule
widlProxyRule ( "$(source): ${$(module_name)_precondition}\n"
1119 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.h: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1121 "\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -h -H $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.h -p -P $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.c $(source)\n"
1122 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.o: $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.c $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.h$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1124 "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
1125 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.h",
1126 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.c",
1127 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_p.o",
1128 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1129 Rule
widlTlbRule ( "$(source): ${$(module_name)_precondition}\n"
1130 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(module_name).tlb: $(source)$(dependencies) $(WIDL_TARGET) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1132 "\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -t -T $(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext).tlb $(source)\n",
1133 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)", NULL
);
1134 Rule
gccRule ( "$(source): ${$(module_name)_precondition}\n"
1135 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1137 "\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
1138 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o", NULL
);
1139 Rule
gccHostRule ( "$(source): ${$(module_name)_precondition}\n"
1140 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1142 "\t${host_gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
1143 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o", NULL
);
1144 Rule
gppRule ( "$(source): ${$(module_name)_precondition}\n"
1145 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1147 "\t${gpp} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
1148 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o", NULL
);
1149 Rule
gppHostRule ( "$(source): ${$(module_name)_precondition}\n"
1150 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o: $(source)$(dependencies) | $(INTERMEDIATE)$(SEP)$(source_dir)\n"
1152 "\t${host_gpp} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -c $<\n",
1153 "$(INTERMEDIATE)$(SEP)$(source_dir)$(SEP)$(source_name_noext)_$(module_name).o", NULL
);
1154 Rule
emptyRule ( "", NULL
);
1157 MingwModuleHandler::GenerateGccCommand (
1158 const FileLocation
* sourceFile
,
1160 const string
& extraDependencies
)
1162 const FileLocation
*pchFilename
= GetPrecompiledHeaderFilename ();
1163 string dependencies
= extraDependencies
;
1166 string extension
= GetExtension ( *sourceFile
);
1167 if ( extension
== ".cc" || extension
== ".cpp" || extension
== ".cxx" )
1168 flags
= GenerateCompilerParametersFromVector ( module
.non_if_data
.compilerFlags
, CompilerTypeCPP
);
1170 flags
= GenerateCompilerParametersFromVector ( module
.non_if_data
.compilerFlags
, CompilerTypeCC
);
1174 dependencies
+= " " + backend
->GetFullName ( *pchFilename
);
1178 /* WIDL generated headers may be used */
1179 vector
<FileLocation
> rpcDependencies
;
1180 GetRpcHeaderDependencies ( rpcDependencies
);
1181 if ( rpcDependencies
.size () > 0 )
1182 dependencies
+= " " + v2s ( backend
, rpcDependencies
, 5 );
1184 rule
->Execute ( fMakefile
, backend
, module
, sourceFile
, clean_files
, dependencies
, flags
);
1188 MingwModuleHandler::GetPropertyValue ( const Module
& module
, const std::string
& name
)
1190 const Property
* property
= module
.project
.LookupProperty(name
);
1193 return property
->value
;
1195 return string ( "" );
1198 /* caller needs to delete the returned object */
1200 MingwModuleHandler::GetRpcServerHeaderFilename ( const FileLocation
*base
) const
1202 string newname
= GetBasename ( base
->name
) + "_s.h";
1203 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1206 /* caller needs to delete the returned object */
1208 MingwModuleHandler::GetRpcClientHeaderFilename ( const FileLocation
*base
) const
1210 string newname
= GetBasename ( base
->name
) + "_c.h";
1211 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1214 /* caller needs to delete the returned object */
1216 MingwModuleHandler::GetRpcProxyHeaderFilename ( const FileLocation
*base
) const
1218 string newname
= GetBasename ( base
->name
) + "_p.h";
1219 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1222 /* caller needs to delete the returned object */
1224 MingwModuleHandler::GetIdlHeaderFilename ( const FileLocation
*base
) const
1226 string newname
= GetBasename ( base
->name
) + ".h";
1227 return new FileLocation ( IntermediateDirectory
, base
->relative_path
, newname
);
1230 /* caller needs to delete the returned object */
1232 MingwModuleHandler::GetMcHeaderFilename ( const FileLocation
*base
) const
1234 string newname
= GetBasename ( base
->name
) + ".h";
1235 return new FileLocation ( IntermediateDirectory
, "include/reactos" , newname
);
1239 MingwModuleHandler::GenerateCommands (
1240 const CompilationUnit
& compilationUnit
,
1241 const string
& extraDependencies
)
1243 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
1244 string extension
= GetExtension ( sourceFile
);
1245 std::transform ( extension
.begin (), extension
.end (), extension
.begin (), tolower
);
1254 { HostDontCare
, TypeDontCare
, ".s", &gasRule
},
1255 { HostDontCare
, BootSector
, ".asm", &bootRule
},
1256 { HostDontCare
, TypeDontCare
, ".asm", &nasmRule
},
1257 { HostDontCare
, TypeDontCare
, ".rc", &windresRule
},
1258 { HostDontCare
, TypeDontCare
, ".mc", &wmcRule
},
1259 { HostDontCare
, TypeDontCare
, ".pspec", &winebuildPRule
},
1260 { HostDontCare
, TypeDontCare
, ".spec", &winebuildRule
},
1261 { HostDontCare
, RpcServer
, ".idl", &widlServerRule
},
1262 { HostDontCare
, RpcClient
, ".idl", &widlClientRule
},
1263 { HostDontCare
, RpcProxy
, ".idl", &widlProxyRule
},
1264 { HostDontCare
, EmbeddedTypeLib
, ".idl", &widlTlbRule
},
1265 { HostDontCare
, TypeDontCare
, ".idl", &widlHeaderRule
},
1266 { HostTrue
, TypeDontCare
, ".c", &gccHostRule
},
1267 { HostTrue
, TypeDontCare
, ".cc", &gppHostRule
},
1268 { HostTrue
, TypeDontCare
, ".cpp", &gppHostRule
},
1269 { HostTrue
, TypeDontCare
, ".cxx", &gppHostRule
},
1270 { HostFalse
, TypeDontCare
, ".c", &gccRule
},
1271 { HostFalse
, TypeDontCare
, ".cc", &gppRule
},
1272 { HostFalse
, TypeDontCare
, ".cpp", &gppRule
},
1273 { HostFalse
, TypeDontCare
, ".cxx", &gppRule
},
1274 { HostFalse
, Cabinet
, ".*", &emptyRule
}
1277 Rule
*customRule
= NULL
;
1279 fprintf ( fMakefile
, "# COMMANDS\n" );
1281 for ( i
= 0; i
< sizeof ( rules
) / sizeof ( rules
[0] ); i
++ )
1283 if ( rules
[i
].host
!= HostDontCare
&& rules
[i
].host
!= ModuleHandlerInformations
[module
.type
].DefaultHost
)
1285 if ( rules
[i
].type
!= TypeDontCare
&& rules
[i
].type
!= module
.type
)
1287 if ( rules
[i
].extension
!= extension
&& rules
[i
].extension
!= ".*")
1289 customRule
= rules
[i
].rule
;
1293 if ( extension
== ".c" || extension
== ".cc" || extension
== ".cpp" || extension
== ".cxx" )
1295 GenerateGccCommand ( &sourceFile
,
1297 GetCompilationUnitDependencies ( compilationUnit
) + extraDependencies
);
1299 else if ( customRule
)
1300 customRule
->Execute ( fMakefile
, backend
, module
, &sourceFile
, clean_files
);
1303 throw InvalidOperationException ( __FILE__
,
1305 "Unsupported filename extension '%s' in file '%s'",
1307 backend
->GetFullName ( sourceFile
).c_str () );
1312 MingwModuleHandler::GenerateBuildMapCode ( const FileLocation
*mapTarget
)
1314 fprintf ( fMakefile
, "# BUILD MAP CODE\n" );
1316 fprintf ( fMakefile
,
1317 "ifeq ($(ROS_BUILDMAP),full)\n" );
1319 FileLocation
mapFilename ( OutputDirectory
,
1320 module
.output
->relative_path
,
1321 GetBasename ( module
.output
->name
) + ".map" );
1322 CLEAN_FILE ( mapFilename
);
1324 fprintf ( fMakefile
,
1325 "\t$(ECHO_OBJDUMP)\n" );
1326 fprintf ( fMakefile
,
1327 "\t$(Q)${objdump} -d -S %s > %s\n",
1328 mapTarget
? backend
->GetFullName ( *mapTarget
).c_str () : "$@",
1329 backend
->GetFullName ( mapFilename
).c_str () );
1331 fprintf ( fMakefile
,
1333 fprintf ( fMakefile
,
1334 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1336 fprintf ( fMakefile
,
1338 fprintf ( fMakefile
,
1339 "\t$(Q)${nm} --numeric-sort %s > %s\n",
1340 mapTarget
? backend
->GetFullName ( *mapTarget
).c_str () : "$@",
1341 backend
->GetFullName ( mapFilename
).c_str () );
1343 fprintf ( fMakefile
,
1346 fprintf ( fMakefile
,
1351 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1353 fprintf ( fMakefile
, "# BUILD NO STRIP CODE\n" );
1355 fprintf ( fMakefile
,
1356 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1358 FileLocation
nostripFilename ( OutputDirectory
,
1359 module
.output
->relative_path
,
1360 GetBasename ( module
.output
->name
) + ".nostrip" + GetExtension ( *module
.output
) );
1361 CLEAN_FILE ( nostripFilename
);
1363 OutputCopyCommand ( *module
.output
, nostripFilename
);
1365 fprintf ( fMakefile
,
1370 MergeStringVector ( const Backend
* backend
,
1371 const vector
<FileLocation
>& input
,
1372 vector
<string
>& output
)
1376 int wrap_count
= -1;
1377 for ( size_t i
= 0; i
< input
.size (); i
++ )
1379 if ( wrap_count
++ == wrap_at
)
1381 output
.push_back ( s
);
1385 else if ( s
.size () > 0)
1387 s
+= backend
->GetFullName ( input
[i
] );
1389 if ( s
.length () > 0 )
1390 output
.push_back ( s
);
1394 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1395 vector
<FileLocation
>& objectFiles
) const
1397 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1399 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1400 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
1401 const FileLocation
*object_file
= GetObjectFilename ( &compilationName
, module
);
1402 objectFiles
.push_back ( *object_file
);
1408 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1410 if ( backend
->configuration
.CleanAsYouGo
)
1412 vector
<FileLocation
> objectFiles
;
1413 GetObjectsVector ( module
.non_if_data
,
1415 vector
<string
> lines
;
1416 MergeStringVector ( backend
,
1419 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1421 fprintf ( fMakefile
,
1422 "\t-@${rm} %s 2>$(NUL)\n",
1423 lines
[i
].c_str () );
1429 MingwModuleHandler::GenerateRunRsymCode () const
1431 fprintf ( fMakefile
, "# RUN RSYM CODE\n" );
1432 fprintf ( fMakefile
,
1433 "ifneq ($(ROS_GENERATE_RSYM),no)\n" );
1434 fprintf ( fMakefile
,
1435 "\t$(ECHO_RSYM)\n" );
1436 fprintf ( fMakefile
,
1437 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1438 fprintf ( fMakefile
,
1443 MingwModuleHandler::GenerateRunStripCode () const
1445 fprintf ( fMakefile
, "# RUN STRIP CODE\n" );
1446 fprintf ( fMakefile
,
1447 "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" );
1448 fprintf ( fMakefile
,
1449 "\t$(ECHO_STRIP)\n" );
1450 fprintf ( fMakefile
,
1451 "\t${strip} -s -x -X $@\n\n" );
1452 fprintf ( fMakefile
,
1457 MingwModuleHandler::GenerateLinkerCommand (
1458 const string
& dependencies
,
1459 const string
& linkerParameters
,
1460 const string
& pefixupParameters
)
1462 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
1463 const FileLocation
*definitionFilename
= GetDefinitionFilename ();
1464 string linker
= "${ld}";
1465 string objectsMacro
= GetObjectsMacro ( module
);
1466 string libsMacro
= GetLibsMacro ();
1468 fprintf ( fMakefile
, "# LINKER COMMAND\n" );
1470 string
target_macro ( GetTargetMacro ( module
) );
1471 string
target_folder ( backend
->GetFullPath ( *target_file
) );
1473 string linkerScriptArgument
;
1474 if ( module
.linkerScript
!= NULL
)
1475 linkerScriptArgument
= ssprintf ( " -T %s", backend
->GetFullName ( *module
.linkerScript
->file
).c_str () );
1477 linkerScriptArgument
= "";
1479 fprintf ( fMakefile
,
1480 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1481 target_macro
.c_str (),
1482 definitionFilename
? backend
->GetFullName ( *definitionFilename
).c_str () : "",
1483 dependencies
.c_str (),
1484 target_folder
.c_str () );
1485 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1486 string
targetName ( module
.output
->name
);
1488 /* check if we need to add default C++ libraries, ie if we have
1489 * a C++ user-mode module without the -nostdlib linker flag
1491 bool link_defaultlibs
= module
.cplusplus
&&
1492 linkerParameters
.find ("-nostdlib") == string::npos
&&
1493 !(module
.type
== KernelModeDLL
|| module
.type
== KernelModeDriver
);
1495 if ( !module
.HasImportLibrary() )
1497 fprintf ( fMakefile
,
1498 "\t%s %s%s %s %s %s %s -o %s\n",
1500 linkerParameters
.c_str (),
1501 linkerScriptArgument
.c_str (),
1502 objectsMacro
.c_str (),
1503 link_defaultlibs
? "$(PROJECT_LPPFLAGS) " : "",
1505 GetLinkerMacro ().c_str (),
1506 target_macro
.c_str () );
1510 FileLocation
temp_exp ( TemporaryDirectory
,
1512 module
.name
+ ".temp.exp" );
1513 CLEAN_FILE ( temp_exp
);
1515 fprintf ( fMakefile
,
1516 "\t${dlltool} --dllname %s --def %s --output-exp %s%s%s\n",
1517 targetName
.c_str (),
1518 definitionFilename
? backend
->GetFullName ( *definitionFilename
).c_str () : "",
1519 backend
->GetFullName ( temp_exp
).c_str (),
1520 module
.mangledSymbols
? "" : " --kill-at",
1521 module
.underscoreSymbols
? " --add-underscore" : "" );
1523 fprintf ( fMakefile
,
1524 "\t%s %s%s %s %s %s %s %s -o %s\n",
1527 linkerParameters
.c_str (),
1528 linkerScriptArgument
.c_str (),
1529 backend
->GetFullName ( temp_exp
).c_str (),
1530 objectsMacro
.c_str (),
1531 link_defaultlibs
? "$(PROJECT_LPPFLAGS) " : "",
1533 GetLinkerMacro ().c_str (),
1534 target_macro
.c_str () );
1536 fprintf ( fMakefile
,
1537 "\t$(Q)$(PEFIXUP_TARGET) %s -exports%s\n",
1538 target_macro
.c_str (),
1539 pefixupParameters
.c_str() );
1541 fprintf ( fMakefile
,
1542 "\t-@${rm} %s 2>$(NUL)\n",
1543 backend
->GetFullName ( temp_exp
).c_str () );
1546 GenerateBuildMapCode ();
1547 GenerateBuildNonSymbolStrippedCode ();
1548 GenerateRunRsymCode ();
1549 GenerateRunStripCode ();
1550 GenerateCleanObjectsAsYouGoCode ();
1552 if ( definitionFilename
)
1553 delete definitionFilename
;
1558 MingwModuleHandler::GeneratePhonyTarget() const
1560 string
targetMacro ( GetTargetMacro ( module
) );
1561 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
1563 fprintf ( fMakefile
, "# PHONY TARGET\n" );
1564 fprintf ( fMakefile
,
1566 targetMacro
.c_str ());
1567 fprintf ( fMakefile
, "%s: | %s\n",
1568 targetMacro
.c_str (),
1569 backend
->GetFullPath ( *target_file
).c_str () );
1575 MingwModuleHandler::GenerateObjectFileTargets ( const IfableData
& data
)
1578 string moduleDependencies
;
1580 fprintf ( fMakefile
, "# OBJECT FILE TARGETS\n" );
1582 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1583 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1585 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1586 const FileLocation
& compilationName
= compilationUnit
.GetFilename ();
1587 const FileLocation
*objectFilename
= GetObjectFilename ( &compilationName
, module
);
1588 if ( GetExtension ( *objectFilename
) == ".h" )
1589 moduleDependencies
+= ssprintf ( " $(%s_HEADERS)", module
.name
.c_str () );
1590 else if ( GetExtension ( *objectFilename
) == ".rc" )
1591 moduleDependencies
+= ssprintf ( " $(%s_RESOURCES)", module
.name
.c_str () );
1592 delete objectFilename
;
1595 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1597 GenerateCommands ( *compilationUnits
[i
],
1598 moduleDependencies
);
1599 fprintf ( fMakefile
,
1603 vector
<CompilationUnit
*> sourceCompilationUnits
;
1604 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1605 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1607 GenerateCommands ( *sourceCompilationUnits
[i
],
1608 moduleDependencies
);
1610 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1614 MingwModuleHandler::GenerateObjectFileTargets ()
1616 const FileLocation
*pchFilename
= GetPrecompiledHeaderFilename ();
1618 fprintf ( fMakefile
, "# OBJECT FILE TARGETS\n" );
1622 string cc
= ( ModuleHandlerInformations
[module
.type
].DefaultHost
== HostTrue
? "${host_gcc}" : "${gcc}" );
1623 string cppc
= ( ModuleHandlerInformations
[module
.type
].DefaultHost
== HostTrue
? "${host_gpp}" : "${gpp}" );
1625 const FileLocation
& baseHeaderFile
= *module
.pch
->file
;
1626 CLEAN_FILE ( *pchFilename
);
1627 string dependencies
= backend
->GetFullName ( baseHeaderFile
);
1628 /* WIDL generated headers may be used */
1629 vector
<FileLocation
> rpcDependencies
;
1630 GetRpcHeaderDependencies ( rpcDependencies
);
1631 if ( rpcDependencies
.size () > 0 )
1632 dependencies
+= " " + v2s ( backend
, rpcDependencies
, 5 );
1633 fprintf ( fMakefile
,
1635 backend
->GetFullName ( *pchFilename
).c_str(),
1636 dependencies
.c_str(),
1637 backend
->GetFullPath ( *pchFilename
).c_str() );
1638 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1639 fprintf ( fMakefile
,
1640 "\t%s -o %s %s -g %s\n\n",
1641 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1642 backend
->GetFullName ( *pchFilename
).c_str(),
1643 cflagsMacro
.c_str(),
1644 backend
->GetFullName ( baseHeaderFile
).c_str() );
1648 GenerateObjectFileTargets ( module
.non_if_data
);
1649 fprintf ( fMakefile
, "\n" );
1652 /* caller needs to delete the returned object */
1654 MingwModuleHandler::GenerateArchiveTarget ()
1656 const FileLocation
*archiveFilename
= GetModuleArchiveFilename ();
1657 const FileLocation
*definitionFilename
= GetDefinitionFilename ();
1659 fprintf ( fMakefile
, "# ARCHIVE TARGET\n" );
1661 if ( IsStaticLibrary ( module
) && definitionFilename
)
1663 arRule1
.Execute ( fMakefile
,
1668 backend
->GetFullName ( *definitionFilename
).c_str () );
1670 fprintf ( fMakefile
,
1671 "\t${dlltool} --dllname %s --def %s --output-lib $@%s%s\n",
1672 module
.importLibrary
->dllname
.c_str (),
1673 backend
->GetFullName ( *definitionFilename
).c_str (),
1674 module
.mangledSymbols
? "" : " --kill-at",
1675 module
.underscoreSymbols
? " --add-underscore" : "" );
1678 arRule1
.Execute ( fMakefile
, backend
, module
, archiveFilename
, clean_files
);
1680 if ( definitionFilename
)
1681 delete definitionFilename
;
1683 if(module
.type
== HostStaticLibrary
)
1684 arHostRule2
.Execute ( fMakefile
, backend
, module
, archiveFilename
, clean_files
);
1686 arRule2
.Execute ( fMakefile
, backend
, module
, archiveFilename
, clean_files
);
1688 GenerateCleanObjectsAsYouGoCode ();
1690 fprintf ( fMakefile
, "\n" );
1692 return archiveFilename
;
1696 MingwModuleHandler::GetCFlagsMacro () const
1698 return ssprintf ( "$(%s_CFLAGS)",
1699 module
.name
.c_str () );
1703 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1705 return ssprintf ( "$(%s_OBJS)",
1706 module
.name
.c_str () );
1710 MingwModuleHandler::GetLinkingDependenciesMacro () const
1712 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1716 MingwModuleHandler::GetLibsMacro () const
1718 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1722 MingwModuleHandler::GetLinkerMacro () const
1724 return ssprintf ( "$(%s_LFLAGS)",
1725 module
.name
.c_str () );
1729 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1731 if ( ReferenceObjects ( module
) )
1732 return GetObjectsMacro ( module
);
1735 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
1736 string target
= backend
->GetFullName ( *target_file
).c_str ();
1743 MingwModuleHandler::GenerateSourceMacro ()
1745 sourcesMacro
= ssprintf ( "%s_SOURCES", module
.name
.c_str ());
1747 GenerateSourceMacros ( module
.non_if_data
);
1749 // future references to the macro will be to get its values
1750 sourcesMacro
= ssprintf ("$(%s)", sourcesMacro
.c_str ());
1754 MingwModuleHandler::GenerateObjectMacro ()
1756 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1758 GenerateObjectMacros ( module
.non_if_data
);
1760 // future references to the macro will be to get its values
1761 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1765 MingwModuleHandler::GenerateTargetMacro ()
1767 fprintf ( fMakefile
, "# TARGET MACRO\n" );
1768 fprintf ( fMakefile
,
1770 GetTargetMacro ( module
, false ).c_str (),
1771 GetModuleTargets ( module
).c_str () );
1775 MingwModuleHandler::GetRpcHeaderDependencies (
1776 vector
<FileLocation
>& dependencies
) const
1778 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1780 Library
& library
= *module
.non_if_data
.libraries
[i
];
1781 if ( library
.importedModule
->type
== RpcServer
||
1782 library
.importedModule
->type
== RpcClient
||
1783 library
.importedModule
->type
== RpcProxy
||
1784 library
.importedModule
->type
== IdlHeader
)
1786 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
1788 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
1789 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
1790 string extension
= GetExtension ( sourceFile
);
1791 if ( extension
== ".idl" || extension
== ".IDL" )
1793 string basename
= GetBasename ( sourceFile
.name
);
1794 if ( library
.importedModule
->type
== RpcServer
)
1796 const FileLocation
*header
= GetRpcServerHeaderFilename ( &sourceFile
);
1797 dependencies
.push_back ( *header
);
1800 if ( library
.importedModule
->type
== RpcClient
)
1802 const FileLocation
*header
= GetRpcClientHeaderFilename ( &sourceFile
);
1803 dependencies
.push_back ( *header
);
1806 if ( library
.importedModule
->type
== RpcProxy
)
1808 const FileLocation
*header
= GetRpcProxyHeaderFilename ( &sourceFile
);
1809 dependencies
.push_back ( *header
);
1812 if ( library
.importedModule
->type
== IdlHeader
)
1814 const FileLocation
*header
= GetIdlHeaderFilename ( &sourceFile
);
1815 dependencies
.push_back ( *header
);
1825 MingwModuleHandler::GenerateOtherMacros ()
1827 set
<const Define
*> used_defs
;
1829 fprintf ( fMakefile
, "# OTHER MACROS\n" );
1831 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1832 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1833 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1834 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1835 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1836 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1837 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1842 &module
.linkerFlags
,
1845 if ( ModuleHandlerInformations
[module
.type
].DefaultHost
== HostTrue
)
1847 GenerateMacros("+=", module
.project
.host_non_if_data
, NULL
, used_defs
);
1853 module
.project
.non_if_data
,
1858 if ( IsSpecDefinitionFile() )
1860 vector
<FileLocation
> s
;
1861 GetSpecImplibDependencies ( s
, module
.importLibrary
->source
);
1866 linkDepsMacro
.c_str() );
1867 for ( size_t i
= 0; i
< s
.size(); i
++ )
1868 fprintf ( fMakefile
,
1870 backend
->GetFullName ( s
[i
] ).c_str () );
1871 fprintf ( fMakefile
, "\n" );
1874 string globalCflags
= "";
1875 if ( ModuleHandlerInformations
[module
.type
].DefaultHost
== HostFalse
)
1876 globalCflags
+= " $(PROJECT_CFLAGS)";
1878 globalCflags
+= " -Wall -Wpointer-arith";
1879 globalCflags
+= " -g";
1880 if ( backend
->usePipe
)
1881 globalCflags
+= " -pipe";
1882 if ( !module
.allowWarnings
)
1883 globalCflags
+= " -Werror";
1884 if ( ModuleHandlerInformations
[module
.type
].DefaultHost
== HostTrue
)
1886 if ( module
.cplusplus
)
1887 globalCflags
+= " $(HOST_CPPFLAGS)";
1889 globalCflags
+= " -Wno-strict-aliasing $(HOST_CFLAGS)";
1893 if ( module
.cplusplus
)
1895 // HACK: use host headers when building C++
1896 globalCflags
+= " $(HOST_CPPFLAGS)";
1899 globalCflags
+= " -nostdinc";
1902 // Always force disabling of sibling calls optimisation for GCC
1903 // (TODO: Move to version-specific once this bug is fixed in GCC)
1904 globalCflags
+= " -fno-optimize-sibling-calls";
1909 cflagsMacro
.c_str (),
1910 globalCflags
.c_str () );
1912 if ( ModuleHandlerInformations
[module
.type
].DefaultHost
== HostFalse
)
1916 "%s += $(PROJECT_RCFLAGS)\n",
1917 windresflagsMacro
.c_str () );
1921 "%s += $(PROJECT_WIDLFLAGS) -I%s\n",
1922 widlflagsMacro
.c_str (),
1923 module
.output
->relative_path
.c_str () );
1927 "%s_LFLAGS := $(PROJECT_LFLAGS) -g $(%s_LFLAGS)\n",
1928 module
.name
.c_str (),
1929 module
.name
.c_str () );
1935 "%s_LFLAGS += $(HOST_LFLAGS)\n",
1936 module
.name
.c_str () );
1942 linkDepsMacro
.c_str (),
1943 libsMacro
.c_str () );
1945 const char *cflags
= ModuleHandlerInformations
[module
.type
].cflags
;
1946 if ( strlen( cflags
) > 0 )
1948 fprintf ( fMakefile
,
1950 cflagsMacro
.c_str (),
1954 const char* nasmflags
= ModuleHandlerInformations
[module
.type
].nasmflags
;
1955 if ( strlen( nasmflags
) > 0 )
1957 fprintf ( fMakefile
,
1959 nasmflagsMacro
.c_str (),
1963 const char *linkerflags
= ModuleHandlerInformations
[module
.type
].linkerflags
;
1964 if ( strlen( linkerflags
) > 0 )
1966 fprintf ( fMakefile
,
1968 linkerflagsMacro
.c_str (),
1972 if ( IsStaticLibrary ( module
) && module
.isStartupLib
)
1974 fprintf ( fMakefile
,
1975 "%s += -Wno-main\n\n",
1976 cflagsMacro
.c_str () );
1979 fprintf ( fMakefile
, "\n\n" );
1981 // future references to the macros will be to get their values
1982 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1983 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1984 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
1988 MingwModuleHandler::GenerateRules ()
1992 fprintf ( fMakefile
, "# RULES\n" );
1993 string targetMacro
= GetTargetMacro ( module
);
1994 //CLEAN_FILE ( targetMacro );
1995 CLEAN_FILE ( FileLocation ( SourceDirectory
, "", targetMacro
) );
1997 // generate phony target for module name
1998 fprintf ( fMakefile
, ".PHONY: %s\n",
1999 module
.name
.c_str () );
2000 string dependencies
= GetTargetMacro ( module
);
2001 if ( module
.type
== Test
)
2002 dependencies
+= " $(REGTESTS_RUN_TARGET)";
2003 fprintf ( fMakefile
, "%s: %s\n\n",
2004 module
.name
.c_str (),
2005 dependencies
.c_str () );
2006 if ( module
.type
== Test
)
2008 fprintf ( fMakefile
,
2010 targetMacro
.c_str ());
2013 if ( !ReferenceObjects ( module
) )
2015 const FileLocation
* ar_target
= GenerateArchiveTarget ();
2020 spec
= IsSpecDefinitionFile();
2027 defRule
= &winebuildPDefRule
;
2029 defRule
= &winebuildDefRule
;
2031 defRule
->Execute ( fMakefile
, backend
, module
, module
.importLibrary
->source
, clean_files
);
2034 GenerateObjectFileTargets ();
2038 MingwModuleHandler::GetInvocationDependencies (
2039 const Module
& module
,
2040 string_list
& dependencies
)
2042 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
2044 Invoke
& invoke
= *module
.invocations
[i
];
2045 if ( invoke
.invokeModule
== &module
)
2046 /* Protect against circular dependencies */
2048 invoke
.GetTargets ( dependencies
);
2053 MingwModuleHandler::GenerateInvocations () const
2055 if ( module
.invocations
.size () == 0 )
2058 fprintf ( fMakefile
, "# INVOCATIONS\n" );
2060 size_t iend
= module
.invocations
.size ();
2061 for ( size_t i
= 0; i
< iend
; i
++ )
2063 const Invoke
& invoke
= *module
.invocations
[i
];
2065 if ( invoke
.invokeModule
->type
!= BuildTool
)
2067 throw XMLInvalidBuildFileException (
2068 module
.node
.location
,
2069 "Only modules of type buildtool can be invoked." );
2072 string invokeTarget
= module
.GetInvocationTarget ( i
);
2073 string_list invoke_targets
;
2074 assert ( invoke_targets
.size() );
2075 invoke
.GetTargets ( invoke_targets
);
2076 fprintf ( fMakefile
,
2078 invokeTarget
.c_str () );
2079 fprintf ( fMakefile
,
2081 invokeTarget
.c_str () );
2082 size_t j
, jend
= invoke_targets
.size();
2083 for ( j
= 0; j
< jend
; j
++ )
2085 fprintf ( fMakefile
,
2087 invoke_targets
[i
].c_str () );
2089 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
2090 for ( j
= 1; j
< jend
; j
++ )
2091 fprintf ( fMakefile
,
2093 invoke_targets
[i
].c_str () );
2094 fprintf ( fMakefile
,
2096 NormalizeFilename ( backend
->GetFullName ( *invoke
.invokeModule
->output
) ).c_str () );
2097 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
2098 fprintf ( fMakefile
,
2100 NormalizeFilename ( backend
->GetFullName ( *invoke
.invokeModule
->output
) ).c_str (),
2101 invoke
.GetParameters ().c_str () );
2106 MingwModuleHandler::GetPreconditionDependenciesName () const
2108 return module
.name
+ "_precondition";
2112 MingwModuleHandler::GetDefaultDependencies (
2113 string_list
& dependencies
) const
2115 /* Avoid circular dependency */
2116 if ( ModuleHandlerInformations
[module
.type
].DefaultHost
== HostTrue
)
2119 if (module
.name
!= "psdk" &&
2120 module
.name
!= "dxsdk")
2122 dependencies
.push_back ( "$(PSDK_TARGET) $(psdk_HEADERS)" );
2123 dependencies
.push_back ( "$(DXSDK_TARGET) $(dxsdk_HEADERS)" );
2126 if (module
.name
!= "errcodes" &&
2127 module
.name
!= "bugcodes" &&
2128 module
.name
!= "ntstatus")
2130 dependencies
.push_back ( "$(ERRCODES_TARGET) $(ERRCODES_MCHEADERS)" );
2131 dependencies
.push_back ( "$(BUGCODES_TARGET) $(BUGCODES_MCHEADERS)" );
2132 dependencies
.push_back ( "$(NTSTATUS_TARGET) $(NTSTATUS_MCHEADERS)" );
2135 ///* Check if any dependent library relies on the generated headers */
2136 //for ( size_t i = 0; i < module.project.modules.size (); i++ )
2138 // const Module& m = *module.project.modules[i];
2139 // for ( size_t j = 0; j < m.non_if_data.compilationUnits.size (); j++ )
2141 // CompilationUnit& compilationUnit = *m.non_if_data.compilationUnits[j];
2142 // const FileLocation& sourceFile = compilationUnit.GetFilename ();
2143 // string extension = GetExtension ( sourceFile );
2144 // if (extension == ".mc" || extension == ".MC" )
2146 // string dependency = ssprintf ( "$(%s_MCHEADERS)", m.name.c_str () );
2147 // dependencies.push_back ( dependency );
2154 MingwModuleHandler::GeneratePreconditionDependencies ()
2156 fprintf ( fMakefile
, "# PRECONDITION DEPENDENCIES\n" );
2157 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2158 string_list dependencies
;
2159 GetDefaultDependencies ( dependencies
);
2160 GetModuleDependencies ( dependencies
);
2162 GetInvocationDependencies ( module
, dependencies
);
2164 if ( dependencies
.size() )
2166 fprintf ( fMakefile
,
2168 preconditionDependenciesName
.c_str () );
2169 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2170 fprintf ( fMakefile
,
2172 dependencies
[i
].c_str () );
2173 fprintf ( fMakefile
, "\n\n" );
2176 fprintf ( fMakefile
, "\n" );
2180 MingwModuleHandler::IsSpecDefinitionFile () const
2182 if(!module
.importLibrary
)
2185 if(module
.importLibrary
->source
->name
.rfind(".spec") != string::npos
)
2188 if(module
.importLibrary
->source
->name
.rfind(".pspec") != string::npos
)
2194 /* caller needs to delete the returned object */
2196 MingwModuleHandler::GetDefinitionFilename () const
2198 if ( module
.importLibrary
== NULL
)
2201 if ( IsSpecDefinitionFile () )
2203 return new FileLocation ( IntermediateDirectory
,
2204 module
.importLibrary
->source
->relative_path
,
2205 GetBasename ( module
.importLibrary
->source
->name
) + "_" + module
.name
+ ".auto.def" );
2209 return new FileLocation ( SourceDirectory
,
2210 module
.importLibrary
->source
->relative_path
,
2211 module
.importLibrary
->source
->name
);
2216 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2218 if ( module
.importLibrary
!= NULL
)
2220 const FileLocation
*library_target
= GetImportLibraryFilename ( module
, &clean_files
);
2221 const FileLocation
*defFilename
= GetDefinitionFilename ();
2222 string empty
= "tools" + sSep
+ "rbuild" + sSep
+ "empty.def";
2224 vector
<FileLocation
> deps
;
2225 GetDefinitionDependencies ( deps
);
2227 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE\n" );
2229 fprintf ( fMakefile
, "%s:",
2230 backend
->GetFullName ( *library_target
).c_str () );
2234 fprintf ( fMakefile
, " %s",
2235 backend
->GetFullName ( *defFilename
).c_str () );
2238 size_t i
, iend
= deps
.size();
2239 for ( i
= 0; i
< iend
; i
++ )
2240 fprintf ( fMakefile
, " %s",
2241 backend
->GetFullName ( deps
[i
] ).c_str () );
2243 fprintf ( fMakefile
, " | %s\n",
2244 backend
->GetFullPath ( *library_target
).c_str () );
2246 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2248 fprintf ( fMakefile
,
2249 "\t${dlltool} --dllname %s --def %s --output-lib %s%s%s\n\n",
2250 module
.output
->name
.c_str (),
2251 defFilename
? backend
->GetFullName ( *defFilename
).c_str ()
2253 backend
->GetFullName ( *library_target
).c_str (),
2254 module
.mangledSymbols
? "" : " --kill-at",
2255 module
.underscoreSymbols
? " --add-underscore" : "" );
2259 delete library_target
;
2264 MingwModuleHandler::GetSpecObjectDependencies (
2265 vector
<FileLocation
>& dependencies
,
2266 const FileLocation
*file
) const
2268 dependencies
.push_back ( FileLocation ( IntermediateDirectory
,
2269 file
->relative_path
,
2270 GetBasename ( file
->name
) + "_" + module
.name
+ ".stubs.c" ) );
2274 MingwModuleHandler::GetSpecImplibDependencies (
2275 vector
<FileLocation
>& dependencies
,
2276 const FileLocation
*file
) const
2278 dependencies
.push_back ( FileLocation ( IntermediateDirectory
,
2279 file
->relative_path
,
2280 GetBasename ( file
->name
) + "_" + module
.name
+ ".auto.def" ) );
2284 MingwModuleHandler::GetMcObjectDependencies (
2285 vector
<FileLocation
>& dependencies
,
2286 const FileLocation
*file
) const
2288 string basename
= GetBasename ( file
->name
);
2290 FileLocation
defDependency ( IntermediateDirectory
,
2293 dependencies
.push_back ( defDependency
);
2295 FileLocation
stubsDependency ( IntermediateDirectory
,
2296 file
->relative_path
,
2298 dependencies
.push_back ( stubsDependency
);
2302 MingwModuleHandler::GetWidlObjectDependencies (
2303 vector
<FileLocation
>& dependencies
,
2304 const FileLocation
*file
) const
2306 string basename
= GetBasename ( file
->name
);
2307 const FileLocation
*generatedHeaderFilename
= GetRpcServerHeaderFilename ( file
);
2309 FileLocation
serverSourceDependency ( IntermediateDirectory
,
2310 file
->relative_path
,
2311 basename
+ "_s.c" );
2312 dependencies
.push_back ( serverSourceDependency
);
2313 dependencies
.push_back ( *generatedHeaderFilename
);
2315 delete generatedHeaderFilename
;
2319 MingwModuleHandler::GetDefinitionDependencies (
2320 vector
<FileLocation
>& dependencies
) const
2322 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2323 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2325 const CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2326 const FileLocation
& sourceFile
= compilationUnit
.GetFilename ();
2327 string extension
= GetExtension ( sourceFile
);
2329 if (extension
== ".spec" || extension
== ".pspec")
2330 GetSpecObjectDependencies ( dependencies
, &sourceFile
);
2332 if (extension
== ".idl")
2334 if ( ( module
.type
== RpcServer
) || ( module
.type
== RpcClient
) || ( module
.type
== RpcProxy
) )
2335 GetWidlObjectDependencies ( dependencies
, &sourceFile
);
2340 enum DebugSupportType
2347 MingwAddDebugSupportLibraries ( Module
& module
, DebugSupportType type
)
2353 case DebugKernelMode
:
2354 pLibrary
= new Library ( module
, "debugsup_ntoskrnl" );
2358 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2365 module
.non_if_data
.libraries
.push_back(pLibrary
);
2368 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2369 : MingwModuleHandler ( module_
)
2374 MingwBuildToolModuleHandler::Process ()
2376 GenerateBuildToolModuleTarget ();
2380 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2382 string
targetMacro ( GetTargetMacro (module
) );
2383 string objectsMacro
= GetObjectsMacro ( module
);
2384 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2385 string libsMacro
= GetLibsMacro ();
2389 fprintf ( fMakefile
, "# BUILD TOOL MODULE TARGET\n" );
2392 if ( module
.cplusplus
)
2393 linker
= "${host_gpp}";
2395 linker
= "${host_gcc}";
2397 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
2398 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2399 targetMacro
.c_str (),
2400 objectsMacro
.c_str (),
2401 linkDepsMacro
.c_str (),
2402 backend
->GetFullPath ( *target_file
).c_str () );
2403 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2404 fprintf ( fMakefile
,
2405 "\t%s %s -o $@ %s %s\n\n",
2407 GetLinkerMacro ().c_str (),
2408 objectsMacro
.c_str (),
2409 libsMacro
.c_str () );
2415 MingwKernelModuleHandler::MingwKernelModuleHandler (
2416 const Module
& module_
)
2418 : MingwModuleHandler ( module_
)
2423 MingwKernelModuleHandler::Process ()
2425 GenerateKernelModuleTarget ();
2429 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2431 string
targetMacro ( GetTargetMacro ( module
) );
2432 string workingDirectory
= GetWorkingDirectory ( );
2433 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2435 GenerateImportLibraryTargetIfNeeded ();
2437 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2441 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2443 string linkerParameters
= ssprintf ( "-subsystem=native -entry=%s -image-base=%s",
2444 module
.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (),
2445 module
.baseaddress
.c_str () );
2447 GenerateLinkerCommand ( dependencies
,
2448 linkerParameters
+ " $(NTOSKRNL_SHARED)",
2453 GeneratePhonyTarget();
2458 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2459 const Module
& module_
)
2461 : MingwModuleHandler ( module_
)
2467 MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2469 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2473 MingwKernelModeDLLModuleHandler::Process ()
2475 GenerateKernelModeDLLModuleTarget ();
2479 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2481 string
targetMacro ( GetTargetMacro ( module
) );
2482 string workingDirectory
= GetWorkingDirectory ();
2483 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2485 GenerateImportLibraryTargetIfNeeded ();
2487 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2491 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2493 string linkerParameters
= ssprintf ( "-subsystem=native -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared",
2494 module
.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (),
2495 module
.baseaddress
.c_str () );
2496 GenerateLinkerCommand ( dependencies
,
2502 GeneratePhonyTarget();
2507 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2508 const Module
& module_
)
2510 : MingwModuleHandler ( module_
)
2515 MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2517 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2521 MingwNativeDLLModuleHandler::Process ()
2523 GenerateNativeDLLModuleTarget ();
2527 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2529 string
targetMacro ( GetTargetMacro (module
) );
2530 string workingDirectory
= GetWorkingDirectory ( );
2531 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2533 GenerateImportLibraryTargetIfNeeded ();
2535 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2539 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2541 string linkerParameters
= ssprintf ( "-subsystem=native -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared",
2542 module
.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (),
2543 module
.baseaddress
.c_str () );
2544 GenerateLinkerCommand ( dependencies
,
2550 GeneratePhonyTarget();
2555 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2556 const Module
& module_
)
2558 : MingwModuleHandler ( module_
)
2563 MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2565 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2569 MingwNativeCUIModuleHandler::Process ()
2571 GenerateNativeCUIModuleTarget ();
2575 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2577 string
targetMacro ( GetTargetMacro (module
) );
2578 string workingDirectory
= GetWorkingDirectory ( );
2579 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2581 GenerateImportLibraryTargetIfNeeded ();
2583 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2587 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2589 string linkerParameters
= ssprintf ( "-subsystem=native -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000",
2590 module
.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (),
2591 module
.baseaddress
.c_str () );
2592 GenerateLinkerCommand ( dependencies
,
2598 GeneratePhonyTarget();
2603 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2604 const Module
& module_
)
2606 : MingwModuleHandler ( module_
)
2610 MingwWin32OCXModuleHandler::MingwWin32OCXModuleHandler (
2611 const Module
& module_
)
2613 : MingwModuleHandler ( module_
)
2618 LinksToCrt( Module
&module
)
2620 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
2622 Library
& library
= *module
.non_if_data
.libraries
[i
];
2623 if ( library
.name
== "libcntpr" || library
.name
== "crt" )
2630 MingwAddImplicitLibraries( Module
&module
)
2635 if ( module
.type
!= Win32DLL
2636 && module
.type
!= Win32OCX
2637 && module
.type
!= Win32CUI
2638 && module
.type
!= Win32GUI
2639 && module
.type
!= Win32SCR
)
2641 // no implicit libraries
2645 links_to_crt
= LinksToCrt ( module
);
2647 if ( !module
.isDefaultEntryPoint
)
2649 if ( module
.GetEntryPoint(false) == "0" )
2651 if ( !links_to_crt
)
2653 pLibrary
= new Library ( module
, "mingw_common" );
2654 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() , pLibrary
);
2656 pLibrary
= new Library ( module
, "msvcrt" );
2657 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2658 links_to_crt
= true;
2661 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2662 module
.non_if_data
.libraries
.push_back(pLibrary
);
2666 if ( module
.IsDLL () )
2668 //pLibrary = new Library ( module, "__mingw_dllmain" );
2669 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
2673 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
2674 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
2677 pLibrary
= new Library ( module
, "mingw_common" );
2678 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
2680 if ( !links_to_crt
)
2682 // always link in msvcrt to get the basic routines
2683 pLibrary
= new Library ( module
, "msvcrt" );
2684 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2687 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2688 module
.non_if_data
.libraries
.push_back(pLibrary
);
2692 MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2694 MingwAddImplicitLibraries ( module
);
2698 MingwWin32DLLModuleHandler::Process ()
2700 GenerateWin32DLLModuleTarget ();
2704 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2706 string
targetMacro ( GetTargetMacro (module
) );
2707 string workingDirectory
= GetWorkingDirectory ( );
2708 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2710 GenerateImportLibraryTargetIfNeeded ();
2712 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2716 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2718 string linkerParameters
= ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared",
2719 module
.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (),
2720 module
.baseaddress
.c_str () );
2721 GenerateLinkerCommand ( dependencies
,
2727 GeneratePhonyTarget();
2733 MingwWin32OCXModuleHandler::AddImplicitLibraries ( Module
& module
)
2735 MingwAddImplicitLibraries ( module
);
2739 MingwWin32OCXModuleHandler::Process ()
2741 GenerateWin32OCXModuleTarget ();
2745 MingwWin32OCXModuleHandler::GenerateWin32OCXModuleTarget ()
2747 string
targetMacro ( GetTargetMacro (module
) );
2748 string workingDirectory
= GetWorkingDirectory ( );
2749 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2751 GenerateImportLibraryTargetIfNeeded ();
2753 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2757 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2759 string linkerParameters
= ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared",
2760 module
.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (),
2761 module
.baseaddress
.c_str () );
2762 GenerateLinkerCommand ( dependencies
,
2768 GeneratePhonyTarget();
2773 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2774 const Module
& module_
)
2776 : MingwModuleHandler ( module_
)
2781 MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2783 MingwAddImplicitLibraries ( module
);
2787 MingwWin32CUIModuleHandler::Process ()
2789 GenerateWin32CUIModuleTarget ();
2793 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2795 string
targetMacro ( GetTargetMacro (module
) );
2796 string workingDirectory
= GetWorkingDirectory ( );
2797 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2799 GenerateImportLibraryTargetIfNeeded ();
2801 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2805 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2807 string linkerParameters
= ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000",
2808 module
.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (),
2809 module
.baseaddress
.c_str () );
2810 GenerateLinkerCommand ( dependencies
,
2816 GeneratePhonyTarget();
2821 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2822 const Module
& module_
)
2824 : MingwModuleHandler ( module_
)
2829 MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2831 MingwAddImplicitLibraries ( module
);
2835 MingwWin32GUIModuleHandler::Process ()
2837 GenerateWin32GUIModuleTarget ();
2841 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2843 string
targetMacro ( GetTargetMacro (module
) );
2844 string workingDirectory
= GetWorkingDirectory ( );
2845 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2847 GenerateImportLibraryTargetIfNeeded ();
2849 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2853 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2855 string linkerParameters
= ssprintf ( "-subsystem=windows -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000",
2856 module
.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (),
2857 module
.baseaddress
.c_str () );
2858 GenerateLinkerCommand ( dependencies
,
2864 GeneratePhonyTarget();
2869 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2870 const Module
& module_
)
2872 : MingwModuleHandler ( module_
)
2877 MingwBootLoaderModuleHandler::Process ()
2879 GenerateBootLoaderModuleTarget ();
2883 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2885 string
targetName ( module
.output
->name
);
2886 string
targetMacro ( GetTargetMacro (module
) );
2887 string workingDirectory
= GetWorkingDirectory ();
2888 FileLocation
junk_tmp ( TemporaryDirectory
,
2890 module
.name
+ ".junk.tmp" );
2891 CLEAN_FILE ( junk_tmp
);
2892 string objectsMacro
= GetObjectsMacro ( module
);
2893 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2897 fprintf ( fMakefile
, "# BOOT LOADER MODULE TARGET\n" );
2899 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
2900 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2901 targetMacro
.c_str (),
2902 objectsMacro
.c_str (),
2903 linkDepsMacro
.c_str (),
2904 backend
->GetFullPath ( *target_file
).c_str () );
2906 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2908 if (Environment::GetArch() == "arm")
2910 fprintf ( fMakefile
,
2911 "\t${gcc} -Wl,--subsystem,native -Wl,--section-start,startup=0x8000 -o %s %s %s %s\n",
2912 backend
->GetFullName ( junk_tmp
).c_str (),
2913 objectsMacro
.c_str (),
2914 linkDepsMacro
.c_str (),
2915 GetLinkerMacro ().c_str ());
2919 fprintf ( fMakefile
,
2920 "\t${gcc} -Wl,--subsystem,native -Wl,-Ttext,0x8000 -o %s %s %s %s\n",
2921 backend
->GetFullName ( junk_tmp
).c_str (),
2922 objectsMacro
.c_str (),
2923 linkDepsMacro
.c_str (),
2924 GetLinkerMacro ().c_str ());
2926 fprintf ( fMakefile
,
2927 "\t${objcopy} -O binary %s $@\n",
2928 backend
->GetFullName ( junk_tmp
).c_str () );
2929 GenerateBuildMapCode ( &junk_tmp
);
2930 fprintf ( fMakefile
,
2931 "\t-@${rm} %s 2>$(NUL)\n",
2932 backend
->GetFullName ( junk_tmp
).c_str () );
2938 MingwBootProgramModuleHandler::MingwBootProgramModuleHandler (
2939 const Module
& module_
)
2940 : MingwModuleHandler ( module_
)
2945 MingwBootProgramModuleHandler::Process ()
2947 GenerateBootProgramModuleTarget ();
2951 MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
2953 string
targetName ( module
.output
->name
);
2954 string
targetMacro ( GetTargetMacro (module
) );
2955 string workingDirectory
= GetWorkingDirectory ();
2956 FileLocation
junk_tmp ( TemporaryDirectory
,
2958 module
.name
+ ".junk.tmp" );
2959 FileLocation
junk_elf ( TemporaryDirectory
,
2961 module
.name
+ ".junk.elf" );
2962 FileLocation
junk_cpy ( TemporaryDirectory
,
2964 module
.name
+ ".junk.elf" );
2965 CLEAN_FILE ( junk_tmp
);
2966 CLEAN_FILE ( junk_elf
);
2967 CLEAN_FILE ( junk_cpy
);
2968 string objectsMacro
= GetObjectsMacro ( module
);
2969 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2970 const Module
*payload
= module
.project
.LocateModule ( module
.payload
);
2974 fprintf ( fMakefile
, "# BOOT PROGRAM MODULE TARGET\n" );
2976 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
2977 fprintf ( fMakefile
, "%s: %s %s %s | %s\n",
2978 targetMacro
.c_str (),
2979 objectsMacro
.c_str (),
2980 linkDepsMacro
.c_str (),
2981 payload
->name
.c_str (),
2982 backend
->GetFullPath ( *target_file
).c_str () );
2984 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
2986 fprintf ( fMakefile
, "\t$(%s_PREPARE) $(OUTPUT)$(SEP)%s %s\n",
2987 module
.buildtype
.c_str (),
2988 NormalizeFilename( backend
->GetFullName ( *payload
->output
) ).c_str (),
2989 backend
->GetFullName ( junk_cpy
).c_str () );
2991 fprintf ( fMakefile
, "\t${objcopy} $(%s_FLATFORMAT) %s %s\n",
2992 module
.buildtype
.c_str (),
2993 backend
->GetFullName ( junk_cpy
).c_str (),
2994 backend
->GetFullName ( junk_tmp
).c_str () );
2996 fprintf ( fMakefile
, "\t${ld} $(%s_LINKFORMAT) %s %s -g -o %s\n",
2997 module
.buildtype
.c_str (),
2998 linkDepsMacro
.c_str (),
2999 backend
->GetFullName ( junk_tmp
).c_str (),
3000 backend
->GetFullName ( junk_elf
).c_str () );
3002 fprintf ( fMakefile
, "\t${objcopy} $(%s_COPYFORMAT) %s $(INTERMEDIATE)$(SEP)%s\n",
3003 module
.buildtype
.c_str (),
3004 backend
->GetFullName ( junk_elf
).c_str (),
3005 backend
->GetFullName ( *module
.output
) .c_str () );
3007 fprintf ( fMakefile
,
3008 "\t-@${rm} %s %s %s 2>$(NUL)\n",
3009 backend
->GetFullName ( junk_tmp
).c_str (),
3010 backend
->GetFullName ( junk_elf
).c_str (),
3011 backend
->GetFullName ( junk_cpy
).c_str () );
3017 MingwIsoModuleHandler::MingwIsoModuleHandler (
3018 const Module
& module_
)
3020 : MingwModuleHandler ( module_
)
3025 MingwIsoModuleHandler::Process ()
3027 GenerateIsoModuleTarget ();
3031 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
3032 const string
& bootcdDirectory
)
3034 for ( std::map
<std::string
, Module
*>::const_iterator p
= module
.project
.modules
.begin (); p
!= module
.project
.modules
.end (); ++ p
)
3036 const Module
& m
= *p
->second
;
3039 if ( m
.bootstrap
!= NULL
)
3041 FileLocation
targetFile ( OutputDirectory
,
3042 m
.bootstrap
->base
.length () > 0
3043 ? bootcdDirectory
+ sSep
+ m
.bootstrap
->base
3045 m
.bootstrap
->nameoncd
);
3046 OutputCopyCommand ( *m
.output
, targetFile
);
3052 MingwIsoModuleHandler::OutputCdfileCopyCommands (
3053 const string
& bootcdDirectory
)
3055 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3057 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3058 FileLocation
targetFile ( OutputDirectory
,
3059 cdfile
.target
->relative_path
.length () > 0
3060 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3062 cdfile
.target
->name
);
3063 OutputCopyCommand ( *cdfile
.source
, targetFile
);
3068 MingwIsoModuleHandler::GetBootstrapCdDirectories ( vector
<FileLocation
>& out
,
3069 const string
& bootcdDirectory
)
3071 for ( std::map
<std::string
, Module
*>::const_iterator p
= module
.project
.modules
.begin (); p
!= module
.project
.modules
.end (); ++ p
)
3073 const Module
& m
= *p
->second
;
3076 if ( m
.bootstrap
!= NULL
)
3078 FileLocation
targetDirectory ( OutputDirectory
,
3079 m
.bootstrap
->base
.length () > 0
3080 ? bootcdDirectory
+ sSep
+ m
.bootstrap
->base
3083 out
.push_back ( targetDirectory
);
3089 MingwIsoModuleHandler::GetNonModuleCdDirectories ( vector
<FileLocation
>& out
,
3090 const string
& bootcdDirectory
)
3092 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3094 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3095 FileLocation
targetDirectory ( OutputDirectory
,
3096 cdfile
.target
->relative_path
.length () > 0
3097 ? bootcdDirectory
+ sSep
+ cdfile
.target
->relative_path
3100 out
.push_back( targetDirectory
);
3105 MingwIsoModuleHandler::GetCdDirectories ( vector
<FileLocation
>& out
,
3106 const string
& bootcdDirectory
)
3108 GetBootstrapCdDirectories ( out
, bootcdDirectory
);
3109 GetNonModuleCdDirectories ( out
, bootcdDirectory
);
3113 MingwIsoModuleHandler::GetBootstrapCdFiles (
3114 vector
<FileLocation
>& out
) const
3116 for ( std::map
<std::string
, Module
*>::const_iterator p
= module
.project
.modules
.begin (); p
!= module
.project
.modules
.end (); ++ p
)
3118 const Module
& m
= *p
->second
;
3121 if ( m
.bootstrap
!= NULL
)
3123 out
.push_back ( *m
.output
);
3129 MingwIsoModuleHandler::GetNonModuleCdFiles (
3130 vector
<FileLocation
>& out
) const
3132 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3134 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3135 out
.push_back ( *cdfile
.source
);
3140 MingwIsoModuleHandler::GetCdFiles (
3141 vector
<FileLocation
>& out
) const
3143 GetBootstrapCdFiles ( out
);
3144 GetNonModuleCdFiles ( out
);
3148 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
3150 fprintf ( fMakefile
, "# ISO MODULE TARGET\n" );
3151 string bootcdDirectory
= "cd";
3152 FileLocation
bootcd ( OutputDirectory
,
3155 FileLocation
bootcdReactos ( OutputDirectory
,
3156 bootcdDirectory
+ sSep
+ Environment::GetCdOutputPath (),
3158 vector
<FileLocation
> vSourceFiles
, vCdFiles
;
3159 vector
<FileLocation
> vCdDirectories
;
3162 FileLocation
srcunattend ( SourceDirectory
,
3163 "boot" + sSep
+ "bootdata" + sSep
+ "bootcdregtest",
3165 FileLocation
tarunattend ( bootcdReactos
.directory
,
3166 bootcdReactos
.relative_path
,
3168 if (module
.type
== IsoRegTest
)
3169 vSourceFiles
.push_back ( srcunattend
);
3172 const Module
* bootModule
= module
.bootSector
->bootSectorModule
;
3176 throw InvalidOperationException ( module
.node
.location
.c_str(),
3178 "Invalid bootsector. module '%s' requires <bootsector>",
3179 module
.name
.c_str ());
3182 const FileLocation
*isoboot
= bootModule
->output
;
3183 vSourceFiles
.push_back ( *isoboot
);
3185 // prepare reactos.dff and reactos.inf
3186 FileLocation
reactosDff ( SourceDirectory
,
3187 "boot" + sSep
+ "bootdata" + sSep
+ "packages",
3189 FileLocation
reactosInf ( bootcdReactos
.directory
,
3190 bootcdReactos
.relative_path
,
3193 vSourceFiles
.push_back ( reactosDff
);
3196 We use only the name and not full FileLocation(ouput) because Iso/LiveIso are an exception to the general rule.
3197 Iso/LiveIso outputs are generated in code base root
3199 string IsoName
= module
.output
->name
;
3201 string sourceFiles
= v2s ( backend
, vSourceFiles
, 5 );
3204 GetCdDirectories ( vCdDirectories
, bootcdDirectory
);
3205 GetCdFiles ( vCdFiles
);
3206 string cdDirectories
= "";//v2s ( vCdDirectories, 5 );
3207 string cdFiles
= v2s ( backend
, vCdFiles
, 5 );
3209 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3210 module
.name
.c_str ());
3211 fprintf ( fMakefile
,
3212 "%s: all %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET) %s\n",
3213 module
.name
.c_str (),
3214 backend
->GetFullName ( *isoboot
).c_str (),
3215 sourceFiles
.c_str (),
3217 cdDirectories
.c_str () );
3218 fprintf ( fMakefile
,
3219 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
3220 backend
->GetFullName ( reactosDff
).c_str (),
3221 backend
->GetFullPath ( bootcdReactos
).c_str () );
3222 fprintf ( fMakefile
,
3223 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
3224 backend
->GetFullName ( reactosDff
).c_str (),
3225 backend
->GetFullName ( reactosInf
).c_str (),
3226 backend
->GetFullPath ( bootcdReactos
).c_str ());
3227 fprintf ( fMakefile
,
3228 "\t-@${rm} %s 2>$(NUL)\n",
3229 backend
->GetFullName ( reactosInf
).c_str () );
3230 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
3231 OutputCdfileCopyCommands ( bootcdDirectory
);
3233 if (module
.type
== IsoRegTest
)
3234 OutputCopyCommand ( srcunattend
, tarunattend
);
3236 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3237 fprintf ( fMakefile
,
3238 "\t$(Q)$(CDMAKE_TARGET) -v -j -m -b %s %s REACTOS %s\n",
3239 backend
->GetFullName ( *isoboot
).c_str (),
3240 backend
->GetFullPath ( bootcd
).c_str (),
3242 fprintf ( fMakefile
,
3247 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
3248 const Module
& module_
)
3250 : MingwModuleHandler ( module_
)
3255 MingwLiveIsoModuleHandler::Process ()
3257 GenerateLiveIsoModuleTarget ();
3261 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
3263 FileLocation
dir ( OutputDirectory
,
3266 MingwModuleHandler::PassThruCacheDirectory ( &dir
);
3270 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
3271 string
& reactosDirectory
)
3273 for ( std::map
<std::string
, Module
*>::const_iterator p
= module
.project
.modules
.begin (); p
!= module
.project
.modules
.end (); ++ p
)
3275 const Module
& m
= *p
->second
;
3280 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
3281 FileLocation
destination ( OutputDirectory
,
3282 m
.install
->relative_path
.length () > 0
3283 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.install
->relative_path
3284 : livecdDirectory
+ sSep
+ reactosDirectory
,
3286 OutputCopyCommand ( *aliasedModule
.output
,
3293 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
3294 string
& reactosDirectory
)
3296 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
3298 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
3299 FileLocation
target ( OutputDirectory
,
3300 installfile
.target
->relative_path
.length () > 0
3301 ? livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.target
->relative_path
3302 : livecdDirectory
+ sSep
+ reactosDirectory
,
3303 installfile
.target
->name
);
3304 OutputCopyCommand ( *installfile
.source
, target
);
3309 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
3311 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
3312 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
3313 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
3314 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
3315 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
3316 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
3318 FileLocation
livecdIni ( SourceDirectory
,
3319 "boot" + sSep
+ "bootdata",
3321 FileLocation
destination ( OutputDirectory
,
3324 OutputCopyCommand ( livecdIni
,
3329 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3331 FileLocation
freeldr ( OutputDirectory
,
3332 "boot" + sSep
+ "freeldr" + sSep
+ "freeldr",
3334 FileLocation
destination ( OutputDirectory
,
3335 livecdDirectory
+ sSep
+ "loader",
3337 OutputCopyCommand ( freeldr
,
3342 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3344 fprintf ( fMakefile
, "# REGISTRY COMMANDS\n" );
3345 FileLocation
reactosSystem32ConfigDirectory ( OutputDirectory
,
3346 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config",
3348 fprintf ( fMakefile
,
3349 "\t$(ECHO_MKHIVE)\n" );
3350 fprintf ( fMakefile
,
3351 "\t$(MKHIVE_TARGET) boot%cbootdata %s $(ARCH) boot%cbootdata%clivecd.inf boot%cbootdata%chiveinst_$(ARCH).inf\n",
3352 cSep
, backend
->GetFullPath ( reactosSystem32ConfigDirectory
).c_str (),
3353 cSep
, cSep
, cSep
, cSep
);
3357 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
3359 fprintf ( fMakefile
, "# LIVE ISO MODULE TARGET\n" );
3360 string livecdDirectory
= module
.name
;
3361 FileLocation
livecd ( OutputDirectory
, livecdDirectory
, "" );
3366 const Module
* bootModule
= module
.bootSector
->bootSectorModule
;
3370 throw InvalidOperationException ( module
.node
.location
.c_str(),
3372 "Invalid bootsector. module '%s' requires <bootsector>",
3373 module
.name
.c_str ());
3376 const FileLocation
*isoboot
= bootModule
->output
;
3379 We use only the name and not full FileLocation(ouput) because Iso/LiveIso are an exception to the general rule.
3380 Iso/LiveIso outputs are generated in code base root
3382 IsoName
= module
.output
->name
;
3384 string reactosDirectory
= "reactos";
3385 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3386 FileLocation
livecdReactos ( OutputDirectory
,
3387 livecdReactosNoFixup
,
3389 CLEAN_FILE ( livecdReactos
);
3391 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3392 module
.name
.c_str ());
3393 fprintf ( fMakefile
,
3394 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3395 module
.name
.c_str (),
3396 backend
->GetFullName ( *isoboot
) .c_str (),
3397 backend
->GetFullPath ( livecdReactos
).c_str () );
3398 OutputModuleCopyCommands ( livecdDirectory
,
3400 OutputNonModuleCopyCommands ( livecdDirectory
,
3402 OutputProfilesDirectoryCommands ( livecdDirectory
);
3403 OutputLoaderCommands ( livecdDirectory
);
3404 OutputRegistryCommands ( livecdDirectory
);
3405 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3406 fprintf ( fMakefile
,
3407 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS %s\n",
3408 backend
->GetFullName( *isoboot
).c_str (),
3409 backend
->GetFullPath ( livecd
).c_str (),
3411 fprintf ( fMakefile
,
3416 MingwTestModuleHandler::MingwTestModuleHandler (
3417 const Module
& module_
)
3419 : MingwModuleHandler ( module_
)
3424 MingwTestModuleHandler::Process ()
3426 GenerateTestModuleTarget ();
3429 /* caller needs to delete the returned object */
3431 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
3433 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_hooks.c", false, "", false ) ) );
3434 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_stubs.S", false, "", false ) ) );
3435 compilationUnits
.push_back ( new CompilationUnit ( new File ( IntermediateDirectory
, module
.output
->relative_path
+ sSep
+ "..", module
.name
+ "_startup.c", false, "", false ) ) );
3439 MingwTestModuleHandler::GenerateTestModuleTarget ()
3441 string
targetMacro ( GetTargetMacro ( module
) );
3442 string workingDirectory
= GetWorkingDirectory ( );
3443 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3445 GenerateImportLibraryTargetIfNeeded ();
3447 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3451 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3453 string linkerParameters
= ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000",
3454 module
.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (),
3455 module
.baseaddress
.c_str () );
3456 GenerateLinkerCommand ( dependencies
,
3462 GeneratePhonyTarget();
3467 MingwAliasModuleHandler::MingwAliasModuleHandler (
3468 const Module
& module_
)
3470 : MingwModuleHandler ( module_
)
3475 MingwAliasModuleHandler::Process ()
3480 MingwCabinetModuleHandler::MingwCabinetModuleHandler (
3481 const Module
& module_
)
3483 : MingwModuleHandler ( module_
)
3488 MingwCabinetModuleHandler::Process ()
3490 string
targetMacro ( GetTargetMacro (module
) );
3494 fprintf ( fMakefile
, "# CABINET MODULE TARGET\n" );
3495 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
3496 fprintf ( fMakefile
, "%s: $(CABMAN_TARGET) | %s\n",
3497 targetMacro
.c_str (),
3498 backend
->GetFullPath ( *target_file
).c_str () );
3500 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
3501 fprintf ( fMakefile
,
3502 "\t$(Q)$(CABMAN_TARGET) -M raw -S %s $(%s_SOURCES)\n", // Escape the asterisk for Make
3503 targetMacro
.c_str (),
3504 module
.name
.c_str());
3507 MingwElfExecutableModuleHandler::MingwElfExecutableModuleHandler (
3508 const Module
& module_
)
3510 : MingwModuleHandler ( module_
)
3515 MingwElfExecutableModuleHandler::Process ()
3517 string
targetName ( module
.output
->name
);
3518 string
targetMacro ( GetTargetMacro (module
) );
3519 string workingDirectory
= GetWorkingDirectory ();
3520 string objectsMacro
= GetObjectsMacro ( module
);
3521 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3522 string libsMacro
= GetLibsMacro ();
3526 fprintf ( fMakefile
, "# ELF EXECUTABLE TARGET\n" );
3527 const FileLocation
*target_file
= GetTargetFilename ( module
, NULL
);
3528 fprintf ( fMakefile
, "%s: %s %s | %s\n",
3529 targetMacro
.c_str (),
3530 objectsMacro
.c_str (),
3531 linkDepsMacro
.c_str (),
3532 backend
->GetFullPath ( *target_file
).c_str () );
3534 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
3536 fprintf ( fMakefile
, "\t${gcc} $(%s_LINKFORMAT) %s %s -g -o %s\n",
3537 module
.buildtype
.c_str(),
3538 objectsMacro
.c_str(),
3540 targetMacro
.c_str () );