4 #include "../../rbuild.h"
6 #include "modulehandler.h"
11 #define CLEAN_FILE(f) clean_files.push_back ( f ); /*if ( module.name == "crt" ) printf ( "%s(%i): clean: %s\n", __FILE__, __LINE__, f.c_str() )*/
13 static string ros_temp
= "$(TEMPORARY)";
15 MingwModuleHandler::backend
= NULL
;
17 MingwModuleHandler::fMakefile
= NULL
;
19 MingwModuleHandler::use_pch
= false;
23 const string
& filename
,
24 const string
& prefix
)
26 if ( !prefix
.length() )
29 const char* pfilename
= filename
.c_str();
30 const char* p1
= strrchr ( pfilename
, '/' );
31 const char* p2
= strrchr ( pfilename
, '\\' );
36 out
+= string(pfilename
,p1
-pfilename
) + CSEP
;
39 out
+= prefix
+ pfilename
;
44 GetTargetMacro ( const Module
& module
, bool with_dollar
)
46 string
s ( module
.name
);
50 return ssprintf ( "$(%s)", s
.c_str() );
54 MingwModuleHandler::MingwModuleHandler (
55 const Module
& module_
)
61 MingwModuleHandler::~MingwModuleHandler()
66 MingwModuleHandler::SetBackend ( MingwBackend
* backend_
)
72 MingwModuleHandler::SetMakefile ( FILE* f
)
78 MingwModuleHandler::SetUsePch ( bool b
)
84 MingwModuleHandler::RemoveVariables ( string path
)
86 size_t i
= path
.find ( '$' );
87 if ( i
!= string::npos
)
89 size_t j
= path
.find ( ')', i
);
90 if ( j
!= string::npos
)
92 if ( j
+ 2 < path
.length () && path
[j
+ 1] == CSEP
)
93 return path
.substr ( j
+ 2);
95 return path
.substr ( j
+ 1);
102 MingwModuleHandler::PassThruCacheDirectory (
104 Directory
* directoryTree
)
106 string
directory ( GetDirectory ( RemoveVariables ( file
) ) );
107 string generatedFilesDirectory
= backend
->AddDirectoryTarget ( directory
,
109 if ( directory
.find ( generatedFilesDirectory
) != string::npos
)
110 /* This path already includes the generated files directory variable */
113 return generatedFilesDirectory
+ SSEP
+ file
;
117 MingwModuleHandler::GetTargetFilename (
118 const Module
& module
,
119 string_list
* pclean_files
)
121 string target
= PassThruCacheDirectory (
122 NormalizeFilename ( module
.GetPath () ),
123 backend
->outputDirectory
);
126 string_list
& clean_files
= *pclean_files
;
127 CLEAN_FILE ( target
);
133 MingwModuleHandler::GetImportLibraryFilename (
134 const Module
& module
,
135 string_list
* pclean_files
)
137 string target
= PassThruCacheDirectory (
138 NormalizeFilename ( module
.GetDependencyPath () ),
139 backend
->outputDirectory
);
142 string_list
& clean_files
= *pclean_files
;
143 CLEAN_FILE ( target
);
148 /*static*/ MingwModuleHandler
*
149 MingwModuleHandler::InstanciateHandler (
150 const Module
& module
,
151 MingwBackend
* backend
)
153 MingwModuleHandler
* handler
;
154 switch ( module
.type
)
157 handler
= new MingwBuildToolModuleHandler ( module
);
160 handler
= new MingwStaticLibraryModuleHandler ( module
);
163 handler
= new MingwObjectLibraryModuleHandler ( module
);
166 handler
= new MingwKernelModuleHandler ( module
);
169 handler
= new MingwNativeCUIModuleHandler ( module
);
172 handler
= new MingwWin32CUIModuleHandler ( module
);
175 handler
= new MingwWin32GUIModuleHandler ( module
);
178 handler
= new MingwKernelModeDLLModuleHandler ( module
);
181 handler
= new MingwNativeDLLModuleHandler ( module
);
184 handler
= new MingwWin32DLLModuleHandler ( module
);
186 case KernelModeDriver
:
187 handler
= new MingwKernelModeDriverModuleHandler ( module
);
190 handler
= new MingwBootLoaderModuleHandler ( module
);
193 handler
= new MingwBootSectorModuleHandler ( module
);
196 handler
= new MingwIsoModuleHandler ( module
);
199 handler
= new MingwTestModuleHandler ( module
);
202 throw UnknownModuleTypeException (
203 module
.node
.location
,
211 MingwModuleHandler::GetWorkingDirectory () const
217 MingwModuleHandler::GetBasename ( const string
& filename
) const
219 size_t index
= filename
.find_last_of ( '.' );
220 if ( index
!= string::npos
)
221 return filename
.substr ( 0, index
);
226 MingwModuleHandler::GetActualSourceFilename (
227 const string
& filename
) const
229 string extension
= GetExtension ( filename
);
230 if ( extension
== ".spec" || extension
== ".SPEC" )
232 string basename
= GetBasename ( filename
);
233 return PassThruCacheDirectory ( NormalizeFilename ( basename
+ ".stubs.c" ),
234 backend
->intermediateDirectory
);
241 MingwModuleHandler::GetModuleArchiveFilename () const
243 if ( module
.type
== StaticLibrary
)
244 return GetTargetFilename ( module
, NULL
);
245 return PassThruCacheDirectory ( ReplaceExtension (
246 NormalizeFilename ( module
.GetPath () ),
248 backend
->intermediateDirectory
);
252 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
254 string extension
= GetExtension ( file
.name
);
255 return ( extension
== ".spec" || extension
== ".SPEC" );
259 MingwModuleHandler::GetImportLibraryDependency (
260 const Module
& importedModule
)
263 if ( importedModule
.type
== ObjectLibrary
)
264 dep
= GetTargetMacro ( importedModule
);
266 dep
= GetImportLibraryFilename ( importedModule
, NULL
);
271 MingwModuleHandler::GetModuleDependencies (
272 string_list
& dependencies
)
274 size_t iend
= module
.dependencies
.size ();
276 // TODO FIXME - do we *really* not want to call
277 // GetDefinitionDependencies() if dependencies.size() == 0 ???
281 for ( size_t i
= 0; i
< iend
; i
++ )
283 const Dependency
& dependency
= *module
.dependencies
[i
];
284 const Module
& dependencyModule
= *dependency
.dependencyModule
;
285 dependencyModule
.GetTargets ( dependencies
);
287 GetDefinitionDependencies ( dependencies
);
291 MingwModuleHandler::GetSourceFilenames (
293 bool includeGeneratedFiles
) const
297 const vector
<File
*>& files
= module
.non_if_data
.files
;
298 for ( i
= 0; i
< files
.size (); i
++ )
300 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *files
[i
] ) )
303 GetActualSourceFilename ( files
[i
]->name
) );
306 // intentionally make a copy so that we can append more work in
307 // the middle of processing without having to go recursive
308 vector
<If
*> v
= module
.non_if_data
.ifs
;
309 for ( i
= 0; i
< v
.size (); i
++ )
313 // check for sub-ifs to add to list
314 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
315 for ( j
= 0; j
< ifs
.size (); j
++ )
316 v
.push_back ( ifs
[j
] );
317 const vector
<File
*>& files
= rIf
.data
.files
;
318 for ( j
= 0; j
< files
.size (); j
++ )
320 File
& file
= *files
[j
];
321 if ( includeGeneratedFiles
|| !IsGeneratedFile ( file
) )
324 GetActualSourceFilename ( file
.name
) );
331 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
332 string_list
& list
) const
334 GetSourceFilenames ( list
, false );
338 MingwModuleHandler::GetObjectFilename (
339 const string
& sourceFilename
,
340 string_list
* pclean_files
) const
342 Directory
* directoryTree
;
345 string extension
= GetExtension ( sourceFilename
);
346 if ( extension
== ".rc" || extension
== ".RC" )
347 newExtension
= ".coff";
348 else if ( extension
== ".spec" || extension
== ".SPEC" )
349 newExtension
= ".stubs.o";
353 if ( module
.type
== BootSector
)
354 directoryTree
= backend
->outputDirectory
;
356 directoryTree
= backend
->intermediateDirectory
;
358 string obj_file
= PassThruCacheDirectory (
359 NormalizeFilename ( ReplaceExtension (
360 RemoveVariables ( sourceFilename
),
365 string_list
& clean_files
= *pclean_files
;
366 CLEAN_FILE ( obj_file
);
372 MingwModuleHandler::GenerateCleanTarget () const
374 if ( 0 == clean_files
.size() )
376 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
377 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
378 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
381 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
382 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
384 fprintf ( fMakefile
, " 2>$(NUL)\n" );
385 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
389 MingwModuleHandler::GetObjectFilenames ()
391 const vector
<File
*>& files
= module
.non_if_data
.files
;
392 if ( files
.size () == 0 )
395 string
objectFilenames ( "" );
396 for ( size_t i
= 0; i
< files
.size (); i
++ )
398 if ( objectFilenames
.size () > 0 )
399 objectFilenames
+= " ";
401 GetObjectFilename ( files
[i
]->name
, NULL
);
403 return objectFilenames
;
407 MingwModuleHandler::GenerateGccDefineParametersFromVector (
408 const vector
<Define
*>& defines
) const
411 for ( size_t i
= 0; i
< defines
.size (); i
++ )
413 Define
& define
= *defines
[i
];
414 if (parameters
.length () > 0)
417 parameters
+= define
.name
;
418 if (define
.value
.length () > 0)
421 parameters
+= define
.value
;
428 MingwModuleHandler::GenerateGccDefineParameters () const
430 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
431 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
432 if ( s
.length () > 0 )
441 MingwModuleHandler::ConcatenatePaths (
443 const string
& path2
) const
445 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
447 if ( path1
[path1
.length ()] == CSEP
)
448 return path1
+ path2
;
450 return path1
+ CSEP
+ path2
;
454 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
457 for ( size_t i
= 0; i
< includes
.size (); i
++ )
459 Include
& include
= *includes
[i
];
460 if ( parameters
.length () > 0 )
462 parameters
+= "-I" + include
.directory
;
468 MingwModuleHandler::GenerateGccIncludeParameters () const
470 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
471 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
472 if ( s
.length () > 0 )
482 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
485 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
487 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
488 if ( parameters
.length () > 0 )
490 parameters
+= compilerFlag
.flag
;
496 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
499 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
501 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
502 if ( parameters
.length () > 0 )
504 parameters
+= linkerFlag
.flag
;
510 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
511 const vector
<Library
*>& libraries
)
513 string
dependencies ( "" );
515 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
517 if ( wrap_count
++ == 5 )
518 dependencies
+= " \\\n\t\t", wrap_count
= 0;
519 else if ( dependencies
.size () > 0 )
521 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->imported_module
);
527 MingwModuleHandler::GenerateLinkerParameters () const
529 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
533 MingwModuleHandler::GenerateMacro (
534 const char* assignmentOperation
,
536 const IfableData
& data
,
537 const vector
<CompilerFlag
*>* compilerFlags
)
545 assignmentOperation
);
547 if ( compilerFlags
!= NULL
)
549 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
550 if ( compilerParameters
.size () > 0 )
555 compilerParameters
.c_str () );
559 for ( i
= 0; i
< data
.includes
.size(); i
++ )
564 data
.includes
[i
]->directory
.c_str() );
566 for ( i
= 0; i
< data
.defines
.size(); i
++ )
568 Define
& d
= *data
.defines
[i
];
573 if ( d
.value
.size() )
579 fprintf ( fMakefile
, "\n" );
583 MingwModuleHandler::GenerateMacros (
584 const char* assignmentOperation
,
585 const IfableData
& data
,
586 const vector
<CompilerFlag
*>* compilerFlags
,
587 const vector
<LinkerFlag
*>* linkerFlags
)
591 if ( data
.includes
.size () > 0 || data
.defines
.size () > 0 )
593 GenerateMacro ( assignmentOperation
,
597 GenerateMacro ( assignmentOperation
,
603 if ( linkerFlags
!= NULL
)
605 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
606 if ( linkerParameters
.size () > 0 )
611 linkerflagsMacro
.c_str (),
613 linkerParameters
.c_str() );
617 if ( data
.libraries
.size () > 0 )
619 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
620 if ( deps
.size () > 0 )
631 const vector
<If
*>& ifs
= data
.ifs
;
632 for ( i
= 0; i
< ifs
.size(); i
++ )
635 if ( rIf
.data
.defines
.size()
636 || rIf
.data
.includes
.size()
637 || rIf
.data
.libraries
.size()
638 || rIf
.data
.files
.size()
639 || rIf
.data
.ifs
.size() )
643 "ifeq (\"$(%s)\",\"%s\")\n",
644 rIf
.property
.c_str(),
659 MingwModuleHandler::GenerateObjectMacros (
660 const char* assignmentOperation
,
661 const IfableData
& data
,
662 const vector
<CompilerFlag
*>* compilerFlags
,
663 const vector
<LinkerFlag
*>* linkerFlags
)
667 const vector
<File
*>& files
= data
.files
;
668 if ( files
.size () > 0 )
670 for ( i
= 0; i
< files
.size (); i
++ )
672 File
& file
= *files
[i
];
677 objectsMacro
.c_str(),
679 file
.name
, NULL
).c_str (),
680 objectsMacro
.c_str() );
686 objectsMacro
.c_str (),
687 assignmentOperation
);
688 for ( i
= 0; i
< files
.size(); i
++ )
690 File
& file
= *files
[i
];
696 ( i
%10 == 9 ? " \\\n\t" : " " ),
698 file
.name
, NULL
).c_str () );
701 fprintf ( fMakefile
, "\n" );
704 const vector
<If
*>& ifs
= data
.ifs
;
705 for ( i
= 0; i
< ifs
.size(); i
++ )
708 if ( rIf
.data
.defines
.size()
709 || rIf
.data
.includes
.size()
710 || rIf
.data
.libraries
.size()
711 || rIf
.data
.files
.size()
712 || rIf
.data
.ifs
.size() )
716 "ifeq (\"$(%s)\",\"%s\")\n",
717 rIf
.property
.c_str(),
719 GenerateObjectMacros (
732 MingwModuleHandler::GenerateGccCommand (
733 const string
& sourceFilename
,
735 const string
& cflagsMacro
)
737 string deps
= sourceFilename
;
738 if ( module
.pch
&& use_pch
)
739 deps
+= " " + module
.pch
->header
+ ".gch";
740 string objectFilename
= GetObjectFilename (
741 sourceFilename
, &clean_files
);
744 objectFilename
.c_str (),
746 GetDirectory ( objectFilename
).c_str () );
747 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
749 "\t%s -c $< -o $@ %s\n",
751 cflagsMacro
.c_str () );
755 MingwModuleHandler::GenerateGccAssemblerCommand (
756 const string
& sourceFilename
,
758 const string
& cflagsMacro
)
760 string objectFilename
= GetObjectFilename (
761 sourceFilename
, &clean_files
);
764 objectFilename
.c_str (),
765 sourceFilename
.c_str (),
766 GetDirectory ( objectFilename
).c_str () );
767 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
769 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
771 cflagsMacro
.c_str () );
775 MingwModuleHandler::GenerateNasmCommand (
776 const string
& sourceFilename
,
777 const string
& nasmflagsMacro
)
779 string objectFilename
= GetObjectFilename (
780 sourceFilename
, &clean_files
);
783 objectFilename
.c_str (),
784 sourceFilename
.c_str (),
785 GetDirectory ( objectFilename
).c_str () );
786 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
788 "\t%s -f win32 $< -o $@ %s\n",
790 nasmflagsMacro
.c_str () );
794 MingwModuleHandler::GenerateWindresCommand (
795 const string
& sourceFilename
,
796 const string
& windresflagsMacro
)
798 string objectFilename
=
799 GetObjectFilename ( sourceFilename
, &clean_files
);
800 string rciFilename
= ros_temp
+
801 ReplaceExtension ( sourceFilename
, ".rci" );
802 string resFilename
= ros_temp
+
803 ReplaceExtension ( sourceFilename
, ".res" );
805 "%s: %s $(WRC_TARGET) | %s\n",
806 objectFilename
.c_str (),
807 sourceFilename
.c_str (),
808 GetDirectory ( objectFilename
).c_str () );
809 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
811 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
812 windresflagsMacro
.c_str (),
813 sourceFilename
.c_str (),
814 rciFilename
.c_str () );
816 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
817 windresflagsMacro
.c_str (),
818 rciFilename
.c_str (),
819 resFilename
.c_str () );
821 "\t-@${rm} %s 2>$(NUL)\n",
822 rciFilename
.c_str () );
824 "\t${windres} %s -o $@\n",
825 resFilename
.c_str () );
827 "\t-@${rm} %s 2>$(NUL)\n",
828 resFilename
.c_str () );
832 MingwModuleHandler::GenerateWinebuildCommands (
833 const string
& sourceFilename
)
835 string basename
= GetBasename ( sourceFilename
);
837 string def_file
= PassThruCacheDirectory (
838 basename
+ ".spec.def",
839 backend
->intermediateDirectory
);
840 CLEAN_FILE(def_file
);
842 string stub_file
= PassThruCacheDirectory (
843 basename
+ ".stubs.c",
844 backend
->intermediateDirectory
);
845 CLEAN_FILE(stub_file
)
848 "%s: %s $(WINEBUILD_TARGET)\n",
850 sourceFilename
.c_str () );
851 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
853 "\t%s --def=%s -o %s\n",
854 "$(Q)$(WINEBUILD_TARGET)",
855 sourceFilename
.c_str (),
859 "%s: %s $(WINEBUILD_TARGET)\n",
861 sourceFilename
.c_str () );
862 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
864 "\t%s --pedll=%s -o %s\n",
865 "$(Q)$(WINEBUILD_TARGET)",
866 sourceFilename
.c_str (),
867 stub_file
.c_str () );
871 MingwModuleHandler::GenerateCommands (
872 const string
& sourceFilename
,
875 const string
& cflagsMacro
,
876 const string
& nasmflagsMacro
,
877 const string
& windresflagsMacro
)
879 string extension
= GetExtension ( sourceFilename
);
880 if ( extension
== ".c" || extension
== ".C" )
882 GenerateGccCommand ( sourceFilename
,
887 else if ( extension
== ".cc" || extension
== ".CC" ||
888 extension
== ".cpp" || extension
== ".CPP" ||
889 extension
== ".cxx" || extension
== ".CXX" )
891 GenerateGccCommand ( sourceFilename
,
896 else if ( extension
== ".s" || extension
== ".S" )
898 GenerateGccAssemblerCommand ( sourceFilename
,
903 else if ( extension
== ".asm" || extension
== ".ASM" )
905 GenerateNasmCommand ( sourceFilename
,
909 else if ( extension
== ".rc" || extension
== ".RC" )
911 GenerateWindresCommand ( sourceFilename
,
915 else if ( extension
== ".spec" || extension
== ".SPEC" )
917 GenerateWinebuildCommands ( sourceFilename
);
918 GenerateGccCommand ( GetActualSourceFilename ( sourceFilename
),
924 throw InvalidOperationException ( __FILE__
,
926 "Unsupported filename extension '%s' in file '%s'",
928 sourceFilename
.c_str () );
932 MingwModuleHandler::GenerateBuildMapCode ()
935 "ifeq ($(ROS_BUILDMAP),full)\n" );
937 string mapFilename
= PassThruCacheDirectory (
938 GetBasename ( module
.GetPath () ) + ".map",
939 backend
->outputDirectory
);
940 CLEAN_FILE ( mapFilename
);
943 "\t$(ECHO_OBJDUMP)\n" );
945 "\t$(Q)${objdump} -d -S $@ > %s\n",
946 mapFilename
.c_str () );
951 "ifeq ($(ROS_BUILDMAP),yes)\n" );
956 "\t$(Q)${nm} --numeric-sort $@ > %s\n",
957 mapFilename
.c_str () );
967 MingwModuleHandler::GenerateLinkerCommand (
968 const string
& dependencies
,
969 const string
& linker
,
970 const string
& linkerParameters
,
971 const string
& objectsMacro
,
972 const string
& libsMacro
)
974 string
target ( GetTargetMacro ( module
) );
975 string
target_folder ( GetDirectory ( GetTargetFilename ( module
, NULL
) ) );
978 "%s: %s $(RSYM_TARGET) | %s\n",
980 dependencies
.c_str (),
981 target_folder
.c_str () );
982 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
983 string
targetName ( module
.GetTargetName () );
984 if ( module
.importLibrary
!= NULL
)
986 string base_tmp
= ros_temp
+ module
.name
+ ".base.tmp";
987 CLEAN_FILE ( base_tmp
);
988 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
989 CLEAN_FILE ( junk_tmp
);
990 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
991 CLEAN_FILE ( temp_exp
);
992 string def_file
= GetDefinitionFilename ();
995 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
997 linkerParameters
.c_str (),
1000 objectsMacro
.c_str (),
1002 GetLinkerMacro ().c_str () );
1004 fprintf ( fMakefile
,
1005 "\t-@${rm} %s 2>$(NUL)\n",
1006 junk_tmp
.c_str () );
1008 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1009 fprintf ( fMakefile
,
1010 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
1011 targetName
.c_str (),
1017 fprintf ( fMakefile
,
1018 "\t-@${rm} %s 2>$(NUL)\n",
1019 base_tmp
.c_str () );
1021 fprintf ( fMakefile
,
1022 "\t%s %s %s -o %s %s %s %s\n",
1024 linkerParameters
.c_str (),
1027 objectsMacro
.c_str (),
1029 GetLinkerMacro ().c_str () );
1031 fprintf ( fMakefile
,
1032 "\t-@${rm} %s 2>$(NUL)\n",
1033 temp_exp
.c_str () );
1037 fprintf ( fMakefile
,
1038 "\t%s %s -o %s %s %s %s\n",
1040 linkerParameters
.c_str (),
1042 objectsMacro
.c_str (),
1044 GetLinkerMacro ().c_str () );
1047 GenerateBuildMapCode ();
1049 fprintf ( fMakefile
,
1050 "\t$(ECHO_RSYM)\n" );
1051 fprintf ( fMakefile
,
1052 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1056 MingwModuleHandler::GeneratePhonyTarget() const
1058 string
targetMacro ( GetTargetMacro(module
) );
1059 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1060 targetMacro
.c_str ());
1061 fprintf ( fMakefile
, "%s: | %s\n",
1062 targetMacro
.c_str (),
1063 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1067 MingwModuleHandler::GenerateObjectFileTargets (
1068 const IfableData
& data
,
1071 const string
& cflagsMacro
,
1072 const string
& nasmflagsMacro
,
1073 const string
& windresflagsMacro
)
1077 const vector
<File
*>& files
= data
.files
;
1078 for ( i
= 0; i
< files
.size (); i
++ )
1080 string sourceFilename
= files
[i
]->name
;
1081 GenerateCommands ( sourceFilename
,
1086 windresflagsMacro
);
1087 fprintf ( fMakefile
,
1091 const vector
<If
*>& ifs
= data
.ifs
;
1092 for ( i
= 0; i
< ifs
.size(); i
++ )
1094 GenerateObjectFileTargets ( ifs
[i
]->data
,
1099 windresflagsMacro
);
1104 MingwModuleHandler::GenerateObjectFileTargets (
1107 const string
& cflagsMacro
,
1108 const string
& nasmflagsMacro
,
1109 const string
& windresflagsMacro
)
1113 const string
& pch_file
= module
.pch
->header
;
1114 string gch_file
= pch_file
+ ".gch";
1115 CLEAN_FILE(gch_file
);
1123 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1126 "\t%s -o %s %s -g %s\n\n",
1127 ( module
.cplusplus
? cppc
.c_str() : cc
.c_str() ),
1129 cflagsMacro
.c_str(),
1134 GenerateObjectFileTargets ( module
.non_if_data
,
1139 windresflagsMacro
);
1140 fprintf ( fMakefile
, "\n" );
1144 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1145 const string
& objs_macro
) const
1147 string
archiveFilename ( GetModuleArchiveFilename () );
1149 fprintf ( fMakefile
,
1151 archiveFilename
.c_str (),
1152 objs_macro
.c_str (),
1153 GetDirectory(archiveFilename
).c_str() );
1155 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1157 fprintf ( fMakefile
,
1158 "\t%s -rc $@ %s\n\n",
1160 objs_macro
.c_str ());
1162 return archiveFilename
;
1166 MingwModuleHandler::GetCFlagsMacro () const
1168 return ssprintf ( "$(%s_CFLAGS)",
1169 module
.name
.c_str () );
1173 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1175 return ssprintf ( "$(%s_OBJS)",
1176 module
.name
.c_str () );
1180 MingwModuleHandler::GetLinkingDependenciesMacro () const
1182 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1186 MingwModuleHandler::GetLibsMacro () const
1188 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1192 MingwModuleHandler::GetLinkerMacro () const
1194 return ssprintf ( "$(%s_LFLAGS)",
1195 module
.name
.c_str () );
1199 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1201 if ( module
.type
== ObjectLibrary
)
1202 return GetObjectsMacro ( module
);
1204 return GetTargetFilename ( module
, NULL
);
1208 MingwModuleHandler::GenerateObjectMacro ()
1210 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1212 GenerateObjectMacros (
1215 &module
.compilerFlags
,
1216 &module
.linkerFlags
);
1218 // future references to the macro will be to get its values
1219 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1223 MingwModuleHandler::GenerateTargetMacro ()
1225 fprintf ( fMakefile
,
1227 GetTargetMacro ( module
, false ).c_str (),
1228 GetModuleTargets ( module
).c_str () );
1232 MingwModuleHandler::GenerateOtherMacros ()
1234 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1235 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1236 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1237 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1238 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1239 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1244 &module
.compilerFlags
,
1245 &module
.linkerFlags
);
1247 if ( module
.importLibrary
)
1250 const vector
<File
*>& files
= module
.non_if_data
.files
;
1251 for ( size_t i
= 0; i
< files
.size (); i
++ )
1253 File
& file
= *files
[i
];
1254 string extension
= GetExtension ( file
.name
);
1255 if ( extension
== ".spec" || extension
== ".SPEC" )
1256 GetSpecObjectDependencies ( s
, file
.name
);
1258 if ( s
.size () > 0 )
1263 linkDepsMacro
.c_str() );
1264 for ( size_t i
= 0; i
< s
.size(); i
++ )
1265 fprintf ( fMakefile
,
1268 fprintf ( fMakefile
, "\n" );
1272 string globalCflags
= "-g";
1273 if ( backend
->usePipe
)
1274 globalCflags
+= " -pipe";
1278 "%s += $(PROJECT_CFLAGS) %s\n",
1279 cflagsMacro
.c_str (),
1280 globalCflags
.c_str () );
1284 "%s += $(PROJECT_RCFLAGS)\n",
1285 windresflagsMacro
.c_str () );
1289 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1290 module
.name
.c_str () );
1295 linkDepsMacro
.c_str (),
1296 libsMacro
.c_str () );
1298 string cflags
= TypeSpecificCFlags();
1299 if ( cflags
.size() > 0 )
1301 fprintf ( fMakefile
,
1303 cflagsMacro
.c_str (),
1307 string nasmflags
= TypeSpecificNasmFlags();
1308 if ( nasmflags
.size () > 0 )
1310 fprintf ( fMakefile
,
1312 nasmflagsMacro
.c_str (),
1313 nasmflags
.c_str () );
1316 fprintf ( fMakefile
, "\n\n" );
1318 // future references to the macros will be to get their values
1319 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1320 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1324 MingwModuleHandler::GenerateRules ()
1326 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1327 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1328 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1330 string targetMacro
= GetTargetMacro ( module
);
1332 CLEAN_FILE ( targetMacro
);
1334 // generate phony target for module name
1335 fprintf ( fMakefile
, ".PHONY: %s\n",
1336 module
.name
.c_str () );
1337 fprintf ( fMakefile
, "%s: %s\n\n",
1338 module
.name
.c_str (),
1339 GetTargetMacro ( module
).c_str () );
1341 if ( module
.type
!= ObjectLibrary
)
1343 string
ar_target ( GenerateArchiveTarget ( ar
, objectsMacro
) );
1344 if ( targetMacro
!= ar_target
)
1346 CLEAN_FILE ( ar_target
);
1350 GenerateObjectFileTargets ( cc
,
1354 windresflagsMacro
);
1358 MingwModuleHandler::GetInvocationDependencies (
1359 const Module
& module
,
1360 string_list
& dependencies
)
1362 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1364 Invoke
& invoke
= *module
.invocations
[i
];
1365 if ( invoke
.invokeModule
== &module
)
1366 /* Protect against circular dependencies */
1368 invoke
.GetTargets ( dependencies
);
1373 MingwModuleHandler::GenerateInvocations () const
1375 if ( module
.invocations
.size () == 0 )
1378 size_t iend
= module
.invocations
.size ();
1379 for ( size_t i
= 0; i
< iend
; i
++ )
1381 const Invoke
& invoke
= *module
.invocations
[i
];
1383 if ( invoke
.invokeModule
->type
!= BuildTool
)
1385 throw InvalidBuildFileException ( module
.node
.location
,
1386 "Only modules of type buildtool can be invoked." );
1389 string invokeTarget
= module
.GetInvocationTarget ( i
);
1390 string_list invoke_targets
;
1391 assert ( invoke_targets
.size() );
1392 invoke
.GetTargets ( invoke_targets
);
1393 fprintf ( fMakefile
,
1395 invokeTarget
.c_str () );
1396 fprintf ( fMakefile
,
1398 invokeTarget
.c_str () );
1399 size_t j
, jend
= invoke_targets
.size();
1400 for ( j
= 0; j
< jend
; j
++ )
1402 fprintf ( fMakefile
,
1404 invoke_targets
[i
].c_str () );
1406 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
1407 for ( j
= 1; j
< jend
; j
++ )
1408 fprintf ( fMakefile
,
1410 invoke_targets
[i
].c_str () );
1411 fprintf ( fMakefile
,
1413 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1414 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1415 fprintf ( fMakefile
,
1417 NormalizeFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1418 invoke
.GetParameters ().c_str () );
1423 MingwModuleHandler::GetPreconditionDependenciesName () const
1425 return module
.name
+ "_precondition";
1429 MingwModuleHandler::GetDefaultDependencies (
1430 string_list
& dependencies
) const
1432 /* Avoid circular dependency */
1433 if ( module
.type
!= BuildTool
1434 && module
.name
!= "zlib"
1435 && module
.name
!= "hostzlib" )
1437 dependencies
.push_back ( "$(INIT)" );
1441 MingwModuleHandler::GeneratePreconditionDependencies ()
1443 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
1444 string_list sourceFilenames
;
1445 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
1446 string_list dependencies
;
1447 GetDefaultDependencies ( dependencies
);
1448 GetModuleDependencies ( dependencies
);
1450 GetInvocationDependencies ( module
, dependencies
);
1452 if ( dependencies
.size() )
1454 fprintf ( fMakefile
,
1456 preconditionDependenciesName
.c_str () );
1457 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
1458 fprintf ( fMakefile
,
1460 dependencies
[i
].c_str () );
1461 fprintf ( fMakefile
, "\n\n" );
1464 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
1466 fprintf ( fMakefile
,
1468 sourceFilenames
[i
].c_str(),
1469 preconditionDependenciesName
.c_str ());
1471 fprintf ( fMakefile
, "\n" );
1475 MingwModuleHandler::IsWineModule () const
1477 if ( module
.importLibrary
== NULL
)
1480 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
1481 return ( index
!= string::npos
);
1485 MingwModuleHandler::GetDefinitionFilename () const
1487 string defFilename
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
1488 if ( IsWineModule () )
1489 return PassThruCacheDirectory ( NormalizeFilename ( defFilename
),
1490 backend
->intermediateDirectory
);
1496 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
1498 if ( module
.importLibrary
!= NULL
)
1500 string
library_target (
1501 GetImportLibraryFilename ( module
, &clean_files
) );
1504 GetDefinitionDependencies ( deps
);
1506 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
1508 fprintf ( fMakefile
, "%s:",
1509 library_target
.c_str () );
1511 size_t i
, iend
= deps
.size();
1512 for ( i
= 0; i
< iend
; i
++ )
1513 fprintf ( fMakefile
, " %s",
1516 fprintf ( fMakefile
, " | %s\n",
1517 GetDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1519 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1521 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1522 fprintf ( fMakefile
,
1523 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1524 module
.GetTargetName ().c_str (),
1525 GetDefinitionFilename ().c_str (),
1526 library_target
.c_str (),
1532 MingwModuleHandler::GetSpecObjectDependencies (
1533 string_list
& dependencies
,
1534 const string
& filename
) const
1536 string basename
= GetBasename ( filename
);
1537 string defDependency
= PassThruCacheDirectory (
1538 NormalizeFilename ( basename
+ ".spec.def" ),
1539 backend
->intermediateDirectory
);
1540 dependencies
.push_back ( defDependency
);
1541 string stubsDependency
= PassThruCacheDirectory (
1542 NormalizeFilename ( basename
+ ".stubs.c" ),
1543 backend
->intermediateDirectory
);
1544 dependencies
.push_back ( stubsDependency
);
1548 MingwModuleHandler::GetDefinitionDependencies (
1549 string_list
& dependencies
) const
1551 string dkNkmLibNoFixup
= "dk/nkm/lib";
1552 const vector
<File
*>& files
= module
.non_if_data
.files
;
1553 for ( size_t i
= 0; i
< files
.size (); i
++ )
1555 File
& file
= *files
[i
];
1556 string extension
= GetExtension ( file
.name
);
1557 if ( extension
== ".spec" || extension
== ".SPEC" )
1559 GetSpecObjectDependencies ( dependencies
, file
.name
);
1565 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
1566 : MingwModuleHandler ( module_
)
1571 MingwBuildToolModuleHandler::Process ()
1573 GenerateBuildToolModuleTarget ();
1577 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
1579 string
targetMacro ( GetTargetMacro (module
) );
1580 string objectsMacro
= GetObjectsMacro ( module
);
1581 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1582 string libsMacro
= GetLibsMacro ();
1587 if ( module
.cplusplus
)
1588 linker
= "${host_gpp}";
1590 linker
= "${host_gcc}";
1592 fprintf ( fMakefile
, "%s: %s %s | %s\n",
1593 targetMacro
.c_str (),
1594 objectsMacro
.c_str (),
1595 linkDepsMacro
.c_str (),
1596 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1597 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1598 fprintf ( fMakefile
,
1599 "\t%s %s -o $@ %s %s\n\n",
1601 GetLinkerMacro ().c_str (),
1602 objectsMacro
.c_str (),
1603 libsMacro
.c_str () );
1607 MingwKernelModuleHandler::MingwKernelModuleHandler (
1608 const Module
& module_
)
1610 : MingwModuleHandler ( module_
)
1615 MingwKernelModuleHandler::Process ()
1617 GenerateKernelModuleTarget ();
1621 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
1623 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1624 string
targetMacro ( GetTargetMacro (module
) ); // i.e. "$(NTOSKRNL_TARGET)"
1625 string workingDirectory
= GetWorkingDirectory ();
1626 string objectsMacro
= GetObjectsMacro ( module
);
1627 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1628 string libsMacro
= GetLibsMacro ();
1629 string base_tmp
= ros_temp
+ module
.name
+ ".base.tmp";
1630 CLEAN_FILE ( base_tmp
);
1631 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
1632 CLEAN_FILE ( junk_tmp
);
1633 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1634 CLEAN_FILE ( temp_exp
);
1635 string gccOptions
= 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 -mdll",
1636 module
.GetBasePath ().c_str (),
1637 module
.entrypoint
.c_str (),
1638 module
.baseaddress
.c_str () );
1642 GenerateImportLibraryTargetIfNeeded ();
1644 fprintf ( fMakefile
, "%s: %s %s $(RSYM_TARGET) | %s\n",
1645 targetMacro
.c_str (),
1646 objectsMacro
.c_str (),
1647 linkDepsMacro
.c_str (),
1648 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1649 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1650 fprintf ( fMakefile
,
1651 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1652 GetLinkerMacro ().c_str (),
1653 gccOptions
.c_str (),
1656 objectsMacro
.c_str (),
1657 linkDepsMacro
.c_str () );
1658 fprintf ( fMakefile
,
1659 "\t-@${rm} %s 2>$(NUL)\n",
1660 junk_tmp
.c_str () );
1661 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1662 fprintf ( fMakefile
,
1663 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1664 targetName
.c_str (),
1668 fprintf ( fMakefile
,
1669 "\t-@${rm} %s 2>$(NUL)\n",
1670 base_tmp
.c_str () );
1671 fprintf ( fMakefile
,
1672 "\t${gcc} %s %s -Wl,%s -o $@ %s %s\n",
1673 GetLinkerMacro ().c_str (),
1674 gccOptions
.c_str (),
1676 objectsMacro
.c_str (),
1677 linkDepsMacro
.c_str () );
1678 fprintf ( fMakefile
,
1679 "\t-@${rm} %s 2>$(NUL)\n",
1680 temp_exp
.c_str () );
1681 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1682 fprintf ( fMakefile
,
1683 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1687 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
1688 const Module
& module_
)
1690 : MingwModuleHandler ( module_
)
1695 MingwStaticLibraryModuleHandler::Process ()
1697 GenerateStaticLibraryModuleTarget ();
1701 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
1707 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
1708 const Module
& module_
)
1710 : MingwModuleHandler ( module_
)
1715 MingwObjectLibraryModuleHandler::Process ()
1717 GenerateObjectLibraryModuleTarget ();
1721 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
1727 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
1728 const Module
& module_
)
1730 : MingwModuleHandler ( module_
)
1735 MingwKernelModeDLLModuleHandler::Process ()
1737 GenerateKernelModeDLLModuleTarget ();
1741 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
1743 string
targetMacro ( GetTargetMacro (module
) );
1744 string workingDirectory
= GetWorkingDirectory ( );
1745 string objectsMacro
= GetObjectsMacro ( module
);
1746 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1747 string libsMacro
= GetLibsMacro ();
1749 GenerateImportLibraryTargetIfNeeded ();
1751 if ( module
.non_if_data
.files
.size () > 0 )
1755 string dependencies
=
1756 objectsMacro
+ " " + linkDepsMacro
;
1758 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1759 module
.entrypoint
.c_str (),
1760 module
.baseaddress
.c_str () );
1761 GenerateLinkerCommand ( dependencies
,
1769 GeneratePhonyTarget();
1774 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
1775 const Module
& module_
)
1777 : MingwModuleHandler ( module_
)
1782 MingwKernelModeDriverModuleHandler::Process ()
1784 GenerateKernelModeDriverModuleTarget ();
1789 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
1791 string
targetMacro ( GetTargetMacro (module
) );
1792 string workingDirectory
= GetWorkingDirectory ();
1793 string objectsMacro
= GetObjectsMacro ( module
);
1794 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1795 string libsMacro
= GetLibsMacro ();
1797 GenerateImportLibraryTargetIfNeeded ();
1799 if ( module
.non_if_data
.files
.size () > 0 )
1803 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
1805 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1806 module
.entrypoint
.c_str (),
1807 module
.baseaddress
.c_str () );
1808 GenerateLinkerCommand ( dependencies
,
1816 GeneratePhonyTarget();
1821 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
1822 const Module
& module_
)
1824 : MingwModuleHandler ( module_
)
1829 MingwNativeDLLModuleHandler::Process ()
1831 GenerateNativeDLLModuleTarget ();
1835 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
1837 string
targetMacro ( GetTargetMacro (module
) );
1838 string workingDirectory
= GetWorkingDirectory ( );
1839 string objectsMacro
= GetObjectsMacro ( module
);
1840 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1841 string libsMacro
= GetLibsMacro ();
1843 GenerateImportLibraryTargetIfNeeded ();
1845 if ( module
.non_if_data
.files
.size () > 0 )
1849 string dependencies
=
1850 objectsMacro
+ " " + linkDepsMacro
;
1852 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1853 module
.entrypoint
.c_str (),
1854 module
.baseaddress
.c_str () );
1855 GenerateLinkerCommand ( dependencies
,
1863 GeneratePhonyTarget();
1868 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
1869 const Module
& module_
)
1871 : MingwModuleHandler ( module_
)
1876 MingwNativeCUIModuleHandler::Process ()
1878 GenerateNativeCUIModuleTarget ();
1882 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
1884 string
targetMacro ( GetTargetMacro (module
) );
1885 string workingDirectory
= GetWorkingDirectory ( );
1886 string objectsMacro
= GetObjectsMacro ( module
);
1887 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1888 string libsMacro
= GetLibsMacro ();
1890 GenerateImportLibraryTargetIfNeeded ();
1892 if ( module
.non_if_data
.files
.size () > 0 )
1896 string dependencies
=
1897 objectsMacro
+ " " + linkDepsMacro
;
1899 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1900 module
.entrypoint
.c_str (),
1901 module
.baseaddress
.c_str () );
1902 GenerateLinkerCommand ( dependencies
,
1910 GeneratePhonyTarget();
1915 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
1916 const Module
& module_
)
1918 : MingwModuleHandler ( module_
)
1923 MingwWin32DLLModuleHandler::Process ()
1925 GenerateExtractWineDLLResourcesTarget ();
1926 GenerateWin32DLLModuleTarget ();
1930 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ()
1932 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1933 module
.name
.c_str () );
1934 fprintf ( fMakefile
, "%s_extractresources: $(BIN2RES_TARGET)\n",
1935 module
.name
.c_str () );
1936 const vector
<File
*>& files
= module
.non_if_data
.files
;
1937 for ( size_t i
= 0; i
< files
.size (); i
++ )
1939 File
& file
= *files
[i
];
1940 string extension
= GetExtension ( file
.name
);
1941 if ( extension
== ".rc" || extension
== ".RC" )
1943 string resource
= NormalizeFilename ( file
.name
);
1944 fprintf ( fMakefile
, "\t$(ECHO_BIN2RES)\n" );
1945 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1946 resource
.c_str () );
1949 fprintf ( fMakefile
, "\n");
1953 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
1955 string
targetMacro ( GetTargetMacro (module
) );
1956 string workingDirectory
= GetWorkingDirectory ( );
1957 string objectsMacro
= GetObjectsMacro ( module
);
1958 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1959 string libsMacro
= GetLibsMacro ();
1961 GenerateImportLibraryTargetIfNeeded ();
1963 if ( module
.non_if_data
.files
.size () > 0 )
1967 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
1970 if ( module
.cplusplus
)
1975 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1976 module
.entrypoint
.c_str (),
1977 module
.baseaddress
.c_str () );
1978 GenerateLinkerCommand ( dependencies
,
1986 GeneratePhonyTarget();
1991 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
1992 const Module
& module_
)
1994 : MingwModuleHandler ( module_
)
1999 MingwWin32CUIModuleHandler::Process ()
2001 GenerateWin32CUIModuleTarget ();
2005 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2007 string
targetMacro ( GetTargetMacro (module
) );
2008 string workingDirectory
= GetWorkingDirectory ( );
2009 string objectsMacro
= GetObjectsMacro ( module
);
2010 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2011 string libsMacro
= GetLibsMacro ();
2013 GenerateImportLibraryTargetIfNeeded ();
2015 if ( module
.non_if_data
.files
.size () > 0 )
2019 string dependencies
=
2020 objectsMacro
+ " " + linkDepsMacro
;
2023 if ( module
.cplusplus
)
2028 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2029 module
.entrypoint
.c_str (),
2030 module
.baseaddress
.c_str () );
2031 GenerateLinkerCommand ( dependencies
,
2039 GeneratePhonyTarget();
2044 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2045 const Module
& module_
)
2047 : MingwModuleHandler ( module_
)
2052 MingwWin32GUIModuleHandler::Process ()
2054 GenerateWin32GUIModuleTarget ();
2058 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2060 string
targetMacro ( GetTargetMacro (module
) );
2061 string workingDirectory
= GetWorkingDirectory ( );
2062 string objectsMacro
= GetObjectsMacro ( module
);
2063 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2064 string libsMacro
= GetLibsMacro ();
2066 GenerateImportLibraryTargetIfNeeded ();
2068 if ( module
.non_if_data
.files
.size () > 0 )
2072 string dependencies
=
2073 objectsMacro
+ " " + linkDepsMacro
;
2076 if ( module
.cplusplus
)
2081 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2082 module
.entrypoint
.c_str (),
2083 module
.baseaddress
.c_str () );
2084 GenerateLinkerCommand ( dependencies
,
2092 GeneratePhonyTarget();
2097 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2098 const Module
& module_
)
2100 : MingwModuleHandler ( module_
)
2105 MingwBootLoaderModuleHandler::Process ()
2107 GenerateBootLoaderModuleTarget ();
2111 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2113 string
targetName ( module
.GetTargetName () );
2114 string
targetMacro ( GetTargetMacro (module
) );
2115 string workingDirectory
= GetWorkingDirectory ();
2116 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2117 CLEAN_FILE ( junk_tmp
);
2118 string objectsMacro
= GetObjectsMacro ( module
);
2119 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2120 string libsMacro
= GetLibsMacro ();
2124 fprintf ( fMakefile
, "%s: %s %s | %s\n",
2125 targetMacro
.c_str (),
2126 objectsMacro
.c_str (),
2127 linkDepsMacro
.c_str (),
2128 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2130 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2132 fprintf ( fMakefile
,
2133 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2134 GetLinkerMacro ().c_str (),
2136 objectsMacro
.c_str (),
2137 linkDepsMacro
.c_str () );
2138 fprintf ( fMakefile
,
2139 "\t${objcopy} -O binary %s $@\n",
2140 junk_tmp
.c_str () );
2141 fprintf ( fMakefile
,
2142 "\t-@${rm} %s 2>$(NUL)\n",
2143 junk_tmp
.c_str () );
2147 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2148 const Module
& module_
)
2150 : MingwModuleHandler ( module_
)
2155 MingwBootSectorModuleHandler::Process ()
2157 GenerateBootSectorModuleTarget ();
2161 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2163 string objectsMacro
= GetObjectsMacro ( module
);
2167 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2168 module
.name
.c_str ());
2169 fprintf ( fMakefile
,
2171 module
.name
.c_str (),
2172 objectsMacro
.c_str () );
2176 MingwIsoModuleHandler::MingwIsoModuleHandler (
2177 const Module
& module_
)
2179 : MingwModuleHandler ( module_
)
2184 MingwIsoModuleHandler::Process ()
2186 GenerateIsoModuleTarget ();
2190 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2191 const string
& bootcdDirectory
)
2193 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2195 const Module
& m
= *module
.project
.modules
[i
];
2196 if ( m
.bootstrap
!= NULL
)
2198 string sourceFilename
= PassThruCacheDirectory (
2199 NormalizeFilename ( m
.GetPath () ),
2200 backend
->outputDirectory
);
2201 string
targetFilenameNoFixup ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
);
2202 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2203 NormalizeFilename ( targetFilenameNoFixup
),
2204 backend
->outputDirectory
);
2205 fprintf ( fMakefile
,
2207 fprintf ( fMakefile
,
2208 "\t${cp} %s %s 1>$(NUL)\n",
2209 sourceFilename
.c_str (),
2210 targetFilename
.c_str () );
2216 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2217 const string
& bootcdDirectory
)
2219 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2221 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2222 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2223 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2224 NormalizeFilename ( targetFilenameNoFixup
),
2225 backend
->outputDirectory
);
2226 fprintf ( fMakefile
,
2228 fprintf ( fMakefile
,
2229 "\t${cp} %s %s 1>$(NUL)\n",
2230 cdfile
.GetPath ().c_str (),
2231 targetFilename
.c_str () );
2236 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
2239 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2241 const Module
& m
= *module
.project
.modules
[i
];
2242 if ( m
.bootstrap
!= NULL
)
2244 string
targetDirectory ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
);
2245 if ( directories
.size () > 0 )
2247 directories
+= PassThruCacheDirectory (
2248 NormalizeFilename ( targetDirectory
),
2249 backend
->outputDirectory
);
2256 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
2259 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2261 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2262 string
targetDirectory ( bootcdDirectory
+ SSEP
+ cdfile
.base
);
2263 if ( directories
.size () > 0 )
2265 directories
+= PassThruCacheDirectory (
2266 NormalizeFilename ( targetDirectory
),
2267 backend
->outputDirectory
);
2273 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
2275 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
2276 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
2281 MingwIsoModuleHandler::GetBootstrapCdFiles (
2282 vector
<string
>& out
) const
2284 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2286 const Module
& m
= *module
.project
.modules
[i
];
2287 if ( m
.bootstrap
!= NULL
)
2289 string filename
= PassThruCacheDirectory (
2290 NormalizeFilename ( m
.GetPath () ),
2291 backend
->outputDirectory
);
2292 out
.push_back ( filename
);
2298 MingwIsoModuleHandler::GetNonModuleCdFiles (
2299 vector
<string
>& out
) const
2301 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2303 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2304 out
.push_back ( cdfile
.GetPath () );
2309 MingwIsoModuleHandler::GetCdFiles (
2310 vector
<string
>& out
) const
2312 GetBootstrapCdFiles ( out
);
2313 GetNonModuleCdFiles ( out
);
2317 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2319 string bootcdDirectory
= "cd";
2320 string bootcd
= PassThruCacheDirectory (
2321 NormalizeFilename ( bootcdDirectory
+ SSEP
),
2322 backend
->outputDirectory
);
2323 string isoboot
= PassThruCacheDirectory (
2324 NormalizeFilename ( "boot" SSEP
"freeldr" SSEP
"bootsect" SSEP
"isoboot.o" ),
2325 backend
->outputDirectory
);
2326 string bootcdReactosNoFixup
= bootcdDirectory
+ SSEP
"reactos";
2327 string bootcdReactos
= PassThruCacheDirectory (
2328 NormalizeFilename ( bootcdReactosNoFixup
),
2329 backend
->outputDirectory
);
2330 CLEAN_FILE ( bootcdReactos
);
2331 string reactosInf
= PassThruCacheDirectory (
2332 NormalizeFilename ( bootcdReactosNoFixup
+ SSEP
"reactos.inf" ),
2333 backend
->outputDirectory
);
2334 string reactosDff
= NormalizeFilename ( "bootdata" SSEP
"packages" SSEP
"reactos.dff" );
2335 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
2336 vector
<string
> vCdFiles
;
2337 GetCdFiles ( vCdFiles
);
2338 string cdFiles
= v2s ( vCdFiles
, 5 );
2340 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2341 module
.name
.c_str ());
2342 fprintf ( fMakefile
,
2343 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2344 module
.name
.c_str (),
2346 bootcdReactos
.c_str (),
2347 cdDirectories
.c_str (),
2349 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2350 fprintf ( fMakefile
,
2351 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
2352 reactosDff
.c_str (),
2353 bootcdReactos
.c_str () );
2354 fprintf ( fMakefile
,
2355 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2356 reactosDff
.c_str (),
2357 reactosInf
.c_str (),
2358 bootcdReactos
.c_str ());
2359 fprintf ( fMakefile
,
2360 "\t-@${rm} %s 2>$(NUL)\n",
2361 reactosInf
.c_str () );
2362 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
2363 OutputCdfileCopyCommands ( bootcdDirectory
);
2364 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2365 fprintf ( fMakefile
,
2366 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2369 fprintf ( fMakefile
,
2374 MingwTestModuleHandler::MingwTestModuleHandler (
2375 const Module
& module_
)
2377 : MingwModuleHandler ( module_
)
2382 MingwTestModuleHandler::Process ()
2384 GenerateTestModuleTarget ();
2388 MingwTestModuleHandler::GenerateTestModuleTarget ()
2390 string
targetMacro ( GetTargetMacro ( module
) );
2391 string workingDirectory
= GetWorkingDirectory ( );
2392 string objectsMacro
= GetObjectsMacro ( module
);
2393 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2394 string libsMacro
= GetLibsMacro ();
2396 GenerateImportLibraryTargetIfNeeded ();
2398 if ( module
.non_if_data
.files
.size () > 0 )
2402 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
2405 if ( module
.cplusplus
)
2410 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2411 module
.entrypoint
.c_str (),
2412 module
.baseaddress
.c_str () );
2413 GenerateLinkerCommand ( dependencies
,
2421 GeneratePhonyTarget();