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
);
213 handler
= new MingwWin32GUIModuleHandler ( module
);
216 handler
= new MingwKernelModeDLLModuleHandler ( module
);
219 handler
= new MingwNativeDLLModuleHandler ( module
);
222 handler
= new MingwWin32DLLModuleHandler ( module
);
224 case KernelModeDriver
:
225 handler
= new MingwKernelModeDriverModuleHandler ( module
);
228 handler
= new MingwBootLoaderModuleHandler ( module
);
231 handler
= new MingwBootSectorModuleHandler ( module
);
234 handler
= new MingwIsoModuleHandler ( module
);
237 handler
= new MingwLiveIsoModuleHandler ( module
);
240 handler
= new MingwTestModuleHandler ( module
);
243 handler
= new MingwRpcServerModuleHandler ( module
);
246 handler
= new MingwRpcClientModuleHandler ( module
);
249 handler
= new MingwAliasModuleHandler ( module
);
252 throw UnknownModuleTypeException (
253 module
.node
.location
,
261 MingwModuleHandler::GetWorkingDirectory () const
267 MingwModuleHandler::GetBasename ( const string
& filename
) const
269 size_t index
= filename
.find_last_of ( '.' );
270 if ( index
!= string::npos
)
271 return filename
.substr ( 0, index
);
276 MingwModuleHandler::GetActualSourceFilename (
277 const FileLocation
* fileLocation
) const
279 string filename
= fileLocation
->filename
;
280 string extension
= GetExtension ( filename
);
281 if ( extension
== ".spec" || extension
== ".SPEC" )
283 string basename
= GetBasename ( filename
);
284 PassThruCacheDirectory ( NormalizeFilename ( basename
+ ".stubs.c" ),
285 backend
->intermediateDirectory
);
286 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( basename
+ ".stubs.c" ) );
288 else if ( extension
== ".idl" || extension
== ".IDL" )
290 string basename
= GetBasename ( filename
);
292 if ( module
.type
== RpcServer
)
293 newname
= basename
+ "_s.c";
295 newname
= basename
+ "_c.c";
296 PassThruCacheDirectory ( NormalizeFilename ( newname
),
297 backend
->intermediateDirectory
);
298 return new FileLocation ( backend
->intermediateDirectory
, NormalizeFilename ( newname
) );
301 return new FileLocation ( fileLocation
->directory
, filename
);
305 MingwModuleHandler::GetExtraDependencies (
306 const string
& filename
) const
308 string extension
= GetExtension ( filename
);
309 if ( extension
== ".idl" || extension
== ".IDL" )
311 string basename
= GetBasename ( filename
);
312 return GetRpcServerHeaderFilename ( basename
) + " " + GetRpcClientHeaderFilename ( basename
);
319 MingwModuleHandler::GetCompilationUnitDependencies (
320 const CompilationUnit
& compilationUnit
) const
322 if ( compilationUnit
.files
.size () <= 1 )
324 vector
<string
> sourceFiles
;
325 for ( size_t i
= 0; i
< compilationUnit
.files
.size (); i
++ )
327 File
& file
= *compilationUnit
.files
[i
];
328 sourceFiles
.push_back ( NormalizeFilename ( file
.name
) );
330 return v2s ( sourceFiles
, 10 );
334 MingwModuleHandler::GetModuleArchiveFilename () const
336 if ( module
.type
== StaticLibrary
)
337 return GetTargetFilename ( module
, NULL
);
338 return PassThruCacheDirectory ( ReplaceExtension (
339 NormalizeFilename ( module
.GetPath () ),
341 backend
->intermediateDirectory
);
345 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
347 string extension
= GetExtension ( file
.name
);
348 return ( extension
== ".spec" || extension
== ".SPEC" );
352 MingwModuleHandler::ReferenceObjects (
353 const Module
& module
)
355 if ( module
.type
== ObjectLibrary
)
357 if ( module
.type
== RpcServer
)
359 if ( module
.type
== RpcClient
)
365 MingwModuleHandler::GetImportLibraryDependency (
366 const Module
& importedModule
)
369 if ( ReferenceObjects ( importedModule
) )
370 dep
= GetTargetMacro ( importedModule
);
372 dep
= GetImportLibraryFilename ( importedModule
, NULL
);
377 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
378 string_list
& targets
)
380 if ( dependencyModule
.invocations
.size () > 0 )
382 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
384 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
385 invoke
.GetTargets ( targets
);
389 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
393 MingwModuleHandler::GetModuleDependencies (
394 string_list
& dependencies
)
396 size_t iend
= module
.dependencies
.size ();
401 for ( size_t i
= 0; i
< iend
; i
++ )
403 const Dependency
& dependency
= *module
.dependencies
[i
];
404 const Module
& dependencyModule
= *dependency
.dependencyModule
;
405 GetTargets ( dependencyModule
,
408 GetDefinitionDependencies ( dependencies
);
412 MingwModuleHandler::GetSourceFilenames ( string_list
& list
,
413 bool includeGeneratedFiles
) const
417 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
418 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
420 if ( includeGeneratedFiles
|| !compilationUnits
[i
]->IsGeneratedFile () )
422 FileLocation
* sourceFileLocation
= GetActualSourceFilename (
423 compilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
) );
424 list
.push_back ( PassThruCacheDirectory ( sourceFileLocation
->filename
,
425 sourceFileLocation
->directory
) );
428 // intentionally make a copy so that we can append more work in
429 // the middle of processing without having to go recursive
430 vector
<If
*> v
= module
.non_if_data
.ifs
;
431 for ( i
= 0; i
< v
.size (); i
++ )
435 // check for sub-ifs to add to list
436 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
437 for ( j
= 0; j
< ifs
.size (); j
++ )
438 v
.push_back ( ifs
[j
] );
439 const vector
<CompilationUnit
*>& compilationUnits
= rIf
.data
.compilationUnits
;
440 for ( j
= 0; j
< compilationUnits
.size (); j
++ )
442 CompilationUnit
& compilationUnit
= *compilationUnits
[j
];
443 if ( includeGeneratedFiles
|| !compilationUnit
.IsGeneratedFile () )
445 FileLocation
* sourceFileLocation
= GetActualSourceFilename (
446 compilationUnit
.GetFilename ( backend
->intermediateDirectory
) );
447 list
.push_back ( PassThruCacheDirectory ( sourceFileLocation
->filename
,
448 sourceFileLocation
->directory
) );
455 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
456 string_list
& list
) const
458 GetSourceFilenames ( list
, false );
462 MingwModuleHandler::GetObjectFilename (
463 const FileLocation
* sourceFileLocation
,
464 string_list
* pclean_files
) const
466 string sourceFilename
= sourceFileLocation
->filename
;
467 Directory
* directoryTree
;
469 string extension
= GetExtension ( sourceFilename
);
470 if ( extension
== ".rc" || extension
== ".RC" )
471 newExtension
= ".coff";
472 else if ( extension
== ".spec" || extension
== ".SPEC" )
473 newExtension
= ".stubs.o";
474 else if ( extension
== ".idl" || extension
== ".IDL" )
476 if ( module
.type
== RpcServer
)
477 newExtension
= "_s.o";
479 newExtension
= "_c.o";
484 if ( module
.type
== BootSector
)
485 directoryTree
= backend
->outputDirectory
;
487 directoryTree
= backend
->intermediateDirectory
;
489 string obj_file
= PassThruCacheDirectory (
490 NormalizeFilename ( ReplaceExtension (
491 RemoveVariables ( sourceFilename
),
496 string_list
& clean_files
= *pclean_files
;
497 CLEAN_FILE ( obj_file
);
503 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
505 return module
.name
+ "_clean";
509 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
511 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
513 Library
& library
= *module
.non_if_data
.libraries
[i
];
514 if ( library
.importedModule
->type
== ObjectLibrary
)
515 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
520 MingwModuleHandler::GenerateCleanTarget () const
522 if ( module
.type
== Alias
)
526 ".PHONY: %s_clean\n",
527 module
.name
.c_str() );
528 vector
<string
> referencedModuleNames
;
529 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
532 GetModuleCleanTarget ( module
).c_str(),
533 v2s ( referencedModuleNames
, 10 ).c_str () );
534 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
537 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
538 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
540 fprintf ( fMakefile
, " 2>$(NUL)\n" );
541 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
545 MingwModuleHandler::GenerateInstallTarget () const
547 if ( module
.installName
.length () == 0 )
549 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
550 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
551 NormalizeFilename ( module
.installBase
+ sSep
+ module
.installName
),
552 backend
->installDirectory
);
555 module
.name
.c_str (),
556 normalizedTargetFilename
.c_str() );
560 MingwModuleHandler::GenerateDependsTarget () const
563 ".PHONY: %s_depends\n",
564 module
.name
.c_str() );
566 "%s_depends: $(RBUILD_TARGET)\n",
567 module
.name
.c_str () );
569 "\t$(ECHO_RBUILD)\n" );
571 "\t$(Q)$(RBUILD_TARGET) -dm%s mingw\n",
572 module
.name
.c_str () );
576 MingwModuleHandler::GetObjectFilenames ()
578 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
579 if ( compilationUnits
.size () == 0 )
582 string
objectFilenames ( "" );
583 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
585 if ( objectFilenames
.size () > 0 )
586 objectFilenames
+= " ";
587 objectFilenames
+= GetObjectFilename ( compilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
), NULL
);
589 return objectFilenames
;
593 MingwModuleHandler::GenerateGccDefineParametersFromVector (
594 const vector
<Define
*>& defines
)
597 for ( size_t i
= 0; i
< defines
.size (); i
++ )
599 Define
& define
= *defines
[i
];
600 if (parameters
.length () > 0)
603 parameters
+= define
.name
;
604 if (define
.value
.length () > 0)
607 parameters
+= define
.value
;
614 MingwModuleHandler::GenerateGccDefineParameters () const
616 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
617 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
618 if ( s
.length () > 0 )
627 MingwModuleHandler::ConcatenatePaths (
629 const string
& path2
) const
631 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
633 if ( path1
[path1
.length ()] == cSep
)
634 return path1
+ path2
;
636 return path1
+ cSep
+ path2
;
640 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
643 for ( size_t i
= 0; i
< includes
.size (); i
++ )
645 Include
& include
= *includes
[i
];
646 if ( parameters
.length () > 0 )
648 parameters
+= "-I" + include
.directory
;
654 MingwModuleHandler::GenerateGccIncludeParameters () const
656 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
657 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
658 if ( s
.length () > 0 )
667 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
670 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
672 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
673 if ( parameters
.length () > 0 )
675 parameters
+= compilerFlag
.flag
;
681 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
684 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
686 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
687 if ( parameters
.length () > 0 )
689 parameters
+= linkerFlag
.flag
;
695 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
696 const vector
<Library
*>& libraries
)
698 string
dependencies ( "" );
700 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
702 if ( wrap_count
++ == 5 )
703 dependencies
+= " \\\n\t\t", wrap_count
= 0;
704 else if ( dependencies
.size () > 0 )
706 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
712 MingwModuleHandler::GenerateLinkerParameters () const
714 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
718 MingwModuleHandler::GenerateMacro (
719 const char* assignmentOperation
,
721 const IfableData
& data
)
724 bool generateAssignment
;
726 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
727 if ( generateAssignment
)
732 assignmentOperation
);
735 if ( use_pch
&& module
.pch
!= NULL
)
739 GetDirectory ( GetPrecompiledHeaderFilename () ).c_str () );
742 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
743 if ( compilerParameters
.size () > 0 )
748 compilerParameters
.c_str () );
751 for ( i
= 0; i
< data
.includes
.size(); i
++ )
753 const Include
& include
= *data
.includes
[i
];
754 string includeDirectory
;
755 if ( include
.baseModule
!= NULL
&&
756 ( include
.baseModule
->type
== RpcServer
||
757 include
.baseModule
->type
== RpcClient
) )
758 includeDirectory
= PassThruCacheDirectory ( NormalizeFilename ( include
.directory
),
759 backend
->intermediateDirectory
);
761 includeDirectory
= include
.directory
;
765 includeDirectory
.c_str() );
767 for ( i
= 0; i
< data
.defines
.size(); i
++ )
769 Define
& d
= *data
.defines
[i
];
774 if ( d
.value
.size() )
780 if ( generateAssignment
)
782 fprintf ( fMakefile
, "\n" );
787 MingwModuleHandler::GenerateMacros (
788 const char* assignmentOperation
,
789 const IfableData
& data
,
790 const vector
<LinkerFlag
*>* linkerFlags
)
794 GenerateMacro ( assignmentOperation
,
797 GenerateMacro ( assignmentOperation
,
801 if ( linkerFlags
!= NULL
)
803 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
804 if ( linkerParameters
.size () > 0 )
809 linkerflagsMacro
.c_str (),
811 linkerParameters
.c_str() );
815 if ( data
.libraries
.size () > 0 )
817 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
818 if ( deps
.size () > 0 )
829 const vector
<If
*>& ifs
= data
.ifs
;
830 for ( i
= 0; i
< ifs
.size(); i
++ )
833 if ( rIf
.data
.defines
.size()
834 || rIf
.data
.includes
.size()
835 || rIf
.data
.libraries
.size()
836 || rIf
.data
.compilationUnits
.size()
837 || rIf
.data
.compilerFlags
.size()
838 || rIf
.data
.ifs
.size() )
842 "%s (\"$(%s)\",\"%s\")\n",
843 rIf
.negated
? "ifneq" : "ifeq",
844 rIf
.property
.c_str(),
858 MingwModuleHandler::CleanupCompilationUnitVector ( vector
<CompilationUnit
*>& compilationUnits
)
860 for (size_t i
= 0; i
< compilationUnits
.size (); i
++)
861 delete compilationUnits
[i
];
865 MingwModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
870 MingwModuleHandler::GenerateObjectMacros (
871 const char* assignmentOperation
,
872 const IfableData
& data
,
873 const vector
<LinkerFlag
*>* linkerFlags
)
877 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
878 if ( compilationUnits
.size () > 0 )
880 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
882 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
883 if ( compilationUnit
.IsFirstFile () )
887 objectsMacro
.c_str(),
888 GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
).c_str (),
889 objectsMacro
.c_str() );
895 objectsMacro
.c_str (),
896 assignmentOperation
);
897 for ( i
= 0; i
< compilationUnits
.size(); i
++ )
899 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
900 if ( !compilationUnit
.IsFirstFile () )
905 ( i
%10 == 9 ? " \\\n\t" : " " ),
906 GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
).c_str () );
909 fprintf ( fMakefile
, "\n" );
912 const vector
<If
*>& ifs
= data
.ifs
;
913 for ( i
= 0; i
< ifs
.size(); i
++ )
916 if ( rIf
.data
.defines
.size()
917 || rIf
.data
.includes
.size()
918 || rIf
.data
.libraries
.size()
919 || rIf
.data
.compilationUnits
.size()
920 || rIf
.data
.compilerFlags
.size()
921 || rIf
.data
.ifs
.size() )
925 "%s (\"$(%s)\",\"%s\")\n",
926 rIf
.negated
? "ifneq" : "ifeq",
927 rIf
.property
.c_str(),
929 GenerateObjectMacros (
939 vector
<CompilationUnit
*> sourceCompilationUnits
;
940 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
941 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
946 objectsMacro
.c_str(),
947 GetObjectFilename ( sourceCompilationUnits
[i
]->GetFilename ( backend
->intermediateDirectory
), NULL
).c_str () );
949 CleanupCompilationUnitVector ( sourceCompilationUnits
);
953 MingwModuleHandler::GetPrecompiledHeaderFilename () const
955 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
956 return PassThruCacheDirectory ( NormalizeFilename ( basePchFilename
),
957 backend
->intermediateDirectory
);
961 MingwModuleHandler::GenerateGccCommand (
962 const FileLocation
* sourceFileLocation
,
963 const string
& extraDependencies
,
965 const string
& cflagsMacro
)
967 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
968 string dependencies
= sourceFilename
;
969 if ( extraDependencies
!= "" )
970 dependencies
+= " " + extraDependencies
;
971 if ( module
.pch
&& use_pch
)
972 dependencies
+= " " + GetPrecompiledHeaderFilename ();
974 /* WIDL generated headers may be used */
975 vector
<string
> rpcDependencies
;
976 GetRpcHeaderDependencies ( rpcDependencies
);
977 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
978 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
980 string objectFilename
= GetObjectFilename (
981 sourceFileLocation
, &clean_files
);
984 objectFilename
.c_str (),
985 dependencies
.c_str (),
986 GetDirectory ( objectFilename
).c_str () );
987 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
989 "\t%s -c $< -o $@ %s\n",
991 cflagsMacro
.c_str () );
995 MingwModuleHandler::GenerateGccAssemblerCommand (
996 const FileLocation
* sourceFileLocation
,
998 const string
& cflagsMacro
)
1000 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1001 string dependencies
= sourceFilename
;
1002 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1003 string objectFilename
= GetObjectFilename (
1004 sourceFileLocation
, &clean_files
);
1005 fprintf ( fMakefile
,
1007 objectFilename
.c_str (),
1008 dependencies
.c_str (),
1009 GetDirectory ( objectFilename
).c_str () );
1010 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
1011 fprintf ( fMakefile
,
1012 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
1014 cflagsMacro
.c_str () );
1018 MingwModuleHandler::GenerateNasmCommand (
1019 const FileLocation
* sourceFileLocation
,
1020 const string
& nasmflagsMacro
)
1022 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1023 string dependencies
= sourceFilename
;
1024 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1025 string objectFilename
= GetObjectFilename (
1026 sourceFileLocation
, &clean_files
);
1027 fprintf ( fMakefile
,
1029 objectFilename
.c_str (),
1030 dependencies
.c_str (),
1031 GetDirectory ( objectFilename
).c_str () );
1032 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1033 fprintf ( fMakefile
,
1034 "\t%s -f win32 $< -o $@ %s\n",
1036 nasmflagsMacro
.c_str () );
1040 MingwModuleHandler::GenerateWindresCommand (
1041 const FileLocation
* sourceFileLocation
,
1042 const string
& windresflagsMacro
)
1044 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1045 string dependencies
= sourceFilename
;
1046 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1047 string objectFilename
= GetObjectFilename ( sourceFileLocation
, &clean_files
);
1048 string sourceFilenamePart
= ReplaceExtension ( GetFilename ( sourceFilename
), "" );
1049 string rciFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".rci.tmp";
1050 string resFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".res.tmp";
1051 if ( module
.useWRC
)
1053 fprintf ( fMakefile
,
1054 "%s: %s $(WRC_TARGET) | %s\n",
1055 objectFilename
.c_str (),
1056 dependencies
.c_str (),
1057 GetDirectory ( objectFilename
).c_str () );
1058 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1059 fprintf ( fMakefile
,
1060 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1061 windresflagsMacro
.c_str (),
1062 sourceFilename
.c_str (),
1063 rciFilename
.c_str () );
1064 fprintf ( fMakefile
,
1065 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1066 windresflagsMacro
.c_str (),
1067 rciFilename
.c_str (),
1068 resFilename
.c_str () );
1069 fprintf ( fMakefile
,
1070 "\t-@${rm} %s 2>$(NUL)\n",
1071 rciFilename
.c_str () );
1072 fprintf ( fMakefile
,
1073 "\t${windres} %s -o $@\n",
1074 resFilename
.c_str () );
1075 fprintf ( fMakefile
,
1076 "\t-@${rm} %s 2>$(NUL)\n",
1077 resFilename
.c_str () );
1081 fprintf ( fMakefile
,
1082 "%s: %s $(WRC_TARGET) | %s\n",
1083 objectFilename
.c_str (),
1084 dependencies
.c_str (),
1085 GetDirectory ( objectFilename
).c_str () );
1086 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1087 fprintf ( fMakefile
,
1088 "\t${windres} $(%s) %s -o $@\n",
1089 windresflagsMacro
.c_str (),
1090 sourceFilename
.c_str () );
1095 MingwModuleHandler::GenerateWinebuildCommands (
1096 const FileLocation
* sourceFileLocation
)
1098 string sourceFilename
= PassThruCacheDirectory ( sourceFileLocation
);
1099 string dependencies
= sourceFilename
;
1100 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1102 string basename
= GetBasename ( sourceFilename
);
1103 string def_file
= PassThruCacheDirectory (
1104 basename
+ ".spec.def",
1105 backend
->intermediateDirectory
);
1106 CLEAN_FILE(def_file
);
1108 string stub_file
= PassThruCacheDirectory (
1109 basename
+ ".stubs.c",
1110 backend
->intermediateDirectory
);
1111 CLEAN_FILE(stub_file
)
1113 fprintf ( fMakefile
,
1114 "%s: %s $(WINEBUILD_TARGET) | %s\n",
1116 dependencies
.c_str (),
1117 GetDirectory ( def_file
).c_str () );
1118 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1119 fprintf ( fMakefile
,
1120 "\t%s -o %s --def -E %s\n",
1121 "$(Q)$(WINEBUILD_TARGET)",
1123 sourceFilename
.c_str () );
1124 fprintf ( fMakefile
,
1125 "%s: %s $(WINEBUILD_TARGET)\n",
1127 sourceFilename
.c_str () );
1128 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1129 fprintf ( fMakefile
,
1130 "\t%s -o %s --pedll %s\n",
1131 "$(Q)$(WINEBUILD_TARGET)",
1133 sourceFilename
.c_str () );
1137 MingwModuleHandler::GetWidlFlags ( const CompilationUnit
& compilationUnit
)
1139 return compilationUnit
.GetSwitches ();
1143 MingwModuleHandler::GetRpcServerHeaderFilename ( string basename
) const
1145 return PassThruCacheDirectory ( basename
+ "_s.h",
1146 backend
->intermediateDirectory
);
1150 MingwModuleHandler::GenerateWidlCommandsServer (
1151 const CompilationUnit
& compilationUnit
,
1152 const string
& widlflagsMacro
)
1154 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1155 string filename
= sourceFileLocation
->filename
;
1156 string dependencies
= filename
;
1157 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1159 string basename
= GetBasename ( filename
);
1161 string generatedHeaderFilename
= GetRpcServerHeaderFilename ( basename
);
1162 CLEAN_FILE(generatedHeaderFilename
);
1164 string generatedServerFilename
= PassThruCacheDirectory (
1166 backend
->intermediateDirectory
);
1167 CLEAN_FILE(generatedServerFilename
);
1169 fprintf ( fMakefile
,
1170 "%s %s: %s $(WIDL_TARGET) | %s\n",
1171 generatedServerFilename
.c_str (),
1172 generatedHeaderFilename
.c_str (),
1173 dependencies
.c_str (),
1174 GetDirectory ( generatedServerFilename
).c_str () );
1175 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1176 fprintf ( fMakefile
,
1177 "\t%s %s %s -h -H %s -s -S %s %s\n",
1178 "$(Q)$(WIDL_TARGET)",
1179 GetWidlFlags ( compilationUnit
).c_str (),
1180 widlflagsMacro
.c_str (),
1181 generatedHeaderFilename
.c_str (),
1182 generatedServerFilename
.c_str (),
1183 filename
.c_str () );
1187 MingwModuleHandler::GetRpcClientHeaderFilename ( string basename
) const
1189 return PassThruCacheDirectory ( basename
+ "_c.h",
1190 backend
->intermediateDirectory
);
1194 MingwModuleHandler::GenerateWidlCommandsClient (
1195 const CompilationUnit
& compilationUnit
,
1196 const string
& widlflagsMacro
)
1198 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1199 string filename
= sourceFileLocation
->filename
;
1200 string dependencies
= filename
;
1201 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1203 string basename
= GetBasename ( filename
);
1205 string generatedHeaderFilename
= GetRpcClientHeaderFilename ( basename
);
1206 CLEAN_FILE(generatedHeaderFilename
);
1208 string generatedClientFilename
= PassThruCacheDirectory (
1210 backend
->intermediateDirectory
);
1211 CLEAN_FILE(generatedClientFilename
);
1213 fprintf ( fMakefile
,
1214 "%s %s: %s $(WIDL_TARGET) | %s\n",
1215 generatedClientFilename
.c_str (),
1216 generatedHeaderFilename
.c_str (),
1217 dependencies
.c_str (),
1218 GetDirectory ( generatedClientFilename
).c_str () );
1219 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1220 fprintf ( fMakefile
,
1221 "\t%s %s %s -h -H %s -c -C %s %s\n",
1222 "$(Q)$(WIDL_TARGET)",
1223 GetWidlFlags ( compilationUnit
).c_str (),
1224 widlflagsMacro
.c_str (),
1225 generatedHeaderFilename
.c_str (),
1226 generatedClientFilename
.c_str (),
1227 filename
.c_str () );
1231 MingwModuleHandler::GenerateWidlCommands (
1232 const CompilationUnit
& compilationUnit
,
1233 const string
& widlflagsMacro
)
1235 if ( module
.type
== RpcServer
)
1236 GenerateWidlCommandsServer ( compilationUnit
,
1239 GenerateWidlCommandsClient ( compilationUnit
,
1244 MingwModuleHandler::GenerateCommands (
1245 const CompilationUnit
& compilationUnit
,
1248 const string
& cflagsMacro
,
1249 const string
& nasmflagsMacro
,
1250 const string
& windresflagsMacro
,
1251 const string
& widlflagsMacro
)
1253 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1254 string filename
= sourceFileLocation
->filename
;
1255 string extension
= GetExtension ( filename
);
1256 if ( extension
== ".c" || extension
== ".C" )
1258 GenerateGccCommand ( sourceFileLocation
,
1259 GetCompilationUnitDependencies ( compilationUnit
),
1264 else if ( extension
== ".cc" || extension
== ".CC" ||
1265 extension
== ".cpp" || extension
== ".CPP" ||
1266 extension
== ".cxx" || extension
== ".CXX" )
1268 GenerateGccCommand ( sourceFileLocation
,
1269 GetCompilationUnitDependencies ( compilationUnit
),
1274 else if ( extension
== ".s" || extension
== ".S" )
1276 GenerateGccAssemblerCommand ( sourceFileLocation
,
1281 else if ( extension
== ".asm" || extension
== ".ASM" )
1283 GenerateNasmCommand ( sourceFileLocation
,
1287 else if ( extension
== ".rc" || extension
== ".RC" )
1289 GenerateWindresCommand ( sourceFileLocation
,
1290 windresflagsMacro
);
1293 else if ( extension
== ".spec" || extension
== ".SPEC" )
1295 GenerateWinebuildCommands ( sourceFileLocation
);
1296 GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation
),
1302 else if ( extension
== ".idl" || extension
== ".IDL" )
1304 GenerateWidlCommands ( compilationUnit
,
1306 GenerateGccCommand ( GetActualSourceFilename ( sourceFileLocation
),
1307 GetExtraDependencies ( filename
),
1313 throw InvalidOperationException ( __FILE__
,
1315 "Unsupported filename extension '%s' in file '%s'",
1317 filename
.c_str () );
1321 MingwModuleHandler::GenerateBuildMapCode ()
1323 fprintf ( fMakefile
,
1324 "ifeq ($(ROS_BUILDMAP),full)\n" );
1326 string mapFilename
= PassThruCacheDirectory (
1327 GetBasename ( module
.GetPath () ) + ".map",
1328 backend
->outputDirectory
);
1329 CLEAN_FILE ( mapFilename
);
1331 fprintf ( fMakefile
,
1332 "\t$(ECHO_OBJDUMP)\n" );
1333 fprintf ( fMakefile
,
1334 "\t$(Q)${objdump} -d -S $@ > %s\n",
1335 mapFilename
.c_str () );
1337 fprintf ( fMakefile
,
1339 fprintf ( fMakefile
,
1340 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1342 fprintf ( fMakefile
,
1344 fprintf ( fMakefile
,
1345 "\t$(Q)${nm} --numeric-sort $@ > %s\n",
1346 mapFilename
.c_str () );
1348 fprintf ( fMakefile
,
1351 fprintf ( fMakefile
,
1356 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1358 fprintf ( fMakefile
,
1359 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1361 string filename
= module
.GetPath ();
1362 string outputFilename
= PassThruCacheDirectory (
1364 backend
->outputDirectory
);
1365 string nostripFilename
= PassThruCacheDirectory (
1366 GetBasename ( filename
) + ".nostrip" + GetExtension ( filename
),
1367 backend
->outputDirectory
);
1368 CLEAN_FILE ( nostripFilename
);
1370 fprintf ( fMakefile
,
1372 fprintf ( fMakefile
,
1373 "\t${cp} %s %s 1>$(NUL)\n",
1374 outputFilename
.c_str (),
1375 nostripFilename
.c_str () );
1377 fprintf ( fMakefile
,
1382 MergeStringVector ( const vector
<string
>& input
,
1383 vector
<string
>& output
)
1387 int wrap_count
= -1;
1388 for ( size_t i
= 0; i
< input
.size (); i
++ )
1390 if ( input
[i
].size () == 0 )
1392 if ( wrap_count
++ == wrap_at
)
1394 output
.push_back ( s
);
1398 else if ( s
.size () > 0)
1402 if ( s
.length () > 0 )
1403 output
.push_back ( s
);
1407 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1408 vector
<string
>& objectFiles
) const
1410 for ( size_t i
= 0; i
< data
.compilationUnits
.size (); i
++ )
1412 CompilationUnit
& compilationUnit
= *data
.compilationUnits
[i
];
1413 objectFiles
.push_back ( GetObjectFilename ( compilationUnit
.GetFilename ( backend
->intermediateDirectory
), NULL
) );
1418 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1420 if ( backend
->configuration
.CleanAsYouGo
)
1422 vector
<string
> objectFiles
;
1423 GetObjectsVector ( module
.non_if_data
,
1425 vector
<string
> lines
;
1426 MergeStringVector ( objectFiles
,
1428 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1430 fprintf ( fMakefile
,
1431 "\t-@${rm} %s 2>$(NUL)\n",
1432 lines
[i
].c_str () );
1438 MingwModuleHandler::GenerateRunRsymCode () const
1440 fprintf ( fMakefile
,
1441 "\t$(ECHO_RSYM)\n" );
1442 fprintf ( fMakefile
,
1443 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1447 MingwModuleHandler::GenerateLinkerCommand (
1448 const string
& dependencies
,
1449 const string
& linker
,
1450 const string
& linkerParameters
,
1451 const string
& objectsMacro
,
1452 const string
& libsMacro
,
1453 const string
& pefixupParameters
)
1455 string
target ( GetTargetMacro ( module
) );
1456 string
target_folder ( GetDirectory ( GetTargetFilename ( module
, NULL
) ) );
1457 string definitionFilename
= GetDefinitionFilename ();
1459 string linkerScriptArgument
;
1460 if ( module
.linkerScript
!= NULL
)
1461 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", module
.linkerScript
->directory
.c_str () );
1463 linkerScriptArgument
= "";
1465 fprintf ( fMakefile
,
1466 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1468 definitionFilename
.c_str (),
1469 dependencies
.c_str (),
1470 target_folder
.c_str () );
1471 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1472 string
targetName ( module
.GetTargetName () );
1474 if ( module
.IsDLL () )
1476 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1477 CLEAN_FILE ( temp_exp
);
1479 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1480 fprintf ( fMakefile
,
1481 "\t${dlltool} --dllname %s --def %s --output-exp %s %s\n",
1482 targetName
.c_str (),
1483 definitionFilename
.c_str (),
1487 fprintf ( fMakefile
,
1488 "\t%s %s %s %s -o %s %s %s %s\n",
1490 linkerParameters
.c_str (),
1491 linkerScriptArgument
.c_str (),
1494 objectsMacro
.c_str (),
1496 GetLinkerMacro ().c_str () );
1498 fprintf ( fMakefile
,
1499 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1501 pefixupParameters
.c_str() );
1503 fprintf ( fMakefile
,
1504 "\t-@${rm} %s 2>$(NUL)\n",
1505 temp_exp
.c_str () );
1509 fprintf ( fMakefile
,
1510 "\t%s %s %s -o %s %s %s %s\n",
1512 linkerParameters
.c_str (),
1513 linkerScriptArgument
.c_str (),
1515 objectsMacro
.c_str (),
1517 GetLinkerMacro ().c_str () );
1519 if ( pefixupParameters
.length() != 0 )
1521 fprintf ( fMakefile
,
1522 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1524 pefixupParameters
.c_str() );
1528 GenerateBuildMapCode ();
1529 GenerateBuildNonSymbolStrippedCode ();
1530 GenerateRunRsymCode ();
1531 GenerateCleanObjectsAsYouGoCode ();
1535 MingwModuleHandler::GeneratePhonyTarget() const
1537 string
targetMacro ( GetTargetMacro ( module
) );
1538 fprintf ( fMakefile
,
1540 targetMacro
.c_str ());
1541 fprintf ( fMakefile
, "%s: | %s\n",
1542 targetMacro
.c_str (),
1543 GetDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1547 MingwModuleHandler::GenerateObjectFileTargets (
1548 const IfableData
& data
,
1551 const string
& cflagsMacro
,
1552 const string
& nasmflagsMacro
,
1553 const string
& windresflagsMacro
,
1554 const string
& widlflagsMacro
)
1558 const vector
<CompilationUnit
*>& compilationUnits
= data
.compilationUnits
;
1559 for ( i
= 0; i
< compilationUnits
.size (); i
++ )
1561 GenerateCommands ( *compilationUnits
[i
],
1568 fprintf ( fMakefile
,
1572 const vector
<If
*>& ifs
= data
.ifs
;
1573 for ( i
= 0; i
< ifs
.size(); i
++ )
1575 GenerateObjectFileTargets ( ifs
[i
]->data
,
1584 vector
<CompilationUnit
*> sourceCompilationUnits
;
1585 GetModuleSpecificCompilationUnits ( sourceCompilationUnits
);
1586 for ( i
= 0; i
< sourceCompilationUnits
.size (); i
++ )
1588 GenerateCommands ( *sourceCompilationUnits
[i
],
1596 CleanupCompilationUnitVector ( sourceCompilationUnits
);
1600 MingwModuleHandler::GenerateObjectFileTargets (
1603 const string
& cflagsMacro
,
1604 const string
& nasmflagsMacro
,
1605 const string
& windresflagsMacro
,
1606 const string
& widlflagsMacro
)
1608 if ( module
.pch
&& use_pch
)
1610 const string
& baseHeaderFilename
= module
.pch
->file
.name
;
1611 const string
& pchFilename
= GetPrecompiledHeaderFilename ();
1612 CLEAN_FILE(pchFilename
);
1613 string dependencies
= baseHeaderFilename
;
1614 /* WIDL generated headers may be used */
1615 vector
<string
> rpcDependencies
;
1616 GetRpcHeaderDependencies ( rpcDependencies
);
1617 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1618 fprintf ( fMakefile
,
1620 pchFilename
.c_str(),
1621 dependencies
.c_str() );
1622 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1623 fprintf ( fMakefile
,
1624 "\t%s -o %s %s -g %s\n\n",
1625 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1626 pchFilename
.c_str(),
1627 cflagsMacro
.c_str(),
1628 baseHeaderFilename
.c_str() );
1631 GenerateObjectFileTargets ( module
.non_if_data
,
1638 fprintf ( fMakefile
, "\n" );
1642 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1643 const string
& objs_macro
) const
1645 string
archiveFilename ( GetModuleArchiveFilename () );
1647 fprintf ( fMakefile
,
1649 archiveFilename
.c_str (),
1650 objs_macro
.c_str (),
1651 GetDirectory(archiveFilename
).c_str() );
1653 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1655 fprintf ( fMakefile
,
1658 objs_macro
.c_str ());
1660 GenerateCleanObjectsAsYouGoCode ();
1662 fprintf ( fMakefile
, "\n" );
1664 return archiveFilename
;
1668 MingwModuleHandler::GetCFlagsMacro () const
1670 return ssprintf ( "$(%s_CFLAGS)",
1671 module
.name
.c_str () );
1675 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1677 return ssprintf ( "$(%s_OBJS)",
1678 module
.name
.c_str () );
1682 MingwModuleHandler::GetLinkingDependenciesMacro () const
1684 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1688 MingwModuleHandler::GetLibsMacro () const
1690 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1694 MingwModuleHandler::GetLinkerMacro () const
1696 return ssprintf ( "$(%s_LFLAGS)",
1697 module
.name
.c_str () );
1701 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1703 if ( ReferenceObjects ( module
) )
1704 return GetObjectsMacro ( module
);
1706 return GetTargetFilename ( module
, NULL
);
1710 MingwModuleHandler::GenerateObjectMacro ()
1712 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1714 GenerateObjectMacros (
1717 &module
.linkerFlags
);
1719 // future references to the macro will be to get its values
1720 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1724 MingwModuleHandler::GenerateTargetMacro ()
1726 fprintf ( fMakefile
,
1728 GetTargetMacro ( module
, false ).c_str (),
1729 GetModuleTargets ( module
).c_str () );
1733 MingwModuleHandler::GetRpcHeaderDependencies (
1734 vector
<string
>& dependencies
) const
1736 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1738 Library
& library
= *module
.non_if_data
.libraries
[i
];
1739 if ( library
.importedModule
->type
== RpcServer
||
1740 library
.importedModule
->type
== RpcClient
)
1742 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.compilationUnits
.size (); j
++ )
1744 CompilationUnit
& compilationUnit
= *library
.importedModule
->non_if_data
.compilationUnits
[j
];
1745 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1746 string extension
= GetExtension ( sourceFileLocation
->filename
);
1747 if ( extension
== ".idl" || extension
== ".IDL" )
1749 string basename
= GetBasename ( sourceFileLocation
->filename
);
1750 if ( library
.importedModule
->type
== RpcServer
)
1751 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
1752 if ( library
.importedModule
->type
== RpcClient
)
1753 dependencies
.push_back ( GetRpcClientHeaderFilename ( basename
) );
1761 MingwModuleHandler::GenerateOtherMacros ()
1763 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1764 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1765 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1766 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1767 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1768 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1769 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1774 &module
.linkerFlags
);
1777 if ( module
.importLibrary
)
1779 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
1780 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
1782 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
1783 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
1784 string extension
= GetExtension ( sourceFileLocation
->filename
);
1785 if ( extension
== ".spec" || extension
== ".SPEC" )
1786 GetSpecObjectDependencies ( s
, sourceFileLocation
->filename
);
1789 if ( s
.size () > 0 )
1794 linkDepsMacro
.c_str() );
1795 for ( size_t i
= 0; i
< s
.size(); i
++ )
1796 fprintf ( fMakefile
,
1799 fprintf ( fMakefile
, "\n" );
1802 string globalCflags
= "-g";
1803 if ( backend
->usePipe
)
1804 globalCflags
+= " -pipe";
1805 if ( !module
.allowWarnings
)
1806 globalCflags
+= " -Werror";
1810 "%s += $(PROJECT_CFLAGS) %s\n",
1811 cflagsMacro
.c_str (),
1812 globalCflags
.c_str () );
1816 "%s += $(PROJECT_RCFLAGS)\n",
1817 windresflagsMacro
.c_str () );
1821 "%s += $(PROJECT_WIDLFLAGS)\n",
1822 widlflagsMacro
.c_str () );
1826 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1827 module
.name
.c_str () );
1832 linkDepsMacro
.c_str (),
1833 libsMacro
.c_str () );
1835 string cflags
= TypeSpecificCFlags();
1836 if ( cflags
.size() > 0 )
1838 fprintf ( fMakefile
,
1840 cflagsMacro
.c_str (),
1844 string nasmflags
= TypeSpecificNasmFlags();
1845 if ( nasmflags
.size () > 0 )
1847 fprintf ( fMakefile
,
1849 nasmflagsMacro
.c_str (),
1850 nasmflags
.c_str () );
1853 string linkerflags
= TypeSpecificLinkerFlags();
1854 if ( linkerflags
.size() > 0 )
1856 fprintf ( fMakefile
,
1858 linkerflagsMacro
.c_str (),
1859 linkerflags
.c_str () );
1862 fprintf ( fMakefile
, "\n\n" );
1864 // future references to the macros will be to get their values
1865 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1866 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1867 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
1871 MingwModuleHandler::GenerateRules ()
1873 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1874 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1875 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1877 if ( module
.name
!= "zlib" ) /* Avoid make warning */
1879 string proxyMakefile
= PassThruCacheDirectory (
1880 NormalizeFilename ( module
.GetBasePath () + sSep
+ "makefile" ),
1881 backend
->outputDirectory
);
1882 CLEAN_FILE ( proxyMakefile
);
1885 string targetMacro
= GetTargetMacro ( module
);
1886 CLEAN_FILE ( targetMacro
);
1888 // generate phony target for module name
1889 fprintf ( fMakefile
, ".PHONY: %s\n",
1890 module
.name
.c_str () );
1891 string dependencies
= GetTargetMacro ( module
);
1892 if ( module
.type
== Test
)
1893 dependencies
+= " $(REGTESTS_RUN_TARGET)";
1894 fprintf ( fMakefile
, "%s: %s\n\n",
1895 module
.name
.c_str (),
1896 dependencies
.c_str () );
1897 if ( module
.type
== Test
)
1899 fprintf ( fMakefile
,
1901 targetMacro
.c_str ());
1904 if ( !ReferenceObjects ( module
) )
1906 string
ar_target ( GenerateArchiveTarget ( ar
, objectsMacro
) );
1907 if ( targetMacro
!= ar_target
)
1908 CLEAN_FILE ( ar_target
);
1911 GenerateObjectFileTargets ( cc
,
1920 MingwModuleHandler::GetInvocationDependencies (
1921 const Module
& module
,
1922 string_list
& dependencies
)
1924 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1926 Invoke
& invoke
= *module
.invocations
[i
];
1927 if ( invoke
.invokeModule
== &module
)
1928 /* Protect against circular dependencies */
1930 invoke
.GetTargets ( dependencies
);
1935 MingwModuleHandler::GenerateInvocations () const
1937 if ( module
.invocations
.size () == 0 )
1940 size_t iend
= module
.invocations
.size ();
1941 for ( size_t i
= 0; i
< iend
; i
++ )
1943 const Invoke
& invoke
= *module
.invocations
[i
];
1945 if ( invoke
.invokeModule
->type
!= BuildTool
)
1947 throw InvalidBuildFileException ( module
.node
.location
,
1948 "Only modules of type buildtool can be invoked." );
1951 string invokeTarget
= module
.GetInvocationTarget ( i
);
1952 string_list invoke_targets
;
1953 assert ( invoke_targets
.size() );
1954 invoke
.GetTargets ( invoke_targets
);
1955 fprintf ( fMakefile
,
1957 invokeTarget
.c_str () );
1958 fprintf ( fMakefile
,
1960 invokeTarget
.c_str () );
1961 size_t j
, jend
= invoke_targets
.size();
1962 for ( j
= 0; j
< jend
; j
++ )
1964 fprintf ( fMakefile
,
1966 invoke_targets
[i
].c_str () );
1968 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
1969 for ( j
= 1; j
< jend
; j
++ )
1970 fprintf ( fMakefile
,
1972 invoke_targets
[i
].c_str () );
1973 fprintf ( fMakefile
,
1975 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1976 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1977 fprintf ( fMakefile
,
1979 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1980 invoke
.GetParameters ().c_str () );
1985 MingwModuleHandler::GetPreconditionDependenciesName () const
1987 return module
.name
+ "_precondition";
1991 MingwModuleHandler::GetDefaultDependencies (
1992 string_list
& dependencies
) const
1994 /* Avoid circular dependency */
1995 if ( module
.type
!= BuildTool
1996 && module
.name
!= "zlib"
1997 && module
.name
!= "hostzlib" )
1999 dependencies
.push_back ( "$(INIT)" );
2003 MingwModuleHandler::GeneratePreconditionDependencies ()
2005 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
2006 string_list sourceFilenames
;
2007 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
2008 string_list dependencies
;
2009 GetDefaultDependencies ( dependencies
);
2010 GetModuleDependencies ( dependencies
);
2012 GetInvocationDependencies ( module
, dependencies
);
2014 if ( dependencies
.size() )
2016 fprintf ( fMakefile
,
2018 preconditionDependenciesName
.c_str () );
2019 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
2020 fprintf ( fMakefile
,
2022 dependencies
[i
].c_str () );
2023 fprintf ( fMakefile
, "\n\n" );
2026 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
2028 fprintf ( fMakefile
,
2030 sourceFilenames
[i
].c_str(),
2031 preconditionDependenciesName
.c_str ());
2033 fprintf ( fMakefile
, "\n" );
2037 MingwModuleHandler::IsWineModule () const
2039 if ( module
.importLibrary
== NULL
)
2042 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
2043 return ( index
!= string::npos
);
2047 MingwModuleHandler::GetDefinitionFilename () const
2049 if ( module
.importLibrary
!= NULL
)
2051 string defFilename
= module
.GetBasePath () + sSep
+ module
.importLibrary
->definition
;
2052 if ( IsWineModule () )
2053 return PassThruCacheDirectory ( NormalizeFilename ( defFilename
),
2054 backend
->intermediateDirectory
);
2059 return "tools" + sSep
+ "rbuild" + sSep
+ "empty.def";
2063 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2065 if ( module
.importLibrary
!= NULL
)
2067 string
library_target (
2068 GetImportLibraryFilename ( module
, &clean_files
) );
2069 string defFilename
= GetDefinitionFilename ();
2072 GetDefinitionDependencies ( deps
);
2074 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2076 fprintf ( fMakefile
, "%s: %s",
2077 library_target
.c_str (),
2078 defFilename
.c_str () );
2080 size_t i
, iend
= deps
.size();
2081 for ( i
= 0; i
< iend
; i
++ )
2082 fprintf ( fMakefile
, " %s",
2085 fprintf ( fMakefile
, " | %s\n",
2086 GetDirectory ( GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2088 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2090 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
2091 fprintf ( fMakefile
,
2092 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
2093 module
.GetTargetName ().c_str (),
2094 defFilename
.c_str (),
2095 library_target
.c_str (),
2101 MingwModuleHandler::GetSpecObjectDependencies (
2102 string_list
& dependencies
,
2103 const string
& filename
) const
2105 string basename
= GetBasename ( filename
);
2106 string defDependency
= PassThruCacheDirectory (
2107 NormalizeFilename ( basename
+ ".spec.def" ),
2108 backend
->intermediateDirectory
);
2109 dependencies
.push_back ( defDependency
);
2110 string stubsDependency
= PassThruCacheDirectory (
2111 NormalizeFilename ( basename
+ ".stubs.c" ),
2112 backend
->intermediateDirectory
);
2113 dependencies
.push_back ( stubsDependency
);
2117 MingwModuleHandler::GetWidlObjectDependencies (
2118 string_list
& dependencies
,
2119 const string
& filename
) const
2121 string basename
= GetBasename ( filename
);
2122 string serverSourceDependency
= PassThruCacheDirectory (
2123 NormalizeFilename ( basename
+ "_s.c" ),
2124 backend
->intermediateDirectory
);
2125 dependencies
.push_back ( serverSourceDependency
);
2126 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
2130 MingwModuleHandler::GetDefinitionDependencies (
2131 string_list
& dependencies
) const
2133 string dkNkmLibNoFixup
= "dk/nkm/lib";
2134 const vector
<CompilationUnit
*>& compilationUnits
= module
.non_if_data
.compilationUnits
;
2135 for ( size_t i
= 0; i
< compilationUnits
.size (); i
++ )
2137 CompilationUnit
& compilationUnit
= *compilationUnits
[i
];
2138 FileLocation
* sourceFileLocation
= compilationUnit
.GetFilename ( backend
->intermediateDirectory
);
2139 string extension
= GetExtension ( sourceFileLocation
->filename
);
2140 if ( extension
== ".spec" || extension
== ".SPEC" )
2141 GetSpecObjectDependencies ( dependencies
, sourceFileLocation
->filename
);
2142 if ( extension
== ".idl" || extension
== ".IDL" )
2143 GetWidlObjectDependencies ( dependencies
, sourceFileLocation
->filename
);
2148 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2149 : MingwModuleHandler ( module_
)
2154 MingwBuildToolModuleHandler::Process ()
2156 GenerateBuildToolModuleTarget ();
2160 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2162 string
targetMacro ( GetTargetMacro (module
) );
2163 string objectsMacro
= GetObjectsMacro ( module
);
2164 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2165 string libsMacro
= GetLibsMacro ();
2170 if ( module
.cplusplus
)
2171 linker
= "${host_gpp}";
2173 linker
= "${host_gcc}";
2175 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2176 targetMacro
.c_str (),
2177 objectsMacro
.c_str (),
2178 linkDepsMacro
.c_str (),
2179 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2180 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2181 fprintf ( fMakefile
,
2182 "\t%s %s -o $@ %s %s\n\n",
2184 GetLinkerMacro ().c_str (),
2185 objectsMacro
.c_str (),
2186 libsMacro
.c_str () );
2190 MingwKernelModuleHandler::MingwKernelModuleHandler (
2191 const Module
& module_
)
2193 : MingwModuleHandler ( module_
)
2198 MingwKernelModuleHandler::Process ()
2200 GenerateKernelModuleTarget ();
2204 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2206 string
targetMacro ( GetTargetMacro ( module
) );
2207 string workingDirectory
= GetWorkingDirectory ( );
2208 string objectsMacro
= GetObjectsMacro ( module
);
2209 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2210 string libsMacro
= GetLibsMacro ();
2212 GenerateImportLibraryTargetIfNeeded ();
2214 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2218 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2220 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",
2221 module
.GetBasePath ().c_str (),
2223 module
.entrypoint
.c_str (),
2224 module
.baseaddress
.c_str () );
2225 GenerateLinkerCommand ( dependencies
,
2234 GeneratePhonyTarget();
2239 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2240 const Module
& module_
)
2242 : MingwModuleHandler ( module_
)
2247 MingwStaticLibraryModuleHandler::Process ()
2249 GenerateStaticLibraryModuleTarget ();
2253 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2259 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2260 const Module
& module_
)
2262 : MingwModuleHandler ( module_
)
2267 MingwObjectLibraryModuleHandler::Process ()
2269 GenerateObjectLibraryModuleTarget ();
2273 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2279 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2280 const Module
& module_
)
2282 : MingwModuleHandler ( module_
)
2287 MingwKernelModeDLLModuleHandler::Process ()
2289 GenerateKernelModeDLLModuleTarget ();
2293 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2295 string
targetMacro ( GetTargetMacro ( module
) );
2296 string workingDirectory
= GetWorkingDirectory ( );
2297 string objectsMacro
= GetObjectsMacro ( module
);
2298 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2299 string libsMacro
= GetLibsMacro ();
2301 GenerateImportLibraryTargetIfNeeded ();
2303 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2307 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2309 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2310 module
.entrypoint
.c_str (),
2311 module
.baseaddress
.c_str () );
2312 GenerateLinkerCommand ( dependencies
,
2321 GeneratePhonyTarget();
2326 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2327 const Module
& module_
)
2329 : MingwModuleHandler ( module_
)
2334 MingwKernelModeDriverModuleHandler::Process ()
2336 GenerateKernelModeDriverModuleTarget ();
2341 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2343 string
targetMacro ( GetTargetMacro (module
) );
2344 string workingDirectory
= GetWorkingDirectory ();
2345 string objectsMacro
= GetObjectsMacro ( module
);
2346 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2347 string libsMacro
= GetLibsMacro ();
2349 GenerateImportLibraryTargetIfNeeded ();
2351 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2355 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2357 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2358 module
.entrypoint
.c_str (),
2359 module
.baseaddress
.c_str () );
2360 GenerateLinkerCommand ( dependencies
,
2369 GeneratePhonyTarget();
2374 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2375 const Module
& module_
)
2377 : MingwModuleHandler ( module_
)
2382 MingwNativeDLLModuleHandler::Process ()
2384 GenerateNativeDLLModuleTarget ();
2388 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2390 string
targetMacro ( GetTargetMacro (module
) );
2391 string workingDirectory
= GetWorkingDirectory ( );
2392 string objectsMacro
= GetObjectsMacro ( module
);
2393 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2394 string libsMacro
= GetLibsMacro ();
2396 GenerateImportLibraryTargetIfNeeded ();
2398 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2402 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2404 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2405 module
.entrypoint
.c_str (),
2406 module
.baseaddress
.c_str () );
2407 GenerateLinkerCommand ( dependencies
,
2416 GeneratePhonyTarget();
2421 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2422 const Module
& module_
)
2424 : MingwModuleHandler ( module_
)
2429 MingwNativeCUIModuleHandler::Process ()
2431 GenerateNativeCUIModuleTarget ();
2435 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2437 string
targetMacro ( GetTargetMacro (module
) );
2438 string workingDirectory
= GetWorkingDirectory ( );
2439 string objectsMacro
= GetObjectsMacro ( module
);
2440 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2441 string libsMacro
= GetLibsMacro ();
2443 GenerateImportLibraryTargetIfNeeded ();
2445 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2449 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2451 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2452 module
.entrypoint
.c_str (),
2453 module
.baseaddress
.c_str () );
2454 GenerateLinkerCommand ( dependencies
,
2463 GeneratePhonyTarget();
2468 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2469 const Module
& module_
)
2471 : MingwModuleHandler ( module_
)
2476 MingwWin32DLLModuleHandler::Process ()
2478 GenerateWin32DLLModuleTarget ();
2482 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2484 string
targetMacro ( GetTargetMacro (module
) );
2485 string workingDirectory
= GetWorkingDirectory ( );
2486 string objectsMacro
= GetObjectsMacro ( module
);
2487 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2488 string libsMacro
= GetLibsMacro ();
2490 GenerateImportLibraryTargetIfNeeded ();
2492 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2496 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2499 if ( module
.cplusplus
)
2504 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2505 module
.entrypoint
.c_str (),
2506 module
.baseaddress
.c_str () );
2507 GenerateLinkerCommand ( dependencies
,
2516 GeneratePhonyTarget();
2521 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2522 const Module
& module_
)
2524 : MingwModuleHandler ( module_
)
2529 MingwWin32CUIModuleHandler::Process ()
2531 GenerateWin32CUIModuleTarget ();
2535 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2537 string
targetMacro ( GetTargetMacro (module
) );
2538 string workingDirectory
= GetWorkingDirectory ( );
2539 string objectsMacro
= GetObjectsMacro ( module
);
2540 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2541 string libsMacro
= GetLibsMacro ();
2543 GenerateImportLibraryTargetIfNeeded ();
2545 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2549 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2552 if ( module
.cplusplus
)
2557 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2558 module
.entrypoint
.c_str (),
2559 module
.baseaddress
.c_str () );
2560 GenerateLinkerCommand ( dependencies
,
2569 GeneratePhonyTarget();
2574 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2575 const Module
& module_
)
2577 : MingwModuleHandler ( module_
)
2582 MingwWin32GUIModuleHandler::Process ()
2584 GenerateWin32GUIModuleTarget ();
2588 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2590 string
targetMacro ( GetTargetMacro (module
) );
2591 string workingDirectory
= GetWorkingDirectory ( );
2592 string objectsMacro
= GetObjectsMacro ( module
);
2593 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2594 string libsMacro
= GetLibsMacro ();
2596 GenerateImportLibraryTargetIfNeeded ();
2598 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
2602 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2605 if ( module
.cplusplus
)
2610 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2611 module
.entrypoint
.c_str (),
2612 module
.baseaddress
.c_str () );
2613 GenerateLinkerCommand ( dependencies
,
2622 GeneratePhonyTarget();
2627 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2628 const Module
& module_
)
2630 : MingwModuleHandler ( module_
)
2635 MingwBootLoaderModuleHandler::Process ()
2637 GenerateBootLoaderModuleTarget ();
2641 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2643 string
targetName ( module
.GetTargetName () );
2644 string
targetMacro ( GetTargetMacro (module
) );
2645 string workingDirectory
= GetWorkingDirectory ();
2646 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2647 CLEAN_FILE ( junk_tmp
);
2648 string objectsMacro
= GetObjectsMacro ( module
);
2649 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2650 string libsMacro
= GetLibsMacro ();
2654 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2655 targetMacro
.c_str (),
2656 objectsMacro
.c_str (),
2657 linkDepsMacro
.c_str (),
2658 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2660 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2662 fprintf ( fMakefile
,
2663 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2664 GetLinkerMacro ().c_str (),
2666 objectsMacro
.c_str (),
2667 linkDepsMacro
.c_str () );
2668 fprintf ( fMakefile
,
2669 "\t${objcopy} -O binary %s $@\n",
2670 junk_tmp
.c_str () );
2671 fprintf ( fMakefile
,
2672 "\t-@${rm} %s 2>$(NUL)\n",
2673 junk_tmp
.c_str () );
2677 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2678 const Module
& module_
)
2680 : MingwModuleHandler ( module_
)
2685 MingwBootSectorModuleHandler::Process ()
2687 GenerateBootSectorModuleTarget ();
2691 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2693 string objectsMacro
= GetObjectsMacro ( module
);
2697 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2698 module
.name
.c_str ());
2699 fprintf ( fMakefile
,
2701 module
.name
.c_str (),
2702 objectsMacro
.c_str () );
2706 MingwIsoModuleHandler::MingwIsoModuleHandler (
2707 const Module
& module_
)
2709 : MingwModuleHandler ( module_
)
2714 MingwIsoModuleHandler::Process ()
2716 GenerateIsoModuleTarget ();
2720 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2721 const string
& bootcdDirectory
)
2723 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2725 const Module
& m
= *module
.project
.modules
[i
];
2728 if ( m
.bootstrap
!= NULL
)
2730 string sourceFilename
= PassThruCacheDirectory (
2731 NormalizeFilename ( m
.GetPath () ),
2732 backend
->outputDirectory
);
2733 string
targetFilenameNoFixup ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
+ sSep
+ m
.bootstrap
->nameoncd
);
2734 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2735 NormalizeFilename ( targetFilenameNoFixup
),
2736 backend
->outputDirectory
);
2737 fprintf ( fMakefile
,
2739 fprintf ( fMakefile
,
2740 "\t${cp} %s %s 1>$(NUL)\n",
2741 sourceFilename
.c_str (),
2742 targetFilename
.c_str () );
2748 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2749 const string
& bootcdDirectory
)
2751 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2753 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2754 string targetFilenameNoFixup
= bootcdDirectory
+ sSep
+ cdfile
.base
+ sSep
+ cdfile
.nameoncd
;
2755 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2756 NormalizeFilename ( targetFilenameNoFixup
),
2757 backend
->outputDirectory
);
2758 fprintf ( fMakefile
,
2760 fprintf ( fMakefile
,
2761 "\t${cp} %s %s 1>$(NUL)\n",
2762 cdfile
.GetPath ().c_str (),
2763 targetFilename
.c_str () );
2768 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
2771 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2773 const Module
& m
= *module
.project
.modules
[i
];
2776 if ( m
.bootstrap
!= NULL
)
2778 string
targetDirectory ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
);
2779 if ( directories
.size () > 0 )
2781 directories
+= PassThruCacheDirectory (
2782 NormalizeFilename ( targetDirectory
),
2783 backend
->outputDirectory
);
2790 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
2793 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2795 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2796 string
targetDirectory ( bootcdDirectory
+ sSep
+ cdfile
.base
);
2797 if ( directories
.size () > 0 )
2799 directories
+= PassThruCacheDirectory (
2800 NormalizeFilename ( targetDirectory
),
2801 backend
->outputDirectory
);
2807 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
2809 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
2810 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
2815 MingwIsoModuleHandler::GetBootstrapCdFiles (
2816 vector
<string
>& out
) const
2818 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2820 const Module
& m
= *module
.project
.modules
[i
];
2823 if ( m
.bootstrap
!= NULL
)
2825 string filename
= PassThruCacheDirectory (
2826 NormalizeFilename ( m
.GetPath () ),
2827 backend
->outputDirectory
);
2828 out
.push_back ( filename
);
2834 MingwIsoModuleHandler::GetNonModuleCdFiles (
2835 vector
<string
>& out
) const
2837 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2839 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2840 out
.push_back ( cdfile
.GetPath () );
2845 MingwIsoModuleHandler::GetCdFiles (
2846 vector
<string
>& out
) const
2848 GetBootstrapCdFiles ( out
);
2849 GetNonModuleCdFiles ( out
);
2853 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2855 string bootcdDirectory
= "cd";
2856 string bootcd
= PassThruCacheDirectory (
2857 NormalizeFilename ( bootcdDirectory
+ sSep
),
2858 backend
->outputDirectory
);
2859 string isoboot
= PassThruCacheDirectory (
2860 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ "isoboot.o" ),
2861 backend
->outputDirectory
);
2862 string bootcdReactosNoFixup
= bootcdDirectory
+ sSep
+ "reactos";
2863 string bootcdReactos
= PassThruCacheDirectory (
2864 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
),
2865 backend
->outputDirectory
);
2866 CLEAN_FILE ( bootcdReactos
);
2867 string reactosInf
= PassThruCacheDirectory (
2868 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
+ "reactos.inf" ),
2869 backend
->outputDirectory
);
2870 string reactosDff
= NormalizeFilename ( "bootdata" + sSep
+ "packages" + sSep
+ "reactos.dff" );
2871 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
2872 vector
<string
> vCdFiles
;
2873 GetCdFiles ( vCdFiles
);
2874 string cdFiles
= v2s ( vCdFiles
, 5 );
2876 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2877 module
.name
.c_str ());
2878 fprintf ( fMakefile
,
2879 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2880 module
.name
.c_str (),
2882 bootcdReactos
.c_str (),
2883 cdDirectories
.c_str (),
2885 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2886 fprintf ( fMakefile
,
2887 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
2888 reactosDff
.c_str (),
2889 bootcdReactos
.c_str () );
2890 fprintf ( fMakefile
,
2891 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2892 reactosDff
.c_str (),
2893 reactosInf
.c_str (),
2894 bootcdReactos
.c_str ());
2895 fprintf ( fMakefile
,
2896 "\t-@${rm} %s 2>$(NUL)\n",
2897 reactosInf
.c_str () );
2898 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
2899 OutputCdfileCopyCommands ( bootcdDirectory
);
2900 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2901 fprintf ( fMakefile
,
2902 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2905 fprintf ( fMakefile
,
2910 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
2911 const Module
& module_
)
2913 : MingwModuleHandler ( module_
)
2918 MingwLiveIsoModuleHandler::Process ()
2920 GenerateLiveIsoModuleTarget ();
2924 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
2926 string normalizedDirectory
= MingwModuleHandler::PassThruCacheDirectory (
2927 NormalizeFilename ( directory
) + sSep
,
2928 backend
->outputDirectory
);
2932 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string
& sourceFilename
,
2933 const string
& targetFilename
,
2934 const string
& targetDirectory
)
2936 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2937 NormalizeFilename ( targetDirectory
+ sSep
+ targetFilename
),
2938 backend
->outputDirectory
);
2939 fprintf ( fMakefile
,
2941 fprintf ( fMakefile
,
2942 "\t${cp} %s %s 1>$(NUL)\n",
2943 sourceFilename
.c_str (),
2944 normalizedTargetFilename
.c_str () );
2948 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
2949 string
& reactosDirectory
)
2951 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2953 const Module
& m
= *module
.project
.modules
[i
];
2956 if ( m
.installName
.length () > 0 )
2958 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
2959 string sourceFilename
= MingwModuleHandler::PassThruCacheDirectory (
2960 NormalizeFilename ( aliasedModule
.GetPath () ),
2961 backend
->outputDirectory
);
2962 OutputCopyCommand ( sourceFilename
,
2964 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.installBase
);
2970 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
2971 string
& reactosDirectory
)
2973 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
2975 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
2976 OutputCopyCommand ( installfile
.GetPath (),
2977 installfile
.newname
,
2978 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.base
);
2983 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
2985 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
2986 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
2987 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
2988 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
2989 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
2990 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
2992 string livecdIni
= "bootdata" + sSep
+ "livecd.ini";
2993 OutputCopyCommand ( livecdIni
,
2999 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
3001 string freeldr
= PassThruCacheDirectory (
3002 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "freeldr" + sSep
+ "freeldr.sys" ),
3003 backend
->outputDirectory
);
3004 CreateDirectory ( livecdDirectory
+ sSep
+ "loader" );
3005 OutputCopyCommand ( freeldr
,
3007 livecdDirectory
+ sSep
+ "loader" );
3011 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
3013 string reactosSystem32ConfigDirectory
= NormalizeFilename (
3014 MingwModuleHandler::PassThruCacheDirectory (
3015 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config" + sSep
,
3016 backend
->outputDirectory
) );
3017 fprintf ( fMakefile
,
3018 "\t$(ECHO_MKHIVE)\n" );
3019 fprintf ( fMakefile
,
3020 "\t$(MKHIVE_TARGET) bootdata %s bootdata%clivecd.inf bootdata%chiveinst.inf\n",
3021 reactosSystem32ConfigDirectory
.c_str (),
3027 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
3029 string livecdDirectory
= "livecd";
3030 string livecd
= PassThruCacheDirectory (
3031 NormalizeFilename ( livecdDirectory
+ sSep
),
3032 backend
->outputDirectory
);
3033 string isoboot
= PassThruCacheDirectory (
3034 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ "isoboot.o" ),
3035 backend
->outputDirectory
);
3036 string reactosDirectory
= "reactos";
3037 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3038 string livecdReactos
= NormalizeFilename ( PassThruCacheDirectory (
3039 NormalizeFilename ( livecdReactosNoFixup
+ sSep
),
3040 backend
->outputDirectory
) );
3041 CLEAN_FILE ( livecdReactos
);
3043 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3044 module
.name
.c_str ());
3045 fprintf ( fMakefile
,
3046 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3047 module
.name
.c_str (),
3049 livecdReactos
.c_str () );
3050 OutputModuleCopyCommands ( livecdDirectory
,
3052 OutputNonModuleCopyCommands ( livecdDirectory
,
3054 OutputProfilesDirectoryCommands ( livecdDirectory
);
3055 OutputLoaderCommands ( livecdDirectory
);
3056 OutputRegistryCommands ( livecdDirectory
);
3057 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3058 fprintf ( fMakefile
,
3059 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS ReactOS-LiveCD.iso\n",
3062 fprintf ( fMakefile
,
3067 MingwTestModuleHandler::MingwTestModuleHandler (
3068 const Module
& module_
)
3070 : MingwModuleHandler ( module_
)
3075 MingwTestModuleHandler::Process ()
3077 GenerateTestModuleTarget ();
3081 MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector
<CompilationUnit
*>& compilationUnits
)
3083 string basePath
= "$(INTERMEDIATE)" + sSep
+ module
.GetBasePath ();
3084 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_hooks.c", false, "", false ) ) );
3085 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_stubs.S", false, "", false ) ) );
3086 compilationUnits
.push_back ( new CompilationUnit ( new File ( basePath
+ sSep
+ "_startup.c", false, "", false ) ) );
3090 MingwTestModuleHandler::GenerateTestModuleTarget ()
3092 string
targetMacro ( GetTargetMacro ( module
) );
3093 string workingDirectory
= GetWorkingDirectory ( );
3094 string objectsMacro
= GetObjectsMacro ( module
);
3095 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3096 string libsMacro
= GetLibsMacro ();
3098 GenerateImportLibraryTargetIfNeeded ();
3100 if ( module
.non_if_data
.compilationUnits
.size () > 0 )
3104 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3107 if ( module
.cplusplus
)
3112 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3113 module
.entrypoint
.c_str (),
3114 module
.baseaddress
.c_str () );
3115 GenerateLinkerCommand ( dependencies
,
3124 GeneratePhonyTarget();
3129 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3130 const Module
& module_
)
3132 : MingwModuleHandler ( module_
)
3137 MingwRpcServerModuleHandler::Process ()
3143 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3144 const Module
& module_
)
3146 : MingwModuleHandler ( module_
)
3151 MingwRpcClientModuleHandler::Process ()
3157 MingwAliasModuleHandler::MingwAliasModuleHandler (
3158 const Module
& module_
)
3160 : MingwModuleHandler ( module_
)
3165 MingwAliasModuleHandler::Process ()