4 #include "../../rbuild.h"
6 #include "modulehandler.h"
11 #define CLEAN_FILE(f) clean_files.push_back ( f );
13 static string ros_temp
= "$(TEMPORARY)";
15 MingwModuleHandler::backend
= NULL
;
17 MingwModuleHandler::fMakefile
= NULL
;
19 MingwModuleHandler::use_pch
= false;
23 const string
& filename
,
24 const string
& prefix
)
26 if ( !prefix
.length() )
29 const char* pfilename
= filename
.c_str();
30 const char* p1
= strrchr ( pfilename
, '/' );
31 const char* p2
= strrchr ( pfilename
, '\\' );
36 out
+= string(pfilename
,p1
-pfilename
) + CSEP
;
39 out
+= prefix
+ pfilename
;
44 GetTargetMacro ( const Module
& module
, bool with_dollar
)
46 string
s ( module
.name
);
50 return ssprintf ( "$(%s)", s
.c_str() );
54 MingwModuleHandler::MingwModuleHandler (
55 const Module
& module_
)
61 MingwModuleHandler::~MingwModuleHandler()
66 MingwModuleHandler::SetBackend ( MingwBackend
* backend_
)
72 MingwModuleHandler::SetMakefile ( FILE* f
)
78 MingwModuleHandler::SetUsePch ( bool b
)
84 MingwModuleHandler::RemoveVariables ( string path
)
86 size_t i
= path
.find ( '$' );
87 if ( i
!= string::npos
)
89 size_t j
= path
.find ( ')', i
);
90 if ( j
!= string::npos
)
92 if ( j
+ 2 < path
.length () && path
[j
+ 1] == CSEP
)
93 return path
.substr ( j
+ 2);
95 return path
.substr ( j
+ 1);
102 MingwModuleHandler::PassThruCacheDirectory (
104 Directory
* directoryTree
)
106 string
directory ( GetDirectory ( RemoveVariables ( file
) ) );
107 string generatedFilesDirectory
= backend
->AddDirectoryTarget ( directory
,
109 if ( directory
.find ( generatedFilesDirectory
) != string::npos
)
110 /* This path already includes the generated files directory variable */
115 return generatedFilesDirectory
;
116 return generatedFilesDirectory
+ SSEP
+ file
;
120 /*static*/ Directory
*
121 MingwModuleHandler::GetTargetDirectoryTree (
122 const Module
& module
)
124 if ( module
.type
== StaticLibrary
)
125 return backend
->intermediateDirectory
;
126 return backend
->outputDirectory
;
130 MingwModuleHandler::GetTargetFilename (
131 const Module
& module
,
132 string_list
* pclean_files
)
134 string target
= PassThruCacheDirectory (
135 NormalizeFilename ( module
.GetPath () ),
136 GetTargetDirectoryTree ( module
) );
139 string_list
& clean_files
= *pclean_files
;
140 CLEAN_FILE ( target
);
146 MingwModuleHandler::GetImportLibraryFilename (
147 const Module
& module
,
148 string_list
* pclean_files
)
150 string target
= PassThruCacheDirectory (
151 NormalizeFilename ( module
.GetDependencyPath () ),
152 backend
->intermediateDirectory
);
155 string_list
& clean_files
= *pclean_files
;
156 CLEAN_FILE ( target
);
161 /*static*/ MingwModuleHandler
*
162 MingwModuleHandler::InstanciateHandler (
163 const Module
& module
,
164 MingwBackend
* backend
)
166 MingwModuleHandler
* handler
;
167 switch ( module
.type
)
170 handler
= new MingwBuildToolModuleHandler ( module
);
173 handler
= new MingwStaticLibraryModuleHandler ( module
);
176 handler
= new MingwObjectLibraryModuleHandler ( module
);
179 handler
= new MingwKernelModuleHandler ( module
);
182 handler
= new MingwNativeCUIModuleHandler ( module
);
185 handler
= new MingwWin32CUIModuleHandler ( module
);
188 handler
= new MingwWin32GUIModuleHandler ( module
);
191 handler
= new MingwKernelModeDLLModuleHandler ( module
);
194 handler
= new MingwNativeDLLModuleHandler ( module
);
197 handler
= new MingwWin32DLLModuleHandler ( module
);
199 case KernelModeDriver
:
200 handler
= new MingwKernelModeDriverModuleHandler ( module
);
203 handler
= new MingwBootLoaderModuleHandler ( module
);
206 handler
= new MingwBootSectorModuleHandler ( module
);
209 handler
= new MingwIsoModuleHandler ( module
);
212 handler
= new MingwLiveIsoModuleHandler ( module
);
215 handler
= new MingwTestModuleHandler ( module
);
218 handler
= new MingwRpcServerModuleHandler ( module
);
221 handler
= new MingwRpcClientModuleHandler ( module
);
224 throw UnknownModuleTypeException (
225 module
.node
.location
,
233 MingwModuleHandler::GetWorkingDirectory () const
239 MingwModuleHandler::GetBasename ( const string
& filename
) const
241 size_t index
= filename
.find_last_of ( '.' );
242 if ( index
!= string::npos
)
243 return filename
.substr ( 0, index
);
248 MingwModuleHandler::GetActualSourceFilename (
249 const string
& filename
) const
251 string extension
= GetExtension ( filename
);
252 if ( extension
== ".spec" || extension
== ".SPEC" )
254 string basename
= GetBasename ( filename
);
255 return PassThruCacheDirectory ( NormalizeFilename ( basename
+ ".stubs.c" ),
256 backend
->intermediateDirectory
);
258 else if ( extension
== ".idl" || extension
== ".IDL" )
260 string basename
= GetBasename ( filename
);
262 if ( module
.type
== RpcServer
)
263 newname
= basename
+ "_s.c";
265 newname
= basename
+ "_c.c";
266 return PassThruCacheDirectory ( NormalizeFilename ( newname
),
267 backend
->intermediateDirectory
);
274 MingwModuleHandler::GetModuleArchiveFilename () const
276 if ( module
.type
== StaticLibrary
)
277 return GetTargetFilename ( module
, NULL
);
278 return PassThruCacheDirectory ( ReplaceExtension (
279 NormalizeFilename ( module
.GetPath () ),
281 backend
->intermediateDirectory
);
285 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
287 string extension
= GetExtension ( file
.name
);
288 return ( extension
== ".spec" || extension
== ".SPEC" );
292 MingwModuleHandler::ReferenceObjects (
293 const Module
& module
)
295 if ( module
.type
== ObjectLibrary
)
297 if ( module
.type
== RpcServer
)
299 if ( module
.type
== RpcClient
)
305 MingwModuleHandler::GetImportLibraryDependency (
306 const Module
& importedModule
)
309 if ( ReferenceObjects ( importedModule
) )
310 dep
= GetTargetMacro ( importedModule
);
312 dep
= GetImportLibraryFilename ( importedModule
, NULL
);
317 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
318 string_list
& targets
)
320 if ( dependencyModule
.invocations
.size () > 0 )
322 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
324 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
325 invoke
.GetTargets ( targets
);
329 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
333 MingwModuleHandler::GetModuleDependencies (
334 string_list
& dependencies
)
336 size_t iend
= module
.dependencies
.size ();
341 for ( size_t i
= 0; i
< iend
; i
++ )
343 const Dependency
& dependency
= *module
.dependencies
[i
];
344 const Module
& dependencyModule
= *dependency
.dependencyModule
;
345 GetTargets ( dependencyModule
,
348 GetDefinitionDependencies ( dependencies
);
352 MingwModuleHandler::GetSourceFilenames ( string_list
& list
,
353 bool includeGeneratedFiles
) const
357 const vector
<File
*>& files
= module
.non_if_data
.files
;
358 for ( i
= 0; i
< files
.size (); i
++ )
360 if ( includeGeneratedFiles
|| !files
[i
]->IsGeneratedFile () )
363 GetActualSourceFilename ( files
[i
]->name
) );
366 // intentionally make a copy so that we can append more work in
367 // the middle of processing without having to go recursive
368 vector
<If
*> v
= module
.non_if_data
.ifs
;
369 for ( i
= 0; i
< v
.size (); i
++ )
373 // check for sub-ifs to add to list
374 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
375 for ( j
= 0; j
< ifs
.size (); j
++ )
376 v
.push_back ( ifs
[j
] );
377 const vector
<File
*>& files
= rIf
.data
.files
;
378 for ( j
= 0; j
< files
.size (); j
++ )
380 File
& file
= *files
[j
];
381 if ( includeGeneratedFiles
|| !file
.IsGeneratedFile () )
384 GetActualSourceFilename ( file
.name
) );
391 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
392 string_list
& list
) const
394 GetSourceFilenames ( list
, false );
398 MingwModuleHandler::GetObjectFilename (
399 const string
& sourceFilename
,
400 string_list
* pclean_files
) const
402 Directory
* directoryTree
;
405 string extension
= GetExtension ( sourceFilename
);
406 if ( extension
== ".rc" || extension
== ".RC" )
407 newExtension
= ".coff";
408 else if ( extension
== ".spec" || extension
== ".SPEC" )
409 newExtension
= ".stubs.o";
410 else if ( extension
== ".idl" || extension
== ".IDL" )
412 if ( module
.type
== RpcServer
)
413 newExtension
= "_s.o";
415 newExtension
= "_c.o";
420 if ( module
.type
== BootSector
)
421 directoryTree
= backend
->outputDirectory
;
423 directoryTree
= backend
->intermediateDirectory
;
425 string obj_file
= PassThruCacheDirectory (
426 NormalizeFilename ( ReplaceExtension (
427 RemoveVariables ( sourceFilename
),
432 string_list
& clean_files
= *pclean_files
;
433 CLEAN_FILE ( obj_file
);
439 MingwModuleHandler::GenerateCleanTarget () const
441 if ( 0 == clean_files
.size() )
443 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
444 fprintf ( fMakefile
, "%s_clean:\n\t-@${rm}", module
.name
.c_str() );
445 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
448 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
449 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
451 fprintf ( fMakefile
, " 2>$(NUL)\n" );
452 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
456 MingwModuleHandler::GenerateInstallTarget () const
458 if ( module
.installName
.length () == 0 )
460 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
461 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
462 NormalizeFilename ( module
.installBase
+ SSEP
+ module
.installName
),
463 backend
->installDirectory
);
466 module
.name
.c_str (),
467 normalizedTargetFilename
.c_str() );
471 MingwModuleHandler::GenerateDependsTarget () const
474 ".PHONY: %s_depends\n",
475 module
.name
.c_str() );
477 "%s_depends: $(RBUILD_TARGET)\n",
478 module
.name
.c_str () );
480 "\t$(ECHO_RBUILD)\n" );
482 "\t$(Q)$(RBUILD_TARGET) -dm%s mingw\n",
483 module
.name
.c_str () );
487 MingwModuleHandler::GetObjectFilenames ()
489 const vector
<File
*>& files
= module
.non_if_data
.files
;
490 if ( files
.size () == 0 )
493 string
objectFilenames ( "" );
494 for ( size_t i
= 0; i
< files
.size (); i
++ )
496 if ( objectFilenames
.size () > 0 )
497 objectFilenames
+= " ";
499 GetObjectFilename ( files
[i
]->name
, NULL
);
501 return objectFilenames
;
505 MingwModuleHandler::GenerateGccDefineParametersFromVector (
506 const vector
<Define
*>& defines
)
509 for ( size_t i
= 0; i
< defines
.size (); i
++ )
511 Define
& define
= *defines
[i
];
512 if (parameters
.length () > 0)
515 parameters
+= define
.name
;
516 if (define
.value
.length () > 0)
519 parameters
+= define
.value
;
526 MingwModuleHandler::GenerateGccDefineParameters () const
528 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
529 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
530 if ( s
.length () > 0 )
539 MingwModuleHandler::ConcatenatePaths (
541 const string
& path2
) const
543 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
545 if ( path1
[path1
.length ()] == CSEP
)
546 return path1
+ path2
;
548 return path1
+ CSEP
+ path2
;
552 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
555 for ( size_t i
= 0; i
< includes
.size (); i
++ )
557 Include
& include
= *includes
[i
];
558 if ( parameters
.length () > 0 )
560 parameters
+= "-I" + include
.directory
;
566 MingwModuleHandler::GenerateGccIncludeParameters () const
568 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
569 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
570 if ( s
.length () > 0 )
579 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
582 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
584 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
585 if ( parameters
.length () > 0 )
587 parameters
+= compilerFlag
.flag
;
593 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
596 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
598 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
599 if ( parameters
.length () > 0 )
601 parameters
+= linkerFlag
.flag
;
607 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
608 const vector
<Library
*>& libraries
)
610 string
dependencies ( "" );
612 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
614 if ( wrap_count
++ == 5 )
615 dependencies
+= " \\\n\t\t", wrap_count
= 0;
616 else if ( dependencies
.size () > 0 )
618 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
624 MingwModuleHandler::GenerateLinkerParameters () const
626 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
630 MingwModuleHandler::GenerateMacro (
631 const char* assignmentOperation
,
633 const IfableData
& data
)
636 bool generateAssignment
;
638 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
639 if ( generateAssignment
)
644 assignmentOperation
);
647 if ( use_pch
&& module
.pch
!= NULL
)
651 GetDirectory ( GetPrecompiledHeaderFilename () ).c_str () );
654 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
655 if ( compilerParameters
.size () > 0 )
660 compilerParameters
.c_str () );
663 for ( i
= 0; i
< data
.includes
.size(); i
++ )
668 data
.includes
[i
]->directory
.c_str() );
670 for ( i
= 0; i
< data
.defines
.size(); i
++ )
672 Define
& d
= *data
.defines
[i
];
677 if ( d
.value
.size() )
683 if ( generateAssignment
)
685 fprintf ( fMakefile
, "\n" );
690 MingwModuleHandler::GenerateMacros (
691 const char* assignmentOperation
,
692 const IfableData
& data
,
693 const vector
<LinkerFlag
*>* linkerFlags
)
697 GenerateMacro ( assignmentOperation
,
700 GenerateMacro ( assignmentOperation
,
704 if ( linkerFlags
!= NULL
)
706 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
707 if ( linkerParameters
.size () > 0 )
712 linkerflagsMacro
.c_str (),
714 linkerParameters
.c_str() );
718 if ( data
.libraries
.size () > 0 )
720 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
721 if ( deps
.size () > 0 )
732 const vector
<If
*>& ifs
= data
.ifs
;
733 for ( i
= 0; i
< ifs
.size(); i
++ )
736 if ( rIf
.data
.defines
.size()
737 || rIf
.data
.includes
.size()
738 || rIf
.data
.libraries
.size()
739 || rIf
.data
.files
.size()
740 || rIf
.data
.compilerFlags
.size()
741 || rIf
.data
.ifs
.size() )
745 "%s (\"$(%s)\",\"%s\")\n",
746 rIf
.negated
? "ifneq" : "ifeq",
747 rIf
.property
.c_str(),
761 MingwModuleHandler::CleanupFileVector ( vector
<File
*>& sourceFiles
)
763 for (size_t i
= 0; i
< sourceFiles
.size (); i
++)
764 delete sourceFiles
[i
];
768 MingwModuleHandler::GetModuleSpecificSourceFiles ( vector
<File
*>& sourceFiles
)
773 MingwModuleHandler::GenerateObjectMacros (
774 const char* assignmentOperation
,
775 const IfableData
& data
,
776 const vector
<LinkerFlag
*>* linkerFlags
)
780 const vector
<File
*>& files
= data
.files
;
781 if ( files
.size () > 0 )
783 for ( i
= 0; i
< files
.size (); i
++ )
785 File
& file
= *files
[i
];
790 objectsMacro
.c_str(),
792 file
.name
, NULL
).c_str (),
793 objectsMacro
.c_str() );
799 objectsMacro
.c_str (),
800 assignmentOperation
);
801 for ( i
= 0; i
< files
.size(); i
++ )
803 File
& file
= *files
[i
];
809 ( i
%10 == 9 ? " \\\n\t" : " " ),
811 file
.name
, NULL
).c_str () );
814 fprintf ( fMakefile
, "\n" );
817 const vector
<If
*>& ifs
= data
.ifs
;
818 for ( i
= 0; i
< ifs
.size(); i
++ )
821 if ( rIf
.data
.defines
.size()
822 || rIf
.data
.includes
.size()
823 || rIf
.data
.libraries
.size()
824 || rIf
.data
.files
.size()
825 || rIf
.data
.compilerFlags
.size()
826 || rIf
.data
.ifs
.size() )
830 "%s (\"$(%s)\",\"%s\")\n",
831 rIf
.negated
? "ifneq" : "ifeq",
832 rIf
.property
.c_str(),
834 GenerateObjectMacros (
844 vector
<File
*> sourceFiles
;
845 GetModuleSpecificSourceFiles ( sourceFiles
);
846 for ( i
= 0; i
< sourceFiles
.size (); i
++ )
851 objectsMacro
.c_str(),
853 sourceFiles
[i
]->name
, NULL
).c_str () );
855 CleanupFileVector ( sourceFiles
);
859 MingwModuleHandler::GetPrecompiledHeaderFilename () const
861 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
862 return PassThruCacheDirectory ( NormalizeFilename ( basePchFilename
),
863 backend
->intermediateDirectory
);
867 MingwModuleHandler::GenerateGccCommand (
868 const string
& sourceFilename
,
870 const string
& cflagsMacro
)
872 string dependencies
= sourceFilename
;
873 if ( module
.pch
&& use_pch
)
874 dependencies
+= " " + GetPrecompiledHeaderFilename ();
876 /* WIDL generated headers may be used */
877 vector
<string
> rpcDependencies
;
878 GetRpcHeaderDependencies ( rpcDependencies
);
879 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
880 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
882 string objectFilename
= GetObjectFilename (
883 sourceFilename
, &clean_files
);
886 objectFilename
.c_str (),
887 dependencies
.c_str (),
888 GetDirectory ( objectFilename
).c_str () );
889 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
891 "\t%s -c $< -o $@ %s\n",
893 cflagsMacro
.c_str () );
897 MingwModuleHandler::GenerateGccAssemblerCommand (
898 const string
& sourceFilename
,
900 const string
& cflagsMacro
)
902 string dependencies
= sourceFilename
;
903 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
904 string objectFilename
= GetObjectFilename (
905 sourceFilename
, &clean_files
);
908 objectFilename
.c_str (),
909 dependencies
.c_str (),
910 GetDirectory ( objectFilename
).c_str () );
911 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
913 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
915 cflagsMacro
.c_str () );
919 MingwModuleHandler::GenerateNasmCommand (
920 const string
& sourceFilename
,
921 const string
& nasmflagsMacro
)
923 string dependencies
= sourceFilename
;
924 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
925 string objectFilename
= GetObjectFilename (
926 sourceFilename
, &clean_files
);
929 objectFilename
.c_str (),
930 dependencies
.c_str (),
931 GetDirectory ( objectFilename
).c_str () );
932 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
934 "\t%s -f win32 $< -o $@ %s\n",
936 nasmflagsMacro
.c_str () );
940 MingwModuleHandler::GenerateWindresCommand (
941 const string
& sourceFilename
,
942 const string
& windresflagsMacro
)
944 string dependencies
= sourceFilename
;
945 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
946 string objectFilename
=
947 GetObjectFilename ( sourceFilename
, &clean_files
);
948 string sourceFilenamePart
= ReplaceExtension ( GetFilename ( sourceFilename
), "" );
949 string rciFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".rci.tmp";
950 string resFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".res.tmp";
954 "%s: %s $(WRC_TARGET) | %s\n",
955 objectFilename
.c_str (),
956 dependencies
.c_str (),
957 GetDirectory ( objectFilename
).c_str () );
958 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
960 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
961 windresflagsMacro
.c_str (),
962 sourceFilename
.c_str (),
963 rciFilename
.c_str () );
965 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
966 windresflagsMacro
.c_str (),
967 rciFilename
.c_str (),
968 resFilename
.c_str () );
970 "\t-@${rm} %s 2>$(NUL)\n",
971 rciFilename
.c_str () );
973 "\t${windres} %s -o $@\n",
974 resFilename
.c_str () );
976 "\t-@${rm} %s 2>$(NUL)\n",
977 resFilename
.c_str () );
982 "%s: %s $(WRC_TARGET) | %s\n",
983 objectFilename
.c_str (),
984 dependencies
.c_str (),
985 GetDirectory ( objectFilename
).c_str () );
986 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
988 "\t${windres} $(%s) %s -o $@\n",
989 windresflagsMacro
.c_str (),
990 sourceFilename
.c_str () );
995 MingwModuleHandler::GenerateWinebuildCommands (
996 const string
& sourceFilename
)
998 string dependencies
= sourceFilename
;
999 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1001 string basename
= GetBasename ( sourceFilename
);
1002 string def_file
= PassThruCacheDirectory (
1003 basename
+ ".spec.def",
1004 backend
->intermediateDirectory
);
1005 CLEAN_FILE(def_file
);
1007 string stub_file
= PassThruCacheDirectory (
1008 basename
+ ".stubs.c",
1009 backend
->intermediateDirectory
);
1010 CLEAN_FILE(stub_file
)
1012 fprintf ( fMakefile
,
1013 "%s: %s $(WINEBUILD_TARGET)\n",
1015 dependencies
.c_str () );
1016 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1017 fprintf ( fMakefile
,
1018 "\t%s -o %s --def -E %s\n",
1019 "$(Q)$(WINEBUILD_TARGET)",
1021 sourceFilename
.c_str () );
1022 fprintf ( fMakefile
,
1023 "%s: %s $(WINEBUILD_TARGET)\n",
1025 sourceFilename
.c_str () );
1026 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1027 fprintf ( fMakefile
,
1028 "\t%s -o %s --pedll %s\n",
1029 "$(Q)$(WINEBUILD_TARGET)",
1031 sourceFilename
.c_str () );
1035 MingwModuleHandler::GetWidlFlags ( const File
& file
)
1037 return file
.switches
;
1041 MingwModuleHandler::GetRpcServerHeaderFilename ( string basename
) const
1043 return basename
+ "_s.h";
1047 MingwModuleHandler::GenerateWidlCommandsServer (
1049 const string
& widlflagsMacro
)
1051 string dependencies
= file
.name
;
1052 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1054 string basename
= GetBasename ( file
.name
);
1056 /*string generatedHeaderFilename = PassThruCacheDirectory (
1058 backend->intermediateDirectory );
1059 CLEAN_FILE(generatedHeaderFilename);
1061 string generatedHeaderFilename
= GetRpcServerHeaderFilename ( basename
);
1062 CLEAN_FILE(generatedHeaderFilename
);
1064 string generatedServerFilename
= PassThruCacheDirectory (
1066 backend
->intermediateDirectory
);
1067 CLEAN_FILE(generatedServerFilename
);
1069 fprintf ( fMakefile
,
1070 "%s %s: %s $(WIDL_TARGET) | %s\n",
1071 generatedServerFilename
.c_str (),
1072 generatedHeaderFilename
.c_str (),
1073 dependencies
.c_str (),
1074 GetDirectory ( generatedServerFilename
).c_str () );
1075 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1076 fprintf ( fMakefile
,
1077 "\t%s %s %s -h -H %s -s -S %s %s\n",
1078 "$(Q)$(WIDL_TARGET)",
1079 GetWidlFlags ( file
).c_str (),
1080 widlflagsMacro
.c_str (),
1081 generatedHeaderFilename
.c_str (),
1082 generatedServerFilename
.c_str (),
1083 file
.name
.c_str () );
1087 MingwModuleHandler::GetRpcClientHeaderFilename ( string basename
) const
1089 return basename
+ "_c.h";
1093 MingwModuleHandler::GenerateWidlCommandsClient (
1095 const string
& widlflagsMacro
)
1097 string dependencies
= file
.name
;
1098 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1100 string basename
= GetBasename ( file
.name
);
1102 /*string generatedHeaderFilename = PassThruCacheDirectory (
1104 backend->intermediateDirectory );
1105 CLEAN_FILE(generatedHeaderFilename);
1107 string generatedHeaderFilename
= GetRpcClientHeaderFilename ( basename
);
1108 CLEAN_FILE(generatedHeaderFilename
);
1110 string generatedClientFilename
= PassThruCacheDirectory (
1112 backend
->intermediateDirectory
);
1113 CLEAN_FILE(generatedClientFilename
);
1115 fprintf ( fMakefile
,
1116 "%s %s: %s $(WIDL_TARGET) | %s\n",
1117 generatedClientFilename
.c_str (),
1118 generatedHeaderFilename
.c_str (),
1119 dependencies
.c_str (),
1120 GetDirectory ( generatedClientFilename
).c_str () );
1121 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1122 fprintf ( fMakefile
,
1123 "\t%s %s %s -h -H %s -c -C %s %s\n",
1124 "$(Q)$(WIDL_TARGET)",
1125 GetWidlFlags ( file
).c_str (),
1126 widlflagsMacro
.c_str (),
1127 generatedHeaderFilename
.c_str (),
1128 generatedClientFilename
.c_str (),
1129 file
.name
.c_str () );
1133 MingwModuleHandler::GenerateWidlCommands (
1135 const string
& widlflagsMacro
)
1137 if ( module
.type
== RpcServer
)
1138 GenerateWidlCommandsServer ( file
,
1141 GenerateWidlCommandsClient ( file
,
1146 MingwModuleHandler::GenerateCommands (
1150 const string
& cflagsMacro
,
1151 const string
& nasmflagsMacro
,
1152 const string
& windresflagsMacro
,
1153 const string
& widlflagsMacro
)
1155 string extension
= GetExtension ( file
.name
);
1156 if ( extension
== ".c" || extension
== ".C" )
1158 GenerateGccCommand ( file
.name
,
1163 else if ( extension
== ".cc" || extension
== ".CC" ||
1164 extension
== ".cpp" || extension
== ".CPP" ||
1165 extension
== ".cxx" || extension
== ".CXX" )
1167 GenerateGccCommand ( file
.name
,
1172 else if ( extension
== ".s" || extension
== ".S" )
1174 GenerateGccAssemblerCommand ( file
.name
,
1179 else if ( extension
== ".asm" || extension
== ".ASM" )
1181 GenerateNasmCommand ( file
.name
,
1185 else if ( extension
== ".rc" || extension
== ".RC" )
1187 GenerateWindresCommand ( file
.name
,
1188 windresflagsMacro
);
1191 else if ( extension
== ".spec" || extension
== ".SPEC" )
1193 GenerateWinebuildCommands ( file
.name
);
1194 GenerateGccCommand ( GetActualSourceFilename ( file
.name
),
1199 else if ( extension
== ".idl" || extension
== ".IDL" )
1201 GenerateWidlCommands ( file
,
1203 GenerateGccCommand ( GetActualSourceFilename ( file
.name
),
1209 throw InvalidOperationException ( __FILE__
,
1211 "Unsupported filename extension '%s' in file '%s'",
1213 file
.name
.c_str () );
1217 MingwModuleHandler::GenerateBuildMapCode ()
1219 fprintf ( fMakefile
,
1220 "ifeq ($(ROS_BUILDMAP),full)\n" );
1222 string mapFilename
= PassThruCacheDirectory (
1223 GetBasename ( module
.GetPath () ) + ".map",
1224 backend
->outputDirectory
);
1225 CLEAN_FILE ( mapFilename
);
1227 fprintf ( fMakefile
,
1228 "\t$(ECHO_OBJDUMP)\n" );
1229 fprintf ( fMakefile
,
1230 "\t$(Q)${objdump} -d -S $@ > %s\n",
1231 mapFilename
.c_str () );
1233 fprintf ( fMakefile
,
1235 fprintf ( fMakefile
,
1236 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1238 fprintf ( fMakefile
,
1240 fprintf ( fMakefile
,
1241 "\t$(Q)${nm} --numeric-sort $@ > %s\n",
1242 mapFilename
.c_str () );
1244 fprintf ( fMakefile
,
1247 fprintf ( fMakefile
,
1252 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1254 fprintf ( fMakefile
,
1255 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1257 string filename
= module
.GetPath ();
1258 string outputFilename
= PassThruCacheDirectory (
1260 backend
->outputDirectory
);
1261 string nostripFilename
= PassThruCacheDirectory (
1262 GetBasename ( filename
) + ".nostrip" + GetExtension ( filename
),
1263 backend
->outputDirectory
);
1264 CLEAN_FILE ( nostripFilename
);
1266 fprintf ( fMakefile
,
1268 fprintf ( fMakefile
,
1269 "\t${cp} %s %s 1>$(NUL)\n",
1270 outputFilename
.c_str (),
1271 nostripFilename
.c_str () );
1273 fprintf ( fMakefile
,
1278 MergeStringVector ( const vector
<string
>& input
,
1279 vector
<string
>& output
)
1283 int wrap_count
= -1;
1284 for ( size_t i
= 0; i
< input
.size (); i
++ )
1286 if ( input
[i
].size () == 0 )
1288 if ( wrap_count
++ == wrap_at
)
1290 output
.push_back ( s
);
1294 else if ( s
.size () > 0)
1298 if ( s
.length () > 0 )
1299 output
.push_back ( s
);
1303 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1304 vector
<string
>& objectFiles
) const
1306 for ( size_t i
= 0; i
< data
.files
.size (); i
++ )
1308 File
& file
= *data
.files
[i
];
1309 objectFiles
.push_back ( GetObjectFilename ( file
.name
, NULL
) );
1314 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1316 if ( backend
->configuration
.CleanAsYouGo
)
1318 vector
<string
> objectFiles
;
1319 GetObjectsVector ( module
.non_if_data
,
1321 vector
<string
> lines
;
1322 MergeStringVector ( objectFiles
,
1324 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1326 fprintf ( fMakefile
,
1327 "\t-@${rm} %s 2>$(NUL)\n",
1328 lines
[i
].c_str () );
1334 MingwModuleHandler::GenerateRunRsymCode () const
1336 fprintf ( fMakefile
,
1337 "\t$(ECHO_RSYM)\n" );
1338 fprintf ( fMakefile
,
1339 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1343 MingwModuleHandler::GenerateLinkerCommand (
1344 const string
& dependencies
,
1345 const string
& linker
,
1346 const string
& linkerParameters
,
1347 const string
& objectsMacro
,
1348 const string
& libsMacro
)
1350 string
target ( GetTargetMacro ( module
) );
1351 string
target_folder ( GetDirectory ( GetTargetFilename ( module
, NULL
) ) );
1352 string def_file
= GetDefinitionFilename ();
1354 fprintf ( fMakefile
,
1355 "%s: %s %s $(RSYM_TARGET) | %s\n",
1358 dependencies
.c_str (),
1359 target_folder
.c_str () );
1360 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1361 string
targetName ( module
.GetTargetName () );
1363 if ( module
.IsDLL () )
1365 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1366 CLEAN_FILE ( temp_exp
);
1368 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1369 fprintf ( fMakefile
,
1370 "\t${dlltool} --dllname %s --def %s --output-exp %s %s\n",
1371 targetName
.c_str (),
1376 fprintf ( fMakefile
,
1377 "\t%s %s %s -o %s %s %s %s\n",
1379 linkerParameters
.c_str (),
1382 objectsMacro
.c_str (),
1384 GetLinkerMacro ().c_str () );
1386 fprintf ( fMakefile
,
1387 "\t-@${rm} %s 2>$(NUL)\n",
1388 temp_exp
.c_str () );
1392 fprintf ( fMakefile
,
1393 "\t%s %s -o %s %s %s %s\n",
1395 linkerParameters
.c_str (),
1397 objectsMacro
.c_str (),
1399 GetLinkerMacro ().c_str () );
1402 GenerateBuildMapCode ();
1403 GenerateBuildNonSymbolStrippedCode ();
1404 GenerateRunRsymCode ();
1405 GenerateCleanObjectsAsYouGoCode ();
1409 MingwModuleHandler::GeneratePhonyTarget() const
1411 string
targetMacro ( GetTargetMacro ( module
) );
1412 fprintf ( fMakefile
,
1414 targetMacro
.c_str ());
1415 fprintf ( fMakefile
, "%s: | %s\n",
1416 targetMacro
.c_str (),
1417 GetDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1421 MingwModuleHandler::GenerateObjectFileTargets (
1422 const IfableData
& data
,
1425 const string
& cflagsMacro
,
1426 const string
& nasmflagsMacro
,
1427 const string
& windresflagsMacro
,
1428 const string
& widlflagsMacro
)
1432 const vector
<File
*>& files
= data
.files
;
1433 for ( i
= 0; i
< files
.size (); i
++ )
1435 GenerateCommands ( *files
[i
],
1442 fprintf ( fMakefile
,
1446 const vector
<If
*>& ifs
= data
.ifs
;
1447 for ( i
= 0; i
< ifs
.size(); i
++ )
1449 GenerateObjectFileTargets ( ifs
[i
]->data
,
1458 vector
<File
*> sourceFiles
;
1459 GetModuleSpecificSourceFiles ( sourceFiles
);
1460 for ( i
= 0; i
< sourceFiles
.size (); i
++ )
1462 GenerateCommands ( *sourceFiles
[i
],
1470 CleanupFileVector ( sourceFiles
);
1474 MingwModuleHandler::GenerateObjectFileTargets (
1477 const string
& cflagsMacro
,
1478 const string
& nasmflagsMacro
,
1479 const string
& windresflagsMacro
,
1480 const string
& widlflagsMacro
)
1482 if ( module
.pch
&& use_pch
)
1484 const string
& baseHeaderFilename
= module
.pch
->file
.name
;
1485 const string
& pchFilename
= GetPrecompiledHeaderFilename ();
1486 CLEAN_FILE(pchFilename
);
1487 fprintf ( fMakefile
,
1489 pchFilename
.c_str(),
1490 baseHeaderFilename
.c_str() );
1491 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1492 fprintf ( fMakefile
,
1493 "\t%s -o %s %s -g %s\n\n",
1494 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1495 pchFilename
.c_str(),
1496 cflagsMacro
.c_str(),
1497 baseHeaderFilename
.c_str() );
1500 GenerateObjectFileTargets ( module
.non_if_data
,
1507 fprintf ( fMakefile
, "\n" );
1511 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1512 const string
& objs_macro
) const
1514 string
archiveFilename ( GetModuleArchiveFilename () );
1516 fprintf ( fMakefile
,
1518 archiveFilename
.c_str (),
1519 objs_macro
.c_str (),
1520 GetDirectory(archiveFilename
).c_str() );
1522 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1524 fprintf ( fMakefile
,
1527 objs_macro
.c_str ());
1529 GenerateCleanObjectsAsYouGoCode ();
1531 fprintf ( fMakefile
, "\n" );
1533 return archiveFilename
;
1537 MingwModuleHandler::GetCFlagsMacro () const
1539 return ssprintf ( "$(%s_CFLAGS)",
1540 module
.name
.c_str () );
1544 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1546 return ssprintf ( "$(%s_OBJS)",
1547 module
.name
.c_str () );
1551 MingwModuleHandler::GetLinkingDependenciesMacro () const
1553 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1557 MingwModuleHandler::GetLibsMacro () const
1559 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1563 MingwModuleHandler::GetLinkerMacro () const
1565 return ssprintf ( "$(%s_LFLAGS)",
1566 module
.name
.c_str () );
1570 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1572 if ( ReferenceObjects ( module
) )
1573 return GetObjectsMacro ( module
);
1575 return GetTargetFilename ( module
, NULL
);
1579 MingwModuleHandler::GenerateObjectMacro ()
1581 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1583 GenerateObjectMacros (
1586 &module
.linkerFlags
);
1588 // future references to the macro will be to get its values
1589 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1593 MingwModuleHandler::GenerateTargetMacro ()
1595 fprintf ( fMakefile
,
1597 GetTargetMacro ( module
, false ).c_str (),
1598 GetModuleTargets ( module
).c_str () );
1602 MingwModuleHandler::GetRpcHeaderDependencies (
1603 vector
<string
>& dependencies
) const
1605 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1607 Library
& library
= *module
.non_if_data
.libraries
[i
];
1608 if ( library
.importedModule
->type
== RpcServer
||
1609 library
.importedModule
->type
== RpcClient
)
1612 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.files
.size (); j
++ )
1614 File
& file
= *library
.importedModule
->non_if_data
.files
[j
];
1615 string extension
= GetExtension ( file
.name
);
1616 if ( extension
== ".idl" || extension
== ".IDL" )
1618 string basename
= GetBasename ( file
.name
);
1619 if ( library
.importedModule
->type
== RpcServer
)
1620 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
1621 if ( library
.importedModule
->type
== RpcClient
)
1622 dependencies
.push_back ( GetRpcClientHeaderFilename ( basename
) );
1630 MingwModuleHandler::GenerateOtherMacros ()
1632 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1633 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1634 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1635 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1636 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1637 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1638 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1643 &module
.linkerFlags
);
1646 if ( module
.importLibrary
)
1648 const vector
<File
*>& files
= module
.non_if_data
.files
;
1649 for ( size_t i
= 0; i
< files
.size (); i
++ )
1651 File
& file
= *files
[i
];
1652 string extension
= GetExtension ( file
.name
);
1653 if ( extension
== ".spec" || extension
== ".SPEC" )
1654 GetSpecObjectDependencies ( s
, file
.name
);
1657 if ( s
.size () > 0 )
1662 linkDepsMacro
.c_str() );
1663 for ( size_t i
= 0; i
< s
.size(); i
++ )
1664 fprintf ( fMakefile
,
1667 fprintf ( fMakefile
, "\n" );
1670 string globalCflags
= "-g";
1671 if ( backend
->usePipe
)
1672 globalCflags
+= " -pipe";
1673 if ( !module
.enableWarnings
)
1674 globalCflags
+= " -Werror";
1678 "%s += $(PROJECT_CFLAGS) %s\n",
1679 cflagsMacro
.c_str (),
1680 globalCflags
.c_str () );
1684 "%s += $(PROJECT_RCFLAGS)\n",
1685 windresflagsMacro
.c_str () );
1689 "%s += $(PROJECT_WIDLFLAGS)\n",
1690 widlflagsMacro
.c_str () );
1694 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1695 module
.name
.c_str () );
1700 linkDepsMacro
.c_str (),
1701 libsMacro
.c_str () );
1703 string cflags
= TypeSpecificCFlags();
1704 if ( cflags
.size() > 0 )
1706 fprintf ( fMakefile
,
1708 cflagsMacro
.c_str (),
1712 string nasmflags
= TypeSpecificNasmFlags();
1713 if ( nasmflags
.size () > 0 )
1715 fprintf ( fMakefile
,
1717 nasmflagsMacro
.c_str (),
1718 nasmflags
.c_str () );
1721 string linkerflags
= TypeSpecificLinkerFlags();
1722 if ( linkerflags
.size() > 0 )
1724 fprintf ( fMakefile
,
1726 linkerflagsMacro
.c_str (),
1727 linkerflags
.c_str () );
1730 fprintf ( fMakefile
, "\n\n" );
1732 // future references to the macros will be to get their values
1733 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1734 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1735 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
1739 MingwModuleHandler::GenerateRules ()
1741 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1742 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1743 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1745 if ( module
.name
!= "zlib" ) /* Avoid make warning */
1747 string proxyMakefile
= PassThruCacheDirectory (
1748 NormalizeFilename ( module
.GetBasePath () + SSEP
+ "makefile" ),
1749 backend
->outputDirectory
);
1750 CLEAN_FILE ( proxyMakefile
);
1753 string targetMacro
= GetTargetMacro ( module
);
1754 CLEAN_FILE ( targetMacro
);
1756 // generate phony target for module name
1757 fprintf ( fMakefile
, ".PHONY: %s\n",
1758 module
.name
.c_str () );
1759 string dependencies
= GetTargetMacro ( module
);
1760 if ( module
.type
== Test
)
1761 dependencies
+= " $(REGTESTS_RUN_TARGET)";
1762 fprintf ( fMakefile
, "%s: %s\n\n",
1763 module
.name
.c_str (),
1764 dependencies
.c_str () );
1765 if ( module
.type
== Test
)
1767 fprintf ( fMakefile
,
1769 targetMacro
.c_str ());
1772 if ( !ReferenceObjects ( module
) )
1774 string
ar_target ( GenerateArchiveTarget ( ar
, objectsMacro
) );
1775 if ( targetMacro
!= ar_target
)
1776 CLEAN_FILE ( ar_target
);
1779 GenerateObjectFileTargets ( cc
,
1788 MingwModuleHandler::GetInvocationDependencies (
1789 const Module
& module
,
1790 string_list
& dependencies
)
1792 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1794 Invoke
& invoke
= *module
.invocations
[i
];
1795 if ( invoke
.invokeModule
== &module
)
1796 /* Protect against circular dependencies */
1798 invoke
.GetTargets ( dependencies
);
1803 MingwModuleHandler::GenerateInvocations () const
1805 if ( module
.invocations
.size () == 0 )
1808 size_t iend
= module
.invocations
.size ();
1809 for ( size_t i
= 0; i
< iend
; i
++ )
1811 const Invoke
& invoke
= *module
.invocations
[i
];
1813 if ( invoke
.invokeModule
->type
!= BuildTool
)
1815 throw InvalidBuildFileException ( module
.node
.location
,
1816 "Only modules of type buildtool can be invoked." );
1819 string invokeTarget
= module
.GetInvocationTarget ( i
);
1820 string_list invoke_targets
;
1821 assert ( invoke_targets
.size() );
1822 invoke
.GetTargets ( invoke_targets
);
1823 fprintf ( fMakefile
,
1825 invokeTarget
.c_str () );
1826 fprintf ( fMakefile
,
1828 invokeTarget
.c_str () );
1829 size_t j
, jend
= invoke_targets
.size();
1830 for ( j
= 0; j
< jend
; j
++ )
1832 fprintf ( fMakefile
,
1834 invoke_targets
[i
].c_str () );
1836 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
1837 for ( j
= 1; j
< jend
; j
++ )
1838 fprintf ( fMakefile
,
1840 invoke_targets
[i
].c_str () );
1841 fprintf ( fMakefile
,
1843 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1844 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1845 fprintf ( fMakefile
,
1847 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1848 invoke
.GetParameters ().c_str () );
1853 MingwModuleHandler::GetPreconditionDependenciesName () const
1855 return module
.name
+ "_precondition";
1859 MingwModuleHandler::GetDefaultDependencies (
1860 string_list
& dependencies
) const
1862 /* Avoid circular dependency */
1863 if ( module
.type
!= BuildTool
1864 && module
.name
!= "zlib"
1865 && module
.name
!= "hostzlib" )
1867 dependencies
.push_back ( "$(INIT)" );
1871 MingwModuleHandler::GeneratePreconditionDependencies ()
1873 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
1874 string_list sourceFilenames
;
1875 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
1876 string_list dependencies
;
1877 GetDefaultDependencies ( dependencies
);
1878 GetModuleDependencies ( dependencies
);
1880 GetInvocationDependencies ( module
, dependencies
);
1882 if ( dependencies
.size() )
1884 fprintf ( fMakefile
,
1886 preconditionDependenciesName
.c_str () );
1887 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
1888 fprintf ( fMakefile
,
1890 dependencies
[i
].c_str () );
1891 fprintf ( fMakefile
, "\n\n" );
1894 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
1896 fprintf ( fMakefile
,
1898 sourceFilenames
[i
].c_str(),
1899 preconditionDependenciesName
.c_str ());
1901 fprintf ( fMakefile
, "\n" );
1905 MingwModuleHandler::IsWineModule () const
1907 if ( module
.importLibrary
== NULL
)
1910 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
1911 return ( index
!= string::npos
);
1915 MingwModuleHandler::GetDefinitionFilename () const
1917 if ( module
.importLibrary
!= NULL
)
1919 string defFilename
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
1920 if ( IsWineModule () )
1921 return PassThruCacheDirectory ( NormalizeFilename ( defFilename
),
1922 backend
->intermediateDirectory
);
1927 return "tools" SSEP
"rbuild" SSEP
"empty.def";
1931 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
1933 if ( module
.importLibrary
!= NULL
)
1935 string
library_target (
1936 GetImportLibraryFilename ( module
, &clean_files
) );
1937 string defFilename
= GetDefinitionFilename ();
1940 GetDefinitionDependencies ( deps
);
1942 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
1944 fprintf ( fMakefile
, "%s: %s",
1945 library_target
.c_str (),
1946 defFilename
.c_str () );
1948 size_t i
, iend
= deps
.size();
1949 for ( i
= 0; i
< iend
; i
++ )
1950 fprintf ( fMakefile
, " %s",
1953 fprintf ( fMakefile
, " | %s\n",
1954 GetDirectory ( GetImportLibraryFilename ( module
, NULL
) ).c_str () );
1956 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1958 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1959 fprintf ( fMakefile
,
1960 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1961 module
.GetTargetName ().c_str (),
1962 defFilename
.c_str (),
1963 library_target
.c_str (),
1969 MingwModuleHandler::GetSpecObjectDependencies (
1970 string_list
& dependencies
,
1971 const string
& filename
) const
1973 string basename
= GetBasename ( filename
);
1974 string defDependency
= PassThruCacheDirectory (
1975 NormalizeFilename ( basename
+ ".spec.def" ),
1976 backend
->intermediateDirectory
);
1977 dependencies
.push_back ( defDependency
);
1978 string stubsDependency
= PassThruCacheDirectory (
1979 NormalizeFilename ( basename
+ ".stubs.c" ),
1980 backend
->intermediateDirectory
);
1981 dependencies
.push_back ( stubsDependency
);
1985 MingwModuleHandler::GetWidlObjectDependencies (
1986 string_list
& dependencies
,
1987 const string
& filename
) const
1989 string basename
= GetBasename ( filename
);
1990 string serverDependency
= PassThruCacheDirectory (
1991 NormalizeFilename ( basename
+ "_s.c" ),
1992 backend
->intermediateDirectory
);
1993 dependencies
.push_back ( serverDependency
);
1997 MingwModuleHandler::GetDefinitionDependencies (
1998 string_list
& dependencies
) const
2000 string dkNkmLibNoFixup
= "dk/nkm/lib";
2001 const vector
<File
*>& files
= module
.non_if_data
.files
;
2002 for ( size_t i
= 0; i
< files
.size (); i
++ )
2004 File
& file
= *files
[i
];
2005 string extension
= GetExtension ( file
.name
);
2006 if ( extension
== ".spec" || extension
== ".SPEC" )
2008 GetSpecObjectDependencies ( dependencies
, file
.name
);
2010 if ( extension
== ".idl" || extension
== ".IDL" )
2012 GetWidlObjectDependencies ( dependencies
, file
.name
);
2018 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2019 : MingwModuleHandler ( module_
)
2024 MingwBuildToolModuleHandler::Process ()
2026 GenerateBuildToolModuleTarget ();
2030 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2032 string
targetMacro ( GetTargetMacro (module
) );
2033 string objectsMacro
= GetObjectsMacro ( module
);
2034 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2035 string libsMacro
= GetLibsMacro ();
2040 if ( module
.cplusplus
)
2041 linker
= "${host_gpp}";
2043 linker
= "${host_gcc}";
2045 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2046 targetMacro
.c_str (),
2047 objectsMacro
.c_str (),
2048 linkDepsMacro
.c_str (),
2049 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2050 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2051 fprintf ( fMakefile
,
2052 "\t%s %s -o $@ %s %s\n\n",
2054 GetLinkerMacro ().c_str (),
2055 objectsMacro
.c_str (),
2056 libsMacro
.c_str () );
2060 MingwKernelModuleHandler::MingwKernelModuleHandler (
2061 const Module
& module_
)
2063 : MingwModuleHandler ( module_
)
2068 MingwKernelModuleHandler::Process ()
2070 GenerateKernelModuleTarget ();
2074 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2076 string
targetMacro ( GetTargetMacro ( module
) );
2077 string workingDirectory
= GetWorkingDirectory ( );
2078 string objectsMacro
= GetObjectsMacro ( module
);
2079 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2080 string libsMacro
= GetLibsMacro ();
2082 GenerateImportLibraryTargetIfNeeded ();
2084 if ( module
.non_if_data
.files
.size () > 0 )
2088 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2090 string linkerParameters
= ssprintf ( "-Wl,-T,%s" SSEP
"ntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2091 module
.GetBasePath ().c_str (),
2092 module
.entrypoint
.c_str (),
2093 module
.baseaddress
.c_str () );
2094 GenerateLinkerCommand ( dependencies
,
2102 GeneratePhonyTarget();
2107 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2108 const Module
& module_
)
2110 : MingwModuleHandler ( module_
)
2115 MingwStaticLibraryModuleHandler::Process ()
2117 GenerateStaticLibraryModuleTarget ();
2121 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2127 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2128 const Module
& module_
)
2130 : MingwModuleHandler ( module_
)
2135 MingwObjectLibraryModuleHandler::Process ()
2137 GenerateObjectLibraryModuleTarget ();
2141 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2147 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2148 const Module
& module_
)
2150 : MingwModuleHandler ( module_
)
2155 MingwKernelModeDLLModuleHandler::Process ()
2157 GenerateKernelModeDLLModuleTarget ();
2161 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2163 string
targetMacro ( GetTargetMacro ( module
) );
2164 string workingDirectory
= GetWorkingDirectory ( );
2165 string objectsMacro
= GetObjectsMacro ( module
);
2166 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2167 string libsMacro
= GetLibsMacro ();
2169 GenerateImportLibraryTargetIfNeeded ();
2171 if ( module
.non_if_data
.files
.size () > 0 )
2175 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2177 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2178 module
.entrypoint
.c_str (),
2179 module
.baseaddress
.c_str () );
2180 GenerateLinkerCommand ( dependencies
,
2188 GeneratePhonyTarget();
2193 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2194 const Module
& module_
)
2196 : MingwModuleHandler ( module_
)
2201 MingwKernelModeDriverModuleHandler::Process ()
2203 GenerateKernelModeDriverModuleTarget ();
2208 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2210 string
targetMacro ( GetTargetMacro (module
) );
2211 string workingDirectory
= GetWorkingDirectory ();
2212 string objectsMacro
= GetObjectsMacro ( module
);
2213 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2214 string libsMacro
= GetLibsMacro ();
2216 GenerateImportLibraryTargetIfNeeded ();
2218 if ( module
.non_if_data
.files
.size () > 0 )
2222 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2224 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2225 module
.entrypoint
.c_str (),
2226 module
.baseaddress
.c_str () );
2227 GenerateLinkerCommand ( dependencies
,
2235 GeneratePhonyTarget();
2240 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2241 const Module
& module_
)
2243 : MingwModuleHandler ( module_
)
2248 MingwNativeDLLModuleHandler::Process ()
2250 GenerateNativeDLLModuleTarget ();
2254 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2256 string
targetMacro ( GetTargetMacro (module
) );
2257 string workingDirectory
= GetWorkingDirectory ( );
2258 string objectsMacro
= GetObjectsMacro ( module
);
2259 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2260 string libsMacro
= GetLibsMacro ();
2262 GenerateImportLibraryTargetIfNeeded ();
2264 if ( module
.non_if_data
.files
.size () > 0 )
2268 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2270 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2271 module
.entrypoint
.c_str (),
2272 module
.baseaddress
.c_str () );
2273 GenerateLinkerCommand ( dependencies
,
2281 GeneratePhonyTarget();
2286 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2287 const Module
& module_
)
2289 : MingwModuleHandler ( module_
)
2294 MingwNativeCUIModuleHandler::Process ()
2296 GenerateNativeCUIModuleTarget ();
2300 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2302 string
targetMacro ( GetTargetMacro (module
) );
2303 string workingDirectory
= GetWorkingDirectory ( );
2304 string objectsMacro
= GetObjectsMacro ( module
);
2305 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2306 string libsMacro
= GetLibsMacro ();
2308 GenerateImportLibraryTargetIfNeeded ();
2310 if ( module
.non_if_data
.files
.size () > 0 )
2314 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2316 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2317 module
.entrypoint
.c_str (),
2318 module
.baseaddress
.c_str () );
2319 GenerateLinkerCommand ( dependencies
,
2327 GeneratePhonyTarget();
2332 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2333 const Module
& module_
)
2335 : MingwModuleHandler ( module_
)
2340 MingwWin32DLLModuleHandler::Process ()
2342 GenerateWin32DLLModuleTarget ();
2346 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2348 string
targetMacro ( GetTargetMacro (module
) );
2349 string workingDirectory
= GetWorkingDirectory ( );
2350 string objectsMacro
= GetObjectsMacro ( module
);
2351 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2352 string libsMacro
= GetLibsMacro ();
2354 GenerateImportLibraryTargetIfNeeded ();
2356 if ( module
.non_if_data
.files
.size () > 0 )
2360 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2363 if ( module
.cplusplus
)
2368 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2369 module
.entrypoint
.c_str (),
2370 module
.baseaddress
.c_str () );
2371 GenerateLinkerCommand ( dependencies
,
2379 GeneratePhonyTarget();
2384 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2385 const Module
& module_
)
2387 : MingwModuleHandler ( module_
)
2392 MingwWin32CUIModuleHandler::Process ()
2394 GenerateWin32CUIModuleTarget ();
2398 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2400 string
targetMacro ( GetTargetMacro (module
) );
2401 string workingDirectory
= GetWorkingDirectory ( );
2402 string objectsMacro
= GetObjectsMacro ( module
);
2403 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2404 string libsMacro
= GetLibsMacro ();
2406 GenerateImportLibraryTargetIfNeeded ();
2408 if ( module
.non_if_data
.files
.size () > 0 )
2412 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2415 if ( module
.cplusplus
)
2420 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2421 module
.entrypoint
.c_str (),
2422 module
.baseaddress
.c_str () );
2423 GenerateLinkerCommand ( dependencies
,
2431 GeneratePhonyTarget();
2436 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2437 const Module
& module_
)
2439 : MingwModuleHandler ( module_
)
2444 MingwWin32GUIModuleHandler::Process ()
2446 GenerateWin32GUIModuleTarget ();
2450 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2452 string
targetMacro ( GetTargetMacro (module
) );
2453 string workingDirectory
= GetWorkingDirectory ( );
2454 string objectsMacro
= GetObjectsMacro ( module
);
2455 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2456 string libsMacro
= GetLibsMacro ();
2458 GenerateImportLibraryTargetIfNeeded ();
2460 if ( module
.non_if_data
.files
.size () > 0 )
2464 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2467 if ( module
.cplusplus
)
2472 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2473 module
.entrypoint
.c_str (),
2474 module
.baseaddress
.c_str () );
2475 GenerateLinkerCommand ( dependencies
,
2483 GeneratePhonyTarget();
2488 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2489 const Module
& module_
)
2491 : MingwModuleHandler ( module_
)
2496 MingwBootLoaderModuleHandler::Process ()
2498 GenerateBootLoaderModuleTarget ();
2502 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2504 string
targetName ( module
.GetTargetName () );
2505 string
targetMacro ( GetTargetMacro (module
) );
2506 string workingDirectory
= GetWorkingDirectory ();
2507 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2508 CLEAN_FILE ( junk_tmp
);
2509 string objectsMacro
= GetObjectsMacro ( module
);
2510 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2511 string libsMacro
= GetLibsMacro ();
2515 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2516 targetMacro
.c_str (),
2517 objectsMacro
.c_str (),
2518 linkDepsMacro
.c_str (),
2519 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2521 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2523 fprintf ( fMakefile
,
2524 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2525 GetLinkerMacro ().c_str (),
2527 objectsMacro
.c_str (),
2528 linkDepsMacro
.c_str () );
2529 fprintf ( fMakefile
,
2530 "\t${objcopy} -O binary %s $@\n",
2531 junk_tmp
.c_str () );
2532 fprintf ( fMakefile
,
2533 "\t-@${rm} %s 2>$(NUL)\n",
2534 junk_tmp
.c_str () );
2538 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2539 const Module
& module_
)
2541 : MingwModuleHandler ( module_
)
2546 MingwBootSectorModuleHandler::Process ()
2548 GenerateBootSectorModuleTarget ();
2552 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2554 string objectsMacro
= GetObjectsMacro ( module
);
2558 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2559 module
.name
.c_str ());
2560 fprintf ( fMakefile
,
2562 module
.name
.c_str (),
2563 objectsMacro
.c_str () );
2567 MingwIsoModuleHandler::MingwIsoModuleHandler (
2568 const Module
& module_
)
2570 : MingwModuleHandler ( module_
)
2575 MingwIsoModuleHandler::Process ()
2577 GenerateIsoModuleTarget ();
2581 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2582 const string
& bootcdDirectory
)
2584 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2586 const Module
& m
= *module
.project
.modules
[i
];
2589 if ( m
.bootstrap
!= NULL
)
2591 string sourceFilename
= PassThruCacheDirectory (
2592 NormalizeFilename ( m
.GetPath () ),
2593 backend
->outputDirectory
);
2594 string
targetFilenameNoFixup ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
);
2595 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2596 NormalizeFilename ( targetFilenameNoFixup
),
2597 backend
->outputDirectory
);
2598 fprintf ( fMakefile
,
2600 fprintf ( fMakefile
,
2601 "\t${cp} %s %s 1>$(NUL)\n",
2602 sourceFilename
.c_str (),
2603 targetFilename
.c_str () );
2609 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2610 const string
& bootcdDirectory
)
2612 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2614 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2615 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2616 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2617 NormalizeFilename ( targetFilenameNoFixup
),
2618 backend
->outputDirectory
);
2619 fprintf ( fMakefile
,
2621 fprintf ( fMakefile
,
2622 "\t${cp} %s %s 1>$(NUL)\n",
2623 cdfile
.GetPath ().c_str (),
2624 targetFilename
.c_str () );
2629 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
2632 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2634 const Module
& m
= *module
.project
.modules
[i
];
2637 if ( m
.bootstrap
!= NULL
)
2639 string
targetDirectory ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
);
2640 if ( directories
.size () > 0 )
2642 directories
+= PassThruCacheDirectory (
2643 NormalizeFilename ( targetDirectory
),
2644 backend
->outputDirectory
);
2651 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
2654 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2656 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2657 string
targetDirectory ( bootcdDirectory
+ SSEP
+ cdfile
.base
);
2658 if ( directories
.size () > 0 )
2660 directories
+= PassThruCacheDirectory (
2661 NormalizeFilename ( targetDirectory
),
2662 backend
->outputDirectory
);
2668 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
2670 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
2671 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
2676 MingwIsoModuleHandler::GetBootstrapCdFiles (
2677 vector
<string
>& out
) const
2679 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2681 const Module
& m
= *module
.project
.modules
[i
];
2684 if ( m
.bootstrap
!= NULL
)
2686 string filename
= PassThruCacheDirectory (
2687 NormalizeFilename ( m
.GetPath () ),
2688 backend
->outputDirectory
);
2689 out
.push_back ( filename
);
2695 MingwIsoModuleHandler::GetNonModuleCdFiles (
2696 vector
<string
>& out
) const
2698 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2700 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2701 out
.push_back ( cdfile
.GetPath () );
2706 MingwIsoModuleHandler::GetCdFiles (
2707 vector
<string
>& out
) const
2709 GetBootstrapCdFiles ( out
);
2710 GetNonModuleCdFiles ( out
);
2714 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2716 string bootcdDirectory
= "cd";
2717 string bootcd
= PassThruCacheDirectory (
2718 NormalizeFilename ( bootcdDirectory
+ SSEP
),
2719 backend
->outputDirectory
);
2720 string isoboot
= PassThruCacheDirectory (
2721 NormalizeFilename ( "boot" SSEP
"freeldr" SSEP
"bootsect" SSEP
"isoboot.o" ),
2722 backend
->outputDirectory
);
2723 string bootcdReactosNoFixup
= bootcdDirectory
+ SSEP
"reactos";
2724 string bootcdReactos
= PassThruCacheDirectory (
2725 NormalizeFilename ( bootcdReactosNoFixup
+ SSEP
),
2726 backend
->outputDirectory
);
2727 CLEAN_FILE ( bootcdReactos
);
2728 string reactosInf
= PassThruCacheDirectory (
2729 NormalizeFilename ( bootcdReactosNoFixup
+ SSEP
"reactos.inf" ),
2730 backend
->outputDirectory
);
2731 string reactosDff
= NormalizeFilename ( "bootdata" SSEP
"packages" SSEP
"reactos.dff" );
2732 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
2733 vector
<string
> vCdFiles
;
2734 GetCdFiles ( vCdFiles
);
2735 string cdFiles
= v2s ( vCdFiles
, 5 );
2737 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2738 module
.name
.c_str ());
2739 fprintf ( fMakefile
,
2740 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2741 module
.name
.c_str (),
2743 bootcdReactos
.c_str (),
2744 cdDirectories
.c_str (),
2746 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2747 fprintf ( fMakefile
,
2748 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
2749 reactosDff
.c_str (),
2750 bootcdReactos
.c_str () );
2751 fprintf ( fMakefile
,
2752 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2753 reactosDff
.c_str (),
2754 reactosInf
.c_str (),
2755 bootcdReactos
.c_str ());
2756 fprintf ( fMakefile
,
2757 "\t-@${rm} %s 2>$(NUL)\n",
2758 reactosInf
.c_str () );
2759 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
2760 OutputCdfileCopyCommands ( bootcdDirectory
);
2761 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2762 fprintf ( fMakefile
,
2763 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2766 fprintf ( fMakefile
,
2771 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
2772 const Module
& module_
)
2774 : MingwModuleHandler ( module_
)
2779 MingwLiveIsoModuleHandler::Process ()
2781 GenerateLiveIsoModuleTarget ();
2785 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
2787 string normalizedDirectory
= MingwModuleHandler::PassThruCacheDirectory (
2788 NormalizeFilename ( directory
) + SSEP
,
2789 backend
->outputDirectory
);
2793 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string
& sourceFilename
,
2794 const string
& targetFilename
,
2795 const string
& targetDirectory
)
2797 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2798 NormalizeFilename ( targetDirectory
+ SSEP
+ targetFilename
),
2799 backend
->outputDirectory
);
2800 fprintf ( fMakefile
,
2802 fprintf ( fMakefile
,
2803 "\t${cp} %s %s 1>$(NUL)\n",
2804 sourceFilename
.c_str (),
2805 normalizedTargetFilename
.c_str () );
2809 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
2810 string
& reactosDirectory
)
2812 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2814 const Module
& m
= *module
.project
.modules
[i
];
2817 if ( m
.installName
.length () > 0 )
2819 string sourceFilename
= MingwModuleHandler::PassThruCacheDirectory (
2820 NormalizeFilename ( m
.GetPath () ),
2821 backend
->outputDirectory
);
2822 OutputCopyCommand ( sourceFilename
,
2824 livecdDirectory
+ SSEP
+ reactosDirectory
+ SSEP
+ m
.installBase
);
2830 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
2831 string
& reactosDirectory
)
2833 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
2835 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
2836 OutputCopyCommand ( installfile
.GetPath (),
2837 installfile
.newname
,
2838 livecdDirectory
+ SSEP
+ reactosDirectory
+ SSEP
+ installfile
.base
);
2843 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
2845 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" );
2846 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" SSEP
"All Users") ;
2847 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" SSEP
"All Users" SSEP
"Desktop" );
2848 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" SSEP
"Default User" );
2849 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" SSEP
"Default User" SSEP
"Desktop" );
2850 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" SSEP
"Default User" SSEP
"My Documents" );
2852 string livecdIni
= "bootdata" SSEP
"livecd.ini";
2853 OutputCopyCommand ( livecdIni
,
2859 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
2861 string freeldr
= PassThruCacheDirectory (
2862 NormalizeFilename ( "boot" SSEP
"freeldr" SSEP
"freeldr" SSEP
"freeldr.sys" ),
2863 backend
->outputDirectory
);
2864 CreateDirectory ( livecdDirectory
+ SSEP
"loader" );
2865 OutputCopyCommand ( freeldr
,
2867 livecdDirectory
+ SSEP
+ "loader" );
2871 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
2873 string reactosSystem32ConfigDirectory
= NormalizeFilename (
2874 MingwModuleHandler::PassThruCacheDirectory (
2875 livecdDirectory
+ SSEP
"reactos" SSEP
"system32" SSEP
"config" SSEP
,
2876 backend
->outputDirectory
) );
2877 fprintf ( fMakefile
,
2878 "\t$(ECHO_MKHIVE)\n" );
2879 fprintf ( fMakefile
,
2880 "\t$(MKHIVE_TARGET) bootdata %s bootdata" SSEP
"livecd.inf bootdata" SSEP
"hiveinst.inf\n",
2881 reactosSystem32ConfigDirectory
.c_str () );
2885 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
2887 string livecdDirectory
= "livecd";
2888 string livecd
= PassThruCacheDirectory (
2889 NormalizeFilename ( livecdDirectory
+ SSEP
),
2890 backend
->outputDirectory
);
2891 string isoboot
= PassThruCacheDirectory (
2892 NormalizeFilename ( "boot" SSEP
"freeldr" SSEP
"bootsect" SSEP
"isoboot.o" ),
2893 backend
->outputDirectory
);
2894 string reactosDirectory
= "reactos";
2895 string livecdReactosNoFixup
= livecdDirectory
+ SSEP
+ reactosDirectory
;
2896 string livecdReactos
= NormalizeFilename ( PassThruCacheDirectory (
2897 NormalizeFilename ( livecdReactosNoFixup
+ SSEP
),
2898 backend
->outputDirectory
) );
2899 CLEAN_FILE ( livecdReactos
);
2901 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2902 module
.name
.c_str ());
2903 fprintf ( fMakefile
,
2904 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
2905 module
.name
.c_str (),
2907 livecdReactos
.c_str () );
2908 OutputModuleCopyCommands ( livecdDirectory
,
2910 OutputNonModuleCopyCommands ( livecdDirectory
,
2912 OutputProfilesDirectoryCommands ( livecdDirectory
);
2913 OutputLoaderCommands ( livecdDirectory
);
2914 OutputRegistryCommands ( livecdDirectory
);
2915 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2916 fprintf ( fMakefile
,
2917 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS ReactOS-LiveCD.iso\n",
2920 fprintf ( fMakefile
,
2925 MingwTestModuleHandler::MingwTestModuleHandler (
2926 const Module
& module_
)
2928 : MingwModuleHandler ( module_
)
2933 MingwTestModuleHandler::Process ()
2935 GenerateTestModuleTarget ();
2939 MingwTestModuleHandler::GetModuleSpecificSourceFiles ( vector
<File
*>& sourceFiles
)
2941 string basePath
= "$(INTERMEDIATE)" SSEP
+ module
.GetBasePath ();
2942 sourceFiles
.push_back ( new File ( basePath
+ SSEP
"_hooks.c", false, "", false ) );
2943 sourceFiles
.push_back ( new File ( basePath
+ SSEP
"_stubs.S", false, "", false ) );
2944 sourceFiles
.push_back ( new File ( basePath
+ SSEP
"_startup.c", false, "", false ) );
2948 MingwTestModuleHandler::GenerateTestModuleTarget ()
2950 string
targetMacro ( GetTargetMacro ( module
) );
2951 string workingDirectory
= GetWorkingDirectory ( );
2952 string objectsMacro
= GetObjectsMacro ( module
);
2953 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2954 string libsMacro
= GetLibsMacro ();
2956 GenerateImportLibraryTargetIfNeeded ();
2958 if ( module
.non_if_data
.files
.size () > 0 )
2962 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2965 if ( module
.cplusplus
)
2970 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2971 module
.entrypoint
.c_str (),
2972 module
.baseaddress
.c_str () );
2973 GenerateLinkerCommand ( dependencies
,
2981 GeneratePhonyTarget();
2986 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
2987 const Module
& module_
)
2989 : MingwModuleHandler ( module_
)
2994 MingwRpcServerModuleHandler::Process ()
2999 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3000 const Module
& module_
)
3002 : MingwModuleHandler ( module_
)
3007 MingwRpcClientModuleHandler::Process ()