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 definitionFilename
= GetDefinitionFilename ();
1422 string linkerScriptArgument
;
1423 if ( module
.linkerScript
!= NULL
)
1424 linkerScriptArgument
= ssprintf ( "-Wl,-T,%s", module
.linkerScript
->directory
.c_str () );
1426 linkerScriptArgument
= "";
1428 fprintf ( fMakefile
,
1429 "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n",
1431 definitionFilename
.c_str (),
1432 dependencies
.c_str (),
1433 target_folder
.c_str () );
1434 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1435 string
targetName ( module
.GetTargetName () );
1437 if ( module
.IsDLL () )
1439 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1440 CLEAN_FILE ( temp_exp
);
1442 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1443 fprintf ( fMakefile
,
1444 "\t${dlltool} --dllname %s --def %s --output-exp %s %s\n",
1445 targetName
.c_str (),
1446 definitionFilename
.c_str (),
1450 fprintf ( fMakefile
,
1451 "\t%s %s %s %s -o %s %s %s %s\n",
1453 linkerParameters
.c_str (),
1454 linkerScriptArgument
.c_str (),
1457 objectsMacro
.c_str (),
1459 GetLinkerMacro ().c_str () );
1461 fprintf ( fMakefile
,
1462 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1464 pefixupParameters
.c_str() );
1466 fprintf ( fMakefile
,
1467 "\t-@${rm} %s 2>$(NUL)\n",
1468 temp_exp
.c_str () );
1472 fprintf ( fMakefile
,
1473 "\t%s %s %s -o %s %s %s %s\n",
1475 linkerParameters
.c_str (),
1476 linkerScriptArgument
.c_str (),
1478 objectsMacro
.c_str (),
1480 GetLinkerMacro ().c_str () );
1482 if ( pefixupParameters
.length() != 0 )
1484 fprintf ( fMakefile
,
1485 "\t$(Q)$(PEFIXUP_TARGET) %s -exports %s\n",
1487 pefixupParameters
.c_str() );
1491 GenerateBuildMapCode ();
1492 GenerateBuildNonSymbolStrippedCode ();
1493 GenerateRunRsymCode ();
1494 GenerateCleanObjectsAsYouGoCode ();
1498 MingwModuleHandler::GeneratePhonyTarget() const
1500 string
targetMacro ( GetTargetMacro ( module
) );
1501 fprintf ( fMakefile
,
1503 targetMacro
.c_str ());
1504 fprintf ( fMakefile
, "%s: | %s\n",
1505 targetMacro
.c_str (),
1506 GetDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1510 MingwModuleHandler::GenerateObjectFileTargets (
1511 const IfableData
& data
,
1514 const string
& cflagsMacro
,
1515 const string
& nasmflagsMacro
,
1516 const string
& windresflagsMacro
,
1517 const string
& widlflagsMacro
)
1521 const vector
<File
*>& files
= data
.files
;
1522 for ( i
= 0; i
< files
.size (); i
++ )
1524 GenerateCommands ( *files
[i
],
1531 fprintf ( fMakefile
,
1535 const vector
<If
*>& ifs
= data
.ifs
;
1536 for ( i
= 0; i
< ifs
.size(); i
++ )
1538 GenerateObjectFileTargets ( ifs
[i
]->data
,
1547 vector
<File
*> sourceFiles
;
1548 GetModuleSpecificSourceFiles ( sourceFiles
);
1549 for ( i
= 0; i
< sourceFiles
.size (); i
++ )
1551 GenerateCommands ( *sourceFiles
[i
],
1559 CleanupFileVector ( sourceFiles
);
1563 MingwModuleHandler::GenerateObjectFileTargets (
1566 const string
& cflagsMacro
,
1567 const string
& nasmflagsMacro
,
1568 const string
& windresflagsMacro
,
1569 const string
& widlflagsMacro
)
1571 if ( module
.pch
&& use_pch
)
1573 const string
& baseHeaderFilename
= module
.pch
->file
.name
;
1574 const string
& pchFilename
= GetPrecompiledHeaderFilename ();
1575 CLEAN_FILE(pchFilename
);
1576 string dependencies
= baseHeaderFilename
;
1577 /* WIDL generated headers may be used */
1578 vector
<string
> rpcDependencies
;
1579 GetRpcHeaderDependencies ( rpcDependencies
);
1580 dependencies
+= " " + v2s ( rpcDependencies
, 5 );
1581 fprintf ( fMakefile
,
1583 pchFilename
.c_str(),
1584 dependencies
.c_str() );
1585 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1586 fprintf ( fMakefile
,
1587 "\t%s -o %s %s -g %s\n\n",
1588 module
.cplusplus
? cppc
.c_str() : cc
.c_str(),
1589 pchFilename
.c_str(),
1590 cflagsMacro
.c_str(),
1591 baseHeaderFilename
.c_str() );
1594 GenerateObjectFileTargets ( module
.non_if_data
,
1601 fprintf ( fMakefile
, "\n" );
1605 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1606 const string
& objs_macro
) const
1608 string
archiveFilename ( GetModuleArchiveFilename () );
1610 fprintf ( fMakefile
,
1612 archiveFilename
.c_str (),
1613 objs_macro
.c_str (),
1614 GetDirectory(archiveFilename
).c_str() );
1616 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1618 fprintf ( fMakefile
,
1621 objs_macro
.c_str ());
1623 GenerateCleanObjectsAsYouGoCode ();
1625 fprintf ( fMakefile
, "\n" );
1627 return archiveFilename
;
1631 MingwModuleHandler::GetCFlagsMacro () const
1633 return ssprintf ( "$(%s_CFLAGS)",
1634 module
.name
.c_str () );
1638 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1640 return ssprintf ( "$(%s_OBJS)",
1641 module
.name
.c_str () );
1645 MingwModuleHandler::GetLinkingDependenciesMacro () const
1647 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1651 MingwModuleHandler::GetLibsMacro () const
1653 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1657 MingwModuleHandler::GetLinkerMacro () const
1659 return ssprintf ( "$(%s_LFLAGS)",
1660 module
.name
.c_str () );
1664 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1666 if ( ReferenceObjects ( module
) )
1667 return GetObjectsMacro ( module
);
1669 return GetTargetFilename ( module
, NULL
);
1673 MingwModuleHandler::GenerateObjectMacro ()
1675 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1677 GenerateObjectMacros (
1680 &module
.linkerFlags
);
1682 // future references to the macro will be to get its values
1683 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1687 MingwModuleHandler::GenerateTargetMacro ()
1689 fprintf ( fMakefile
,
1691 GetTargetMacro ( module
, false ).c_str (),
1692 GetModuleTargets ( module
).c_str () );
1696 MingwModuleHandler::GetRpcHeaderDependencies (
1697 vector
<string
>& dependencies
) const
1699 for ( size_t i
= 0; i
< module
.non_if_data
.libraries
.size (); i
++ )
1701 Library
& library
= *module
.non_if_data
.libraries
[i
];
1702 if ( library
.importedModule
->type
== RpcServer
||
1703 library
.importedModule
->type
== RpcClient
)
1705 for ( size_t j
= 0; j
< library
.importedModule
->non_if_data
.files
.size (); j
++ )
1707 File
& file
= *library
.importedModule
->non_if_data
.files
[j
];
1708 string extension
= GetExtension ( file
.name
);
1709 if ( extension
== ".idl" || extension
== ".IDL" )
1711 string basename
= GetBasename ( file
.name
);
1712 if ( library
.importedModule
->type
== RpcServer
)
1713 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
1714 if ( library
.importedModule
->type
== RpcClient
)
1715 dependencies
.push_back ( GetRpcClientHeaderFilename ( basename
) );
1723 MingwModuleHandler::GenerateOtherMacros ()
1725 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1726 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1727 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1728 widlflagsMacro
= ssprintf ("%s_WIDLFLAGS", module
.name
.c_str ());
1729 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1730 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1731 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1736 &module
.linkerFlags
);
1739 if ( module
.importLibrary
)
1741 const vector
<File
*>& files
= module
.non_if_data
.files
;
1742 for ( size_t i
= 0; i
< files
.size (); i
++ )
1744 File
& file
= *files
[i
];
1745 string extension
= GetExtension ( file
.name
);
1746 if ( extension
== ".spec" || extension
== ".SPEC" )
1747 GetSpecObjectDependencies ( s
, file
.name
);
1750 if ( s
.size () > 0 )
1755 linkDepsMacro
.c_str() );
1756 for ( size_t i
= 0; i
< s
.size(); i
++ )
1757 fprintf ( fMakefile
,
1760 fprintf ( fMakefile
, "\n" );
1763 string globalCflags
= "-g";
1764 if ( backend
->usePipe
)
1765 globalCflags
+= " -pipe";
1766 if ( !module
.allowWarnings
)
1767 globalCflags
+= " -Werror";
1771 "%s += $(PROJECT_CFLAGS) %s\n",
1772 cflagsMacro
.c_str (),
1773 globalCflags
.c_str () );
1777 "%s += $(PROJECT_RCFLAGS)\n",
1778 windresflagsMacro
.c_str () );
1782 "%s += $(PROJECT_WIDLFLAGS)\n",
1783 widlflagsMacro
.c_str () );
1787 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1788 module
.name
.c_str () );
1793 linkDepsMacro
.c_str (),
1794 libsMacro
.c_str () );
1796 string cflags
= TypeSpecificCFlags();
1797 if ( cflags
.size() > 0 )
1799 fprintf ( fMakefile
,
1801 cflagsMacro
.c_str (),
1805 string nasmflags
= TypeSpecificNasmFlags();
1806 if ( nasmflags
.size () > 0 )
1808 fprintf ( fMakefile
,
1810 nasmflagsMacro
.c_str (),
1811 nasmflags
.c_str () );
1814 string linkerflags
= TypeSpecificLinkerFlags();
1815 if ( linkerflags
.size() > 0 )
1817 fprintf ( fMakefile
,
1819 linkerflagsMacro
.c_str (),
1820 linkerflags
.c_str () );
1823 fprintf ( fMakefile
, "\n\n" );
1825 // future references to the macros will be to get their values
1826 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1827 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1828 widlflagsMacro
= ssprintf ("$(%s)", widlflagsMacro
.c_str ());
1832 MingwModuleHandler::GenerateRules ()
1834 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1835 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1836 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1838 if ( module
.name
!= "zlib" ) /* Avoid make warning */
1840 string proxyMakefile
= PassThruCacheDirectory (
1841 NormalizeFilename ( module
.GetBasePath () + sSep
+ "makefile" ),
1842 backend
->outputDirectory
);
1843 CLEAN_FILE ( proxyMakefile
);
1846 string targetMacro
= GetTargetMacro ( module
);
1847 CLEAN_FILE ( targetMacro
);
1849 // generate phony target for module name
1850 fprintf ( fMakefile
, ".PHONY: %s\n",
1851 module
.name
.c_str () );
1852 string dependencies
= GetTargetMacro ( module
);
1853 if ( module
.type
== Test
)
1854 dependencies
+= " $(REGTESTS_RUN_TARGET)";
1855 fprintf ( fMakefile
, "%s: %s\n\n",
1856 module
.name
.c_str (),
1857 dependencies
.c_str () );
1858 if ( module
.type
== Test
)
1860 fprintf ( fMakefile
,
1862 targetMacro
.c_str ());
1865 if ( !ReferenceObjects ( module
) )
1867 string
ar_target ( GenerateArchiveTarget ( ar
, objectsMacro
) );
1868 if ( targetMacro
!= ar_target
)
1869 CLEAN_FILE ( ar_target
);
1872 GenerateObjectFileTargets ( cc
,
1881 MingwModuleHandler::GetInvocationDependencies (
1882 const Module
& module
,
1883 string_list
& dependencies
)
1885 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1887 Invoke
& invoke
= *module
.invocations
[i
];
1888 if ( invoke
.invokeModule
== &module
)
1889 /* Protect against circular dependencies */
1891 invoke
.GetTargets ( dependencies
);
1896 MingwModuleHandler::GenerateInvocations () const
1898 if ( module
.invocations
.size () == 0 )
1901 size_t iend
= module
.invocations
.size ();
1902 for ( size_t i
= 0; i
< iend
; i
++ )
1904 const Invoke
& invoke
= *module
.invocations
[i
];
1906 if ( invoke
.invokeModule
->type
!= BuildTool
)
1908 throw InvalidBuildFileException ( module
.node
.location
,
1909 "Only modules of type buildtool can be invoked." );
1912 string invokeTarget
= module
.GetInvocationTarget ( i
);
1913 string_list invoke_targets
;
1914 assert ( invoke_targets
.size() );
1915 invoke
.GetTargets ( invoke_targets
);
1916 fprintf ( fMakefile
,
1918 invokeTarget
.c_str () );
1919 fprintf ( fMakefile
,
1921 invokeTarget
.c_str () );
1922 size_t j
, jend
= invoke_targets
.size();
1923 for ( j
= 0; j
< jend
; j
++ )
1925 fprintf ( fMakefile
,
1927 invoke_targets
[i
].c_str () );
1929 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
1930 for ( j
= 1; j
< jend
; j
++ )
1931 fprintf ( fMakefile
,
1933 invoke_targets
[i
].c_str () );
1934 fprintf ( fMakefile
,
1936 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1937 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1938 fprintf ( fMakefile
,
1940 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1941 invoke
.GetParameters ().c_str () );
1946 MingwModuleHandler::GetPreconditionDependenciesName () const
1948 return module
.name
+ "_precondition";
1952 MingwModuleHandler::GetDefaultDependencies (
1953 string_list
& dependencies
) const
1955 /* Avoid circular dependency */
1956 if ( module
.type
!= BuildTool
1957 && module
.name
!= "zlib"
1958 && module
.name
!= "hostzlib" )
1960 dependencies
.push_back ( "$(INIT)" );
1964 MingwModuleHandler::GeneratePreconditionDependencies ()
1966 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
1967 string_list sourceFilenames
;
1968 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
1969 string_list dependencies
;
1970 GetDefaultDependencies ( dependencies
);
1971 GetModuleDependencies ( dependencies
);
1973 GetInvocationDependencies ( module
, dependencies
);
1975 if ( dependencies
.size() )
1977 fprintf ( fMakefile
,
1979 preconditionDependenciesName
.c_str () );
1980 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
1981 fprintf ( fMakefile
,
1983 dependencies
[i
].c_str () );
1984 fprintf ( fMakefile
, "\n\n" );
1987 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
1989 fprintf ( fMakefile
,
1991 sourceFilenames
[i
].c_str(),
1992 preconditionDependenciesName
.c_str ());
1994 fprintf ( fMakefile
, "\n" );
1998 MingwModuleHandler::IsWineModule () const
2000 if ( module
.importLibrary
== NULL
)
2003 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
2004 return ( index
!= string::npos
);
2008 MingwModuleHandler::GetDefinitionFilename () const
2010 if ( module
.importLibrary
!= NULL
)
2012 string defFilename
= module
.GetBasePath () + sSep
+ module
.importLibrary
->definition
;
2013 if ( IsWineModule () )
2014 return PassThruCacheDirectory ( NormalizeFilename ( defFilename
),
2015 backend
->intermediateDirectory
);
2020 return "tools" + sSep
+ "rbuild" + sSep
+ "empty.def";
2024 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
2026 if ( module
.importLibrary
!= NULL
)
2028 string
library_target (
2029 GetImportLibraryFilename ( module
, &clean_files
) );
2030 string defFilename
= GetDefinitionFilename ();
2033 GetDefinitionDependencies ( deps
);
2035 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
2037 fprintf ( fMakefile
, "%s: %s",
2038 library_target
.c_str (),
2039 defFilename
.c_str () );
2041 size_t i
, iend
= deps
.size();
2042 for ( i
= 0; i
< iend
; i
++ )
2043 fprintf ( fMakefile
, " %s",
2046 fprintf ( fMakefile
, " | %s\n",
2047 GetDirectory ( GetImportLibraryFilename ( module
, NULL
) ).c_str () );
2049 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
2051 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
2052 fprintf ( fMakefile
,
2053 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
2054 module
.GetTargetName ().c_str (),
2055 defFilename
.c_str (),
2056 library_target
.c_str (),
2062 MingwModuleHandler::GetSpecObjectDependencies (
2063 string_list
& dependencies
,
2064 const string
& filename
) const
2066 string basename
= GetBasename ( filename
);
2067 string defDependency
= PassThruCacheDirectory (
2068 NormalizeFilename ( basename
+ ".spec.def" ),
2069 backend
->intermediateDirectory
);
2070 dependencies
.push_back ( defDependency
);
2071 string stubsDependency
= PassThruCacheDirectory (
2072 NormalizeFilename ( basename
+ ".stubs.c" ),
2073 backend
->intermediateDirectory
);
2074 dependencies
.push_back ( stubsDependency
);
2078 MingwModuleHandler::GetWidlObjectDependencies (
2079 string_list
& dependencies
,
2080 const string
& filename
) const
2082 string basename
= GetBasename ( filename
);
2083 string serverSourceDependency
= PassThruCacheDirectory (
2084 NormalizeFilename ( basename
+ "_s.c" ),
2085 backend
->intermediateDirectory
);
2086 dependencies
.push_back ( serverSourceDependency
);
2087 dependencies
.push_back ( GetRpcServerHeaderFilename ( basename
) );
2091 MingwModuleHandler::GetDefinitionDependencies (
2092 string_list
& dependencies
) const
2094 string dkNkmLibNoFixup
= "dk/nkm/lib";
2095 const vector
<File
*>& files
= module
.non_if_data
.files
;
2096 for ( size_t i
= 0; i
< files
.size (); i
++ )
2098 File
& file
= *files
[i
];
2099 string extension
= GetExtension ( file
.name
);
2100 if ( extension
== ".spec" || extension
== ".SPEC" )
2102 GetSpecObjectDependencies ( dependencies
, file
.name
);
2104 if ( extension
== ".idl" || extension
== ".IDL" )
2106 GetWidlObjectDependencies ( dependencies
, file
.name
);
2112 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
2113 : MingwModuleHandler ( module_
)
2118 MingwBuildToolModuleHandler::Process ()
2120 GenerateBuildToolModuleTarget ();
2124 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
2126 string
targetMacro ( GetTargetMacro (module
) );
2127 string objectsMacro
= GetObjectsMacro ( module
);
2128 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2129 string libsMacro
= GetLibsMacro ();
2134 if ( module
.cplusplus
)
2135 linker
= "${host_gpp}";
2137 linker
= "${host_gcc}";
2139 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2140 targetMacro
.c_str (),
2141 objectsMacro
.c_str (),
2142 linkDepsMacro
.c_str (),
2143 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2144 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2145 fprintf ( fMakefile
,
2146 "\t%s %s -o $@ %s %s\n\n",
2148 GetLinkerMacro ().c_str (),
2149 objectsMacro
.c_str (),
2150 libsMacro
.c_str () );
2154 MingwKernelModuleHandler::MingwKernelModuleHandler (
2155 const Module
& module_
)
2157 : MingwModuleHandler ( module_
)
2162 MingwKernelModuleHandler::Process ()
2164 GenerateKernelModuleTarget ();
2168 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
2170 string
targetMacro ( GetTargetMacro ( module
) );
2171 string workingDirectory
= GetWorkingDirectory ( );
2172 string objectsMacro
= GetObjectsMacro ( module
);
2173 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2174 string libsMacro
= GetLibsMacro ();
2176 GenerateImportLibraryTargetIfNeeded ();
2178 if ( module
.non_if_data
.files
.size () > 0 )
2182 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2184 string linkerParameters
= ssprintf ( "-Wl,-T,%s%cntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2185 module
.GetBasePath ().c_str (),
2187 module
.entrypoint
.c_str (),
2188 module
.baseaddress
.c_str () );
2189 GenerateLinkerCommand ( dependencies
,
2198 GeneratePhonyTarget();
2203 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2204 const Module
& module_
)
2206 : MingwModuleHandler ( module_
)
2211 MingwStaticLibraryModuleHandler::Process ()
2213 GenerateStaticLibraryModuleTarget ();
2217 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2223 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2224 const Module
& module_
)
2226 : MingwModuleHandler ( module_
)
2231 MingwObjectLibraryModuleHandler::Process ()
2233 GenerateObjectLibraryModuleTarget ();
2237 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2243 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2244 const Module
& module_
)
2246 : MingwModuleHandler ( module_
)
2251 MingwKernelModeDLLModuleHandler::Process ()
2253 GenerateKernelModeDLLModuleTarget ();
2257 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2259 string
targetMacro ( GetTargetMacro ( module
) );
2260 string workingDirectory
= GetWorkingDirectory ( );
2261 string objectsMacro
= GetObjectsMacro ( module
);
2262 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2263 string libsMacro
= GetLibsMacro ();
2265 GenerateImportLibraryTargetIfNeeded ();
2267 if ( module
.non_if_data
.files
.size () > 0 )
2271 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2273 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2274 module
.entrypoint
.c_str (),
2275 module
.baseaddress
.c_str () );
2276 GenerateLinkerCommand ( dependencies
,
2285 GeneratePhonyTarget();
2290 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2291 const Module
& module_
)
2293 : MingwModuleHandler ( module_
)
2298 MingwKernelModeDriverModuleHandler::Process ()
2300 GenerateKernelModeDriverModuleTarget ();
2305 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2307 string
targetMacro ( GetTargetMacro (module
) );
2308 string workingDirectory
= GetWorkingDirectory ();
2309 string objectsMacro
= GetObjectsMacro ( module
);
2310 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2311 string libsMacro
= GetLibsMacro ();
2313 GenerateImportLibraryTargetIfNeeded ();
2315 if ( module
.non_if_data
.files
.size () > 0 )
2319 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2321 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -shared",
2322 module
.entrypoint
.c_str (),
2323 module
.baseaddress
.c_str () );
2324 GenerateLinkerCommand ( dependencies
,
2333 GeneratePhonyTarget();
2338 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2339 const Module
& module_
)
2341 : MingwModuleHandler ( module_
)
2346 MingwNativeDLLModuleHandler::Process ()
2348 GenerateNativeDLLModuleTarget ();
2352 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2354 string
targetMacro ( GetTargetMacro (module
) );
2355 string workingDirectory
= GetWorkingDirectory ( );
2356 string objectsMacro
= GetObjectsMacro ( module
);
2357 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2358 string libsMacro
= GetLibsMacro ();
2360 GenerateImportLibraryTargetIfNeeded ();
2362 if ( module
.non_if_data
.files
.size () > 0 )
2366 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2368 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -shared",
2369 module
.entrypoint
.c_str (),
2370 module
.baseaddress
.c_str () );
2371 GenerateLinkerCommand ( dependencies
,
2380 GeneratePhonyTarget();
2385 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2386 const Module
& module_
)
2388 : MingwModuleHandler ( module_
)
2393 MingwNativeCUIModuleHandler::Process ()
2395 GenerateNativeCUIModuleTarget ();
2399 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2401 string
targetMacro ( GetTargetMacro (module
) );
2402 string workingDirectory
= GetWorkingDirectory ( );
2403 string objectsMacro
= GetObjectsMacro ( module
);
2404 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2405 string libsMacro
= GetLibsMacro ();
2407 GenerateImportLibraryTargetIfNeeded ();
2409 if ( module
.non_if_data
.files
.size () > 0 )
2413 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2415 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2416 module
.entrypoint
.c_str (),
2417 module
.baseaddress
.c_str () );
2418 GenerateLinkerCommand ( dependencies
,
2427 GeneratePhonyTarget();
2432 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2433 const Module
& module_
)
2435 : MingwModuleHandler ( module_
)
2440 MingwWin32DLLModuleHandler::Process ()
2442 GenerateWin32DLLModuleTarget ();
2446 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2448 string
targetMacro ( GetTargetMacro (module
) );
2449 string workingDirectory
= GetWorkingDirectory ( );
2450 string objectsMacro
= GetObjectsMacro ( module
);
2451 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2452 string libsMacro
= GetLibsMacro ();
2454 GenerateImportLibraryTargetIfNeeded ();
2456 if ( module
.non_if_data
.files
.size () > 0 )
2460 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2463 if ( module
.cplusplus
)
2468 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -shared",
2469 module
.entrypoint
.c_str (),
2470 module
.baseaddress
.c_str () );
2471 GenerateLinkerCommand ( dependencies
,
2480 GeneratePhonyTarget();
2485 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2486 const Module
& module_
)
2488 : MingwModuleHandler ( module_
)
2493 MingwWin32CUIModuleHandler::Process ()
2495 GenerateWin32CUIModuleTarget ();
2499 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2501 string
targetMacro ( GetTargetMacro (module
) );
2502 string workingDirectory
= GetWorkingDirectory ( );
2503 string objectsMacro
= GetObjectsMacro ( module
);
2504 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2505 string libsMacro
= GetLibsMacro ();
2507 GenerateImportLibraryTargetIfNeeded ();
2509 if ( module
.non_if_data
.files
.size () > 0 )
2513 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2516 if ( module
.cplusplus
)
2521 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2522 module
.entrypoint
.c_str (),
2523 module
.baseaddress
.c_str () );
2524 GenerateLinkerCommand ( dependencies
,
2533 GeneratePhonyTarget();
2538 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2539 const Module
& module_
)
2541 : MingwModuleHandler ( module_
)
2546 MingwWin32GUIModuleHandler::Process ()
2548 GenerateWin32GUIModuleTarget ();
2552 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2554 string
targetMacro ( GetTargetMacro (module
) );
2555 string workingDirectory
= GetWorkingDirectory ( );
2556 string objectsMacro
= GetObjectsMacro ( module
);
2557 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2558 string libsMacro
= GetLibsMacro ();
2560 GenerateImportLibraryTargetIfNeeded ();
2562 if ( module
.non_if_data
.files
.size () > 0 )
2566 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
2569 if ( module
.cplusplus
)
2574 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2575 module
.entrypoint
.c_str (),
2576 module
.baseaddress
.c_str () );
2577 GenerateLinkerCommand ( dependencies
,
2586 GeneratePhonyTarget();
2591 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2592 const Module
& module_
)
2594 : MingwModuleHandler ( module_
)
2599 MingwBootLoaderModuleHandler::Process ()
2601 GenerateBootLoaderModuleTarget ();
2605 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2607 string
targetName ( module
.GetTargetName () );
2608 string
targetMacro ( GetTargetMacro (module
) );
2609 string workingDirectory
= GetWorkingDirectory ();
2610 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2611 CLEAN_FILE ( junk_tmp
);
2612 string objectsMacro
= GetObjectsMacro ( module
);
2613 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2614 string libsMacro
= GetLibsMacro ();
2618 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2619 targetMacro
.c_str (),
2620 objectsMacro
.c_str (),
2621 linkDepsMacro
.c_str (),
2622 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2624 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2626 fprintf ( fMakefile
,
2627 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2628 GetLinkerMacro ().c_str (),
2630 objectsMacro
.c_str (),
2631 linkDepsMacro
.c_str () );
2632 fprintf ( fMakefile
,
2633 "\t${objcopy} -O binary %s $@\n",
2634 junk_tmp
.c_str () );
2635 fprintf ( fMakefile
,
2636 "\t-@${rm} %s 2>$(NUL)\n",
2637 junk_tmp
.c_str () );
2641 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2642 const Module
& module_
)
2644 : MingwModuleHandler ( module_
)
2649 MingwBootSectorModuleHandler::Process ()
2651 GenerateBootSectorModuleTarget ();
2655 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2657 string objectsMacro
= GetObjectsMacro ( module
);
2661 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2662 module
.name
.c_str ());
2663 fprintf ( fMakefile
,
2665 module
.name
.c_str (),
2666 objectsMacro
.c_str () );
2670 MingwIsoModuleHandler::MingwIsoModuleHandler (
2671 const Module
& module_
)
2673 : MingwModuleHandler ( module_
)
2678 MingwIsoModuleHandler::Process ()
2680 GenerateIsoModuleTarget ();
2684 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2685 const string
& bootcdDirectory
)
2687 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2689 const Module
& m
= *module
.project
.modules
[i
];
2692 if ( m
.bootstrap
!= NULL
)
2694 string sourceFilename
= PassThruCacheDirectory (
2695 NormalizeFilename ( m
.GetPath () ),
2696 backend
->outputDirectory
);
2697 string
targetFilenameNoFixup ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
+ sSep
+ m
.bootstrap
->nameoncd
);
2698 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2699 NormalizeFilename ( targetFilenameNoFixup
),
2700 backend
->outputDirectory
);
2701 fprintf ( fMakefile
,
2703 fprintf ( fMakefile
,
2704 "\t${cp} %s %s 1>$(NUL)\n",
2705 sourceFilename
.c_str (),
2706 targetFilename
.c_str () );
2712 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2713 const string
& bootcdDirectory
)
2715 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2717 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2718 string targetFilenameNoFixup
= bootcdDirectory
+ sSep
+ cdfile
.base
+ sSep
+ cdfile
.nameoncd
;
2719 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2720 NormalizeFilename ( targetFilenameNoFixup
),
2721 backend
->outputDirectory
);
2722 fprintf ( fMakefile
,
2724 fprintf ( fMakefile
,
2725 "\t${cp} %s %s 1>$(NUL)\n",
2726 cdfile
.GetPath ().c_str (),
2727 targetFilename
.c_str () );
2732 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
2735 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2737 const Module
& m
= *module
.project
.modules
[i
];
2740 if ( m
.bootstrap
!= NULL
)
2742 string
targetDirectory ( bootcdDirectory
+ sSep
+ m
.bootstrap
->base
);
2743 if ( directories
.size () > 0 )
2745 directories
+= PassThruCacheDirectory (
2746 NormalizeFilename ( targetDirectory
),
2747 backend
->outputDirectory
);
2754 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
2757 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2759 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2760 string
targetDirectory ( bootcdDirectory
+ sSep
+ cdfile
.base
);
2761 if ( directories
.size () > 0 )
2763 directories
+= PassThruCacheDirectory (
2764 NormalizeFilename ( targetDirectory
),
2765 backend
->outputDirectory
);
2771 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
2773 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
2774 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
2779 MingwIsoModuleHandler::GetBootstrapCdFiles (
2780 vector
<string
>& out
) const
2782 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2784 const Module
& m
= *module
.project
.modules
[i
];
2787 if ( m
.bootstrap
!= NULL
)
2789 string filename
= PassThruCacheDirectory (
2790 NormalizeFilename ( m
.GetPath () ),
2791 backend
->outputDirectory
);
2792 out
.push_back ( filename
);
2798 MingwIsoModuleHandler::GetNonModuleCdFiles (
2799 vector
<string
>& out
) const
2801 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2803 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2804 out
.push_back ( cdfile
.GetPath () );
2809 MingwIsoModuleHandler::GetCdFiles (
2810 vector
<string
>& out
) const
2812 GetBootstrapCdFiles ( out
);
2813 GetNonModuleCdFiles ( out
);
2817 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2819 string bootcdDirectory
= "cd";
2820 string bootcd
= PassThruCacheDirectory (
2821 NormalizeFilename ( bootcdDirectory
+ sSep
),
2822 backend
->outputDirectory
);
2823 string isoboot
= PassThruCacheDirectory (
2824 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ "isoboot.o" ),
2825 backend
->outputDirectory
);
2826 string bootcdReactosNoFixup
= bootcdDirectory
+ sSep
+ "reactos";
2827 string bootcdReactos
= PassThruCacheDirectory (
2828 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
),
2829 backend
->outputDirectory
);
2830 CLEAN_FILE ( bootcdReactos
);
2831 string reactosInf
= PassThruCacheDirectory (
2832 NormalizeFilename ( bootcdReactosNoFixup
+ sSep
+ "reactos.inf" ),
2833 backend
->outputDirectory
);
2834 string reactosDff
= NormalizeFilename ( "bootdata" + sSep
+ "packages" + sSep
+ "reactos.dff" );
2835 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
2836 vector
<string
> vCdFiles
;
2837 GetCdFiles ( vCdFiles
);
2838 string cdFiles
= v2s ( vCdFiles
, 5 );
2840 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2841 module
.name
.c_str ());
2842 fprintf ( fMakefile
,
2843 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2844 module
.name
.c_str (),
2846 bootcdReactos
.c_str (),
2847 cdDirectories
.c_str (),
2849 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2850 fprintf ( fMakefile
,
2851 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
2852 reactosDff
.c_str (),
2853 bootcdReactos
.c_str () );
2854 fprintf ( fMakefile
,
2855 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2856 reactosDff
.c_str (),
2857 reactosInf
.c_str (),
2858 bootcdReactos
.c_str ());
2859 fprintf ( fMakefile
,
2860 "\t-@${rm} %s 2>$(NUL)\n",
2861 reactosInf
.c_str () );
2862 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
2863 OutputCdfileCopyCommands ( bootcdDirectory
);
2864 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2865 fprintf ( fMakefile
,
2866 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2869 fprintf ( fMakefile
,
2874 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
2875 const Module
& module_
)
2877 : MingwModuleHandler ( module_
)
2882 MingwLiveIsoModuleHandler::Process ()
2884 GenerateLiveIsoModuleTarget ();
2888 MingwLiveIsoModuleHandler::CreateDirectory ( const string
& directory
)
2890 string normalizedDirectory
= MingwModuleHandler::PassThruCacheDirectory (
2891 NormalizeFilename ( directory
) + sSep
,
2892 backend
->outputDirectory
);
2896 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string
& sourceFilename
,
2897 const string
& targetFilename
,
2898 const string
& targetDirectory
)
2900 string normalizedTargetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2901 NormalizeFilename ( targetDirectory
+ sSep
+ targetFilename
),
2902 backend
->outputDirectory
);
2903 fprintf ( fMakefile
,
2905 fprintf ( fMakefile
,
2906 "\t${cp} %s %s 1>$(NUL)\n",
2907 sourceFilename
.c_str (),
2908 normalizedTargetFilename
.c_str () );
2912 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string
& livecdDirectory
,
2913 string
& reactosDirectory
)
2915 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2917 const Module
& m
= *module
.project
.modules
[i
];
2920 if ( m
.installName
.length () > 0 )
2922 const Module
& aliasedModule
= backend
->GetAliasedModuleOrModule ( m
);
2923 string sourceFilename
= MingwModuleHandler::PassThruCacheDirectory (
2924 NormalizeFilename ( aliasedModule
.GetPath () ),
2925 backend
->outputDirectory
);
2926 OutputCopyCommand ( sourceFilename
,
2928 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ m
.installBase
);
2934 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string
& livecdDirectory
,
2935 string
& reactosDirectory
)
2937 for ( size_t i
= 0; i
< module
.project
.installfiles
.size (); i
++ )
2939 const InstallFile
& installfile
= *module
.project
.installfiles
[i
];
2940 OutputCopyCommand ( installfile
.GetPath (),
2941 installfile
.newname
,
2942 livecdDirectory
+ sSep
+ reactosDirectory
+ sSep
+ installfile
.base
);
2947 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string
& livecdDirectory
)
2949 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" );
2950 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users") ;
2951 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "All Users" + sSep
+ "Desktop" );
2952 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" );
2953 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "Desktop" );
2954 CreateDirectory ( livecdDirectory
+ sSep
+ "Profiles" + sSep
+ "Default User" + sSep
+ "My Documents" );
2956 string livecdIni
= "bootdata" + sSep
+ "livecd.ini";
2957 OutputCopyCommand ( livecdIni
,
2963 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string
& livecdDirectory
)
2965 string freeldr
= PassThruCacheDirectory (
2966 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "freeldr" + sSep
+ "freeldr.sys" ),
2967 backend
->outputDirectory
);
2968 CreateDirectory ( livecdDirectory
+ sSep
+ "loader" );
2969 OutputCopyCommand ( freeldr
,
2971 livecdDirectory
+ sSep
+ "loader" );
2975 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string
& livecdDirectory
)
2977 string reactosSystem32ConfigDirectory
= NormalizeFilename (
2978 MingwModuleHandler::PassThruCacheDirectory (
2979 livecdDirectory
+ sSep
+ "reactos" + sSep
+ "system32" + sSep
+ "config" + sSep
,
2980 backend
->outputDirectory
) );
2981 fprintf ( fMakefile
,
2982 "\t$(ECHO_MKHIVE)\n" );
2983 fprintf ( fMakefile
,
2984 "\t$(MKHIVE_TARGET) bootdata %s bootdata%clivecd.inf bootdata%chiveinst.inf\n",
2985 reactosSystem32ConfigDirectory
.c_str (),
2991 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
2993 string livecdDirectory
= "livecd";
2994 string livecd
= PassThruCacheDirectory (
2995 NormalizeFilename ( livecdDirectory
+ sSep
),
2996 backend
->outputDirectory
);
2997 string isoboot
= PassThruCacheDirectory (
2998 NormalizeFilename ( "boot" + sSep
+ "freeldr" + sSep
+ "bootsect" + sSep
+ "isoboot.o" ),
2999 backend
->outputDirectory
);
3000 string reactosDirectory
= "reactos";
3001 string livecdReactosNoFixup
= livecdDirectory
+ sSep
+ reactosDirectory
;
3002 string livecdReactos
= NormalizeFilename ( PassThruCacheDirectory (
3003 NormalizeFilename ( livecdReactosNoFixup
+ sSep
),
3004 backend
->outputDirectory
) );
3005 CLEAN_FILE ( livecdReactos
);
3007 fprintf ( fMakefile
, ".PHONY: %s\n\n",
3008 module
.name
.c_str ());
3009 fprintf ( fMakefile
,
3010 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
3011 module
.name
.c_str (),
3013 livecdReactos
.c_str () );
3014 OutputModuleCopyCommands ( livecdDirectory
,
3016 OutputNonModuleCopyCommands ( livecdDirectory
,
3018 OutputProfilesDirectoryCommands ( livecdDirectory
);
3019 OutputLoaderCommands ( livecdDirectory
);
3020 OutputRegistryCommands ( livecdDirectory
);
3021 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
3022 fprintf ( fMakefile
,
3023 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS ReactOS-LiveCD.iso\n",
3026 fprintf ( fMakefile
,
3031 MingwTestModuleHandler::MingwTestModuleHandler (
3032 const Module
& module_
)
3034 : MingwModuleHandler ( module_
)
3039 MingwTestModuleHandler::Process ()
3041 GenerateTestModuleTarget ();
3045 MingwTestModuleHandler::GetModuleSpecificSourceFiles ( vector
<File
*>& sourceFiles
)
3047 string basePath
= "$(INTERMEDIATE)" + sSep
+ module
.GetBasePath ();
3048 sourceFiles
.push_back ( new File ( basePath
+ sSep
+ "_hooks.c", false, "", false ) );
3049 sourceFiles
.push_back ( new File ( basePath
+ sSep
+ "_stubs.S", false, "", false ) );
3050 sourceFiles
.push_back ( new File ( basePath
+ sSep
+ "_startup.c", false, "", false ) );
3054 MingwTestModuleHandler::GenerateTestModuleTarget ()
3056 string
targetMacro ( GetTargetMacro ( module
) );
3057 string workingDirectory
= GetWorkingDirectory ( );
3058 string objectsMacro
= GetObjectsMacro ( module
);
3059 string linkDepsMacro
= GetLinkingDependenciesMacro ();
3060 string libsMacro
= GetLibsMacro ();
3062 GenerateImportLibraryTargetIfNeeded ();
3064 if ( module
.non_if_data
.files
.size () > 0 )
3068 string dependencies
= linkDepsMacro
+ " " + objectsMacro
;
3071 if ( module
.cplusplus
)
3076 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
3077 module
.entrypoint
.c_str (),
3078 module
.baseaddress
.c_str () );
3079 GenerateLinkerCommand ( dependencies
,
3088 GeneratePhonyTarget();
3093 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
3094 const Module
& module_
)
3096 : MingwModuleHandler ( module_
)
3101 MingwRpcServerModuleHandler::Process ()
3107 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
3108 const Module
& module_
)
3110 : MingwModuleHandler ( module_
)
3115 MingwRpcClientModuleHandler::Process ()
3121 MingwAliasModuleHandler::MingwAliasModuleHandler (
3122 const Module
& module_
)
3124 : MingwModuleHandler ( module_
)
3129 MingwAliasModuleHandler::Process ()