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
;
36 MingwModuleHandler::use_pch
= false;
40 const string
& filename
,
41 const string
& prefix
)
43 if ( !prefix
.length() )
46 const char* pfilename
= filename
.c_str();
47 const char* p1
= strrchr ( pfilename
, '/' );
48 const char* p2
= strrchr ( pfilename
, '\\' );
53 out
+= string(pfilename
,p1
-pfilename
) + CSEP
;
56 out
+= prefix
+ pfilename
;
61 GetTargetMacro ( const Module
& module
, bool with_dollar
)
63 string
s ( module
.name
);
67 return ssprintf ( "$(%s)", s
.c_str() );
71 MingwModuleHandler::MingwModuleHandler (
72 const Module
& module_
)
78 MingwModuleHandler::~MingwModuleHandler()
83 MingwModuleHandler::SetBackend ( MingwBackend
* backend_
)
89 MingwModuleHandler::SetMakefile ( FILE* f
)
95 MingwModuleHandler::SetUsePch ( bool b
)
101 MingwModuleHandler::RemoveVariables ( string path
)
103 size_t i
= path
.find ( '$' );
104 if ( i
!= string::npos
)
106 size_t j
= path
.find ( ')', i
);
107 if ( j
!= string::npos
)
109 if ( j
+ 2 < path
.length () && path
[j
+ 1] == CSEP
)
110 return path
.substr ( j
+ 2);
112 return path
.substr ( j
+ 1);
119 MingwModuleHandler::PassThruCacheDirectory (
121 Directory
* directoryTree
)
123 string
directory ( GetDirectory ( RemoveVariables ( file
) ) );
124 string generatedFilesDirectory
= backend
->AddDirectoryTarget ( directory
,
126 if ( directory
.find ( generatedFilesDirectory
) != string::npos
)
127 /* This path already includes the generated files directory variable */
132 return generatedFilesDirectory
;
133 return generatedFilesDirectory
+ SSEP
+ file
;
137 /*static*/ Directory
*
138 MingwModuleHandler::GetTargetDirectoryTree (
139 const Module
& module
)
141 if ( module
.type
== StaticLibrary
)
142 return backend
->intermediateDirectory
;
143 return backend
->outputDirectory
;
147 MingwModuleHandler::GetTargetFilename (
148 const Module
& module
,
149 string_list
* pclean_files
)
151 string target
= PassThruCacheDirectory (
152 NormalizeFilename ( module
.GetPath () ),
153 GetTargetDirectoryTree ( module
) );
156 string_list
& clean_files
= *pclean_files
;
157 CLEAN_FILE ( target
);
163 MingwModuleHandler::GetImportLibraryFilename (
164 const Module
& module
,
165 string_list
* pclean_files
)
167 string target
= PassThruCacheDirectory (
168 NormalizeFilename ( module
.GetDependencyPath () ),
169 backend
->intermediateDirectory
);
172 string_list
& clean_files
= *pclean_files
;
173 CLEAN_FILE ( target
);
178 /*static*/ MingwModuleHandler
*
179 MingwModuleHandler::InstanciateHandler (
180 const Module
& module
,
181 MingwBackend
* backend
)
183 MingwModuleHandler
* handler
;
184 switch ( module
.type
)
187 handler
= new MingwBuildToolModuleHandler ( module
);
190 handler
= new MingwStaticLibraryModuleHandler ( module
);
193 handler
= new MingwObjectLibraryModuleHandler ( module
);
196 handler
= new MingwKernelModuleHandler ( module
);
199 handler
= new MingwNativeCUIModuleHandler ( module
);
202 handler
= new MingwWin32CUIModuleHandler ( module
);
205 handler
= new MingwWin32GUIModuleHandler ( module
);
208 handler
= new MingwKernelModeDLLModuleHandler ( module
);
211 handler
= new MingwNativeDLLModuleHandler ( module
);
214 handler
= new MingwWin32DLLModuleHandler ( module
);
216 case KernelModeDriver
:
217 handler
= new MingwKernelModeDriverModuleHandler ( module
);
220 handler
= new MingwBootLoaderModuleHandler ( module
);
223 handler
= new MingwBootSectorModuleHandler ( module
);
226 handler
= new MingwIsoModuleHandler ( module
);
229 handler
= new MingwLiveIsoModuleHandler ( module
);
232 handler
= new MingwTestModuleHandler ( module
);
235 handler
= new MingwRpcServerModuleHandler ( module
);
238 handler
= new MingwRpcClientModuleHandler ( module
);
241 handler
= new MingwAliasModuleHandler ( module
);
244 throw UnknownModuleTypeException (
245 module
.node
.location
,
253 MingwModuleHandler::GetWorkingDirectory () const
259 MingwModuleHandler::GetBasename ( const string
& filename
) const
261 size_t index
= filename
.find_last_of ( '.' );
262 if ( index
!= string::npos
)
263 return filename
.substr ( 0, index
);
268 MingwModuleHandler::GetActualSourceFilename (
269 const string
& filename
) const
271 string extension
= GetExtension ( filename
);
272 if ( extension
== ".spec" || extension
== ".SPEC" )
274 string basename
= GetBasename ( filename
);
275 return PassThruCacheDirectory ( NormalizeFilename ( basename
+ ".stubs.c" ),
276 backend
->intermediateDirectory
);
278 else if ( extension
== ".idl" || extension
== ".IDL" )
280 string basename
= GetBasename ( filename
);
282 if ( module
.type
== RpcServer
)
283 newname
= basename
+ "_s.c";
285 newname
= basename
+ "_c.c";
286 return PassThruCacheDirectory ( NormalizeFilename ( newname
),
287 backend
->intermediateDirectory
);
294 MingwModuleHandler::GetExtraDependencies (
295 const string
& filename
) const
297 string extension
= GetExtension ( filename
);
298 if ( extension
== ".idl" || extension
== ".IDL" )
300 string basename
= GetBasename ( filename
);
301 return GetRpcServerHeaderFilename ( basename
) + " " + GetRpcClientHeaderFilename ( basename
);
308 MingwModuleHandler::GetModuleArchiveFilename () const
310 if ( module
.type
== StaticLibrary
)
311 return GetTargetFilename ( module
, NULL
);
312 return PassThruCacheDirectory ( ReplaceExtension (
313 NormalizeFilename ( module
.GetPath () ),
315 backend
->intermediateDirectory
);
319 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
321 string extension
= GetExtension ( file
.name
);
322 return ( extension
== ".spec" || extension
== ".SPEC" );
326 MingwModuleHandler::ReferenceObjects (
327 const Module
& module
)
329 if ( module
.type
== ObjectLibrary
)
331 if ( module
.type
== RpcServer
)
333 if ( module
.type
== RpcClient
)
339 MingwModuleHandler::GetImportLibraryDependency (
340 const Module
& importedModule
)
343 if ( ReferenceObjects ( importedModule
) )
344 dep
= GetTargetMacro ( importedModule
);
346 dep
= GetImportLibraryFilename ( importedModule
, NULL
);
351 MingwModuleHandler::GetTargets ( const Module
& dependencyModule
,
352 string_list
& targets
)
354 if ( dependencyModule
.invocations
.size () > 0 )
356 for ( size_t i
= 0; i
< dependencyModule
.invocations
.size (); i
++ )
358 Invoke
& invoke
= *dependencyModule
.invocations
[i
];
359 invoke
.GetTargets ( targets
);
363 targets
.push_back ( GetImportLibraryDependency ( dependencyModule
) );
367 MingwModuleHandler::GetModuleDependencies (
368 string_list
& dependencies
)
370 size_t iend
= module
.dependencies
.size ();
375 for ( size_t i
= 0; i
< iend
; i
++ )
377 const Dependency
& dependency
= *module
.dependencies
[i
];
378 const Module
& dependencyModule
= *dependency
.dependencyModule
;
379 GetTargets ( dependencyModule
,
382 GetDefinitionDependencies ( dependencies
);
386 MingwModuleHandler::GetSourceFilenames ( string_list
& list
,
387 bool includeGeneratedFiles
) const
391 const vector
<File
*>& files
= module
.non_if_data
.files
;
392 for ( i
= 0; i
< files
.size (); i
++ )
394 if ( includeGeneratedFiles
|| !files
[i
]->IsGeneratedFile () )
397 GetActualSourceFilename ( files
[i
]->name
) );
400 // intentionally make a copy so that we can append more work in
401 // the middle of processing without having to go recursive
402 vector
<If
*> v
= module
.non_if_data
.ifs
;
403 for ( i
= 0; i
< v
.size (); i
++ )
407 // check for sub-ifs to add to list
408 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
409 for ( j
= 0; j
< ifs
.size (); j
++ )
410 v
.push_back ( ifs
[j
] );
411 const vector
<File
*>& files
= rIf
.data
.files
;
412 for ( j
= 0; j
< files
.size (); j
++ )
414 File
& file
= *files
[j
];
415 if ( includeGeneratedFiles
|| !file
.IsGeneratedFile () )
418 GetActualSourceFilename ( file
.name
) );
425 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
426 string_list
& list
) const
428 GetSourceFilenames ( list
, false );
432 MingwModuleHandler::GetObjectFilename (
433 const string
& sourceFilename
,
434 string_list
* pclean_files
) const
436 Directory
* directoryTree
;
439 string extension
= GetExtension ( sourceFilename
);
440 if ( extension
== ".rc" || extension
== ".RC" )
441 newExtension
= ".coff";
442 else if ( extension
== ".spec" || extension
== ".SPEC" )
443 newExtension
= ".stubs.o";
444 else if ( extension
== ".idl" || extension
== ".IDL" )
446 if ( module
.type
== RpcServer
)
447 newExtension
= "_s.o";
449 newExtension
= "_c.o";
454 if ( module
.type
== BootSector
)
455 directoryTree
= backend
->outputDirectory
;
457 directoryTree
= backend
->intermediateDirectory
;
459 string obj_file
= PassThruCacheDirectory (
460 NormalizeFilename ( ReplaceExtension (
461 RemoveVariables ( sourceFilename
),
466 string_list
& clean_files
= *pclean_files
;
467 CLEAN_FILE ( obj_file
);
473 MingwModuleHandler::GetModuleCleanTarget ( const Module
& module
) const
475 return module
.name
+ "_clean";
479 MingwModuleHandler::GetReferencedObjectLibraryModuleCleanTargets ( vector
<string
>& moduleNames
) const
481 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
483 Library
& library
= *module
.non_if_data
.libraries
[i
];
484 if ( library
.importedModule
->type
== ObjectLibrary
)
485 moduleNames
.push_back ( GetModuleCleanTarget ( *library
.importedModule
) );
490 MingwModuleHandler::GenerateCleanTarget () const
492 if ( module
.type
== Alias
)
496 ".PHONY: %s_clean\n",
497 module
.name
.c_str() );
498 vector
<string
> referencedModuleNames
;
499 GetReferencedObjectLibraryModuleCleanTargets ( referencedModuleNames
);
502 GetModuleCleanTarget ( module
).c_str(),
503 v2s ( referencedModuleNames
, 10 ).c_str () );
504 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
507 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@${rm}" );
508 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
510 fprintf ( fMakefile
, " 2>$(NUL)\n" );
511 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
515 MingwModuleHandler::GenerateInstallTarget () const
517 if ( module
.installName
.length () == 0 )
519 fprintf ( fMakefile
, ".PHONY: %s_install\n", module
.name
.c_str() );
520 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
521 NormalizeFilename ( module
.installBase
+ SSEP
+ module
.installName
),
522 backend
->installDirectory
);
525 module
.name
.c_str (),
526 normalizedTargetFilename
.c_str() );
530 MingwModuleHandler::GenerateDependsTarget () const
533 ".PHONY: %s_depends\n",
534 module
.name
.c_str() );
536 "%s_depends: $(RBUILD_TARGET)\n",
537 module
.name
.c_str () );
539 "\t$(ECHO_RBUILD)\n" );
541 "\t$(Q)$(RBUILD_TARGET) -dm%s mingw\n",
542 module
.name
.c_str () );
546 MingwModuleHandler::GetObjectFilenames ()
548 const vector
<File
*>& files
= module
.non_if_data
.files
;
549 if ( files
.size () == 0 )
552 string
objectFilenames ( "" );
553 for ( size_t i
= 0; i
< files
.size (); i
++ )
555 if ( objectFilenames
.size () > 0 )
556 objectFilenames
+= " ";
558 GetObjectFilename ( files
[i
]->name
, NULL
);
560 return objectFilenames
;
564 MingwModuleHandler::GenerateGccDefineParametersFromVector (
565 const vector
<Define
*>& defines
)
568 for ( size_t i
= 0; i
< defines
.size (); i
++ )
570 Define
& define
= *defines
[i
];
571 if (parameters
.length () > 0)
574 parameters
+= define
.name
;
575 if (define
.value
.length () > 0)
578 parameters
+= define
.value
;
585 MingwModuleHandler::GenerateGccDefineParameters () const
587 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
588 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
589 if ( s
.length () > 0 )
598 MingwModuleHandler::ConcatenatePaths (
600 const string
& path2
) const
602 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
604 if ( path1
[path1
.length ()] == CSEP
)
605 return path1
+ path2
;
607 return path1
+ CSEP
+ path2
;
611 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
)
614 for ( size_t i
= 0; i
< includes
.size (); i
++ )
616 Include
& include
= *includes
[i
];
617 if ( parameters
.length () > 0 )
619 parameters
+= "-I" + include
.directory
;
625 MingwModuleHandler::GenerateGccIncludeParameters () const
627 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
628 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
629 if ( s
.length () > 0 )
638 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
641 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
643 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
644 if ( parameters
.length () > 0 )
646 parameters
+= compilerFlag
.flag
;
652 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
655 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
657 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
658 if ( parameters
.length () > 0 )
660 parameters
+= linkerFlag
.flag
;
666 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
667 const vector
<Library
*>& libraries
)
669 string
dependencies ( "" );
671 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
673 if ( wrap_count
++ == 5 )
674 dependencies
+= " \\\n\t\t", wrap_count
= 0;
675 else if ( dependencies
.size () > 0 )
677 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->importedModule
);
683 MingwModuleHandler::GenerateLinkerParameters () const
685 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
689 MingwModuleHandler::GenerateMacro (
690 const char* assignmentOperation
,
692 const IfableData
& data
)
695 bool generateAssignment
;
697 generateAssignment
= (use_pch
&& module
.pch
!= NULL
) || data
.includes
.size () > 0 || data
.defines
.size () > 0 || data
.compilerFlags
.size () > 0;
698 if ( generateAssignment
)
703 assignmentOperation
);
706 if ( use_pch
&& module
.pch
!= NULL
)
710 GetDirectory ( GetPrecompiledHeaderFilename () ).c_str () );
713 string compilerParameters
= GenerateCompilerParametersFromVector ( data
.compilerFlags
);
714 if ( compilerParameters
.size () > 0 )
719 compilerParameters
.c_str () );
722 for ( i
= 0; i
< data
.includes
.size(); i
++ )
724 const Include
& include
= *data
.includes
[i
];
725 string includeDirectory
;
726 if ( include
.baseModule
!= NULL
&&
727 ( include
.baseModule
->type
== RpcServer
||
728 include
.baseModule
->type
== RpcClient
) )
729 includeDirectory
= PassThruCacheDirectory ( NormalizeFilename ( include
.directory
),
730 backend
->intermediateDirectory
);
732 includeDirectory
= include
.directory
;
736 includeDirectory
.c_str() );
738 for ( i
= 0; i
< data
.defines
.size(); i
++ )
740 Define
& d
= *data
.defines
[i
];
745 if ( d
.value
.size() )
751 if ( generateAssignment
)
753 fprintf ( fMakefile
, "\n" );
758 MingwModuleHandler::GenerateMacros (
759 const char* assignmentOperation
,
760 const IfableData
& data
,
761 const vector
<LinkerFlag
*>* linkerFlags
)
765 GenerateMacro ( assignmentOperation
,
768 GenerateMacro ( assignmentOperation
,
772 if ( linkerFlags
!= NULL
)
774 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
775 if ( linkerParameters
.size () > 0 )
780 linkerflagsMacro
.c_str (),
782 linkerParameters
.c_str() );
786 if ( data
.libraries
.size () > 0 )
788 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
789 if ( deps
.size () > 0 )
800 const vector
<If
*>& ifs
= data
.ifs
;
801 for ( i
= 0; i
< ifs
.size(); i
++ )
804 if ( rIf
.data
.defines
.size()
805 || rIf
.data
.includes
.size()
806 || rIf
.data
.libraries
.size()
807 || rIf
.data
.files
.size()
808 || rIf
.data
.compilerFlags
.size()
809 || rIf
.data
.ifs
.size() )
813 "%s (\"$(%s)\",\"%s\")\n",
814 rIf
.negated
? "ifneq" : "ifeq",
815 rIf
.property
.c_str(),
829 MingwModuleHandler::CleanupFileVector ( vector
<File
*>& sourceFiles
)
831 for (size_t i
= 0; i
< sourceFiles
.size (); i
++)
832 delete sourceFiles
[i
];
836 MingwModuleHandler::GetModuleSpecificSourceFiles ( vector
<File
*>& sourceFiles
)
841 MingwModuleHandler::GenerateObjectMacros (
842 const char* assignmentOperation
,
843 const IfableData
& data
,
844 const vector
<LinkerFlag
*>* linkerFlags
)
848 const vector
<File
*>& files
= data
.files
;
849 if ( files
.size () > 0 )
851 for ( i
= 0; i
< files
.size (); i
++ )
853 File
& file
= *files
[i
];
858 objectsMacro
.c_str(),
860 file
.name
, NULL
).c_str (),
861 objectsMacro
.c_str() );
867 objectsMacro
.c_str (),
868 assignmentOperation
);
869 for ( i
= 0; i
< files
.size(); i
++ )
871 File
& file
= *files
[i
];
877 ( i
%10 == 9 ? " \\\n\t" : " " ),
879 file
.name
, NULL
).c_str () );
882 fprintf ( fMakefile
, "\n" );
885 const vector
<If
*>& ifs
= data
.ifs
;
886 for ( i
= 0; i
< ifs
.size(); i
++ )
889 if ( rIf
.data
.defines
.size()
890 || rIf
.data
.includes
.size()
891 || rIf
.data
.libraries
.size()
892 || rIf
.data
.files
.size()
893 || rIf
.data
.compilerFlags
.size()
894 || rIf
.data
.ifs
.size() )
898 "%s (\"$(%s)\",\"%s\")\n",
899 rIf
.negated
? "ifneq" : "ifeq",
900 rIf
.property
.c_str(),
902 GenerateObjectMacros (
912 vector
<File
*> sourceFiles
;
913 GetModuleSpecificSourceFiles ( sourceFiles
);
914 for ( i
= 0; i
< sourceFiles
.size (); i
++ )
919 objectsMacro
.c_str(),
921 sourceFiles
[i
]->name
, NULL
).c_str () );
923 CleanupFileVector ( sourceFiles
);
927 MingwModuleHandler::GetPrecompiledHeaderFilename () const
929 const string
& basePchFilename
= module
.pch
->file
.name
+ ".gch";
930 return PassThruCacheDirectory ( NormalizeFilename ( basePchFilename
),
931 backend
->intermediateDirectory
);
935 MingwModuleHandler::GenerateGccCommand (
936 const string
& sourceFilename
,
937 const string
& extraDependencies
,
939 const string
& cflagsMacro
)
941 string dependencies
= sourceFilename
;
942 if ( extraDependencies
!= "" )
943 dependencies
+= " " + extraDependencies
;
944 if ( module
.pch
&& use_pch
)
945 dependencies
+= " " + GetPrecompiledHeaderFilename ();
947 /* WIDL generated headers may be used */
948 vector
<string
> rpcDependencies
;
949 GetRpcHeaderDependencies ( rpcDependencies
);
950 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
951 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
953 string objectFilename
= GetObjectFilename (
954 sourceFilename
, &clean_files
);
957 objectFilename
.c_str (),
958 dependencies
.c_str (),
959 GetDirectory ( objectFilename
).c_str () );
960 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
962 "\t%s -c $< -o $@ %s\n",
964 cflagsMacro
.c_str () );
968 MingwModuleHandler::GenerateGccAssemblerCommand (
969 const string
& sourceFilename
,
971 const string
& cflagsMacro
)
973 string dependencies
= sourceFilename
;
974 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
975 string objectFilename
= GetObjectFilename (
976 sourceFilename
, &clean_files
);
979 objectFilename
.c_str (),
980 dependencies
.c_str (),
981 GetDirectory ( objectFilename
).c_str () );
982 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
984 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
986 cflagsMacro
.c_str () );
990 MingwModuleHandler::GenerateNasmCommand (
991 const string
& sourceFilename
,
992 const string
& nasmflagsMacro
)
994 string dependencies
= sourceFilename
;
995 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
996 string objectFilename
= GetObjectFilename (
997 sourceFilename
, &clean_files
);
1000 objectFilename
.c_str (),
1001 dependencies
.c_str (),
1002 GetDirectory ( objectFilename
).c_str () );
1003 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
1004 fprintf ( fMakefile
,
1005 "\t%s -f win32 $< -o $@ %s\n",
1007 nasmflagsMacro
.c_str () );
1011 MingwModuleHandler::GenerateWindresCommand (
1012 const string
& sourceFilename
,
1013 const string
& windresflagsMacro
)
1015 string dependencies
= sourceFilename
;
1016 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1017 string objectFilename
=
1018 GetObjectFilename ( sourceFilename
, &clean_files
);
1019 string sourceFilenamePart
= ReplaceExtension ( GetFilename ( sourceFilename
), "" );
1020 string rciFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".rci.tmp";
1021 string resFilename
= ros_temp
+ module
.name
+ "." + sourceFilenamePart
+ ".res.tmp";
1022 if ( module
.useWRC
)
1024 fprintf ( fMakefile
,
1025 "%s: %s $(WRC_TARGET) | %s\n",
1026 objectFilename
.c_str (),
1027 dependencies
.c_str (),
1028 GetDirectory ( objectFilename
).c_str () );
1029 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1030 fprintf ( fMakefile
,
1031 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
1032 windresflagsMacro
.c_str (),
1033 sourceFilename
.c_str (),
1034 rciFilename
.c_str () );
1035 fprintf ( fMakefile
,
1036 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
1037 windresflagsMacro
.c_str (),
1038 rciFilename
.c_str (),
1039 resFilename
.c_str () );
1040 fprintf ( fMakefile
,
1041 "\t-@${rm} %s 2>$(NUL)\n",
1042 rciFilename
.c_str () );
1043 fprintf ( fMakefile
,
1044 "\t${windres} %s -o $@\n",
1045 resFilename
.c_str () );
1046 fprintf ( fMakefile
,
1047 "\t-@${rm} %s 2>$(NUL)\n",
1048 resFilename
.c_str () );
1052 fprintf ( fMakefile
,
1053 "%s: %s $(WRC_TARGET) | %s\n",
1054 objectFilename
.c_str (),
1055 dependencies
.c_str (),
1056 GetDirectory ( objectFilename
).c_str () );
1057 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
1058 fprintf ( fMakefile
,
1059 "\t${windres} $(%s) %s -o $@\n",
1060 windresflagsMacro
.c_str (),
1061 sourceFilename
.c_str () );
1066 MingwModuleHandler::GenerateWinebuildCommands (
1067 const string
& sourceFilename
)
1069 string dependencies
= sourceFilename
;
1070 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1072 string basename
= GetBasename ( sourceFilename
);
1073 string def_file
= PassThruCacheDirectory (
1074 basename
+ ".spec.def",
1075 backend
->intermediateDirectory
);
1076 CLEAN_FILE(def_file
);
1078 string stub_file
= PassThruCacheDirectory (
1079 basename
+ ".stubs.c",
1080 backend
->intermediateDirectory
);
1081 CLEAN_FILE(stub_file
)
1083 fprintf ( fMakefile
,
1084 "%s: %s $(WINEBUILD_TARGET)\n",
1086 dependencies
.c_str () );
1087 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1088 fprintf ( fMakefile
,
1089 "\t%s -o %s --def -E %s\n",
1090 "$(Q)$(WINEBUILD_TARGET)",
1092 sourceFilename
.c_str () );
1093 fprintf ( fMakefile
,
1094 "%s: %s $(WINEBUILD_TARGET)\n",
1096 sourceFilename
.c_str () );
1097 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
1098 fprintf ( fMakefile
,
1099 "\t%s -o %s --pedll %s\n",
1100 "$(Q)$(WINEBUILD_TARGET)",
1102 sourceFilename
.c_str () );
1106 MingwModuleHandler::GetWidlFlags ( const File
& file
)
1108 return file
.switches
;
1112 MingwModuleHandler::GetRpcServerHeaderFilename ( string basename
) const
1114 return PassThruCacheDirectory ( basename
+ "_s.h",
1115 backend
->intermediateDirectory
);
1119 MingwModuleHandler::GenerateWidlCommandsServer (
1121 const string
& widlflagsMacro
)
1123 string dependencies
= file
.name
;
1124 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1126 string basename
= GetBasename ( file
.name
);
1128 string generatedHeaderFilename
= GetRpcServerHeaderFilename ( basename
);
1129 CLEAN_FILE(generatedHeaderFilename
);
1131 string generatedServerFilename
= PassThruCacheDirectory (
1133 backend
->intermediateDirectory
);
1134 CLEAN_FILE(generatedServerFilename
);
1136 fprintf ( fMakefile
,
1137 "%s %s: %s $(WIDL_TARGET) | %s\n",
1138 generatedServerFilename
.c_str (),
1139 generatedHeaderFilename
.c_str (),
1140 dependencies
.c_str (),
1141 GetDirectory ( generatedServerFilename
).c_str () );
1142 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1143 fprintf ( fMakefile
,
1144 "\t%s %s %s -h -H %s -s -S %s %s\n",
1145 "$(Q)$(WIDL_TARGET)",
1146 GetWidlFlags ( file
).c_str (),
1147 widlflagsMacro
.c_str (),
1148 generatedHeaderFilename
.c_str (),
1149 generatedServerFilename
.c_str (),
1150 file
.name
.c_str () );
1154 MingwModuleHandler::GetRpcClientHeaderFilename ( string basename
) const
1156 return PassThruCacheDirectory ( basename
+ "_c.h",
1157 backend
->intermediateDirectory
);
1161 MingwModuleHandler::GenerateWidlCommandsClient (
1163 const string
& widlflagsMacro
)
1165 string dependencies
= file
.name
;
1166 dependencies
+= " " + NormalizeFilename ( module
.xmlbuildFile
);
1168 string basename
= GetBasename ( file
.name
);
1170 string generatedHeaderFilename
= GetRpcClientHeaderFilename ( basename
);
1171 CLEAN_FILE(generatedHeaderFilename
);
1173 string generatedClientFilename
= PassThruCacheDirectory (
1175 backend
->intermediateDirectory
);
1176 CLEAN_FILE(generatedClientFilename
);
1178 fprintf ( fMakefile
,
1179 "%s %s: %s $(WIDL_TARGET) | %s\n",
1180 generatedClientFilename
.c_str (),
1181 generatedHeaderFilename
.c_str (),
1182 dependencies
.c_str (),
1183 GetDirectory ( generatedClientFilename
).c_str () );
1184 fprintf ( fMakefile
, "\t$(ECHO_WIDL)\n" );
1185 fprintf ( fMakefile
,
1186 "\t%s %s %s -h -H %s -c -C %s %s\n",
1187 "$(Q)$(WIDL_TARGET)",
1188 GetWidlFlags ( file
).c_str (),
1189 widlflagsMacro
.c_str (),
1190 generatedHeaderFilename
.c_str (),
1191 generatedClientFilename
.c_str (),
1192 file
.name
.c_str () );
1196 MingwModuleHandler::GenerateWidlCommands (
1198 const string
& widlflagsMacro
)
1200 if ( module
.type
== RpcServer
)
1201 GenerateWidlCommandsServer ( file
,
1204 GenerateWidlCommandsClient ( file
,
1209 MingwModuleHandler::GenerateCommands (
1213 const string
& cflagsMacro
,
1214 const string
& nasmflagsMacro
,
1215 const string
& windresflagsMacro
,
1216 const string
& widlflagsMacro
)
1218 string extension
= GetExtension ( file
.name
);
1219 if ( extension
== ".c" || extension
== ".C" )
1221 GenerateGccCommand ( file
.name
,
1227 else if ( extension
== ".cc" || extension
== ".CC" ||
1228 extension
== ".cpp" || extension
== ".CPP" ||
1229 extension
== ".cxx" || extension
== ".CXX" )
1231 GenerateGccCommand ( file
.name
,
1237 else if ( extension
== ".s" || extension
== ".S" )
1239 GenerateGccAssemblerCommand ( file
.name
,
1244 else if ( extension
== ".asm" || extension
== ".ASM" )
1246 GenerateNasmCommand ( file
.name
,
1250 else if ( extension
== ".rc" || extension
== ".RC" )
1252 GenerateWindresCommand ( file
.name
,
1253 windresflagsMacro
);
1256 else if ( extension
== ".spec" || extension
== ".SPEC" )
1258 GenerateWinebuildCommands ( file
.name
);
1259 GenerateGccCommand ( GetActualSourceFilename ( file
.name
),
1265 else if ( extension
== ".idl" || extension
== ".IDL" )
1267 GenerateWidlCommands ( file
,
1269 GenerateGccCommand ( GetActualSourceFilename ( file
.name
),
1270 GetExtraDependencies ( file
.name
),
1276 throw InvalidOperationException ( __FILE__
,
1278 "Unsupported filename extension '%s' in file '%s'",
1280 file
.name
.c_str () );
1284 MingwModuleHandler::GenerateBuildMapCode ()
1286 fprintf ( fMakefile
,
1287 "ifeq ($(ROS_BUILDMAP),full)\n" );
1289 string mapFilename
= PassThruCacheDirectory (
1290 GetBasename ( module
.GetPath () ) + ".map",
1291 backend
->outputDirectory
);
1292 CLEAN_FILE ( mapFilename
);
1294 fprintf ( fMakefile
,
1295 "\t$(ECHO_OBJDUMP)\n" );
1296 fprintf ( fMakefile
,
1297 "\t$(Q)${objdump} -d -S $@ > %s\n",
1298 mapFilename
.c_str () );
1300 fprintf ( fMakefile
,
1302 fprintf ( fMakefile
,
1303 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1305 fprintf ( fMakefile
,
1307 fprintf ( fMakefile
,
1308 "\t$(Q)${nm} --numeric-sort $@ > %s\n",
1309 mapFilename
.c_str () );
1311 fprintf ( fMakefile
,
1314 fprintf ( fMakefile
,
1319 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1321 fprintf ( fMakefile
,
1322 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1324 string filename
= module
.GetPath ();
1325 string outputFilename
= PassThruCacheDirectory (
1327 backend
->outputDirectory
);
1328 string nostripFilename
= PassThruCacheDirectory (
1329 GetBasename ( filename
) + ".nostrip" + GetExtension ( filename
),
1330 backend
->outputDirectory
);
1331 CLEAN_FILE ( nostripFilename
);
1333 fprintf ( fMakefile
,
1335 fprintf ( fMakefile
,
1336 "\t${cp} %s %s 1>$(NUL)\n",
1337 outputFilename
.c_str (),
1338 nostripFilename
.c_str () );
1340 fprintf ( fMakefile
,
1345 MergeStringVector ( const vector
<string
>& input
,
1346 vector
<string
>& output
)
1350 int wrap_count
= -1;
1351 for ( size_t i
= 0; i
< input
.size (); i
++ )
1353 if ( input
[i
].size () == 0 )
1355 if ( wrap_count
++ == wrap_at
)
1357 output
.push_back ( s
);
1361 else if ( s
.size () > 0)
1365 if ( s
.length () > 0 )
1366 output
.push_back ( s
);
1370 MingwModuleHandler::GetObjectsVector ( const IfableData
& data
,
1371 vector
<string
>& objectFiles
) const
1373 for ( size_t i
= 0; i
< data
.files
.size (); i
++ )
1375 File
& file
= *data
.files
[i
];
1376 objectFiles
.push_back ( GetObjectFilename ( file
.name
, NULL
) );
1381 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1383 if ( backend
->configuration
.CleanAsYouGo
)
1385 vector
<string
> objectFiles
;
1386 GetObjectsVector ( module
.non_if_data
,
1388 vector
<string
> lines
;
1389 MergeStringVector ( objectFiles
,
1391 for ( size_t i
= 0; i
< lines
.size (); i
++ )
1393 fprintf ( fMakefile
,
1394 "\t-@${rm} %s 2>$(NUL)\n",
1395 lines
[i
].c_str () );
1401 MingwModuleHandler::GenerateRunRsymCode () const
1403 fprintf ( fMakefile
,
1404 "\t$(ECHO_RSYM)\n" );
1405 fprintf ( fMakefile
,
1406 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1410 MingwModuleHandler::GenerateLinkerCommand (
1411 const string
& dependencies
,
1412 const string
& linker
,
1413 const string
& linkerParameters
,
1414 const string
& objectsMacro
,
1415 const string
& libsMacro
,
1416 const string
& pefixupParameters
)
1418 string
target ( GetTargetMacro ( module
) );
1419 string
target_folder ( GetDirectory ( GetTargetFilename ( module
, NULL
) ) );
1420 string def_file
= GetDefinitionFilename ();
1422 fprintf ( fMakefile
,
1423 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1426 dependencies
.c_str (),
1427 target_folder
.c_str () );
1428 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1429 string
targetName ( module
.GetTargetName () );
1431 if ( module
.IsDLL () )
1433 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1434 CLEAN_FILE ( temp_exp
);
1436 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1437 fprintf ( fMakefile
,
1438 "\t${dlltool} --dllname %s --def %s --output-exp %s %s\n",
1439 targetName
.c_str (),
1444 fprintf ( fMakefile
,
1445 "\t%s %s %s -o %s %s %s %s\n",
1447 linkerParameters
.c_str (),
1450 objectsMacro
.c_str (),
1452 GetLinkerMacro ().c_str () );
1454 fprintf ( fMakefile
,
1455 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1457 pefixupParameters
.c_str() );
1459 fprintf ( fMakefile
,
1460 "\t-@${rm} %s 2>$(NUL)\n",
1461 temp_exp
.c_str () );
1465 fprintf ( fMakefile
,
1466 "\t%s %s -o %s %s %s %s\n",
1468 linkerParameters
.c_str (),
1470 objectsMacro
.c_str (),
1472 GetLinkerMacro ().c_str () );
1474 if ( pefixupParameters
.length() != 0 )
1476 fprintf ( fMakefile
,
1477 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1479 pefixupParameters
.c_str() );
1483 GenerateBuildMapCode ();
1484 GenerateBuildNonSymbolStrippedCode ();
1485 GenerateRunRsymCode ();
1486 GenerateCleanObjectsAsYouGoCode ();
1490 MingwModuleHandler::GeneratePhonyTarget() const
1492 string
targetMacro ( GetTargetMacro ( module
) );
1493 fprintf ( fMakefile
,
1495 targetMacro
.c_str ());
1496 fprintf ( fMakefile
, "%s: | %s\n",
1497 targetMacro
.c_str (),
1498 GetDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1502 MingwModuleHandler::GenerateObjectFileTargets (
1503 const IfableData
& data
,
1506 const string
& cflagsMacro
,
1507 const string
& nasmflagsMacro
,
1508 const string
& windresflagsMacro
,
1509 const string
& widlflagsMacro
)
1513 const vector
<File
*>& files
= data
.files
;
1514 for ( i
= 0; i
< files
.size (); i
++ )
1516 GenerateCommands ( *files
[i
],
1523 fprintf ( fMakefile
,
1527 const vector
<If
*>& ifs
= data
.ifs
;
1528 for ( i
= 0; i
< ifs
.size(); i
++ )
1530 GenerateObjectFileTargets ( ifs
[i
]->data
,
1539 vector
<File
*> sourceFiles
;
1540 GetModuleSpecificSourceFiles ( sourceFiles
);
1541 for ( i
= 0; i
< sourceFiles
.size (); i
++ )
1543 GenerateCommands ( *sourceFiles
[i
],
1551 CleanupFileVector ( sourceFiles
);
1555 MingwModuleHandler::GenerateObjectFileTargets (
1558 const string
& cflagsMacro
,
1559 const string
& nasmflagsMacro
,
1560 const string
& windresflagsMacro
,
1561 const string
& widlflagsMacro
)
1563 if ( module
.pch
&& use_pch
)
1565 const string
& baseHeaderFilename
= module
.pch
->file
.name
;
1566 const string
& pchFilename
= GetPrecompiledHeaderFilename ();
1567 CLEAN_FILE(pchFilename
);
1568 fprintf ( fMakefile
,
1570 pchFilename
.c_str(),
1571 baseHeaderFilename
.c_str() );
1572 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1573 fprintf ( fMakefile
,
1574 "\t%s -o %s %s -g %s\n\n",
1575 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1576 pchFilename
.c_str(),
1577 cflagsMacro
.c_str(),
1578 baseHeaderFilename
.c_str() );
1581 GenerateObjectFileTargets ( module
.non_if_data
,
1588 fprintf ( fMakefile
, "\n" );
1592 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1593 const string
& objs_macro
) const
1595 string
archiveFilename ( GetModuleArchiveFilename () );
1597 fprintf ( fMakefile
,
1599 archiveFilename
.c_str (),
1600 objs_macro
.c_str (),
1601 GetDirectory(archiveFilename
).c_str() );
1603 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1605 fprintf ( fMakefile
,
1608 objs_macro
.c_str ());
1610 GenerateCleanObjectsAsYouGoCode ();
1612 fprintf ( fMakefile
, "\n" );
1614 return archiveFilename
;
1618 MingwModuleHandler::GetCFlagsMacro () const
1620 return ssprintf ( "$(%s_CFLAGS)",
1621 module
.name
.c_str () );
1625 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1627 return ssprintf ( "$(%s_OBJS)",
1628 module
.name
.c_str () );
1632 MingwModuleHandler::GetLinkingDependenciesMacro () const
1634 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1638 MingwModuleHandler::GetLibsMacro () const
1640 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1644 MingwModuleHandler::GetLinkerMacro () const
1646 return ssprintf ( "$(%s_LFLAGS)",
1647 module
.name
.c_str () );
1651 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1653 if ( ReferenceObjects ( module
) )
1654 return GetObjectsMacro ( module
);
1656 return GetTargetFilename ( module
, NULL
);
1660 MingwModuleHandler::GenerateObjectMacro ()
1662 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1664 GenerateObjectMacros (
1667 &module
.linkerFlags
);
1669 // future references to the macro will be to get its values
1670 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1674 MingwModuleHandler::GenerateTargetMacro ()
1676 fprintf ( fMakefile
,
1678 GetTargetMacro ( module
, false ).c_str (),
1679 GetModuleTargets ( module
).c_str () );
1683 MingwModuleHandler::GetRpcHeaderDependencies (
1684 vector
<string
>& dependencies
) const
1686 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1688 Library
& library
= *module
.non_if_data
.libraries
[i
];
1689 if ( library
.importedModule
->type
== RpcServer
||
1690 library
.importedModule
->type
== RpcClient
)
1692 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.files
.size (); j
++ )
1694 File
& file
= *library
.importedModule
->non_if_data
.files
[j
];
1695 string extension
= GetExtension ( file
.name
);
1696 if ( extension
== ".idl" || extension
== ".IDL" )
1698 string basename
= GetBasename ( file
.name
);
1699 if ( library
.importedModule
->type
== RpcServer
)
1700 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
1701 if ( library
.importedModule
->type
== RpcClient
)
1702 dependencies
.push_back ( GetRpcClientHeaderFilename ( basename
) );
1710 MingwModuleHandler::GenerateOtherMacros ()
1712 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1713 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1714 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1715 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1716 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1717 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1718 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1723 &module
.linkerFlags
);
1726 if ( module
.importLibrary
)
1728 const vector
<File
*>& files
= module
.non_if_data
.files
;
1729 for ( size_t i
= 0; i
< files
.size (); i
++ )
1731 File
& file
= *files
[i
];
1732 string extension
= GetExtension ( file
.name
);
1733 if ( extension
== ".spec" || extension
== ".SPEC" )
1734 GetSpecObjectDependencies ( s
, file
.name
);
1737 if ( s
.size () > 0 )
1742 linkDepsMacro
.c_str() );
1743 for ( size_t i
= 0; i
< s
.size(); i
++ )
1744 fprintf ( fMakefile
,
1747 fprintf ( fMakefile
, "\n" );
1750 string globalCflags
= "-g";
1751 if ( backend
->usePipe
)
1752 globalCflags
+= " -pipe";
1753 if ( !module
.allowWarnings
)
1754 globalCflags
+= " -Werror";
1758 "%s += $(PROJECT_CFLAGS) %s\n",
1759 cflagsMacro
.c_str (),
1760 globalCflags
.c_str () );
1764 "%s += $(PROJECT_RCFLAGS)\n",
1765 windresflagsMacro
.c_str () );
1769 "%s += $(PROJECT_WIDLFLAGS)\n",
1770 widlflagsMacro
.c_str () );
1774 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1775 module
.name
.c_str () );
1780 linkDepsMacro
.c_str (),
1781 libsMacro
.c_str () );
1783 string cflags
= TypeSpecificCFlags();
1784 if ( cflags
.size() > 0 )
1786 fprintf ( fMakefile
,
1788 cflagsMacro
.c_str (),
1792 string nasmflags
= TypeSpecificNasmFlags();
1793 if ( nasmflags
.size () > 0 )
1795 fprintf ( fMakefile
,
1797 nasmflagsMacro
.c_str (),
1798 nasmflags
.c_str () );
1801 string linkerflags
= TypeSpecificLinkerFlags();
1802 if ( linkerflags
.size() > 0 )
1804 fprintf ( fMakefile
,
1806 linkerflagsMacro
.c_str (),
1807 linkerflags
.c_str () );
1810 fprintf ( fMakefile
, "\n\n" );
1812 // future references to the macros will be to get their values
1813 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1814 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1815 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
1819 MingwModuleHandler::GenerateRules ()
1821 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1822 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1823 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1825 if ( module
.name
!= "zlib" ) /* Avoid make warning */
1827 string proxyMakefile
= PassThruCacheDirectory (
1828 NormalizeFilename ( module
.GetBasePath () + SSEP
+ "makefile" ),
1829 backend
->outputDirectory
);
1830 CLEAN_FILE ( proxyMakefile
);
1833 string targetMacro
= GetTargetMacro ( module
);
1834 CLEAN_FILE ( targetMacro
);
1836 // generate phony target for module name
1837 fprintf ( fMakefile
, ".PHONY: %s\n",
1838 module
.name
.c_str () );
1839 string dependencies
= GetTargetMacro ( module
);
1840 if ( module
.type
== Test
)
1841 dependencies
+= " $(REGTESTS_RUN_TARGET)";
1842 fprintf ( fMakefile
, "%s: %s\n\n",
1843 module
.name
.c_str (),
1844 dependencies
.c_str () );
1845 if ( module
.type
== Test
)
1847 fprintf ( fMakefile
,
1849 targetMacro
.c_str ());
1852 if ( !ReferenceObjects ( module
) )
1854 string
ar_target ( GenerateArchiveTarget ( ar
, objectsMacro
) );
1855 if ( targetMacro
!= ar_target
)
1856 CLEAN_FILE ( ar_target
);
1859 GenerateObjectFileTargets ( cc
,
1868 MingwModuleHandler::GetInvocationDependencies (
1869 const Module
& module
,
1870 string_list
& dependencies
)
1872 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1874 Invoke
& invoke
= *module
.invocations
[i
];
1875 if ( invoke
.invokeModule
== &module
)
1876 /* Protect against circular dependencies */
1878 invoke
.GetTargets ( dependencies
);
1883 MingwModuleHandler::GenerateInvocations () const
1885 if ( module
.invocations
.size () == 0 )
1888 size_t iend
= module
.invocations
.size ();
1889 for ( size_t i
= 0; i
< iend
; i
++ )
1891 const Invoke
& invoke
= *module
.invocations
[i
];
1893 if ( invoke
.invokeModule
->type
!= BuildTool
)
1895 throw InvalidBuildFileException ( module
.node
.location
,
1896 "Only modules of type buildtool can be invoked." );
1899 string invokeTarget
= module
.GetInvocationTarget ( i
);
1900 string_list invoke_targets
;
1901 assert ( invoke_targets
.size() );
1902 invoke
.GetTargets ( invoke_targets
);
1903 fprintf ( fMakefile
,
1905 invokeTarget
.c_str () );
1906 fprintf ( fMakefile
,
1908 invokeTarget
.c_str () );
1909 size_t j
, jend
= invoke_targets
.size();
1910 for ( j
= 0; j
< jend
; j
++ )
1912 fprintf ( fMakefile
,
1914 invoke_targets
[i
].c_str () );
1916 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
1917 for ( j
= 1; j
< jend
; j
++ )
1918 fprintf ( fMakefile
,
1920 invoke_targets
[i
].c_str () );
1921 fprintf ( fMakefile
,
1923 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1924 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1925 fprintf ( fMakefile
,
1927 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1928 invoke
.GetParameters ().c_str () );
1933 MingwModuleHandler::GetPreconditionDependenciesName () const
1935 return module
.name
+ "_precondition";
1939 MingwModuleHandler::GetDefaultDependencies (
1940 string_list
& dependencies
) const
1942 /* Avoid circular dependency */
1943 if ( module
.type
!= BuildTool
1944 && module
.name
!= "zlib"
1945 && module
.name
!= "hostzlib" )
1947 dependencies
.push_back ( "$(INIT)" );
1951 MingwModuleHandler::GeneratePreconditionDependencies ()
1953 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
1954 string_list sourceFilenames
;
1955 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
1956 string_list dependencies
;
1957 GetDefaultDependencies ( dependencies
);
1958 GetModuleDependencies ( dependencies
);
1960 GetInvocationDependencies ( module
, dependencies
);
1962 if ( dependencies
.size() )
1964 fprintf ( fMakefile
,
1966 preconditionDependenciesName
.c_str () );
1967 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
1968 fprintf ( fMakefile
,
1970 dependencies
[i
].c_str () );
1971 fprintf ( fMakefile
, "\n\n" );
1974 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
1976 fprintf ( fMakefile
,
1978 sourceFilenames
[i
].c_str(),
1979 preconditionDependenciesName
.c_str ());
1981 fprintf ( fMakefile
, "\n" );
1985 MingwModuleHandler::IsWineModule () const
1987 if ( module
.importLibrary
== NULL
)
1990 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
1991 return ( index
!= string::npos
);
1995 MingwModuleHandler::GetDefinitionFilename () const
1997 if ( module
.importLibrary
!= NULL
)
1999 string defFilename
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
2000 if ( IsWineModule () )
2001 return PassThruCacheDirectory ( NormalizeFilename ( defFilename
),
2002 backend
->intermediateDirectory
);
2007 return "tools" SSEP
"rbuild" SSEP
"empty.def";
2011 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2013 if ( module
.importLibrary
!= NULL
)
2015 string
library_target (
2016 GetImportLibraryFilename ( module
, &clean_files
) );
2017 string defFilename
= GetDefinitionFilename ();
2020 GetDefinitionDependencies ( deps
);
2022 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2024 fprintf ( fMakefile
, "%s: %s",
2025 library_target
.c_str (),
2026 defFilename
.c_str () );
2028 size_t i
, iend
= deps
.size();
2029 for ( i
= 0; i
< iend
; i
++ )
2030 fprintf ( fMakefile
, " %s",
2033 fprintf ( fMakefile
, " | %s\n",
2034 GetDirectory ( GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2036 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2038 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
2039 fprintf ( fMakefile
,
2040 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
2041 module
.GetTargetName ().c_str (),
2042 defFilename
.c_str (),
2043 library_target
.c_str (),
2049 MingwModuleHandler::GetSpecObjectDependencies (
2050 string_list
& dependencies
,
2051 const string
& filename
) const
2053 string basename
= GetBasename ( filename
);
2054 string defDependency
= PassThruCacheDirectory (
2055 NormalizeFilename ( basename
+ ".spec.def" ),
2056 backend
->intermediateDirectory
);
2057 dependencies
.push_back ( defDependency
);
2058 string stubsDependency
= PassThruCacheDirectory (
2059 NormalizeFilename ( basename
+ ".stubs.c" ),
2060 backend
->intermediateDirectory
);
2061 dependencies
.push_back ( stubsDependency
);
2065 MingwModuleHandler::GetWidlObjectDependencies (
2066 string_list
& dependencies
,
2067 const string
& filename
) const
2069 string basename
= GetBasename ( filename
);
2070 string serverSourceDependency
= PassThruCacheDirectory (
2071 NormalizeFilename ( basename
+ "_s.c" ),
2072 backend
->intermediateDirectory
);
2073 dependencies
.push_back ( serverSourceDependency
);
2074 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
2078 MingwModuleHandler::GetDefinitionDependencies (
2079 string_list
& dependencies
) const
2081 string dkNkmLibNoFixup
= "dk/nkm/lib";
2082 const vector
<File
*>& files
= module
.non_if_data
.files
;
2083 for ( size_t i
= 0; i
< files
.size (); i
++ )
2085 File
& file
= *files
[i
];
2086 string extension
= GetExtension ( file
.name
);
2087 if ( extension
== ".spec" || extension
== ".SPEC" )
2089 GetSpecObjectDependencies ( dependencies
, file
.name
);
2091 if ( extension
== ".idl" || extension
== ".IDL" )
2093 GetWidlObjectDependencies ( dependencies
, file
.name
);
2099 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2100 : MingwModuleHandler ( module_
)
2105 MingwBuildToolModuleHandler::Process ()
2107 GenerateBuildToolModuleTarget ();
2111 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2113 string
targetMacro ( GetTargetMacro (module
) );
2114 string objectsMacro
= GetObjectsMacro ( module
);
2115 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2116 string libsMacro
= GetLibsMacro ();
2121 if ( module
.cplusplus
)
2122 linker
= "${host_gpp}";
2124 linker
= "${host_gcc}";
2126 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2127 targetMacro
.c_str (),
2128 objectsMacro
.c_str (),
2129 linkDepsMacro
.c_str (),
2130 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2131 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2132 fprintf ( fMakefile
,
2133 "\t%s %s -o $@ %s %s\n\n",
2135 GetLinkerMacro ().c_str (),
2136 objectsMacro
.c_str (),
2137 libsMacro
.c_str () );
2141 MingwKernelModuleHandler::MingwKernelModuleHandler (
2142 const Module
& module_
)
2144 : MingwModuleHandler ( module_
)
2149 MingwKernelModuleHandler::Process ()
2151 GenerateKernelModuleTarget ();
2155 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2157 string
targetMacro ( GetTargetMacro ( module
) );
2158 string workingDirectory
= GetWorkingDirectory ( );
2159 string objectsMacro
= GetObjectsMacro ( module
);
2160 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2161 string libsMacro
= GetLibsMacro ();
2163 GenerateImportLibraryTargetIfNeeded ();
2165 if ( module
.non_if_data
.files
.size () > 0 )
2169 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2171 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",
2172 module
.GetBasePath ().c_str (),
2173 module
.entrypoint
.c_str (),
2174 module
.baseaddress
.c_str () );
2175 GenerateLinkerCommand ( dependencies
,
2184 GeneratePhonyTarget();
2189 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2190 const Module
& module_
)
2192 : MingwModuleHandler ( module_
)
2197 MingwStaticLibraryModuleHandler::Process ()
2199 GenerateStaticLibraryModuleTarget ();
2203 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2209 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2210 const Module
& module_
)
2212 : MingwModuleHandler ( module_
)
2217 MingwObjectLibraryModuleHandler::Process ()
2219 GenerateObjectLibraryModuleTarget ();
2223 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2229 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2230 const Module
& module_
)
2232 : MingwModuleHandler ( module_
)
2237 MingwKernelModeDLLModuleHandler::Process ()
2239 GenerateKernelModeDLLModuleTarget ();
2243 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2245 string
targetMacro ( GetTargetMacro ( module
) );
2246 string workingDirectory
= GetWorkingDirectory ( );
2247 string objectsMacro
= GetObjectsMacro ( module
);
2248 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2249 string libsMacro
= GetLibsMacro ();
2251 GenerateImportLibraryTargetIfNeeded ();
2253 if ( module
.non_if_data
.files
.size () > 0 )
2257 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2259 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2260 module
.entrypoint
.c_str (),
2261 module
.baseaddress
.c_str () );
2262 GenerateLinkerCommand ( dependencies
,
2271 GeneratePhonyTarget();
2276 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2277 const Module
& module_
)
2279 : MingwModuleHandler ( module_
)
2284 MingwKernelModeDriverModuleHandler::Process ()
2286 GenerateKernelModeDriverModuleTarget ();
2291 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2293 string
targetMacro ( GetTargetMacro (module
) );
2294 string workingDirectory
= GetWorkingDirectory ();
2295 string objectsMacro
= GetObjectsMacro ( module
);
2296 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2297 string libsMacro
= GetLibsMacro ();
2299 GenerateImportLibraryTargetIfNeeded ();
2301 if ( module
.non_if_data
.files
.size () > 0 )
2305 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2307 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2308 module
.entrypoint
.c_str (),
2309 module
.baseaddress
.c_str () );
2310 GenerateLinkerCommand ( dependencies
,
2319 GeneratePhonyTarget();
2324 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2325 const Module
& module_
)
2327 : MingwModuleHandler ( module_
)
2332 MingwNativeDLLModuleHandler::Process ()
2334 GenerateNativeDLLModuleTarget ();
2338 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2340 string
targetMacro ( GetTargetMacro (module
) );
2341 string workingDirectory
= GetWorkingDirectory ( );
2342 string objectsMacro
= GetObjectsMacro ( module
);
2343 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2344 string libsMacro
= GetLibsMacro ();
2346 GenerateImportLibraryTargetIfNeeded ();
2348 if ( module
.non_if_data
.files
.size () > 0 )
2352 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2354 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2355 module
.entrypoint
.c_str (),
2356 module
.baseaddress
.c_str () );
2357 GenerateLinkerCommand ( dependencies
,
2366 GeneratePhonyTarget();
2371 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2372 const Module
& module_
)
2374 : MingwModuleHandler ( module_
)
2379 MingwNativeCUIModuleHandler::Process ()
2381 GenerateNativeCUIModuleTarget ();
2385 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2387 string
targetMacro ( GetTargetMacro (module
) );
2388 string workingDirectory
= GetWorkingDirectory ( );
2389 string objectsMacro
= GetObjectsMacro ( module
);
2390 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2391 string libsMacro
= GetLibsMacro ();
2393 GenerateImportLibraryTargetIfNeeded ();
2395 if ( module
.non_if_data
.files
.size () > 0 )
2399 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2401 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2402 module
.entrypoint
.c_str (),
2403 module
.baseaddress
.c_str () );
2404 GenerateLinkerCommand ( dependencies
,
2413 GeneratePhonyTarget();
2418 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2419 const Module
& module_
)
2421 : MingwModuleHandler ( module_
)
2426 MingwWin32DLLModuleHandler::Process ()
2428 GenerateWin32DLLModuleTarget ();
2432 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2434 string
targetMacro ( GetTargetMacro (module
) );
2435 string workingDirectory
= GetWorkingDirectory ( );
2436 string objectsMacro
= GetObjectsMacro ( module
);
2437 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2438 string libsMacro
= GetLibsMacro ();
2440 GenerateImportLibraryTargetIfNeeded ();
2442 if ( module
.non_if_data
.files
.size () > 0 )
2446 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2449 if ( module
.cplusplus
)
2454 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2455 module
.entrypoint
.c_str (),
2456 module
.baseaddress
.c_str () );
2457 GenerateLinkerCommand ( dependencies
,
2466 GeneratePhonyTarget();
2471 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2472 const Module
& module_
)
2474 : MingwModuleHandler ( module_
)
2479 MingwWin32CUIModuleHandler::Process ()
2481 GenerateWin32CUIModuleTarget ();
2485 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2487 string
targetMacro ( GetTargetMacro (module
) );
2488 string workingDirectory
= GetWorkingDirectory ( );
2489 string objectsMacro
= GetObjectsMacro ( module
);
2490 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2491 string libsMacro
= GetLibsMacro ();
2493 GenerateImportLibraryTargetIfNeeded ();
2495 if ( module
.non_if_data
.files
.size () > 0 )
2499 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2502 if ( module
.cplusplus
)
2507 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2508 module
.entrypoint
.c_str (),
2509 module
.baseaddress
.c_str () );
2510 GenerateLinkerCommand ( dependencies
,
2519 GeneratePhonyTarget();
2524 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2525 const Module
& module_
)
2527 : MingwModuleHandler ( module_
)
2532 MingwWin32GUIModuleHandler::Process ()
2534 GenerateWin32GUIModuleTarget ();
2538 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2540 string
targetMacro ( GetTargetMacro (module
) );
2541 string workingDirectory
= GetWorkingDirectory ( );
2542 string objectsMacro
= GetObjectsMacro ( module
);
2543 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2544 string libsMacro
= GetLibsMacro ();
2546 GenerateImportLibraryTargetIfNeeded ();
2548 if ( module
.non_if_data
.files
.size () > 0 )
2552 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2555 if ( module
.cplusplus
)
2560 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2561 module
.entrypoint
.c_str (),
2562 module
.baseaddress
.c_str () );
2563 GenerateLinkerCommand ( dependencies
,
2572 GeneratePhonyTarget();
2577 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2578 const Module
& module_
)
2580 : MingwModuleHandler ( module_
)
2585 MingwBootLoaderModuleHandler::Process ()
2587 GenerateBootLoaderModuleTarget ();
2591 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2593 string
targetName ( module
.GetTargetName () );
2594 string
targetMacro ( GetTargetMacro (module
) );
2595 string workingDirectory
= GetWorkingDirectory ();
2596 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2597 CLEAN_FILE ( junk_tmp
);
2598 string objectsMacro
= GetObjectsMacro ( module
);
2599 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2600 string libsMacro
= GetLibsMacro ();
2604 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2605 targetMacro
.c_str (),
2606 objectsMacro
.c_str (),
2607 linkDepsMacro
.c_str (),
2608 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2610 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2612 fprintf ( fMakefile
,
2613 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2614 GetLinkerMacro ().c_str (),
2616 objectsMacro
.c_str (),
2617 linkDepsMacro
.c_str () );
2618 fprintf ( fMakefile
,
2619 "\t${objcopy} -O binary %s $@\n",
2620 junk_tmp
.c_str () );
2621 fprintf ( fMakefile
,
2622 "\t-@${rm} %s 2>$(NUL)\n",
2623 junk_tmp
.c_str () );
2627 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2628 const Module
& module_
)
2630 : MingwModuleHandler ( module_
)
2635 MingwBootSectorModuleHandler::Process ()
2637 GenerateBootSectorModuleTarget ();
2641 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2643 string objectsMacro
= GetObjectsMacro ( module
);
2647 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2648 module
.name
.c_str ());
2649 fprintf ( fMakefile
,
2651 module
.name
.c_str (),
2652 objectsMacro
.c_str () );
2656 MingwIsoModuleHandler::MingwIsoModuleHandler (
2657 const Module
& module_
)
2659 : MingwModuleHandler ( module_
)
2664 MingwIsoModuleHandler::Process ()
2666 GenerateIsoModuleTarget ();
2670 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2671 const string
& bootcdDirectory
)
2673 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2675 const Module
& m
= *module
.project
.modules
[i
];
2678 if ( m
.bootstrap
!= NULL
)
2680 string sourceFilename
= PassThruCacheDirectory (
2681 NormalizeFilename ( m
.GetPath () ),
2682 backend
->outputDirectory
);
2683 string
targetFilenameNoFixup ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
);
2684 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2685 NormalizeFilename ( targetFilenameNoFixup
),
2686 backend
->outputDirectory
);
2687 fprintf ( fMakefile
,
2689 fprintf ( fMakefile
,
2690 "\t${cp} %s %s 1>$(NUL)\n",
2691 sourceFilename
.c_str (),
2692 targetFilename
.c_str () );
2698 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2699 const string
& bootcdDirectory
)
2701 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2703 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2704 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2705 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2706 NormalizeFilename ( targetFilenameNoFixup
),
2707 backend
->outputDirectory
);
2708 fprintf ( fMakefile
,
2710 fprintf ( fMakefile
,
2711 "\t${cp} %s %s 1>$(NUL)\n",
2712 cdfile
.GetPath ().c_str (),
2713 targetFilename
.c_str () );
2718 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
2721 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2723 const Module
& m
= *module
.project
.modules
[i
];
2726 if ( m
.bootstrap
!= NULL
)
2728 string
targetDirectory ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
);
2729 if ( directories
.size () > 0 )
2731 directories
+= PassThruCacheDirectory (
2732 NormalizeFilename ( targetDirectory
),
2733 backend
->outputDirectory
);
2740 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
2743 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2745 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2746 string
targetDirectory ( bootcdDirectory
+ SSEP
+ cdfile
.base
);
2747 if ( directories
.size () > 0 )
2749 directories
+= PassThruCacheDirectory (
2750 NormalizeFilename ( targetDirectory
),
2751 backend
->outputDirectory
);
2757 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
2759 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
2760 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
2765 MingwIsoModuleHandler::GetBootstrapCdFiles (
2766 vector
<string
>& out
) const
2768 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2770 const Module
& m
= *module
.project
.modules
[i
];
2773 if ( m
.bootstrap
!= NULL
)
2775 string filename
= PassThruCacheDirectory (
2776 NormalizeFilename ( m
.GetPath () ),
2777 backend
->outputDirectory
);
2778 out
.push_back ( filename
);
2784 MingwIsoModuleHandler::GetNonModuleCdFiles (
2785 vector
<string
>& out
) const
2787 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2789 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2790 out
.push_back ( cdfile
.GetPath () );
2795 MingwIsoModuleHandler::GetCdFiles (
2796 vector
<string
>& out
) const
2798 GetBootstrapCdFiles ( out
);
2799 GetNonModuleCdFiles ( out
);
2803 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2805 string bootcdDirectory
= "cd";
2806 string bootcd
= PassThruCacheDirectory (
2807 NormalizeFilename ( bootcdDirectory
+ SSEP
),
2808 backend
->outputDirectory
);
2809 string isoboot
= PassThruCacheDirectory (
2810 NormalizeFilename ( "boot" SSEP
"freeldr" SSEP
"bootsect" SSEP
"isoboot.o" ),
2811 backend
->outputDirectory
);
2812 string bootcdReactosNoFixup
= bootcdDirectory
+ SSEP
"reactos";
2813 string bootcdReactos
= PassThruCacheDirectory (
2814 NormalizeFilename ( bootcdReactosNoFixup
+ SSEP
),
2815 backend
->outputDirectory
);
2816 CLEAN_FILE ( bootcdReactos
);
2817 string reactosInf
= PassThruCacheDirectory (
2818 NormalizeFilename ( bootcdReactosNoFixup
+ SSEP
"reactos.inf" ),
2819 backend
->outputDirectory
);
2820 string reactosDff
= NormalizeFilename ( "bootdata" SSEP
"packages" SSEP
"reactos.dff" );
2821 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
2822 vector
<string
> vCdFiles
;
2823 GetCdFiles ( vCdFiles
);
2824 string cdFiles
= v2s ( vCdFiles
, 5 );
2826 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2827 module
.name
.c_str ());
2828 fprintf ( fMakefile
,
2829 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2830 module
.name
.c_str (),
2832 bootcdReactos
.c_str (),
2833 cdDirectories
.c_str (),
2835 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2836 fprintf ( fMakefile
,
2837 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
2838 reactosDff
.c_str (),
2839 bootcdReactos
.c_str () );
2840 fprintf ( fMakefile
,
2841 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2842 reactosDff
.c_str (),
2843 reactosInf
.c_str (),
2844 bootcdReactos
.c_str ());
2845 fprintf ( fMakefile
,
2846 "\t-@${rm} %s 2>$(NUL)\n",
2847 reactosInf
.c_str () );
2848 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
2849 OutputCdfileCopyCommands ( bootcdDirectory
);
2850 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2851 fprintf ( fMakefile
,
2852 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2855 fprintf ( fMakefile
,
2860 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
2861 const Module
& module_
)
2863 : MingwModuleHandler ( module_
)
2868 MingwLiveIsoModuleHandler::Process ()
2870 GenerateLiveIsoModuleTarget ();
2874 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
2876 string normalizedDirectory
= MingwModuleHandler::PassThruCacheDirectory (
2877 NormalizeFilename ( directory
) + SSEP
,
2878 backend
->outputDirectory
);
2882 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string
& sourceFilename
,
2883 const string
& targetFilename
,
2884 const string
& targetDirectory
)
2886 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2887 NormalizeFilename ( targetDirectory
+ SSEP
+ targetFilename
),
2888 backend
->outputDirectory
);
2889 fprintf ( fMakefile
,
2891 fprintf ( fMakefile
,
2892 "\t${cp} %s %s 1>$(NUL)\n",
2893 sourceFilename
.c_str (),
2894 normalizedTargetFilename
.c_str () );
2898 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
2899 string
& reactosDirectory
)
2901 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2903 const Module
& m
= *module
.project
.modules
[i
];
2906 if ( m
.installName
.length () > 0 )
2908 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
2909 string sourceFilename
= MingwModuleHandler::PassThruCacheDirectory (
2910 NormalizeFilename ( aliasedModule
.GetPath () ),
2911 backend
->outputDirectory
);
2912 OutputCopyCommand ( sourceFilename
,
2914 livecdDirectory
+ SSEP
+ reactosDirectory
+ SSEP
+ m
.installBase
);
2920 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
2921 string
& reactosDirectory
)
2923 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
2925 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
2926 OutputCopyCommand ( installfile
.GetPath (),
2927 installfile
.newname
,
2928 livecdDirectory
+ SSEP
+ reactosDirectory
+ SSEP
+ installfile
.base
);
2933 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
2935 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" );
2936 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" SSEP
"All Users") ;
2937 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" SSEP
"All Users" SSEP
"Desktop" );
2938 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" SSEP
"Default User" );
2939 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" SSEP
"Default User" SSEP
"Desktop" );
2940 CreateDirectory ( livecdDirectory
+ SSEP
"Profiles" SSEP
"Default User" SSEP
"My Documents" );
2942 string livecdIni
= "bootdata" SSEP
"livecd.ini";
2943 OutputCopyCommand ( livecdIni
,
2949 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
2951 string freeldr
= PassThruCacheDirectory (
2952 NormalizeFilename ( "boot" SSEP
"freeldr" SSEP
"freeldr" SSEP
"freeldr.sys" ),
2953 backend
->outputDirectory
);
2954 CreateDirectory ( livecdDirectory
+ SSEP
"loader" );
2955 OutputCopyCommand ( freeldr
,
2957 livecdDirectory
+ SSEP
+ "loader" );
2961 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
2963 string reactosSystem32ConfigDirectory
= NormalizeFilename (
2964 MingwModuleHandler::PassThruCacheDirectory (
2965 livecdDirectory
+ SSEP
"reactos" SSEP
"system32" SSEP
"config" SSEP
,
2966 backend
->outputDirectory
) );
2967 fprintf ( fMakefile
,
2968 "\t$(ECHO_MKHIVE)\n" );
2969 fprintf ( fMakefile
,
2970 "\t$(MKHIVE_TARGET) bootdata %s bootdata" SSEP
"livecd.inf bootdata" SSEP
"hiveinst.inf\n",
2971 reactosSystem32ConfigDirectory
.c_str () );
2975 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
2977 string livecdDirectory
= "livecd";
2978 string livecd
= PassThruCacheDirectory (
2979 NormalizeFilename ( livecdDirectory
+ SSEP
),
2980 backend
->outputDirectory
);
2981 string isoboot
= PassThruCacheDirectory (
2982 NormalizeFilename ( "boot" SSEP
"freeldr" SSEP
"bootsect" SSEP
"isoboot.o" ),
2983 backend
->outputDirectory
);
2984 string reactosDirectory
= "reactos";
2985 string livecdReactosNoFixup
= livecdDirectory
+ SSEP
+ reactosDirectory
;
2986 string livecdReactos
= NormalizeFilename ( PassThruCacheDirectory (
2987 NormalizeFilename ( livecdReactosNoFixup
+ SSEP
),
2988 backend
->outputDirectory
) );
2989 CLEAN_FILE ( livecdReactos
);
2991 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2992 module
.name
.c_str ());
2993 fprintf ( fMakefile
,
2994 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
2995 module
.name
.c_str (),
2997 livecdReactos
.c_str () );
2998 OutputModuleCopyCommands ( livecdDirectory
,
3000 OutputNonModuleCopyCommands ( livecdDirectory
,
3002 OutputProfilesDirectoryCommands ( livecdDirectory
);
3003 OutputLoaderCommands ( livecdDirectory
);
3004 OutputRegistryCommands ( livecdDirectory
);
3005 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3006 fprintf ( fMakefile
,
3007 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS ReactOS-LiveCD.iso\n",
3010 fprintf ( fMakefile
,
3015 MingwTestModuleHandler::MingwTestModuleHandler (
3016 const Module
& module_
)
3018 : MingwModuleHandler ( module_
)
3023 MingwTestModuleHandler::Process ()
3025 GenerateTestModuleTarget ();
3029 MingwTestModuleHandler::GetModuleSpecificSourceFiles ( vector
<File
*>& sourceFiles
)
3031 string basePath
= "$(INTERMEDIATE)" SSEP
+ module
.GetBasePath ();
3032 sourceFiles
.push_back ( new File ( basePath
+ SSEP
"_hooks.c", false, "", false ) );
3033 sourceFiles
.push_back ( new File ( basePath
+ SSEP
"_stubs.S", false, "", false ) );
3034 sourceFiles
.push_back ( new File ( basePath
+ SSEP
"_startup.c", false, "", false ) );
3038 MingwTestModuleHandler::GenerateTestModuleTarget ()
3040 string
targetMacro ( GetTargetMacro ( module
) );
3041 string workingDirectory
= GetWorkingDirectory ( );
3042 string objectsMacro
= GetObjectsMacro ( module
);
3043 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3044 string libsMacro
= GetLibsMacro ();
3046 GenerateImportLibraryTargetIfNeeded ();
3048 if ( module
.non_if_data
.files
.size () > 0 )
3052 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3055 if ( module
.cplusplus
)
3060 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3061 module
.entrypoint
.c_str (),
3062 module
.baseaddress
.c_str () );
3063 GenerateLinkerCommand ( dependencies
,
3072 GeneratePhonyTarget();
3077 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3078 const Module
& module_
)
3080 : MingwModuleHandler ( module_
)
3085 MingwRpcServerModuleHandler::Process ()
3091 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3092 const Module
& module_
)
3094 : MingwModuleHandler ( module_
)
3099 MingwRpcClientModuleHandler::Process ()
3105 MingwAliasModuleHandler::MingwAliasModuleHandler (
3106 const Module
& module_
)
3108 : MingwModuleHandler ( module_
)
3113 MingwAliasModuleHandler::Process ()