2 * Copyright (C) 2005 Casper S. Hornstrup
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #include "../../pch.h"
21 #include "../../rbuild.h"
23 #include "modulehandler.h"
28 #define CLEAN_FILE(f) clean_files.push_back ( f );
30 static string ros_temp
= "$(TEMPORARY)";
32 MingwModuleHandler::backend
= NULL
;
34 MingwModuleHandler::fMakefile
= NULL
;
38 const string
& filename
,
39 const string
& prefix
)
41 if ( !prefix
.length() )
44 const char* pfilename
= filename
.c_str();
45 const char* p1
= strrchr ( pfilename
, '/' );
46 const char* p2
= strrchr ( pfilename
, '\\' );
51 out
+= string(pfilename
,p1
-pfilename
) + cSep
;
54 out
+= prefix
+ pfilename
;
59 GetTargetMacro ( const Module
& module
, bool with_dollar
)
61 string
s ( module
.name
);
65 return ssprintf ( "$(%s)", s
.c_str() );
69 MingwModuleHandler::MingwModuleHandler (
70 const Module
& module_
)
77 MingwModuleHandler::~MingwModuleHandler()
82 MingwModuleHandler::SetBackend ( MingwBackend
* backend_
)
88 MingwModuleHandler::SetMakefile ( FILE* f
)
94 MingwModuleHandler::EnablePreCompiledHeaderSupport ()
100 MingwModuleHandler::RemoveVariables ( string path
)
102 size_t i
= path
.find ( '$' );
103 if ( i
!= string::npos
)
105 size_t j
= path
.find ( ')', i
);
106 if ( j
!= string::npos
)
108 if ( j
+ 2 < path
.length () && path
[j
+ 1] == cSep
)
109 return path
.substr ( j
+ 2);
111 return path
.substr ( j
+ 1);
118 MingwModuleHandler::PassThruCacheDirectory (
120 Directory
* directoryTree
)
122 string
directory ( GetDirectory ( RemoveVariables ( file
) ) );
123 if ( directoryTree
== NULL
)
125 string generatedFilesDirectory
= backend
->AddDirectoryTarget ( directory
,
127 if ( directory
.find ( generatedFilesDirectory
) != string::npos
)
128 /* This path already includes the generated files directory variable */
133 return generatedFilesDirectory
;
134 return generatedFilesDirectory
+ sSep
+ file
;
139 MingwModuleHandler::PassThruCacheDirectory (const FileLocation
* fileLocation
)
141 return PassThruCacheDirectory ( fileLocation
->filename
,
142 fileLocation
->directory
);
145 /*static*/ Directory
*
146 MingwModuleHandler::GetTargetDirectoryTree (
147 const Module
& module
)
149 if ( module
.type
== StaticLibrary
)
150 return backend
->intermediateDirectory
;
151 return backend
->outputDirectory
;
155 MingwModuleHandler::GetTargetFilename (
156 const Module
& module
,
157 string_list
* pclean_files
)
159 string target
= PassThruCacheDirectory (
160 NormalizeFilename ( module
.GetPath () ),
161 GetTargetDirectoryTree ( module
) );
164 string_list
& clean_files
= *pclean_files
;
165 CLEAN_FILE ( target
);
171 MingwModuleHandler::GetImportLibraryFilename (
172 const Module
& module
,
173 string_list
* pclean_files
)
175 string target
= PassThruCacheDirectory (
176 NormalizeFilename ( module
.GetDependencyPath () ),
177 backend
->intermediateDirectory
);
180 string_list
& clean_files
= *pclean_files
;
181 CLEAN_FILE ( target
);
186 /*static*/ MingwModuleHandler
*
187 MingwModuleHandler::InstanciateHandler (
188 const Module
& module
,
189 MingwBackend
* backend
)
191 MingwModuleHandler
* handler
;
192 switch ( module
.type
)
195 handler
= new MingwBuildToolModuleHandler ( module
);
198 handler
= new MingwStaticLibraryModuleHandler ( module
);
201 handler
= new MingwObjectLibraryModuleHandler ( module
);
204 handler
= new MingwKernelModuleHandler ( module
);
207 handler
= new MingwNativeCUIModuleHandler ( module
);
210 handler
= new MingwWin32CUIModuleHandler ( module
);
214 handler
= new MingwWin32GUIModuleHandler ( module
);
217 handler
= new MingwKernelModeDLLModuleHandler ( module
);
220 handler
= new MingwNativeDLLModuleHandler ( module
);
223 handler
= new MingwWin32DLLModuleHandler ( module
);
225 case KernelModeDriver
:
226 case ExportDriver
: // maybe change this later
227 handler
= new MingwKernelModeDriverModuleHandler ( module
);
230 handler
= new MingwBootLoaderModuleHandler ( module
);
233 handler
= new MingwBootSectorModuleHandler ( module
);
236 handler
= new MingwBootProgramModuleHandler ( module
);
239 handler
= new MingwIsoModuleHandler ( module
);
242 handler
= new MingwLiveIsoModuleHandler ( module
);
245 handler
= new MingwIsoModuleHandler ( module
);
248 handler
= new MingwLiveIsoModuleHandler ( module
);
251 handler
= new MingwTestModuleHandler ( module
);
254 handler
= new MingwRpcServerModuleHandler ( module
);
257 handler
= new MingwRpcClientModuleHandler ( module
);
260 handler
= new MingwAliasModuleHandler ( module
);
263 handler
= new MingwIdlHeaderModuleHandler ( module
);
266 throw UnknownModuleTypeException (
267 module
.node
.location
,
275 MingwModuleHandler::GetWorkingDirectory () const
281 MingwModuleHandler::GetBasename ( const string
& filename
) const
283 size_t index
= filename
.find_last_of ( '.' );
284 if ( index
!= string::npos
)
285 return filename
.substr ( 0, index
);
290 MingwModuleHandler::GetActualSourceFilename (
291 const FileLocation
* fileLocation
) const
293 string filename
= fileLocation
->filename
;
294 string extension
= GetExtension ( filename
);
295 if ( extension
== ".spec" || extension
== ".SPEC" )
297 string basename
= GetBasename ( filename
);
298 PassThruCacheDirectory ( NormalizeFilename ( basename
+ ".stubs.c" ),
299 backend
->intermediateDirectory
);
300 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( basename
+ ".stubs.c" ) );
302 else if ( extension
== ".idl" || extension
== ".IDL" )
304 string basename
= GetBasename ( filename
);
306 if ( module
.type
== RpcServer
)
308 newname
= basename
+ "_s.c";
309 PassThruCacheDirectory ( NormalizeFilename ( newname
),
310 backend
->intermediateDirectory
);
311 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( newname
) );
313 else if ( module
.type
== RpcClient
)
315 newname
= basename
+ "_c.c";
316 PassThruCacheDirectory ( NormalizeFilename ( newname
),
317 backend
->intermediateDirectory
);
318 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( newname
) );
320 else //if ( module.type == IdlHeader )
322 newname
= basename
+ ".h";
323 return new FileLocation ( fileLocation
->directory
, filename
);
327 return new FileLocation ( fileLocation
->directory
, filename
);
331 MingwModuleHandler::GetExtraDependencies (
332 const string
& filename
) const
334 string extension
= GetExtension ( filename
);
335 if ( extension
== ".idl" || extension
== ".IDL" )
337 string basename
= GetBasename ( filename
);
338 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
339 return GetRpcServerHeaderFilename ( basename
) + " " + GetRpcClientHeaderFilename ( basename
);
341 return GetIdlHeaderFilename ( basename
);
348 MingwModuleHandler::GetCompilationUnitDependencies (
349 const CompilationUnit
& compilationUnit
) const
351 if ( compilationUnit
.files
.size () <= 1 )
353 vector
<string
> sourceFiles
;
354 for ( size_t i
= 0; i
< compilationUnit
.files
.size (); i
++ )
356 File
& file
= *compilationUnit
.files
[i
];
357 sourceFiles
.push_back ( NormalizeFilename ( file
.name
) );
359 return v2s ( sourceFiles
, 10 );
363 MingwModuleHandler::GetModuleArchiveFilename () const
365 if ( module
.type
== StaticLibrary
)
366 return GetTargetFilename ( module
, NULL
);
367 return PassThruCacheDirectory ( ReplaceExtension (
368 NormalizeFilename ( module
.GetPath () ),
370 backend
->intermediateDirectory
);
374 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
376 string extension
= GetExtension ( file
.name
);
377 return ( extension
== ".spec" || extension
== ".SPEC" );
381 MingwModuleHandler::ReferenceObjects (
382 const Module
& module
)
384 if ( module
.type
== ObjectLibrary
)
386 if ( module
.type
== RpcServer
)
388 if ( module
.type
== RpcClient
)
390 if ( module
.type
== IdlHeader
)
396 MingwModuleHandler::GetImportLibraryDependency (
397 const Module
& importedModule
)
400 if ( ReferenceObjects ( importedModule
) )
401 dep
= GetTargetMacro ( importedModule
);
403 dep
= GetImportLibraryFilename ( importedModule
, NULL
);
408 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
409 string_list
& targets
)
411 if ( dependencyModule
.invocations
.size () > 0 )
413 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
415 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
416 invoke
.GetTargets ( targets
);
420 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
424 MingwModuleHandler::GetModuleDependencies (
425 string_list
& dependencies
)
427 size_t iend
= module
.dependencies
.size ();
432 for ( size_t i
= 0; i
< iend
; i
++ )
434 const Dependency
& dependency
= *module
.dependencies
[i
];
435 const Module
& dependencyModule
= *dependency
.dependencyModule
;
436 GetTargets ( dependencyModule
,
439 GetDefinitionDependencies ( dependencies
);
443 MingwModuleHandler::GetSourceFilenames ( string_list
& list
,
444 bool includeGeneratedFiles
) const
448 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
449 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
451 if ( includeGeneratedFiles
|| !compilationUnits
[i
]->IsGeneratedFile () )
453 FileLocation
* sourceFileLocation
= GetActualSourceFilename (
454 compilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
) );
455 list
.push_back ( PassThruCacheDirectory ( sourceFileLocation
->filename
,
456 sourceFileLocation
->directory
) );
459 // intentionally make a copy so that we can append more work in
460 // the middle of processing without having to go recursive
461 vector
<If
*> v
= module
.non_if_data
.ifs
;
462 for ( i
= 0; i
< v
.size (); i
++ )
466 // check for sub-ifs to add to list
467 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
468 for ( j
= 0; j
< ifs
.size (); j
++ )
469 v
.push_back ( ifs
[j
] );
470 const vector
<CompilationUnit
*>& compilationUnits
= rIf
.data
.compilationUnits
;
471 for ( j
= 0; j
< compilationUnits
.size (); j
++ )
473 CompilationUnit
& compilationUnit
= *compilationUnits
[j
];
474 if ( includeGeneratedFiles
|| !compilationUnit
.IsGeneratedFile () )
476 FileLocation
* sourceFileLocation
= GetActualSourceFilename (
477 compilationUnit
.GetFilename ( backend
->intermediateDirectory
) );
478 list
.push_back ( PassThruCacheDirectory ( sourceFileLocation
->filename
,
479 sourceFileLocation
->directory
) );
486 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
487 string_list
& list
) const
489 GetSourceFilenames ( list
, false );
493 MingwModuleHandler::GetObjectFilename (
494 const FileLocation
* sourceFileLocation
,
495 string_list
* pclean_files
) const
497 string sourceFilename
= sourceFileLocation
->filename
;
498 Directory
* directoryTree
;
500 string extension
= GetExtension ( sourceFilename
);
501 if ( extension
== ".rc" || extension
== ".RC" )
502 newExtension
= ".coff";
503 else if ( extension
== ".spec" || extension
== ".SPEC" )
504 newExtension
= ".stubs.o";
505 else if ( extension
== ".idl" || extension
== ".IDL" )
507 if ( module
.type
== RpcServer
)
508 newExtension
= "_s.o";
509 else if ( module
.type
== RpcClient
)
510 newExtension
= "_c.o";
517 if ( module
.type
== BootSector
)
518 directoryTree
= backend
->outputDirectory
;
520 directoryTree
= backend
->intermediateDirectory
;
522 if (newExtension
== ".h")
523 directoryTree
= NULL
;
525 string obj_file
= PassThruCacheDirectory (
526 NormalizeFilename ( ReplaceExtension (
527 RemoveVariables ( sourceFilename
),
533 string_list
& clean_files
= *pclean_files
;
534 CLEAN_FILE ( obj_file
);
540 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
542 return module
.name
+ "_clean";
546 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
548 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
550 Library
& library
= *module
.non_if_data
.libraries
[i
];
551 if ( library
.importedModule
->type
== ObjectLibrary
)
552 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
557 MingwModuleHandler::GenerateCleanTarget () const
559 if ( module
.type
== Alias
)
563 ".PHONY: %s_clean\n",
564 module
.name
.c_str() );
565 vector
<string
> referencedModuleNames
;
566 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
569 GetModuleCleanTarget ( module
).c_str(),
570 v2s ( referencedModuleNames
, 10 ).c_str () );
571 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
574 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
575 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
577 fprintf ( fMakefile
, " 2>$(NUL)\n" );
578 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
582 MingwModuleHandler::GenerateInstallTarget () const
584 if ( module
.installName
.length () == 0 )
586 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
587 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
588 NormalizeFilename ( module
.installBase
+ sSep
+ module
.installName
),
589 backend
->installDirectory
);
592 module
.name
.c_str (),
593 normalizedTargetFilename
.c_str() );
597 MingwModuleHandler::GenerateDependsTarget () const
600 ".PHONY: %s_depends\n",
601 module
.name
.c_str() );
603 "%s_depends: $(RBUILD_TARGET)\n",
604 module
.name
.c_str () );
606 "\t$(ECHO_RBUILD)\n" );
608 "\t$(Q)$(RBUILD_TARGET) -dm%s mingw\n",
609 module
.name
.c_str () );
613 MingwModuleHandler::GetObjectFilenames ()
615 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
616 if ( compilationUnits
.size () == 0 )
619 string
objectFilenames ( "" );
620 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
622 if ( objectFilenames
.size () > 0 )
623 objectFilenames
+= " ";
624 objectFilenames
+= GetObjectFilename ( compilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
), NULL
);
626 return objectFilenames
;
630 MingwModuleHandler::GenerateGccDefineParametersFromVector (
631 const vector
<Define
*>& defines
)
634 for ( size_t i
= 0; i
< defines
.size (); i
++ )
636 Define
& define
= *defines
[i
];
637 if (parameters
.length () > 0)
640 parameters
+= define
.name
;
641 if (define
.value
.length () > 0)
644 parameters
+= define
.value
;
651 MingwModuleHandler::GenerateGccDefineParameters () const
653 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
654 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
655 if ( s
.length () > 0 )
664 MingwModuleHandler::ConcatenatePaths (
666 const string
& path2
) const
668 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
670 if ( path1
[path1
.length ()] == cSep
)
671 return path1
+ path2
;
673 return path1
+ cSep
+ path2
;
677 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
680 for ( size_t i
= 0; i
< includes
.size (); i
++ )
682 Include
& include
= *includes
[i
];
683 if ( parameters
.length () > 0 )
685 parameters
+= "-I" + include
.directory
;
691 MingwModuleHandler::GenerateGccIncludeParameters () const
693 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
694 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
695 if ( s
.length () > 0 )
704 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
707 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
709 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
710 if ( parameters
.length () > 0 )
712 parameters
+= compilerFlag
.flag
;
718 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
721 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
723 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
724 if ( parameters
.length () > 0 )
726 parameters
+= linkerFlag
.flag
;
732 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
733 const vector
<Library
*>& libraries
)
735 string
dependencies ( "" );
737 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
739 if ( wrap_count
++ == 5 )
740 dependencies
+= " \\\n\t\t", wrap_count
= 0;
741 else if ( dependencies
.size () > 0 )
743 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
749 MingwModuleHandler::GenerateLinkerParameters () const
751 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
755 MingwModuleHandler::GenerateMacro (
756 const char* assignmentOperation
,
758 const IfableData
& data
)
761 bool generateAssignment
;
763 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
764 if ( generateAssignment
)
769 assignmentOperation
);
772 if ( use_pch
&& module
.pch
!= NULL
)
776 GetDirectory ( GetPrecompiledHeaderFilename () ).c_str () );
779 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
780 if ( compilerParameters
.size () > 0 )
785 compilerParameters
.c_str () );
788 for ( i
= 0; i
< data
.includes
.size(); i
++ )
790 const Include
& include
= *data
.includes
[i
];
791 string includeDirectory
;
792 if ( include
.baseModule
!= NULL
&&
793 ( include
.baseModule
->type
== RpcServer
||
794 include
.baseModule
->type
== RpcClient
||
795 include
.baseModule
->type
== IdlHeader
) )
796 includeDirectory
= PassThruCacheDirectory ( NormalizeFilename ( include
.directory
),
797 backend
->intermediateDirectory
);
799 includeDirectory
= include
.directory
;
803 includeDirectory
.c_str() );
805 for ( i
= 0; i
< data
.defines
.size(); i
++ )
807 Define
& d
= *data
.defines
[i
];
812 if ( d
.value
.size() )
818 if ( generateAssignment
)
820 fprintf ( fMakefile
, "\n" );
825 MingwModuleHandler::GenerateMacros (
826 const char* assignmentOperation
,
827 const IfableData
& data
,
828 const vector
<LinkerFlag
*>* linkerFlags
)
832 GenerateMacro ( assignmentOperation
,
835 GenerateMacro ( assignmentOperation
,
839 if ( linkerFlags
!= NULL
)
841 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
842 if ( linkerParameters
.size () > 0 )
847 linkerflagsMacro
.c_str (),
849 linkerParameters
.c_str() );
853 if ( data
.libraries
.size () > 0 )
855 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
856 if ( deps
.size () > 0 )
867 const vector
<If
*>& ifs
= data
.ifs
;
868 for ( i
= 0; i
< ifs
.size(); i
++ )
871 if ( rIf
.data
.defines
.size()
872 || rIf
.data
.includes
.size()
873 || rIf
.data
.libraries
.size()
874 || rIf
.data
.compilationUnits
.size()
875 || rIf
.data
.compilerFlags
.size()
876 || rIf
.data
.ifs
.size() )
880 "%s (\"$(%s)\",\"%s\")\n",
881 rIf
.negated
? "ifneq" : "ifeq",
882 rIf
.property
.c_str(),
896 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
898 for (size_t i
= 0; i
< compilationUnits
.size (); i
++)
899 delete compilationUnits
[i
];
903 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
908 MingwModuleHandler::GenerateObjectMacros (
909 const char* assignmentOperation
,
910 const IfableData
& data
,
911 const vector
<LinkerFlag
*>* linkerFlags
)
915 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
916 if ( compilationUnits
.size () > 0 )
918 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
920 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
921 if ( compilationUnit
.IsFirstFile () )
925 objectsMacro
.c_str(),
926 GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
).c_str (),
927 objectsMacro
.c_str() );
933 objectsMacro
.c_str (),
934 assignmentOperation
);
935 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
937 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
938 if ( !compilationUnit
.IsFirstFile () )
943 ( i
%10 == 9 ? " \\\n\t" : " " ),
944 GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
).c_str () );
947 fprintf ( fMakefile
, "\n" );
950 const vector
<If
*>& ifs
= data
.ifs
;
951 for ( i
= 0; i
< ifs
.size(); i
++ )
954 if ( rIf
.data
.defines
.size()
955 || rIf
.data
.includes
.size()
956 || rIf
.data
.libraries
.size()
957 || rIf
.data
.compilationUnits
.size()
958 || rIf
.data
.compilerFlags
.size()
959 || rIf
.data
.ifs
.size() )
963 "%s (\"$(%s)\",\"%s\")\n",
964 rIf
.negated
? "ifneq" : "ifeq",
965 rIf
.property
.c_str(),
967 GenerateObjectMacros (
977 vector
<CompilationUnit
*> sourceCompilationUnits
;
978 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
979 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
984 objectsMacro
.c_str(),
985 GetObjectFilename ( sourceCompilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
), NULL
).c_str () );
987 CleanupCompilationUnitVector ( sourceCompilationUnits
);
991 MingwModuleHandler::GetPrecompiledHeaderFilename () const
993 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
994 return PassThruCacheDirectory ( NormalizeFilename ( basePchFilename
),
995 backend
->intermediateDirectory
);
999 MingwModuleHandler::GenerateGccCommand (
1000 const FileLocation
* sourceFileLocation
,
1001 const string
& extraDependencies
,
1003 const string
& cflagsMacro
)
1005 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1006 string dependencies
= sourceFilename
;
1007 if ( extraDependencies
!= "" )
1008 dependencies
+= " " + extraDependencies
;
1009 if ( module
.pch
&& use_pch
)
1010 dependencies
+= " " + GetPrecompiledHeaderFilename ();
1012 /* WIDL generated headers may be used */
1013 vector
<string
> rpcDependencies
;
1014 GetRpcHeaderDependencies ( rpcDependencies
);
1015 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1016 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1018 string objectFilename
= GetObjectFilename (
1019 sourceFileLocation
, &clean_files
);
1020 fprintf ( fMakefile
,
1022 objectFilename
.c_str (),
1023 dependencies
.c_str (),
1024 GetDirectory ( objectFilename
).c_str () );
1025 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
1026 fprintf ( fMakefile
,
1027 "\t%s -c $< -o $@ %s\n",
1029 cflagsMacro
.c_str () );
1033 MingwModuleHandler::GenerateGccAssemblerCommand (
1034 const FileLocation
* sourceFileLocation
,
1036 const string
& cflagsMacro
)
1038 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1039 string dependencies
= sourceFilename
;
1040 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1041 string objectFilename
= GetObjectFilename (
1042 sourceFileLocation
, &clean_files
);
1043 fprintf ( fMakefile
,
1045 objectFilename
.c_str (),
1046 dependencies
.c_str (),
1047 GetDirectory ( objectFilename
).c_str () );
1048 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
1049 fprintf ( fMakefile
,
1050 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
1052 cflagsMacro
.c_str () );
1056 MingwModuleHandler::GenerateNasmCommand (
1057 const FileLocation
* sourceFileLocation
,
1058 const string
& nasmflagsMacro
)
1060 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1061 string dependencies
= sourceFilename
;
1062 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1063 string objectFilename
= GetObjectFilename (
1064 sourceFileLocation
, &clean_files
);
1065 fprintf ( fMakefile
,
1067 objectFilename
.c_str (),
1068 dependencies
.c_str (),
1069 GetDirectory ( objectFilename
).c_str () );
1070 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1071 fprintf ( fMakefile
,
1072 "\t%s -f win32 $< -o $@ %s\n",
1074 nasmflagsMacro
.c_str () );
1078 MingwModuleHandler::GenerateWindresCommand (
1079 const FileLocation
* sourceFileLocation
,
1080 const string
& windresflagsMacro
)
1082 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1083 string dependencies
= sourceFilename
;
1084 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1085 string objectFilename
= GetObjectFilename ( sourceFileLocation
, &clean_files
);
1086 string sourceFilenamePart
= ReplaceExtension ( GetFilename ( sourceFilename
), "" );
1087 string rciFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".rci.tmp";
1088 string resFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".res.tmp";
1089 if ( module
.useWRC
)
1091 fprintf ( fMakefile
,
1092 "%s: %s $(WRC_TARGET) | %s\n",
1093 objectFilename
.c_str (),
1094 dependencies
.c_str (),
1095 GetDirectory ( objectFilename
).c_str () );
1096 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1097 fprintf ( fMakefile
,
1098 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1099 windresflagsMacro
.c_str (),
1100 sourceFilename
.c_str (),
1101 rciFilename
.c_str () );
1102 fprintf ( fMakefile
,
1103 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1104 windresflagsMacro
.c_str (),
1105 rciFilename
.c_str (),
1106 resFilename
.c_str () );
1107 fprintf ( fMakefile
,
1108 "\t-@${rm} %s 2>$(NUL)\n",
1109 rciFilename
.c_str () );
1110 fprintf ( fMakefile
,
1111 "\t${windres} %s -o $@\n",
1112 resFilename
.c_str () );
1113 fprintf ( fMakefile
,
1114 "\t-@${rm} %s 2>$(NUL)\n",
1115 resFilename
.c_str () );
1119 fprintf ( fMakefile
,
1120 "%s: %s $(WRC_TARGET) | %s\n",
1121 objectFilename
.c_str (),
1122 dependencies
.c_str (),
1123 GetDirectory ( objectFilename
).c_str () );
1124 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1125 fprintf ( fMakefile
,
1126 "\t${windres} $(%s) %s -o $@\n",
1127 windresflagsMacro
.c_str (),
1128 sourceFilename
.c_str () );
1133 MingwModuleHandler::GenerateWinebuildCommands (
1134 const FileLocation
* sourceFileLocation
)
1136 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1137 string dependencies
= sourceFilename
;
1138 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1140 string basename
= GetBasename ( sourceFilename
);
1141 string def_file
= PassThruCacheDirectory (
1142 basename
+ ".spec.def",
1143 backend
->intermediateDirectory
);
1144 CLEAN_FILE(def_file
);
1146 string stub_file
= PassThruCacheDirectory (
1147 basename
+ ".stubs.c",
1148 backend
->intermediateDirectory
);
1149 CLEAN_FILE(stub_file
)
1151 fprintf ( fMakefile
,
1152 "%s: %s $(WINEBUILD_TARGET) | %s\n",
1154 dependencies
.c_str (),
1155 GetDirectory ( def_file
).c_str () );
1156 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1157 fprintf ( fMakefile
,
1158 "\t%s -o %s --def -E %s\n",
1159 "$(Q)$(WINEBUILD_TARGET)",
1161 sourceFilename
.c_str () );
1162 fprintf ( fMakefile
,
1163 "%s: %s $(WINEBUILD_TARGET)\n",
1165 sourceFilename
.c_str () );
1166 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1167 fprintf ( fMakefile
,
1168 "\t%s -o %s --pedll %s\n",
1169 "$(Q)$(WINEBUILD_TARGET)",
1171 sourceFilename
.c_str () );
1175 MingwModuleHandler::GetWidlFlags ( const CompilationUnit
& compilationUnit
)
1177 return compilationUnit
.GetSwitches ();
1181 MingwModuleHandler::GetRpcServerHeaderFilename ( string basename
) const
1183 return PassThruCacheDirectory ( basename
+ "_s.h",
1184 backend
->intermediateDirectory
);
1188 MingwModuleHandler::GenerateWidlCommandsServer (
1189 const CompilationUnit
& compilationUnit
,
1190 const string
& widlflagsMacro
)
1192 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1193 string filename
= sourceFileLocation
->filename
;
1194 string dependencies
= filename
;
1195 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1197 string basename
= GetBasename ( filename
);
1199 string generatedHeaderFilename
= GetRpcServerHeaderFilename ( basename
);
1200 CLEAN_FILE(generatedHeaderFilename
);
1202 string generatedServerFilename
= PassThruCacheDirectory (
1204 backend
->intermediateDirectory
);
1205 CLEAN_FILE(generatedServerFilename
);
1207 fprintf ( fMakefile
,
1208 "%s %s: %s $(WIDL_TARGET) | %s\n",
1209 generatedServerFilename
.c_str (),
1210 generatedHeaderFilename
.c_str (),
1211 dependencies
.c_str (),
1212 GetDirectory ( generatedServerFilename
).c_str () );
1213 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1214 fprintf ( fMakefile
,
1215 "\t%s %s %s -h -H %s -s -S %s %s\n",
1216 "$(Q)$(WIDL_TARGET)",
1217 GetWidlFlags ( compilationUnit
).c_str (),
1218 widlflagsMacro
.c_str (),
1219 generatedHeaderFilename
.c_str (),
1220 generatedServerFilename
.c_str (),
1221 filename
.c_str () );
1225 MingwModuleHandler::GetRpcClientHeaderFilename ( string basename
) const
1227 return PassThruCacheDirectory ( basename
+ "_c.h",
1228 backend
->intermediateDirectory
);
1232 MingwModuleHandler::GetIdlHeaderFilename ( string basename
) const
1234 return basename
+ ".h";
1238 MingwModuleHandler::GenerateWidlCommandsClient (
1239 const CompilationUnit
& compilationUnit
,
1240 const string
& widlflagsMacro
)
1242 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1243 string filename
= sourceFileLocation
->filename
;
1244 string dependencies
= filename
;
1245 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1247 string basename
= GetBasename ( filename
);
1249 string generatedHeaderFilename
= GetRpcClientHeaderFilename ( basename
);
1250 CLEAN_FILE(generatedHeaderFilename
);
1252 string generatedClientFilename
= PassThruCacheDirectory (
1254 backend
->intermediateDirectory
);
1255 CLEAN_FILE(generatedClientFilename
);
1257 fprintf ( fMakefile
,
1258 "%s %s: %s $(WIDL_TARGET) | %s\n",
1259 generatedClientFilename
.c_str (),
1260 generatedHeaderFilename
.c_str (),
1261 dependencies
.c_str (),
1262 GetDirectory ( generatedClientFilename
).c_str () );
1263 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1264 fprintf ( fMakefile
,
1265 "\t%s %s %s -h -H %s -c -C %s %s\n",
1266 "$(Q)$(WIDL_TARGET)",
1267 GetWidlFlags ( compilationUnit
).c_str (),
1268 widlflagsMacro
.c_str (),
1269 generatedHeaderFilename
.c_str (),
1270 generatedClientFilename
.c_str (),
1271 filename
.c_str () );
1275 MingwModuleHandler::GenerateWidlCommandsIdlHeader (
1276 const CompilationUnit
& compilationUnit
,
1277 const string
& widlflagsMacro
)
1279 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1280 string filename
= sourceFileLocation
->filename
;
1281 string dependencies
= filename
;
1282 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1284 string basename
= GetBasename ( filename
);
1286 string generatedHeaderFilename
= GetIdlHeaderFilename ( basename
);
1287 CLEAN_FILE(generatedHeaderFilename
);
1289 fprintf ( fMakefile
,
1290 "%s: %s $(WIDL_TARGET) | %s\n",
1291 generatedHeaderFilename
.c_str (),
1292 dependencies
.c_str (),
1293 GetDirectory ( generatedHeaderFilename
).c_str () );
1294 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1295 fprintf ( fMakefile
,
1296 "\t%s %s %s -h -H %s %s\n",
1297 "$(Q)$(WIDL_TARGET)",
1298 GetWidlFlags ( compilationUnit
).c_str (),
1299 widlflagsMacro
.c_str (),
1300 generatedHeaderFilename
.c_str (),
1301 filename
.c_str () );
1305 MingwModuleHandler::GenerateWidlCommands (
1306 const CompilationUnit
& compilationUnit
,
1307 const string
& widlflagsMacro
)
1309 if ( module
.type
== RpcServer
)
1310 GenerateWidlCommandsServer ( compilationUnit
,
1312 else if ( module
.type
== RpcClient
)
1313 GenerateWidlCommandsClient ( compilationUnit
,
1316 GenerateWidlCommandsIdlHeader ( compilationUnit
,
1321 MingwModuleHandler::GenerateCommands (
1322 const CompilationUnit
& compilationUnit
,
1325 const string
& cflagsMacro
,
1326 const string
& nasmflagsMacro
,
1327 const string
& windresflagsMacro
,
1328 const string
& widlflagsMacro
)
1330 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1331 string filename
= sourceFileLocation
->filename
;
1332 string extension
= GetExtension ( filename
);
1333 if ( extension
== ".c" || extension
== ".C" )
1335 GenerateGccCommand ( sourceFileLocation
,
1336 GetCompilationUnitDependencies ( compilationUnit
),
1341 else if ( extension
== ".cc" || extension
== ".CC" ||
1342 extension
== ".cpp" || extension
== ".CPP" ||
1343 extension
== ".cxx" || extension
== ".CXX" )
1345 GenerateGccCommand ( sourceFileLocation
,
1346 GetCompilationUnitDependencies ( compilationUnit
),
1351 else if ( extension
== ".s" || extension
== ".S" )
1353 GenerateGccAssemblerCommand ( sourceFileLocation
,
1358 else if ( extension
== ".asm" || extension
== ".ASM" )
1360 GenerateNasmCommand ( sourceFileLocation
,
1364 else if ( extension
== ".rc" || extension
== ".RC" )
1366 GenerateWindresCommand ( sourceFileLocation
,
1367 windresflagsMacro
);
1370 else if ( extension
== ".spec" || extension
== ".SPEC" )
1372 GenerateWinebuildCommands ( sourceFileLocation
);
1373 GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation
),
1379 else if ( extension
== ".idl" || extension
== ".IDL" )
1381 GenerateWidlCommands ( compilationUnit
,
1383 if ( (module
.type
== RpcServer
) || (module
.type
== RpcClient
) )
1385 GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation
),
1386 GetExtraDependencies ( filename
),
1393 throw InvalidOperationException ( __FILE__
,
1395 "Unsupported filename extension '%s' in file '%s'",
1397 filename
.c_str () );
1401 MingwModuleHandler::GenerateBuildMapCode ( const char *mapTarget
)
1403 fprintf ( fMakefile
,
1404 "ifeq ($(ROS_BUILDMAP),full)\n" );
1406 string mapFilename
= PassThruCacheDirectory (
1407 GetBasename ( module
.GetPath () ) + ".map",
1408 backend
->outputDirectory
);
1409 CLEAN_FILE ( mapFilename
);
1411 fprintf ( fMakefile
,
1412 "\t$(ECHO_OBJDUMP)\n" );
1413 fprintf ( fMakefile
,
1414 "\t$(Q)${objdump} -d -S %s > %s\n",
1415 mapTarget
? mapTarget
: "$@",
1416 mapFilename
.c_str () );
1418 fprintf ( fMakefile
,
1420 fprintf ( fMakefile
,
1421 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1423 fprintf ( fMakefile
,
1425 fprintf ( fMakefile
,
1426 "\t$(Q)${nm} --numeric-sort %s > %s\n",
1427 mapTarget
? mapTarget
: "$@",
1428 mapFilename
.c_str () );
1430 fprintf ( fMakefile
,
1433 fprintf ( fMakefile
,
1438 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1440 fprintf ( fMakefile
,
1441 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1443 string filename
= module
.GetPath ();
1444 string outputFilename
= PassThruCacheDirectory (
1446 backend
->outputDirectory
);
1447 string nostripFilename
= PassThruCacheDirectory (
1448 GetBasename ( filename
) + ".nostrip" + GetExtension ( filename
),
1449 backend
->outputDirectory
);
1450 CLEAN_FILE ( nostripFilename
);
1452 fprintf ( fMakefile
,
1454 fprintf ( fMakefile
,
1455 "\t${cp} %s %s 1>$(NUL)\n",
1456 outputFilename
.c_str (),
1457 nostripFilename
.c_str () );
1459 fprintf ( fMakefile
,
1464 MergeStringVector ( const vector
<string
>& input
,
1465 vector
<string
>& output
)
1469 int wrap_count
= -1;
1470 for ( size_t i
= 0; i
< input
.size (); i
++ )
1472 if ( input
[i
].size () == 0 )
1474 if ( wrap_count
++ == wrap_at
)
1476 output
.push_back ( s
);
1480 else if ( s
.size () > 0)
1484 if ( s
.length () > 0 )
1485 output
.push_back ( s
);
1489 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1490 vector
<string
>& objectFiles
) const
1492 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1494 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1495 objectFiles
.push_back ( GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
) );
1500 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1502 if ( backend
->configuration
.CleanAsYouGo
)
1504 vector
<string
> objectFiles
;
1505 GetObjectsVector ( module
.non_if_data
,
1507 vector
<string
> lines
;
1508 MergeStringVector ( objectFiles
,
1510 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1512 fprintf ( fMakefile
,
1513 "\t-@${rm} %s 2>$(NUL)\n",
1514 lines
[i
].c_str () );
1520 MingwModuleHandler::GenerateRunRsymCode () const
1522 fprintf ( fMakefile
,
1523 "\t$(ECHO_RSYM)\n" );
1524 fprintf ( fMakefile
,
1525 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1529 MingwModuleHandler::GenerateRunStripCode () const
1531 fprintf ( fMakefile
,
1532 "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" );
1533 fprintf ( fMakefile
,
1534 "\t$(ECHO_STRIP)\n" );
1535 fprintf ( fMakefile
,
1536 "\t${strip} -s -x -X $@\n\n" );
1537 fprintf ( fMakefile
,
1542 MingwModuleHandler::GenerateLinkerCommand (
1543 const string
& dependencies
,
1544 const string
& linker
,
1545 const string
& linkerParameters
,
1546 const string
& objectsMacro
,
1547 const string
& libsMacro
,
1548 const string
& pefixupParameters
)
1550 string
target ( GetTargetMacro ( module
) );
1551 string
target_folder ( GetDirectory ( GetTargetFilename ( module
, NULL
) ) );
1552 string definitionFilename
= GetDefinitionFilename ();
1554 string linkerScriptArgument
;
1555 if ( module
.linkerScript
!= NULL
)
1556 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", module
.linkerScript
->directory
.c_str () );
1558 linkerScriptArgument
= "";
1560 fprintf ( fMakefile
,
1561 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1563 definitionFilename
.c_str (),
1564 dependencies
.c_str (),
1565 target_folder
.c_str () );
1566 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1567 string
targetName ( module
.GetTargetName () );
1569 if ( module
.IsDLL () )
1571 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1572 CLEAN_FILE ( temp_exp
);
1574 fprintf ( fMakefile
,
1575 "\t${dlltool} --dllname %s --def %s --output-exp %s %s %s\n",
1576 targetName
.c_str (),
1577 definitionFilename
.c_str (),
1579 module
.mangledSymbols
? "" : "--kill-at",
1580 module
.underscoreSymbols
? "--add-underscore" : "" );
1582 fprintf ( fMakefile
,
1583 "\t%s %s %s %s -o %s %s %s %s\n",
1585 linkerParameters
.c_str (),
1586 linkerScriptArgument
.c_str (),
1589 objectsMacro
.c_str (),
1591 GetLinkerMacro ().c_str () );
1593 fprintf ( fMakefile
,
1594 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1596 pefixupParameters
.c_str() );
1598 fprintf ( fMakefile
,
1599 "\t-@${rm} %s 2>$(NUL)\n",
1600 temp_exp
.c_str () );
1604 fprintf ( fMakefile
,
1605 "\t%s %s %s -o %s %s %s %s\n",
1607 linkerParameters
.c_str (),
1608 linkerScriptArgument
.c_str (),
1610 objectsMacro
.c_str (),
1612 GetLinkerMacro ().c_str () );
1614 #if 0 // causes crashes sometimes
1615 fprintf ( fMakefile
,
1616 "\t${objcopy} -R .edata %s\n",
1621 GenerateBuildMapCode ();
1622 GenerateBuildNonSymbolStrippedCode ();
1623 GenerateRunRsymCode ();
1624 GenerateRunStripCode ();
1625 GenerateCleanObjectsAsYouGoCode ();
1629 MingwModuleHandler::GeneratePhonyTarget() const
1631 string
targetMacro ( GetTargetMacro ( module
) );
1632 fprintf ( fMakefile
,
1634 targetMacro
.c_str ());
1635 fprintf ( fMakefile
, "%s: | %s\n",
1636 targetMacro
.c_str (),
1637 GetDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1641 MingwModuleHandler::GenerateObjectFileTargets (
1642 const IfableData
& data
,
1645 const string
& cflagsMacro
,
1646 const string
& nasmflagsMacro
,
1647 const string
& windresflagsMacro
,
1648 const string
& widlflagsMacro
)
1652 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1653 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1655 GenerateCommands ( *compilationUnits
[i
],
1662 fprintf ( fMakefile
,
1666 const vector
<If
*>& ifs
= data
.ifs
;
1667 for ( i
= 0; i
< ifs
.size(); i
++ )
1669 GenerateObjectFileTargets ( ifs
[i
]->data
,
1678 vector
<CompilationUnit
*> sourceCompilationUnits
;
1679 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1680 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1682 GenerateCommands ( *sourceCompilationUnits
[i
],
1690 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1694 MingwModuleHandler::GenerateObjectFileTargets (
1697 const string
& cflagsMacro
,
1698 const string
& nasmflagsMacro
,
1699 const string
& windresflagsMacro
,
1700 const string
& widlflagsMacro
)
1702 if ( module
.pch
&& use_pch
)
1704 const string
& baseHeaderFilename
= module
.pch
->file
.name
;
1705 const string
& pchFilename
= GetPrecompiledHeaderFilename ();
1706 CLEAN_FILE(pchFilename
);
1707 string dependencies
= baseHeaderFilename
;
1708 /* WIDL generated headers may be used */
1709 vector
<string
> rpcDependencies
;
1710 GetRpcHeaderDependencies ( rpcDependencies
);
1711 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1712 fprintf ( fMakefile
,
1714 pchFilename
.c_str(),
1715 dependencies
.c_str() );
1716 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1717 fprintf ( fMakefile
,
1718 "\t%s -o %s %s -g %s\n\n",
1719 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1720 pchFilename
.c_str(),
1721 cflagsMacro
.c_str(),
1722 baseHeaderFilename
.c_str() );
1725 GenerateObjectFileTargets ( module
.non_if_data
,
1732 fprintf ( fMakefile
, "\n" );
1736 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1737 const string
& objs_macro
) const
1739 string
archiveFilename ( GetModuleArchiveFilename () );
1741 fprintf ( fMakefile
,
1743 archiveFilename
.c_str (),
1744 objs_macro
.c_str (),
1745 GetDirectory(archiveFilename
).c_str() );
1747 if ( module
.type
== StaticLibrary
&& module
.importLibrary
)
1749 string
archiveFilename ( GetModuleArchiveFilename () );
1750 string
definitionFilename ( GetDefinitionFilename () );
1752 fprintf ( fMakefile
,
1753 "\t${dlltool} --dllname %s --def %s --output-lib $@ %s %s\n",
1754 module
.importLibrary
->dllname
.c_str (),
1755 definitionFilename
.c_str (),
1756 module
.mangledSymbols
? "" : "--kill-at",
1757 module
.underscoreSymbols
? "--add-underscore" : "" );
1760 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1762 fprintf ( fMakefile
,
1765 objs_macro
.c_str ());
1767 GenerateCleanObjectsAsYouGoCode ();
1769 fprintf ( fMakefile
, "\n" );
1771 return archiveFilename
;
1775 MingwModuleHandler::GetCFlagsMacro () const
1777 return ssprintf ( "$(%s_CFLAGS)",
1778 module
.name
.c_str () );
1782 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1784 return ssprintf ( "$(%s_OBJS)",
1785 module
.name
.c_str () );
1789 MingwModuleHandler::GetLinkingDependenciesMacro () const
1791 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1795 MingwModuleHandler::GetLibsMacro () const
1797 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1801 MingwModuleHandler::GetLinkerMacro () const
1803 return ssprintf ( "$(%s_LFLAGS)",
1804 module
.name
.c_str () );
1808 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1810 if ( ReferenceObjects ( module
) )
1811 return GetObjectsMacro ( module
);
1813 return GetTargetFilename ( module
, NULL
);
1817 MingwModuleHandler::GenerateObjectMacro ()
1819 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1821 GenerateObjectMacros (
1824 &module
.linkerFlags
);
1826 // future references to the macro will be to get its values
1827 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1831 MingwModuleHandler::GenerateTargetMacro ()
1833 fprintf ( fMakefile
,
1835 GetTargetMacro ( module
, false ).c_str (),
1836 GetModuleTargets ( module
).c_str () );
1840 MingwModuleHandler::GetRpcHeaderDependencies (
1841 vector
<string
>& dependencies
) const
1843 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1845 Library
& library
= *module
.non_if_data
.libraries
[i
];
1846 if ( library
.importedModule
->type
== RpcServer
||
1847 library
.importedModule
->type
== RpcClient
||
1848 library
.importedModule
->type
== IdlHeader
)
1850 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
1852 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
1853 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1854 string extension
= GetExtension ( sourceFileLocation
->filename
);
1855 if ( extension
== ".idl" || extension
== ".IDL" )
1857 string basename
= GetBasename ( sourceFileLocation
->filename
);
1858 if ( library
.importedModule
->type
== RpcServer
)
1859 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
1860 if ( library
.importedModule
->type
== RpcClient
)
1861 dependencies
.push_back ( GetRpcClientHeaderFilename ( basename
) );
1862 if ( library
.importedModule
->type
== IdlHeader
)
1863 dependencies
.push_back ( GetIdlHeaderFilename ( basename
) );
1871 MingwModuleHandler::GenerateOtherMacros ()
1873 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1874 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1875 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1876 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1877 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1878 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1879 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1884 &module
.linkerFlags
);
1887 if ( module
.importLibrary
)
1889 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
1890 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
1892 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1893 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1894 string extension
= GetExtension ( sourceFileLocation
->filename
);
1895 if ( extension
== ".spec" || extension
== ".SPEC" )
1896 GetSpecObjectDependencies ( s
, sourceFileLocation
->filename
);
1899 if ( s
.size () > 0 )
1904 linkDepsMacro
.c_str() );
1905 for ( size_t i
= 0; i
< s
.size(); i
++ )
1906 fprintf ( fMakefile
,
1909 fprintf ( fMakefile
, "\n" );
1912 string globalCflags
= "-g";
1913 if ( backend
->usePipe
)
1914 globalCflags
+= " -pipe";
1915 if ( !module
.allowWarnings
)
1916 globalCflags
+= " -Werror";
1918 // Always force disabling of sibling calls optimisation for GCC
1919 // (TODO: Move to version-specific once this bug is fixed in GCC)
1920 globalCflags
+= " -fno-optimize-sibling-calls";
1924 "%s += $(PROJECT_CFLAGS) %s\n",
1925 cflagsMacro
.c_str (),
1926 globalCflags
.c_str () );
1930 "%s += $(PROJECT_RCFLAGS)\n",
1931 windresflagsMacro
.c_str () );
1935 "%s += $(PROJECT_WIDLFLAGS)\n",
1936 widlflagsMacro
.c_str () );
1940 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1941 module
.name
.c_str () );
1946 linkDepsMacro
.c_str (),
1947 libsMacro
.c_str () );
1949 string cflags
= TypeSpecificCFlags();
1950 if ( cflags
.size() > 0 )
1952 fprintf ( fMakefile
,
1954 cflagsMacro
.c_str (),
1958 string nasmflags
= TypeSpecificNasmFlags();
1959 if ( nasmflags
.size () > 0 )
1961 fprintf ( fMakefile
,
1963 nasmflagsMacro
.c_str (),
1964 nasmflags
.c_str () );
1967 string linkerflags
= TypeSpecificLinkerFlags();
1968 if ( linkerflags
.size() > 0 )
1970 fprintf ( fMakefile
,
1972 linkerflagsMacro
.c_str (),
1973 linkerflags
.c_str () );
1976 if ( module
.type
== StaticLibrary
&& module
.isStartupLib
)
1978 fprintf ( fMakefile
,
1979 "%s += -Wno-main\n\n",
1980 cflagsMacro
.c_str () );
1983 fprintf ( fMakefile
, "\n\n" );
1985 // future references to the macros will be to get their values
1986 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1987 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1988 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
1992 MingwModuleHandler::GenerateRules ()
1994 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1995 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1996 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1998 if ( module
.name
!= "zlib" ) /* Avoid make warning */
2000 string proxyMakefile
= PassThruCacheDirectory (
2001 NormalizeFilename ( module
.GetBasePath () + sSep
+ "makefile" ),
2002 backend
->outputDirectory
);
2003 CLEAN_FILE ( proxyMakefile
);
2006 string targetMacro
= GetTargetMacro ( module
);
2007 CLEAN_FILE ( targetMacro
);
2009 // generate phony target for module name
2010 fprintf ( fMakefile
, ".PHONY: %s\n",
2011 module
.name
.c_str () );
2012 string dependencies
= GetTargetMacro ( module
);
2013 if ( module
.type
== Test
)
2014 dependencies
+= " $(REGTESTS_RUN_TARGET)";
2015 fprintf ( fMakefile
, "%s: %s\n\n",
2016 module
.name
.c_str (),
2017 dependencies
.c_str () );
2018 if ( module
.type
== Test
)
2020 fprintf ( fMakefile
,
2022 targetMacro
.c_str ());
2025 if ( !ReferenceObjects ( module
) )
2027 string
ar_target ( GenerateArchiveTarget ( ar
, objectsMacro
) );
2028 if ( targetMacro
!= ar_target
)
2029 CLEAN_FILE ( ar_target
);
2032 GenerateObjectFileTargets ( cc
,
2041 MingwModuleHandler::GetInvocationDependencies (
2042 const Module
& module
,
2043 string_list
& dependencies
)
2045 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
2047 Invoke
& invoke
= *module
.invocations
[i
];
2048 if ( invoke
.invokeModule
== &module
)
2049 /* Protect against circular dependencies */
2051 invoke
.GetTargets ( dependencies
);
2056 MingwModuleHandler::GenerateInvocations () const
2058 if ( module
.invocations
.size () == 0 )
2061 size_t iend
= module
.invocations
.size ();
2062 for ( size_t i
= 0; i
< iend
; i
++ )
2064 const Invoke
& invoke
= *module
.invocations
[i
];
2066 if ( invoke
.invokeModule
->type
!= BuildTool
)
2068 throw XMLInvalidBuildFileException (
2069 module
.node
.location
,
2070 "Only modules of type buildtool can be invoked." );
2073 string invokeTarget
= module
.GetInvocationTarget ( i
);
2074 string_list invoke_targets
;
2075 assert ( invoke_targets
.size() );
2076 invoke
.GetTargets ( invoke_targets
);
2077 fprintf ( fMakefile
,
2079 invokeTarget
.c_str () );
2080 fprintf ( fMakefile
,
2082 invokeTarget
.c_str () );
2083 size_t j
, jend
= invoke_targets
.size();
2084 for ( j
= 0; j
< jend
; j
++ )
2086 fprintf ( fMakefile
,
2088 invoke_targets
[i
].c_str () );
2090 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
2091 for ( j
= 1; j
< jend
; j
++ )
2092 fprintf ( fMakefile
,
2094 invoke_targets
[i
].c_str () );
2095 fprintf ( fMakefile
,
2097 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
2098 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
2099 fprintf ( fMakefile
,
2101 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
2102 invoke
.GetParameters ().c_str () );
2107 MingwModuleHandler::GetPreconditionDependenciesName () const
2109 return module
.name
+ "_precondition";
2113 MingwModuleHandler::GetDefaultDependencies (
2114 string_list
& dependencies
) const
2116 /* Avoid circular dependency */
2117 if ( module
.type
!= BuildTool
2118 && module
.name
!= "zlib"
2119 && module
.name
!= "hostzlib" )
2121 dependencies
.push_back ( "$(INIT)" );
2125 MingwModuleHandler::GeneratePreconditionDependencies ()
2127 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2128 string_list sourceFilenames
;
2129 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
2130 string_list dependencies
;
2131 GetDefaultDependencies ( dependencies
);
2132 GetModuleDependencies ( dependencies
);
2134 GetInvocationDependencies ( module
, dependencies
);
2136 if ( dependencies
.size() )
2138 fprintf ( fMakefile
,
2140 preconditionDependenciesName
.c_str () );
2141 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2142 fprintf ( fMakefile
,
2144 dependencies
[i
].c_str () );
2145 fprintf ( fMakefile
, "\n\n" );
2148 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
2150 fprintf ( fMakefile
,
2152 sourceFilenames
[i
].c_str(),
2153 preconditionDependenciesName
.c_str ());
2155 fprintf ( fMakefile
, "\n" );
2159 MingwModuleHandler::IsWineModule () const
2161 if ( module
.importLibrary
== NULL
)
2164 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
2165 return ( index
!= string::npos
);
2169 MingwModuleHandler::GetDefinitionFilename () const
2171 if ( module
.importLibrary
!= NULL
)
2173 string defFilename
= module
.GetBasePath () + sSep
+ module
.importLibrary
->definition
;
2174 if ( IsWineModule () )
2175 return PassThruCacheDirectory ( NormalizeFilename ( defFilename
),
2176 backend
->intermediateDirectory
);
2181 return "tools" + sSep
+ "rbuild" + sSep
+ "empty.def";
2185 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2187 if ( module
.importLibrary
!= NULL
)
2189 string
library_target (
2190 GetImportLibraryFilename ( module
, &clean_files
) );
2191 string defFilename
= GetDefinitionFilename ();
2194 GetDefinitionDependencies ( deps
);
2196 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2198 fprintf ( fMakefile
, "%s: %s",
2199 library_target
.c_str (),
2200 defFilename
.c_str () );
2202 size_t i
, iend
= deps
.size();
2203 for ( i
= 0; i
< iend
; i
++ )
2204 fprintf ( fMakefile
, " %s",
2207 fprintf ( fMakefile
, " | %s\n",
2208 GetDirectory ( GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2210 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2212 fprintf ( fMakefile
,
2213 "\t${dlltool} --dllname %s --def %s --output-lib %s %s %s\n\n",
2214 module
.GetTargetName ().c_str (),
2215 defFilename
.c_str (),
2216 library_target
.c_str (),
2217 module
.mangledSymbols
? "" : "--kill-at",
2218 module
.underscoreSymbols
? "--add-underscore" : "" );
2223 MingwModuleHandler::GetSpecObjectDependencies (
2224 string_list
& dependencies
,
2225 const string
& filename
) const
2227 string basename
= GetBasename ( filename
);
2228 string defDependency
= PassThruCacheDirectory (
2229 NormalizeFilename ( basename
+ ".spec.def" ),
2230 backend
->intermediateDirectory
);
2231 dependencies
.push_back ( defDependency
);
2232 string stubsDependency
= PassThruCacheDirectory (
2233 NormalizeFilename ( basename
+ ".stubs.c" ),
2234 backend
->intermediateDirectory
);
2235 dependencies
.push_back ( stubsDependency
);
2239 MingwModuleHandler::GetWidlObjectDependencies (
2240 string_list
& dependencies
,
2241 const string
& filename
) const
2243 string basename
= GetBasename ( filename
);
2244 string serverSourceDependency
= PassThruCacheDirectory (
2245 NormalizeFilename ( basename
+ "_s.c" ),
2246 backend
->intermediateDirectory
);
2247 dependencies
.push_back ( serverSourceDependency
);
2248 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
2252 MingwModuleHandler::GetDefinitionDependencies (
2253 string_list
& dependencies
) const
2255 string dkNkmLibNoFixup
= "dk/nkm/lib";
2256 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2257 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2259 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2260 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
2261 string extension
= GetExtension ( sourceFileLocation
->filename
);
2262 if ( extension
== ".spec" || extension
== ".SPEC" )
2263 GetSpecObjectDependencies ( dependencies
, sourceFileLocation
->filename
);
2264 if ( extension
== ".idl" || extension
== ".IDL" )
2266 if ( ( module
.type
== RpcServer
) || ( module
.type
== RpcClient
) )
2267 GetWidlObjectDependencies ( dependencies
, sourceFileLocation
->filename
);
2272 enum DebugSupportType
2279 MingwAddDebugSupportLibraries ( Module
& module
, DebugSupportType type
)
2285 case DebugKernelMode
:
2286 pLibrary
= new Library ( module
, "debugsup_ntoskrnl" );
2290 pLibrary
= new Library ( module
, "debugsup_ntdll" );
2297 module
.non_if_data
.libraries
.push_back(pLibrary
);
2300 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2301 : MingwModuleHandler ( module_
)
2306 MingwBuildToolModuleHandler::Process ()
2308 GenerateBuildToolModuleTarget ();
2312 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2314 string
targetMacro ( GetTargetMacro (module
) );
2315 string objectsMacro
= GetObjectsMacro ( module
);
2316 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2317 string libsMacro
= GetLibsMacro ();
2322 if ( module
.cplusplus
)
2323 linker
= "${host_gpp}";
2325 linker
= "${host_gcc}";
2327 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2328 targetMacro
.c_str (),
2329 objectsMacro
.c_str (),
2330 linkDepsMacro
.c_str (),
2331 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2332 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2333 fprintf ( fMakefile
,
2334 "\t%s %s -o $@ %s %s\n\n",
2336 GetLinkerMacro ().c_str (),
2337 objectsMacro
.c_str (),
2338 libsMacro
.c_str () );
2342 MingwKernelModuleHandler::MingwKernelModuleHandler (
2343 const Module
& module_
)
2345 : MingwModuleHandler ( module_
)
2350 MingwKernelModuleHandler::Process ()
2352 GenerateKernelModuleTarget ();
2356 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2358 string
targetMacro ( GetTargetMacro ( module
) );
2359 string workingDirectory
= GetWorkingDirectory ( );
2360 string objectsMacro
= GetObjectsMacro ( module
);
2361 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2362 string libsMacro
= GetLibsMacro ();
2364 GenerateImportLibraryTargetIfNeeded ();
2366 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2370 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2372 string linkerParameters
= ssprintf ( "-Wl,-T,%s%cntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2373 module
.GetBasePath ().c_str (),
2375 module
.GetEntryPoint(true).c_str (),
2376 module
.baseaddress
.c_str () );
2377 GenerateLinkerCommand ( dependencies
,
2386 GeneratePhonyTarget();
2391 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2392 const Module
& module_
)
2394 : MingwModuleHandler ( module_
)
2399 MingwStaticLibraryModuleHandler::Process ()
2401 GenerateStaticLibraryModuleTarget ();
2405 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2411 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2412 const Module
& module_
)
2414 : MingwModuleHandler ( module_
)
2419 MingwObjectLibraryModuleHandler::Process ()
2421 GenerateObjectLibraryModuleTarget ();
2425 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2431 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2432 const Module
& module_
)
2434 : MingwModuleHandler ( module_
)
2439 MingwKernelModeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2441 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2445 MingwKernelModeDLLModuleHandler::Process ()
2447 GenerateKernelModeDLLModuleTarget ();
2451 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2453 string
targetMacro ( GetTargetMacro ( module
) );
2454 string workingDirectory
= GetWorkingDirectory ( );
2455 string objectsMacro
= GetObjectsMacro ( module
);
2456 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2457 string libsMacro
= GetLibsMacro ();
2459 GenerateImportLibraryTargetIfNeeded ();
2461 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2465 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2467 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2468 module
.GetEntryPoint(true).c_str (),
2469 module
.baseaddress
.c_str () );
2470 GenerateLinkerCommand ( dependencies
,
2479 GeneratePhonyTarget();
2484 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2485 const Module
& module_
)
2487 : MingwModuleHandler ( module_
)
2492 MingwKernelModeDriverModuleHandler::AddImplicitLibraries ( Module
& module
)
2494 MingwAddDebugSupportLibraries ( module
, DebugKernelMode
);
2498 MingwKernelModeDriverModuleHandler::Process ()
2500 GenerateKernelModeDriverModuleTarget ();
2505 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2507 string
targetMacro ( GetTargetMacro (module
) );
2508 string workingDirectory
= GetWorkingDirectory ();
2509 string objectsMacro
= GetObjectsMacro ( module
);
2510 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2511 string libsMacro
= GetLibsMacro ();
2513 GenerateImportLibraryTargetIfNeeded ();
2515 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2519 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2521 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2522 module
.GetEntryPoint(true).c_str (),
2523 module
.baseaddress
.c_str () );
2524 GenerateLinkerCommand ( dependencies
,
2533 GeneratePhonyTarget();
2538 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2539 const Module
& module_
)
2541 : MingwModuleHandler ( module_
)
2546 MingwNativeDLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2548 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2552 MingwNativeDLLModuleHandler::Process ()
2554 GenerateNativeDLLModuleTarget ();
2558 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2560 string
targetMacro ( GetTargetMacro (module
) );
2561 string workingDirectory
= GetWorkingDirectory ( );
2562 string objectsMacro
= GetObjectsMacro ( module
);
2563 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2564 string libsMacro
= GetLibsMacro ();
2566 GenerateImportLibraryTargetIfNeeded ();
2568 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2572 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2574 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2575 module
.GetEntryPoint(true).c_str (),
2576 module
.baseaddress
.c_str () );
2577 GenerateLinkerCommand ( dependencies
,
2586 GeneratePhonyTarget();
2591 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2592 const Module
& module_
)
2594 : MingwModuleHandler ( module_
)
2599 MingwNativeCUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2601 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2605 MingwNativeCUIModuleHandler::Process ()
2607 GenerateNativeCUIModuleTarget ();
2611 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2613 string
targetMacro ( GetTargetMacro (module
) );
2614 string workingDirectory
= GetWorkingDirectory ( );
2615 string objectsMacro
= GetObjectsMacro ( module
);
2616 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2617 string libsMacro
= GetLibsMacro ();
2619 GenerateImportLibraryTargetIfNeeded ();
2621 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2625 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2627 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2628 module
.GetEntryPoint(true).c_str (),
2629 module
.baseaddress
.c_str () );
2630 GenerateLinkerCommand ( dependencies
,
2639 GeneratePhonyTarget();
2644 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2645 const Module
& module_
)
2647 : MingwModuleHandler ( module_
)
2652 MingwAddImplicitLibraries( Module
&module
)
2656 if ( !module
.isDefaultEntryPoint
)
2659 if ( module
.IsDLL () )
2661 //pLibrary = new Library ( module, "__mingw_dllmain" );
2662 //module.non_if_data.libraries.insert ( module.non_if_data.libraries.begin(), pLibrary );
2666 pLibrary
= new Library ( module
, module
.isUnicode
? "mingw_wmain" : "mingw_main" );
2667 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin(), pLibrary
);
2670 pLibrary
= new Library ( module
, "mingw_common" );
2671 module
.non_if_data
.libraries
.insert ( module
.non_if_data
.libraries
.begin() + 1, pLibrary
);
2673 if ( module
.name
!= "msvcrt" )
2675 // always link in msvcrt to get the basic routines
2676 pLibrary
= new Library ( module
, "msvcrt" );
2677 module
.non_if_data
.libraries
.push_back ( pLibrary
);
2682 MingwWin32DLLModuleHandler::AddImplicitLibraries ( Module
& module
)
2684 MingwAddImplicitLibraries ( module
);
2685 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2689 MingwWin32DLLModuleHandler::Process ()
2691 GenerateWin32DLLModuleTarget ();
2695 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2697 string
targetMacro ( GetTargetMacro (module
) );
2698 string workingDirectory
= GetWorkingDirectory ( );
2699 string objectsMacro
= GetObjectsMacro ( module
);
2700 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2701 string libsMacro
= GetLibsMacro ();
2703 GenerateImportLibraryTargetIfNeeded ();
2705 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2709 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2712 if ( module
.cplusplus
)
2717 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2718 module
.GetEntryPoint(true).c_str (),
2719 module
.baseaddress
.c_str () );
2720 GenerateLinkerCommand ( dependencies
,
2729 GeneratePhonyTarget();
2734 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2735 const Module
& module_
)
2737 : MingwModuleHandler ( module_
)
2742 MingwWin32CUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2744 MingwAddImplicitLibraries ( module
);
2745 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2749 MingwWin32CUIModuleHandler::Process ()
2751 GenerateWin32CUIModuleTarget ();
2755 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2757 string
targetMacro ( GetTargetMacro (module
) );
2758 string workingDirectory
= GetWorkingDirectory ( );
2759 string objectsMacro
= GetObjectsMacro ( module
);
2760 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2761 string libsMacro
= GetLibsMacro ();
2763 GenerateImportLibraryTargetIfNeeded ();
2765 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2769 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2772 if ( module
.cplusplus
)
2777 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2778 module
.GetEntryPoint(true).c_str (),
2779 module
.baseaddress
.c_str () );
2780 GenerateLinkerCommand ( dependencies
,
2789 GeneratePhonyTarget();
2794 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2795 const Module
& module_
)
2797 : MingwModuleHandler ( module_
)
2802 MingwWin32GUIModuleHandler::AddImplicitLibraries ( Module
& module
)
2804 MingwAddImplicitLibraries ( module
);
2805 MingwAddDebugSupportLibraries ( module
, DebugUserMode
);
2809 MingwWin32GUIModuleHandler::Process ()
2811 GenerateWin32GUIModuleTarget ();
2815 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2817 string
targetMacro ( GetTargetMacro (module
) );
2818 string workingDirectory
= GetWorkingDirectory ( );
2819 string objectsMacro
= GetObjectsMacro ( module
);
2820 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2821 string libsMacro
= GetLibsMacro ();
2823 GenerateImportLibraryTargetIfNeeded ();
2825 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2829 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2832 if ( module
.cplusplus
)
2837 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2838 module
.GetEntryPoint(true).c_str (),
2839 module
.baseaddress
.c_str () );
2840 GenerateLinkerCommand ( dependencies
,
2849 GeneratePhonyTarget();
2854 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2855 const Module
& module_
)
2857 : MingwModuleHandler ( module_
)
2862 MingwBootLoaderModuleHandler::Process ()
2864 GenerateBootLoaderModuleTarget ();
2868 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2870 string
targetName ( module
.GetTargetName () );
2871 string
targetMacro ( GetTargetMacro (module
) );
2872 string workingDirectory
= GetWorkingDirectory ();
2873 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2874 CLEAN_FILE ( junk_tmp
);
2875 string objectsMacro
= GetObjectsMacro ( module
);
2876 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2877 string libsMacro
= GetLibsMacro ();
2881 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2882 targetMacro
.c_str (),
2883 objectsMacro
.c_str (),
2884 linkDepsMacro
.c_str (),
2885 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2887 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2889 fprintf ( fMakefile
,
2890 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2891 GetLinkerMacro ().c_str (),
2893 objectsMacro
.c_str (),
2894 linkDepsMacro
.c_str () );
2895 fprintf ( fMakefile
,
2896 "\t${objcopy} -O binary %s $@\n",
2897 junk_tmp
.c_str () );
2898 GenerateBuildMapCode ( junk_tmp
.c_str() );
2899 fprintf ( fMakefile
,
2900 "\t-@${rm} %s 2>$(NUL)\n",
2901 junk_tmp
.c_str () );
2905 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2906 const Module
& module_
)
2908 : MingwModuleHandler ( module_
)
2913 MingwBootSectorModuleHandler::Process ()
2915 GenerateBootSectorModuleTarget ();
2919 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2921 string objectsMacro
= GetObjectsMacro ( module
);
2925 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2926 module
.name
.c_str ());
2927 fprintf ( fMakefile
,
2929 module
.name
.c_str (),
2930 objectsMacro
.c_str () );
2934 MingwBootProgramModuleHandler::MingwBootProgramModuleHandler (
2935 const Module
& module_
)
2936 : MingwModuleHandler ( module_
)
2941 MingwBootProgramModuleHandler::Process ()
2943 GenerateBootProgramModuleTarget ();
2947 MingwBootProgramModuleHandler::GenerateBootProgramModuleTarget ()
2949 string
targetName ( module
.GetTargetName () );
2950 string
targetMacro ( GetTargetMacro (module
) );
2951 string workingDirectory
= GetWorkingDirectory ();
2952 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2953 string junk_elf
= ros_temp
+ module
.name
+ ".junk.elf";
2954 string junk_cpy
= ros_temp
+ module
.name
+ ".junk.cpy";
2955 CLEAN_FILE ( junk_tmp
);
2956 CLEAN_FILE ( junk_elf
);
2957 CLEAN_FILE ( junk_cpy
);
2958 string objectsMacro
= GetObjectsMacro ( module
);
2959 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2960 string libsMacro
= GetLibsMacro ();
2961 const Module
*payload
= module
.project
.LocateModule ( module
.payload
);
2965 fprintf ( fMakefile
, "%s: %s %s %s | %s\n",
2966 targetMacro
.c_str (),
2967 objectsMacro
.c_str (),
2968 linkDepsMacro
.c_str (),
2969 payload
->name
.c_str (),
2970 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2972 fprintf ( fMakefile
, "\t$(ECHO_BOOTPROG)\n" );
2974 fprintf ( fMakefile
, "\t$(BOOTPROG_PREPARE) $(OUTPUT)$(SEP)%s %s\n",
2975 NormalizeFilename( payload
->GetPath() ).c_str (),
2976 junk_cpy
.c_str () );
2978 fprintf ( fMakefile
, "\t${objcopy} $(BOOTPROG_FLATFORMAT) %s %s\n",
2980 junk_tmp
.c_str () );
2982 fprintf ( fMakefile
, "\t${ld} $(BOOTPROG_LINKFORMAT) %s %s -g -o %s\n",
2983 linkDepsMacro
.c_str (),
2985 junk_elf
.c_str () );
2987 fprintf ( fMakefile
, "\t${objcopy} $(BOOTPROG_COPYFORMAT) %s %s\n",
2989 module
.GetPath().c_str () );
2991 fprintf ( fMakefile
,
2992 "\t-@${rm} %s %s %s 2>$(NUL)\n",
2993 junk_tmp
.c_str (), junk_elf
.c_str (), junk_cpy
.c_str () );
2997 MingwIsoModuleHandler::MingwIsoModuleHandler (
2998 const Module
& module_
)
3000 : MingwModuleHandler ( module_
)
3005 MingwIsoModuleHandler::Process ()
3007 GenerateIsoModuleTarget ();
3011 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
3012 const string
& bootcdDirectory
)
3014 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3016 const Module
& m
= *module
.project
.modules
[i
];
3019 if ( m
.bootstrap
!= NULL
)
3021 string sourceFilename
= PassThruCacheDirectory (
3022 NormalizeFilename ( m
.GetPath () ),
3023 backend
->outputDirectory
);
3024 string
targetFilenameNoFixup ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
+ sSep
+ m
.bootstrap
->nameoncd
);
3025 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3026 NormalizeFilename ( targetFilenameNoFixup
),
3027 backend
->outputDirectory
);
3028 fprintf ( fMakefile
,
3030 fprintf ( fMakefile
,
3031 "\t${cp} %s %s 1>$(NUL)\n",
3032 sourceFilename
.c_str (),
3033 targetFilename
.c_str () );
3039 MingwIsoModuleHandler::OutputCdfileCopyCommands (
3040 const string
& bootcdDirectory
)
3042 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3044 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3045 string targetFilenameNoFixup
= bootcdDirectory
+ sSep
+ cdfile
.base
+ sSep
+ cdfile
.nameoncd
;
3046 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3047 NormalizeFilename ( targetFilenameNoFixup
),
3048 backend
->outputDirectory
);
3049 fprintf ( fMakefile
,
3051 fprintf ( fMakefile
,
3052 "\t${cp} %s %s 1>$(NUL)\n",
3053 cdfile
.GetPath ().c_str (),
3054 targetFilename
.c_str () );
3059 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
3062 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3064 const Module
& m
= *module
.project
.modules
[i
];
3067 if ( m
.bootstrap
!= NULL
)
3069 string
targetDirectory ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
);
3070 if ( directories
.size () > 0 )
3072 directories
+= PassThruCacheDirectory (
3073 NormalizeFilename ( targetDirectory
),
3074 backend
->outputDirectory
);
3081 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
3084 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3086 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3087 string
targetDirectory ( bootcdDirectory
+ sSep
+ cdfile
.base
);
3088 if ( directories
.size () > 0 )
3090 directories
+= PassThruCacheDirectory (
3091 NormalizeFilename ( targetDirectory
),
3092 backend
->outputDirectory
);
3098 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
3100 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
3101 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
3106 MingwIsoModuleHandler::GetBootstrapCdFiles (
3107 vector
<string
>& out
) const
3109 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3111 const Module
& m
= *module
.project
.modules
[i
];
3114 if ( m
.bootstrap
!= NULL
)
3116 string filename
= PassThruCacheDirectory (
3117 NormalizeFilename ( m
.GetPath () ),
3118 backend
->outputDirectory
);
3119 out
.push_back ( filename
);
3125 MingwIsoModuleHandler::GetNonModuleCdFiles (
3126 vector
<string
>& out
) const
3128 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
3130 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
3131 out
.push_back ( cdfile
.GetPath () );
3136 MingwIsoModuleHandler::GetCdFiles (
3137 vector
<string
>& out
) const
3139 GetBootstrapCdFiles ( out
);
3140 GetNonModuleCdFiles ( out
);
3144 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
3146 string bootcdDirectory
= "cd";
3147 string bootcd
= PassThruCacheDirectory (
3148 NormalizeFilename ( bootcdDirectory
+ sSep
),
3149 backend
->outputDirectory
);
3154 if (module
.name
== "bootcdregtest")
3156 bootloader
= "isobtrt.o";
3157 IsoName
= "ReactOS-RegTest.iso";
3161 bootloader
= "isoboot.o";
3162 IsoName
= "ReactOS.iso";
3165 string isoboot
= PassThruCacheDirectory (
3166 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ bootloader
.c_str() ),
3167 backend
->outputDirectory
);
3169 string bootcdReactosNoFixup
= bootcdDirectory
+ sSep
+ Environment::GetCdOutputPath ();
3170 string bootcdReactos
= PassThruCacheDirectory (
3171 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
),
3172 backend
->outputDirectory
);
3173 CLEAN_FILE ( bootcdReactos
);
3174 string reactosInf
= PassThruCacheDirectory (
3175 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
+ "reactos.inf" ),
3176 backend
->outputDirectory
);
3177 string reactosDff
= NormalizeFilename ( "boot" + sSep
+ "bootdata" + sSep
+ "packages" + sSep
+ "reactos.dff" );
3178 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
3179 vector
<string
> vCdFiles
;
3180 GetCdFiles ( vCdFiles
);
3181 string cdFiles
= v2s ( vCdFiles
, 5 );
3183 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3184 module
.name
.c_str ());
3185 fprintf ( fMakefile
,
3186 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
3187 module
.name
.c_str (),
3189 bootcdReactos
.c_str (),
3190 cdDirectories
.c_str (),
3192 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
3193 fprintf ( fMakefile
,
3194 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
3195 reactosDff
.c_str (),
3196 bootcdReactos
.c_str () );
3197 fprintf ( fMakefile
,
3198 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
3199 reactosDff
.c_str (),
3200 reactosInf
.c_str (),
3201 bootcdReactos
.c_str ());
3202 fprintf ( fMakefile
,
3203 "\t-@${rm} %s 2>$(NUL)\n",
3204 reactosInf
.c_str () );
3205 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
3206 OutputCdfileCopyCommands ( bootcdDirectory
);
3207 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3208 fprintf ( fMakefile
,
3209 "\t$(Q)$(CDMAKE_TARGET) -v -j -m -b %s %s REACTOS %s\n",
3213 fprintf ( fMakefile
,
3218 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
3219 const Module
& module_
)
3221 : MingwModuleHandler ( module_
)
3226 MingwLiveIsoModuleHandler::Process ()
3228 GenerateLiveIsoModuleTarget ();
3232 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
3234 string normalizedDirectory
= MingwModuleHandler::PassThruCacheDirectory (
3235 NormalizeFilename ( directory
) + sSep
,
3236 backend
->outputDirectory
);
3240 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string
& sourceFilename
,
3241 const string
& targetFilename
,
3242 const string
& targetDirectory
)
3244 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
3245 NormalizeFilename ( targetDirectory
+ sSep
+ targetFilename
),
3246 backend
->outputDirectory
);
3247 fprintf ( fMakefile
,
3249 fprintf ( fMakefile
,
3250 "\t${cp} %s %s 1>$(NUL)\n",
3251 sourceFilename
.c_str (),
3252 normalizedTargetFilename
.c_str () );
3256 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
3257 string
& reactosDirectory
)
3259 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
3261 const Module
& m
= *module
.project
.modules
[i
];
3264 if ( m
.installName
.length () > 0 )
3266 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
3267 string sourceFilename
= MingwModuleHandler::PassThruCacheDirectory (
3268 NormalizeFilename ( aliasedModule
.GetPath () ),
3269 backend
->outputDirectory
);
3270 OutputCopyCommand ( sourceFilename
,
3272 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.installBase
);
3278 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
3279 string
& reactosDirectory
)
3281 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
3283 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
3284 OutputCopyCommand ( installfile
.GetPath (),
3285 installfile
.newname
,
3286 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.base
);
3291 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
3293 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
3294 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
3295 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
3296 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
3297 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
3298 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
3300 string livecdIni
= "boot" + sSep
+ "bootdata" + sSep
+ "livecd.ini";
3301 OutputCopyCommand ( livecdIni
,
3307 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3309 string freeldr
= PassThruCacheDirectory (
3310 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "freeldr" + sSep
+ "freeldr.sys" ),
3311 backend
->outputDirectory
);
3312 CreateDirectory ( livecdDirectory
+ sSep
+ "loader" );
3313 OutputCopyCommand ( freeldr
,
3315 livecdDirectory
+ sSep
+ "loader" );
3319 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3321 string reactosSystem32ConfigDirectory
= NormalizeFilename (
3322 MingwModuleHandler::PassThruCacheDirectory (
3323 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config" + sSep
,
3324 backend
->outputDirectory
) );
3325 fprintf ( fMakefile
,
3326 "\t$(ECHO_MKHIVE)\n" );
3327 fprintf ( fMakefile
,
3328 "\t$(MKHIVE_TARGET) boot%cbootdata %s boot%cbootdata%clivecd.inf boot%cbootdata%chiveinst.inf\n",
3329 cSep
, reactosSystem32ConfigDirectory
.c_str (),
3330 cSep
, cSep
, cSep
, cSep
);
3334 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
3336 string livecdDirectory
= module
.name
;
3337 string livecd
= PassThruCacheDirectory (
3338 NormalizeFilename ( livecdDirectory
+ sSep
),
3339 backend
->outputDirectory
);
3344 if (module
.name
== "livecdregtest")
3346 bootloader
= "isobtrt.o";
3347 IsoName
= "ReactOS-LiveCD-RegTest.iso";
3351 bootloader
= "isoboot.o";
3352 IsoName
= "ReactOS-LiveCD.iso";
3355 string isoboot
= PassThruCacheDirectory (
3356 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ bootloader
.c_str() ),
3357 backend
->outputDirectory
);
3359 string reactosDirectory
= "reactos";
3360 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3361 string livecdReactos
= NormalizeFilename ( PassThruCacheDirectory (
3362 NormalizeFilename ( livecdReactosNoFixup
+ sSep
),
3363 backend
->outputDirectory
) );
3364 CLEAN_FILE ( livecdReactos
);
3366 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3367 module
.name
.c_str ());
3368 fprintf ( fMakefile
,
3369 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3370 module
.name
.c_str (),
3372 livecdReactos
.c_str () );
3373 OutputModuleCopyCommands ( livecdDirectory
,
3375 OutputNonModuleCopyCommands ( livecdDirectory
,
3377 OutputProfilesDirectoryCommands ( livecdDirectory
);
3378 OutputLoaderCommands ( livecdDirectory
);
3379 OutputRegistryCommands ( livecdDirectory
);
3380 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3381 fprintf ( fMakefile
,
3382 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS %s\n",
3386 fprintf ( fMakefile
,
3391 MingwTestModuleHandler::MingwTestModuleHandler (
3392 const Module
& module_
)
3394 : MingwModuleHandler ( module_
)
3399 MingwTestModuleHandler::Process ()
3401 GenerateTestModuleTarget ();
3405 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
3407 string basePath
= "$(INTERMEDIATE)" + sSep
+ module
.GetBasePath ();
3408 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_hooks.c", false, "", false ) ) );
3409 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_stubs.S", false, "", false ) ) );
3410 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_startup.c", false, "", false ) ) );
3414 MingwTestModuleHandler::GenerateTestModuleTarget ()
3416 string
targetMacro ( GetTargetMacro ( module
) );
3417 string workingDirectory
= GetWorkingDirectory ( );
3418 string objectsMacro
= GetObjectsMacro ( module
);
3419 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3420 string libsMacro
= GetLibsMacro ();
3422 GenerateImportLibraryTargetIfNeeded ();
3424 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3428 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3431 if ( module
.cplusplus
)
3436 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3437 module
.GetEntryPoint(true).c_str (),
3438 module
.baseaddress
.c_str () );
3439 GenerateLinkerCommand ( dependencies
,
3448 GeneratePhonyTarget();
3453 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3454 const Module
& module_
)
3456 : MingwModuleHandler ( module_
)
3461 MingwRpcServerModuleHandler::Process ()
3467 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3468 const Module
& module_
)
3470 : MingwModuleHandler ( module_
)
3475 MingwRpcClientModuleHandler::Process ()
3481 MingwAliasModuleHandler::MingwAliasModuleHandler (
3482 const Module
& module_
)
3484 : MingwModuleHandler ( module_
)
3489 MingwAliasModuleHandler::Process ()
3493 MingwIdlHeaderModuleHandler::MingwIdlHeaderModuleHandler (
3494 const Module
& module_
)
3496 : MingwModuleHandler ( module_
)
3501 MingwIdlHeaderModuleHandler::Process ()