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
= "$(ROS_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 (
103 const string
&file
, bool out
)
105 string
directory ( GetDirectory ( RemoveVariables ( file
) ) );
106 string generatedFilesDirectory
= backend
->AddDirectoryTarget ( directory
, out
);
107 if ( directory
.find ( generatedFilesDirectory
) != string::npos
)
108 /* This path already includes the generated files directory variable */
111 return generatedFilesDirectory
+ SSEP
+ file
;
115 MingwModuleHandler::GetTargetFilename (
116 const Module
& module
,
117 string_list
* pclean_files
)
119 string target
= PassThruCacheDirectory (
120 FixupTargetFilename ( module
.GetPath () ),
124 string_list
& clean_files
= *pclean_files
;
125 CLEAN_FILE ( target
);
131 MingwModuleHandler::GetImportLibraryFilename (
132 const Module
& module
,
133 string_list
* pclean_files
)
135 string target
= PassThruCacheDirectory (
136 FixupTargetFilename ( module
.GetDependencyPath () ),
140 string_list
& clean_files
= *pclean_files
;
141 CLEAN_FILE ( target
);
146 /*static*/ MingwModuleHandler
*
147 MingwModuleHandler::InstanciateHandler (
148 const Module
& module
,
149 MingwBackend
* backend
)
151 MingwModuleHandler
* handler
;
152 switch ( module
.type
)
155 handler
= new MingwBuildToolModuleHandler ( module
);
158 handler
= new MingwStaticLibraryModuleHandler ( module
);
161 handler
= new MingwObjectLibraryModuleHandler ( module
);
164 handler
= new MingwKernelModuleHandler ( module
);
167 handler
= new MingwNativeCUIModuleHandler ( module
);
170 handler
= new MingwWin32CUIModuleHandler ( module
);
173 handler
= new MingwWin32GUIModuleHandler ( module
);
176 handler
= new MingwKernelModeDLLModuleHandler ( module
);
179 handler
= new MingwNativeDLLModuleHandler ( module
);
182 handler
= new MingwWin32DLLModuleHandler ( module
);
184 case KernelModeDriver
:
185 handler
= new MingwKernelModeDriverModuleHandler ( module
);
188 handler
= new MingwBootLoaderModuleHandler ( module
);
191 handler
= new MingwBootSectorModuleHandler ( module
);
194 handler
= new MingwIsoModuleHandler ( module
);
197 handler
= new MingwTestModuleHandler ( module
);
200 throw UnknownModuleTypeException (
201 module
.node
.location
,
209 MingwModuleHandler::GetWorkingDirectory () const
215 MingwModuleHandler::GetBasename ( const string
& filename
) const
217 size_t index
= filename
.find_last_of ( '.' );
218 if ( index
!= string::npos
)
219 return filename
.substr ( 0, index
);
224 MingwModuleHandler::GetActualSourceFilename (
225 const string
& filename
) const
227 string extension
= GetExtension ( filename
);
228 if ( extension
== ".spec" || extension
== ".SPEC" )
230 string basename
= GetBasename ( filename
);
231 return PassThruCacheDirectory ( FixupTargetFilename ( basename
+ ".stubs.c" ),
239 MingwModuleHandler::GetModuleArchiveFilename () const
241 if ( module
.type
== StaticLibrary
)
242 return GetTargetFilename ( module
, NULL
);
243 return PassThruCacheDirectory ( ReplaceExtension (
244 FixupTargetFilename ( module
.GetPath () ),
245 ".temp.a" ), false );
249 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
251 string extension
= GetExtension ( file
.name
);
252 return ( extension
== ".spec" || extension
== ".SPEC" );
256 MingwModuleHandler::GetImportLibraryDependency (
257 const Module
& importedModule
)
260 if ( importedModule
.type
== ObjectLibrary
)
261 dep
= GetTargetMacro ( importedModule
);
263 dep
= GetImportLibraryFilename ( importedModule
, NULL
);
268 MingwModuleHandler::GetModuleDependencies (
269 string_list
& dependencies
)
271 size_t iend
= module
.dependencies
.size ();
273 // TODO FIXME - do we *really* not want to call
274 // GetDefinitionDependencies() if dependencies.size() == 0 ???
278 for ( size_t i
= 0; i
< iend
; i
++ )
280 const Dependency
& dependency
= *module
.dependencies
[i
];
281 const Module
& dependencyModule
= *dependency
.dependencyModule
;
282 dependencyModule
.GetTargets ( dependencies
);
284 GetDefinitionDependencies ( dependencies
);
288 MingwModuleHandler::GetSourceFilenames (
290 bool includeGeneratedFiles
) const
294 const vector
<File
*>& files
= module
.non_if_data
.files
;
295 for ( i
= 0; i
< files
.size (); i
++ )
297 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *files
[i
] ) )
300 GetActualSourceFilename ( files
[i
]->name
) );
303 // intentionally make a copy so that we can append more work in
304 // the middle of processing without having to go recursive
305 vector
<If
*> v
= module
.non_if_data
.ifs
;
306 for ( i
= 0; i
< v
.size (); i
++ )
310 // check for sub-ifs to add to list
311 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
312 for ( j
= 0; j
< ifs
.size (); j
++ )
313 v
.push_back ( ifs
[j
] );
314 const vector
<File
*>& files
= rIf
.data
.files
;
315 for ( j
= 0; j
< files
.size (); j
++ )
317 File
& file
= *files
[j
];
318 if ( includeGeneratedFiles
|| !IsGeneratedFile ( file
) )
321 GetActualSourceFilename ( file
.name
) );
328 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
329 string_list
& list
) const
331 GetSourceFilenames ( list
, false );
335 MingwModuleHandler::GetObjectFilename (
336 const string
& sourceFilename
,
337 string_list
* pclean_files
) const
340 string extension
= GetExtension ( sourceFilename
);
341 if ( extension
== ".rc" || extension
== ".RC" )
342 newExtension
= ".coff";
343 else if ( extension
== ".spec" || extension
== ".SPEC" )
344 newExtension
= ".stubs.o";
347 string obj_file
= PassThruCacheDirectory (
348 FixupTargetFilename ( ReplaceExtension (
349 RemoveVariables ( sourceFilename
),
354 string_list
& clean_files
= *pclean_files
;
355 CLEAN_FILE ( obj_file
);
361 MingwModuleHandler::GenerateCleanTarget () const
363 if ( 0 == clean_files
.size() )
365 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
366 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
367 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
370 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
371 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
373 fprintf ( fMakefile
, " 2>$(NUL)\n" );
374 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
378 MingwModuleHandler::GetObjectFilenames ()
380 const vector
<File
*>& files
= module
.non_if_data
.files
;
381 if ( files
.size () == 0 )
384 string
objectFilenames ( "" );
385 for ( size_t i
= 0; i
< files
.size (); i
++ )
387 if ( objectFilenames
.size () > 0 )
388 objectFilenames
+= " ";
390 GetObjectFilename ( files
[i
]->name
, NULL
);
392 return objectFilenames
;
396 MingwModuleHandler::GenerateGccDefineParametersFromVector (
397 const vector
<Define
*>& defines
) const
400 for ( size_t i
= 0; i
< defines
.size (); i
++ )
402 Define
& define
= *defines
[i
];
403 if (parameters
.length () > 0)
406 parameters
+= define
.name
;
407 if (define
.value
.length () > 0)
410 parameters
+= define
.value
;
417 MingwModuleHandler::GenerateGccDefineParameters () const
419 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
420 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
421 if ( s
.length () > 0 )
430 MingwModuleHandler::ConcatenatePaths (
432 const string
& path2
) const
434 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
436 if ( path1
[path1
.length ()] == CSEP
)
437 return path1
+ path2
;
439 return path1
+ CSEP
+ path2
;
443 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
446 for ( size_t i
= 0; i
< includes
.size (); i
++ )
448 Include
& include
= *includes
[i
];
449 if ( parameters
.length () > 0 )
451 parameters
+= "-I" + include
.directory
;
457 MingwModuleHandler::GenerateGccIncludeParameters () const
459 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
460 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
461 if ( s
.length () > 0 )
471 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
474 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
476 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
477 if ( parameters
.length () > 0 )
479 parameters
+= compilerFlag
.flag
;
485 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
488 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
490 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
491 if ( parameters
.length () > 0 )
493 parameters
+= linkerFlag
.flag
;
499 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
500 const vector
<Library
*>& libraries
)
502 string
dependencies ( "" );
504 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
506 if ( wrap_count
++ == 5 )
507 dependencies
+= " \\\n\t\t", wrap_count
= 0;
508 else if ( dependencies
.size () > 0 )
510 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->imported_module
);
516 MingwModuleHandler::GenerateLinkerParameters () const
518 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
522 MingwModuleHandler::GenerateMacro (
523 const char* assignmentOperation
,
525 const IfableData
& data
,
526 const vector
<CompilerFlag
*>* compilerFlags
)
534 assignmentOperation
);
536 if ( compilerFlags
!= NULL
)
538 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
539 if ( compilerParameters
.size () > 0 )
544 compilerParameters
.c_str () );
548 for ( i
= 0; i
< data
.includes
.size(); i
++ )
553 data
.includes
[i
]->directory
.c_str() );
555 for ( i
= 0; i
< data
.defines
.size(); i
++ )
557 Define
& d
= *data
.defines
[i
];
562 if ( d
.value
.size() )
568 fprintf ( fMakefile
, "\n" );
572 MingwModuleHandler::GenerateMacros (
573 const char* assignmentOperation
,
574 const IfableData
& data
,
575 const vector
<CompilerFlag
*>* compilerFlags
,
576 const vector
<LinkerFlag
*>* linkerFlags
)
580 if ( data
.includes
.size () > 0 || data
.defines
.size () > 0 )
582 GenerateMacro ( assignmentOperation
,
586 GenerateMacro ( assignmentOperation
,
592 if ( linkerFlags
!= NULL
)
594 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
595 if ( linkerParameters
.size () > 0 )
600 linkerflagsMacro
.c_str (),
602 linkerParameters
.c_str() );
606 if ( data
.libraries
.size () > 0 )
608 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
609 if ( deps
.size () > 0 )
620 const vector
<If
*>& ifs
= data
.ifs
;
621 for ( i
= 0; i
< ifs
.size(); i
++ )
624 if ( rIf
.data
.defines
.size()
625 || rIf
.data
.includes
.size()
626 || rIf
.data
.libraries
.size()
627 || rIf
.data
.files
.size()
628 || rIf
.data
.ifs
.size() )
632 "ifeq (\"$(%s)\",\"%s\")\n",
633 rIf
.property
.c_str(),
648 MingwModuleHandler::GenerateObjectMacros (
649 const char* assignmentOperation
,
650 const IfableData
& data
,
651 const vector
<CompilerFlag
*>* compilerFlags
,
652 const vector
<LinkerFlag
*>* linkerFlags
)
656 const vector
<File
*>& files
= data
.files
;
657 if ( files
.size () > 0 )
659 for ( i
= 0; i
< files
.size (); i
++ )
661 File
& file
= *files
[i
];
666 objectsMacro
.c_str(),
668 file
.name
, NULL
).c_str (),
669 objectsMacro
.c_str() );
675 objectsMacro
.c_str (),
676 assignmentOperation
);
677 for ( i
= 0; i
< files
.size(); i
++ )
679 File
& file
= *files
[i
];
685 ( i
%10 == 9 ? " \\\n\t" : " " ),
687 file
.name
, NULL
).c_str () );
690 fprintf ( fMakefile
, "\n" );
693 const vector
<If
*>& ifs
= data
.ifs
;
694 for ( i
= 0; i
< ifs
.size(); i
++ )
697 if ( rIf
.data
.defines
.size()
698 || rIf
.data
.includes
.size()
699 || rIf
.data
.libraries
.size()
700 || rIf
.data
.files
.size()
701 || rIf
.data
.ifs
.size() )
705 "ifeq (\"$(%s)\",\"%s\")\n",
706 rIf
.property
.c_str(),
708 GenerateObjectMacros (
721 MingwModuleHandler::GenerateGccCommand (
722 const string
& sourceFilename
,
724 const string
& cflagsMacro
)
726 string deps
= sourceFilename
;
727 if ( module
.pch
&& use_pch
)
728 deps
+= " " + module
.pch
->header
+ ".gch";
729 string objectFilename
= GetObjectFilename (
730 sourceFilename
, NULL
);
733 objectFilename
.c_str (),
735 GetDirectory ( objectFilename
).c_str () );
736 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
738 "\t%s -c $< -o $@ %s\n",
740 cflagsMacro
.c_str () );
744 MingwModuleHandler::GenerateGccAssemblerCommand (
745 const string
& sourceFilename
,
747 const string
& cflagsMacro
)
749 string objectFilename
= GetObjectFilename (
750 sourceFilename
, &clean_files
);
753 objectFilename
.c_str (),
754 sourceFilename
.c_str (),
755 GetDirectory ( objectFilename
).c_str () );
756 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
758 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
760 cflagsMacro
.c_str () );
764 MingwModuleHandler::GenerateNasmCommand (
765 const string
& sourceFilename
,
766 const string
& nasmflagsMacro
)
768 string objectFilename
= GetObjectFilename (
769 sourceFilename
, &clean_files
);
772 objectFilename
.c_str (),
773 sourceFilename
.c_str (),
774 GetDirectory ( objectFilename
).c_str () );
775 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
777 "\t%s -f win32 $< -o $@ %s\n",
779 nasmflagsMacro
.c_str () );
783 MingwModuleHandler::GenerateWindresCommand (
784 const string
& sourceFilename
,
785 const string
& windresflagsMacro
)
787 string objectFilename
=
788 GetObjectFilename ( sourceFilename
, &clean_files
);
789 string rciFilename
= ros_temp
+
790 ReplaceExtension ( sourceFilename
, ".rci" );
791 string resFilename
= ros_temp
+
792 ReplaceExtension ( sourceFilename
, ".res" );
794 "%s: %s %s $(WRC_TARGET)\n",
795 objectFilename
.c_str (),
796 sourceFilename
.c_str (),
797 GetDirectory ( objectFilename
).c_str () );
798 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
800 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
801 windresflagsMacro
.c_str (),
802 sourceFilename
.c_str (),
803 rciFilename
.c_str () );
805 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
806 windresflagsMacro
.c_str (),
807 rciFilename
.c_str (),
808 resFilename
.c_str () );
810 "\t-@${rm} %s 2>$(NUL)\n",
811 rciFilename
.c_str () );
813 "\t${windres} %s -o $@\n",
814 resFilename
.c_str () );
816 "\t-@${rm} %s 2>$(NUL)\n",
817 resFilename
.c_str () );
821 MingwModuleHandler::GenerateWinebuildCommands (
822 const string
& sourceFilename
)
824 string basename
= GetBasename ( sourceFilename
);
826 string def_file
= PassThruCacheDirectory (
827 basename
+ ".spec.def",
829 CLEAN_FILE(def_file
);
831 string stub_file
= PassThruCacheDirectory (
832 basename
+ ".stubs.c",
834 CLEAN_FILE(stub_file
)
837 "%s: %s $(WINEBUILD_TARGET)\n",
839 sourceFilename
.c_str () );
840 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
842 "\t%s --def=%s -o %s\n",
843 "$(Q)$(WINEBUILD_TARGET)",
844 sourceFilename
.c_str (),
848 "%s: %s $(WINEBUILD_TARGET)\n",
850 sourceFilename
.c_str () );
851 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
853 "\t%s --pedll=%s -o %s\n",
854 "$(Q)$(WINEBUILD_TARGET)",
855 sourceFilename
.c_str (),
856 stub_file
.c_str () );
860 MingwModuleHandler::GenerateCommands (
861 const string
& sourceFilename
,
864 const string
& cflagsMacro
,
865 const string
& nasmflagsMacro
,
866 const string
& windresflagsMacro
)
868 string extension
= GetExtension ( sourceFilename
);
869 if ( extension
== ".c" || extension
== ".C" )
871 GenerateGccCommand ( sourceFilename
,
876 else if ( extension
== ".cc" || extension
== ".CC" ||
877 extension
== ".cpp" || extension
== ".CPP" ||
878 extension
== ".cxx" || extension
== ".CXX" )
880 GenerateGccCommand ( sourceFilename
,
885 else if ( extension
== ".s" || extension
== ".S" )
887 GenerateGccAssemblerCommand ( sourceFilename
,
892 else if ( extension
== ".asm" || extension
== ".ASM" )
894 GenerateNasmCommand ( sourceFilename
,
898 else if ( extension
== ".rc" || extension
== ".RC" )
900 GenerateWindresCommand ( sourceFilename
,
904 else if ( extension
== ".spec" || extension
== ".SPEC" )
906 GenerateWinebuildCommands ( sourceFilename
);
907 GenerateGccCommand ( GetActualSourceFilename ( sourceFilename
),
913 throw InvalidOperationException ( __FILE__
,
915 "Unsupported filename extension '%s' in file '%s'",
917 sourceFilename
.c_str () );
921 MingwModuleHandler::GenerateBuildMapCode ()
924 "ifeq ($(ROS_BUILDMAP),full)\n" );
926 string mapFilename
= PassThruCacheDirectory (
927 GetBasename ( module
.GetPath () ) + ".map",
929 CLEAN_FILE ( mapFilename
);
932 "\t$(ECHO_OBJDUMP)\n" );
934 "\t$(Q)${objdump} -d -S $@ > %s\n",
935 mapFilename
.c_str () );
940 "ifeq ($(ROS_BUILDMAP),yes)\n" );
945 "\t$(Q)${nm} --numeric-sort $@ > %s\n",
946 mapFilename
.c_str () );
956 MingwModuleHandler::GenerateLinkerCommand (
957 const string
& dependencies
,
958 const string
& linker
,
959 const string
& linkerParameters
,
960 const string
& objectsMacro
,
961 const string
& libsMacro
)
963 string
target ( GetTargetMacro ( module
) );
964 string
target_folder ( GetDirectory ( GetTargetFilename ( module
, NULL
) ) );
967 "%s: %s %s $(RSYM_TARGET)\n",
969 dependencies
.c_str (),
970 target_folder
.c_str () );
971 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
972 string
targetName ( module
.GetTargetName () );
973 if ( module
.importLibrary
!= NULL
)
975 string base_tmp
= ros_temp
+ module
.name
+ ".base.tmp";
976 CLEAN_FILE ( base_tmp
);
977 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
978 CLEAN_FILE ( junk_tmp
);
979 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
980 CLEAN_FILE ( temp_exp
);
981 string def_file
= GetDefinitionFilename ();
984 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
986 linkerParameters
.c_str (),
989 objectsMacro
.c_str (),
991 GetLinkerMacro ().c_str () );
994 "\t-@${rm} %s 2>$(NUL)\n",
997 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
999 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
1000 targetName
.c_str (),
1006 fprintf ( fMakefile
,
1007 "\t-@${rm} %s 2>$(NUL)\n",
1008 base_tmp
.c_str () );
1010 fprintf ( fMakefile
,
1011 "\t%s %s %s -o %s %s %s %s\n",
1013 linkerParameters
.c_str (),
1016 objectsMacro
.c_str (),
1018 GetLinkerMacro ().c_str () );
1020 fprintf ( fMakefile
,
1021 "\t-@${rm} %s 2>$(NUL)\n",
1022 temp_exp
.c_str () );
1026 fprintf ( fMakefile
,
1027 "\t%s %s -o %s %s %s %s\n",
1029 linkerParameters
.c_str (),
1031 objectsMacro
.c_str (),
1033 GetLinkerMacro ().c_str () );
1036 GenerateBuildMapCode ();
1038 fprintf ( fMakefile
,
1039 "\t$(ECHO_RSYM)\n" );
1040 fprintf ( fMakefile
,
1041 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1045 MingwModuleHandler::GeneratePhonyTarget() const
1047 string
targetMacro ( GetTargetMacro(module
) );
1048 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1049 targetMacro
.c_str ());
1050 fprintf ( fMakefile
, "%s: %s\n",
1051 targetMacro
.c_str (),
1052 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1056 MingwModuleHandler::GenerateObjectFileTargets (
1057 const IfableData
& data
,
1060 const string
& cflagsMacro
,
1061 const string
& nasmflagsMacro
,
1062 const string
& windresflagsMacro
)
1066 const vector
<File
*>& files
= data
.files
;
1067 for ( i
= 0; i
< files
.size (); i
++ )
1069 string sourceFilename
= files
[i
]->name
;
1070 GenerateCommands ( sourceFilename
,
1075 windresflagsMacro
);
1076 fprintf ( fMakefile
,
1080 const vector
<If
*>& ifs
= data
.ifs
;
1081 for ( i
= 0; i
< ifs
.size(); i
++ )
1083 GenerateObjectFileTargets ( ifs
[i
]->data
,
1088 windresflagsMacro
);
1093 MingwModuleHandler::GenerateObjectFileTargets (
1096 const string
& cflagsMacro
,
1097 const string
& nasmflagsMacro
,
1098 const string
& windresflagsMacro
)
1102 const string
& pch_file
= module
.pch
->header
;
1103 string gch_file
= pch_file
+ ".gch";
1104 CLEAN_FILE(gch_file
);
1112 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1115 "\t%s -o %s %s -g %s\n\n",
1116 ( module
.cplusplus
? cppc
.c_str() : cc
.c_str() ),
1118 cflagsMacro
.c_str(),
1123 GenerateObjectFileTargets ( module
.non_if_data
,
1128 windresflagsMacro
);
1129 fprintf ( fMakefile
, "\n" );
1133 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1134 const string
& objs_macro
) const
1136 string
archiveFilename ( GetModuleArchiveFilename () );
1138 fprintf ( fMakefile
,
1140 archiveFilename
.c_str (),
1141 objs_macro
.c_str (),
1142 GetDirectory(archiveFilename
).c_str() );
1144 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1146 fprintf ( fMakefile
,
1147 "\t%s -rc $@ %s\n\n",
1149 objs_macro
.c_str ());
1151 return archiveFilename
;
1155 MingwModuleHandler::GetCFlagsMacro () const
1157 return ssprintf ( "$(%s_CFLAGS)",
1158 module
.name
.c_str () );
1162 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1164 return ssprintf ( "$(%s_OBJS)",
1165 module
.name
.c_str () );
1169 MingwModuleHandler::GetLinkingDependenciesMacro () const
1171 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1175 MingwModuleHandler::GetLibsMacro () const
1177 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1181 MingwModuleHandler::GetLinkerMacro () const
1183 return ssprintf ( "$(%s_LFLAGS)",
1184 module
.name
.c_str () );
1188 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1190 if ( module
.type
== ObjectLibrary
)
1191 return GetObjectsMacro ( module
);
1193 return GetTargetFilename ( module
, NULL
);
1197 MingwModuleHandler::GenerateObjectMacro ()
1199 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1201 GenerateObjectMacros (
1204 &module
.compilerFlags
,
1205 &module
.linkerFlags
);
1207 // future references to the macro will be to get its values
1208 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1212 MingwModuleHandler::GenerateTargetMacro ()
1214 fprintf ( fMakefile
,
1216 GetTargetMacro ( module
, false ).c_str (),
1217 GetModuleTargets ( module
).c_str () );
1221 MingwModuleHandler::GenerateOtherMacros ()
1223 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1224 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1225 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1226 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1227 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1228 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1233 &module
.compilerFlags
,
1234 &module
.linkerFlags
);
1236 if ( module
.importLibrary
)
1239 const vector
<File
*>& files
= module
.non_if_data
.files
;
1240 for ( size_t i
= 0; i
< files
.size (); i
++ )
1242 File
& file
= *files
[i
];
1243 string extension
= GetExtension ( file
.name
);
1244 if ( extension
== ".spec" || extension
== ".SPEC" )
1245 GetSpecObjectDependencies ( s
, file
.name
);
1247 if ( s
.size () > 0 )
1252 linkDepsMacro
.c_str() );
1253 for ( size_t i
= 0; i
< s
.size(); i
++ )
1254 fprintf ( fMakefile
,
1257 fprintf ( fMakefile
, "\n" );
1261 string globalCflags
= "-g";
1262 if ( backend
->usePipe
)
1263 globalCflags
+= " -pipe";
1267 "%s += $(PROJECT_CFLAGS) %s\n",
1268 cflagsMacro
.c_str (),
1269 globalCflags
.c_str () );
1273 "%s += $(PROJECT_RCFLAGS)\n",
1274 windresflagsMacro
.c_str () );
1278 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1279 module
.name
.c_str () );
1284 linkDepsMacro
.c_str (),
1285 libsMacro
.c_str () );
1287 string cflags
= TypeSpecificCFlags();
1288 if ( cflags
.size() > 0 )
1290 fprintf ( fMakefile
,
1292 cflagsMacro
.c_str (),
1296 string nasmflags
= TypeSpecificNasmFlags();
1297 if ( nasmflags
.size () > 0 )
1299 fprintf ( fMakefile
,
1301 nasmflagsMacro
.c_str (),
1302 nasmflags
.c_str () );
1305 fprintf ( fMakefile
, "\n\n" );
1307 // future references to the macros will be to get their values
1308 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1309 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1313 MingwModuleHandler::GenerateRules ()
1315 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1316 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1317 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1319 string targetMacro
= GetTargetMacro ( module
);
1321 CLEAN_FILE ( targetMacro
);
1323 // generate phony target for module name
1324 fprintf ( fMakefile
, ".PHONY: %s\n",
1325 module
.name
.c_str () );
1326 fprintf ( fMakefile
, "%s: %s\n\n",
1327 module
.name
.c_str (),
1328 GetTargetMacro ( module
).c_str () );
1330 if ( module
.type
!= ObjectLibrary
)
1332 string
ar_target ( GenerateArchiveTarget ( ar
, objectsMacro
) );
1333 if ( targetMacro
!= ar_target
)
1335 CLEAN_FILE ( ar_target
);
1339 GenerateObjectFileTargets ( cc
,
1343 windresflagsMacro
);
1347 MingwModuleHandler::GetInvocationDependencies (
1348 const Module
& module
,
1349 string_list
& dependencies
)
1351 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1353 Invoke
& invoke
= *module
.invocations
[i
];
1354 if ( invoke
.invokeModule
== &module
)
1355 /* Protect against circular dependencies */
1357 invoke
.GetTargets ( dependencies
);
1362 MingwModuleHandler::GenerateInvocations () const
1364 if ( module
.invocations
.size () == 0 )
1367 size_t iend
= module
.invocations
.size ();
1368 for ( size_t i
= 0; i
< iend
; i
++ )
1370 const Invoke
& invoke
= *module
.invocations
[i
];
1372 if ( invoke
.invokeModule
->type
!= BuildTool
)
1374 throw InvalidBuildFileException ( module
.node
.location
,
1375 "Only modules of type buildtool can be invoked." );
1378 string invokeTarget
= module
.GetInvocationTarget ( i
);
1379 string_list invoke_targets
;
1380 assert ( invoke_targets
.size() );
1381 invoke
.GetTargets ( invoke_targets
);
1382 fprintf ( fMakefile
,
1384 invokeTarget
.c_str () );
1385 fprintf ( fMakefile
,
1387 invokeTarget
.c_str () );
1388 size_t j
, jend
= invoke_targets
.size();
1389 for ( j
= 0; j
< jend
; j
++ )
1391 fprintf ( fMakefile
,
1393 invoke_targets
[i
].c_str () );
1395 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
1396 for ( j
= 1; j
< jend
; j
++ )
1397 fprintf ( fMakefile
,
1399 invoke_targets
[i
].c_str () );
1400 fprintf ( fMakefile
,
1402 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1403 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1404 fprintf ( fMakefile
,
1406 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1407 invoke
.GetParameters ().c_str () );
1412 MingwModuleHandler::GetPreconditionDependenciesName () const
1414 return module
.name
+ "_precondition";
1418 MingwModuleHandler::GetDefaultDependencies (
1419 string_list
& dependencies
) const
1421 /* Avoid circular dependency */
1422 if ( module
.type
!= BuildTool
1423 && module
.name
!= "zlib"
1424 && module
.name
!= "hostzlib" )
1426 dependencies
.push_back ( "$(INIT)" );
1430 MingwModuleHandler::GeneratePreconditionDependencies ()
1432 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
1433 string_list sourceFilenames
;
1434 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
1435 string_list dependencies
;
1436 GetDefaultDependencies ( dependencies
);
1437 GetModuleDependencies ( dependencies
);
1439 GetInvocationDependencies ( module
, dependencies
);
1441 if ( dependencies
.size() )
1443 fprintf ( fMakefile
,
1445 preconditionDependenciesName
.c_str () );
1446 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
1447 fprintf ( fMakefile
,
1449 dependencies
[i
].c_str () );
1450 fprintf ( fMakefile
, "\n\n" );
1453 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
1455 fprintf ( fMakefile
,
1457 sourceFilenames
[i
].c_str(),
1458 preconditionDependenciesName
.c_str ());
1460 fprintf ( fMakefile
, "\n" );
1464 MingwModuleHandler::IsWineModule () const
1466 if ( module
.importLibrary
== NULL
)
1469 size_t index
= module
.importLibrary
->definition
.rfind ( ".spec.def" );
1470 return ( index
!= string::npos
);
1474 MingwModuleHandler::GetDefinitionFilename () const
1476 string defFilename
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
1477 if ( IsWineModule () )
1478 return PassThruCacheDirectory ( defFilename
, false );
1484 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
1486 if ( module
.importLibrary
!= NULL
)
1488 string
library_target (
1489 GetImportLibraryFilename ( module
, &clean_files
) );
1492 GetDefinitionDependencies ( deps
);
1494 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
1496 fprintf ( fMakefile
, "%s:",
1497 library_target
.c_str () );
1499 size_t i
, iend
= deps
.size();
1500 for ( i
= 0; i
< iend
; i
++ )
1501 fprintf ( fMakefile
, " %s",
1504 fprintf ( fMakefile
, " %s\n",
1505 GetDirectory ( GetTargetFilename ( module
, NULL
) ).c_str () );
1507 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1509 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1510 fprintf ( fMakefile
,
1511 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1512 module
.GetTargetName ().c_str (),
1513 GetDefinitionFilename ().c_str (),
1514 library_target
.c_str (),
1520 MingwModuleHandler::GetSpecObjectDependencies (
1521 string_list
& dependencies
,
1522 const string
& filename
) const
1524 string basename
= GetBasename ( filename
);
1525 string defDependency
= PassThruCacheDirectory ( FixupTargetFilename ( basename
+ ".spec.def" ), false );
1526 dependencies
.push_back ( defDependency
);
1527 string stubsDependency
= PassThruCacheDirectory ( FixupTargetFilename ( basename
+ ".stubs.c" ), false );
1528 dependencies
.push_back ( stubsDependency
);
1532 MingwModuleHandler::GetDefinitionDependencies (
1533 string_list
& dependencies
) const
1535 string dkNkmLibNoFixup
= "dk/nkm/lib";
1536 // TODO FIXME - verify this is the correct dependency...
1537 // easiest way to tell is to remove it and see what breaks
1538 /*dependencies += PassThruCacheDirectory (
1539 FixupTargetFilename ( dkNkmLibNoFixup ),
1541 const vector
<File
*>& files
= module
.non_if_data
.files
;
1542 for ( size_t i
= 0; i
< files
.size (); i
++ )
1544 File
& file
= *files
[i
];
1545 string extension
= GetExtension ( file
.name
);
1546 if ( extension
== ".spec" || extension
== ".SPEC" )
1548 GetSpecObjectDependencies ( dependencies
, file
.name
);
1554 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
1555 : MingwModuleHandler ( module_
)
1560 MingwBuildToolModuleHandler::Process ()
1562 GenerateBuildToolModuleTarget ();
1566 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
1568 string
targetMacro ( GetTargetMacro (module
) );
1569 string objectsMacro
= GetObjectsMacro ( module
);
1570 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1571 string libsMacro
= GetLibsMacro ();
1576 if ( module
.cplusplus
)
1577 linker
= "${host_gpp}";
1579 linker
= "${host_gcc}";
1581 fprintf ( fMakefile
, "%s: %s %s %s\n",
1582 targetMacro
.c_str (),
1583 objectsMacro
.c_str (),
1584 linkDepsMacro
.c_str (),
1585 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1586 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1587 fprintf ( fMakefile
,
1588 "\t%s %s -o $@ %s %s\n\n",
1590 GetLinkerMacro ().c_str (),
1591 objectsMacro
.c_str (),
1592 libsMacro
.c_str () );
1596 MingwKernelModuleHandler::MingwKernelModuleHandler (
1597 const Module
& module_
)
1599 : MingwModuleHandler ( module_
)
1604 MingwKernelModuleHandler::Process ()
1606 GenerateKernelModuleTarget ();
1610 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
1612 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1613 string
targetMacro ( GetTargetMacro (module
) ); // i.e. "$(NTOSKRNL_TARGET)"
1614 string workingDirectory
= GetWorkingDirectory ();
1615 string objectsMacro
= GetObjectsMacro ( module
);
1616 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1617 string libsMacro
= GetLibsMacro ();
1618 string base_tmp
= ros_temp
+ module
.name
+ ".base.tmp";
1619 CLEAN_FILE ( base_tmp
);
1620 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
1621 CLEAN_FILE ( junk_tmp
);
1622 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1623 CLEAN_FILE ( temp_exp
);
1624 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",
1625 module
.GetBasePath ().c_str (),
1626 module
.entrypoint
.c_str (),
1627 module
.baseaddress
.c_str () );
1631 GenerateImportLibraryTargetIfNeeded ();
1633 fprintf ( fMakefile
, "%s: %s %s %s $(RSYM_TARGET)\n",
1634 targetMacro
.c_str (),
1635 objectsMacro
.c_str (),
1636 linkDepsMacro
.c_str (),
1637 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1638 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1639 fprintf ( fMakefile
,
1640 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1641 GetLinkerMacro ().c_str (),
1642 gccOptions
.c_str (),
1645 objectsMacro
.c_str (),
1646 linkDepsMacro
.c_str () );
1647 fprintf ( fMakefile
,
1648 "\t-@${rm} %s 2>$(NUL)\n",
1649 junk_tmp
.c_str () );
1650 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1651 fprintf ( fMakefile
,
1652 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1653 targetName
.c_str (),
1657 fprintf ( fMakefile
,
1658 "\t-@${rm} %s 2>$(NUL)\n",
1659 base_tmp
.c_str () );
1660 fprintf ( fMakefile
,
1661 "\t${gcc} %s %s -Wl,%s -o $@ %s %s\n",
1662 GetLinkerMacro ().c_str (),
1663 gccOptions
.c_str (),
1665 objectsMacro
.c_str (),
1666 linkDepsMacro
.c_str () );
1667 fprintf ( fMakefile
,
1668 "\t-@${rm} %s 2>$(NUL)\n",
1669 temp_exp
.c_str () );
1670 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1671 fprintf ( fMakefile
,
1672 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1676 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
1677 const Module
& module_
)
1679 : MingwModuleHandler ( module_
)
1684 MingwStaticLibraryModuleHandler::Process ()
1686 GenerateStaticLibraryModuleTarget ();
1690 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
1696 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
1697 const Module
& module_
)
1699 : MingwModuleHandler ( module_
)
1704 MingwObjectLibraryModuleHandler::Process ()
1706 GenerateObjectLibraryModuleTarget ();
1710 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
1716 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
1717 const Module
& module_
)
1719 : MingwModuleHandler ( module_
)
1724 MingwKernelModeDLLModuleHandler::Process ()
1726 GenerateKernelModeDLLModuleTarget ();
1730 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
1732 string
targetMacro ( GetTargetMacro (module
) );
1733 string workingDirectory
= GetWorkingDirectory ( );
1734 string objectsMacro
= GetObjectsMacro ( module
);
1735 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1736 string libsMacro
= GetLibsMacro ();
1738 GenerateImportLibraryTargetIfNeeded ();
1740 if ( module
.non_if_data
.files
.size () > 0 )
1744 string dependencies
=
1745 objectsMacro
+ " " + linkDepsMacro
;
1747 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1748 module
.entrypoint
.c_str (),
1749 module
.baseaddress
.c_str () );
1750 GenerateLinkerCommand ( dependencies
,
1758 GeneratePhonyTarget();
1763 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
1764 const Module
& module_
)
1766 : MingwModuleHandler ( module_
)
1771 MingwKernelModeDriverModuleHandler::Process ()
1773 GenerateKernelModeDriverModuleTarget ();
1778 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
1780 string
targetMacro ( GetTargetMacro (module
) );
1781 string workingDirectory
= GetWorkingDirectory ();
1782 string objectsMacro
= GetObjectsMacro ( module
);
1783 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1784 string libsMacro
= GetLibsMacro ();
1786 GenerateImportLibraryTargetIfNeeded ();
1788 if ( module
.non_if_data
.files
.size () > 0 )
1792 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
1794 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1795 module
.entrypoint
.c_str (),
1796 module
.baseaddress
.c_str () );
1797 GenerateLinkerCommand ( dependencies
,
1805 GeneratePhonyTarget();
1810 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
1811 const Module
& module_
)
1813 : MingwModuleHandler ( module_
)
1818 MingwNativeDLLModuleHandler::Process ()
1820 GenerateNativeDLLModuleTarget ();
1824 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
1826 string
targetMacro ( GetTargetMacro (module
) );
1827 string workingDirectory
= GetWorkingDirectory ( );
1828 string objectsMacro
= GetObjectsMacro ( module
);
1829 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1830 string libsMacro
= GetLibsMacro ();
1832 GenerateImportLibraryTargetIfNeeded ();
1834 if ( module
.non_if_data
.files
.size () > 0 )
1838 string dependencies
=
1839 objectsMacro
+ " " + linkDepsMacro
;
1841 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1842 module
.entrypoint
.c_str (),
1843 module
.baseaddress
.c_str () );
1844 GenerateLinkerCommand ( dependencies
,
1852 GeneratePhonyTarget();
1857 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
1858 const Module
& module_
)
1860 : MingwModuleHandler ( module_
)
1865 MingwNativeCUIModuleHandler::Process ()
1867 GenerateNativeCUIModuleTarget ();
1871 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
1873 string
targetMacro ( GetTargetMacro (module
) );
1874 string workingDirectory
= GetWorkingDirectory ( );
1875 string objectsMacro
= GetObjectsMacro ( module
);
1876 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1877 string libsMacro
= GetLibsMacro ();
1879 GenerateImportLibraryTargetIfNeeded ();
1881 if ( module
.non_if_data
.files
.size () > 0 )
1885 string dependencies
=
1886 objectsMacro
+ " " + linkDepsMacro
;
1888 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1889 module
.entrypoint
.c_str (),
1890 module
.baseaddress
.c_str () );
1891 GenerateLinkerCommand ( dependencies
,
1899 GeneratePhonyTarget();
1904 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
1905 const Module
& module_
)
1907 : MingwModuleHandler ( module_
)
1912 MingwWin32DLLModuleHandler::Process ()
1914 GenerateExtractWineDLLResourcesTarget ();
1915 GenerateWin32DLLModuleTarget ();
1919 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ()
1921 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1922 module
.name
.c_str () );
1923 fprintf ( fMakefile
, "%s_extractresources: $(BIN2RES_TARGET)\n",
1924 module
.name
.c_str () );
1925 const vector
<File
*>& files
= module
.non_if_data
.files
;
1926 for ( size_t i
= 0; i
< files
.size (); i
++ )
1928 File
& file
= *files
[i
];
1929 string extension
= GetExtension ( file
.name
);
1930 if ( extension
== ".rc" || extension
== ".RC" )
1932 string resource
= FixupTargetFilename ( file
.name
);
1933 fprintf ( fMakefile
, "\t$(ECHO_BIN2RES)\n" );
1934 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1935 resource
.c_str () );
1938 fprintf ( fMakefile
, "\n");
1942 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
1944 string
targetMacro ( GetTargetMacro (module
) );
1945 string workingDirectory
= GetWorkingDirectory ( );
1946 string objectsMacro
= GetObjectsMacro ( module
);
1947 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1948 string libsMacro
= GetLibsMacro ();
1950 GenerateImportLibraryTargetIfNeeded ();
1952 if ( module
.non_if_data
.files
.size () > 0 )
1956 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
1959 if ( module
.cplusplus
)
1964 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1965 module
.entrypoint
.c_str (),
1966 module
.baseaddress
.c_str () );
1967 GenerateLinkerCommand ( dependencies
,
1975 GeneratePhonyTarget();
1980 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
1981 const Module
& module_
)
1983 : MingwModuleHandler ( module_
)
1988 MingwWin32CUIModuleHandler::Process ()
1990 GenerateWin32CUIModuleTarget ();
1994 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
1996 string
targetMacro ( GetTargetMacro (module
) );
1997 string workingDirectory
= GetWorkingDirectory ( );
1998 string objectsMacro
= GetObjectsMacro ( module
);
1999 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2000 string libsMacro
= GetLibsMacro ();
2002 GenerateImportLibraryTargetIfNeeded ();
2004 if ( module
.non_if_data
.files
.size () > 0 )
2008 string dependencies
=
2009 objectsMacro
+ " " + linkDepsMacro
;
2012 if ( module
.cplusplus
)
2017 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2018 module
.entrypoint
.c_str (),
2019 module
.baseaddress
.c_str () );
2020 GenerateLinkerCommand ( dependencies
,
2028 GeneratePhonyTarget();
2033 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2034 const Module
& module_
)
2036 : MingwModuleHandler ( module_
)
2041 MingwWin32GUIModuleHandler::Process ()
2043 GenerateWin32GUIModuleTarget ();
2047 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2049 string
targetMacro ( GetTargetMacro (module
) );
2050 string workingDirectory
= GetWorkingDirectory ( );
2051 string objectsMacro
= GetObjectsMacro ( module
);
2052 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2053 string libsMacro
= GetLibsMacro ();
2055 GenerateImportLibraryTargetIfNeeded ();
2057 if ( module
.non_if_data
.files
.size () > 0 )
2061 string dependencies
=
2062 objectsMacro
+ " " + linkDepsMacro
;
2065 if ( module
.cplusplus
)
2070 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2071 module
.entrypoint
.c_str (),
2072 module
.baseaddress
.c_str () );
2073 GenerateLinkerCommand ( dependencies
,
2081 GeneratePhonyTarget();
2086 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2087 const Module
& module_
)
2089 : MingwModuleHandler ( module_
)
2094 MingwBootLoaderModuleHandler::Process ()
2096 GenerateBootLoaderModuleTarget ();
2100 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2102 string
targetName ( module
.GetTargetName () );
2103 string
targetMacro ( GetTargetMacro (module
) );
2104 string workingDirectory
= GetWorkingDirectory ();
2105 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2106 CLEAN_FILE ( junk_tmp
);
2107 string objectsMacro
= GetObjectsMacro ( module
);
2108 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2109 string libsMacro
= GetLibsMacro ();
2113 fprintf ( fMakefile
, "%s: %s %s %s\n",
2114 targetMacro
.c_str (),
2115 objectsMacro
.c_str (),
2116 linkDepsMacro
.c_str (),
2117 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2119 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2121 fprintf ( fMakefile
,
2122 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2123 GetLinkerMacro ().c_str (),
2125 objectsMacro
.c_str (),
2126 linkDepsMacro
.c_str () );
2127 fprintf ( fMakefile
,
2128 "\t${objcopy} -O binary %s $@\n",
2129 junk_tmp
.c_str () );
2130 fprintf ( fMakefile
,
2131 "\t-@${rm} %s 2>$(NUL)\n",
2132 junk_tmp
.c_str () );
2136 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2137 const Module
& module_
)
2139 : MingwModuleHandler ( module_
)
2144 MingwBootSectorModuleHandler::Process ()
2146 GenerateBootSectorModuleTarget ();
2150 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2152 string objectsMacro
= GetObjectsMacro ( module
);
2156 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2157 module
.name
.c_str ());
2158 fprintf ( fMakefile
,
2160 module
.name
.c_str (),
2161 objectsMacro
.c_str () );
2165 MingwIsoModuleHandler::MingwIsoModuleHandler (
2166 const Module
& module_
)
2168 : MingwModuleHandler ( module_
)
2173 MingwIsoModuleHandler::Process ()
2175 GenerateIsoModuleTarget ();
2179 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2180 const string
& bootcdDirectory
)
2182 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2184 const Module
& m
= *module
.project
.modules
[i
];
2185 if ( m
.bootstrap
!= NULL
)
2187 string
targetFilenameNoFixup ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
);
2188 string
targetFilename ( GetTargetMacro ( module
) );
2189 fprintf ( fMakefile
,
2191 fprintf ( fMakefile
,
2193 m
.GetPath ().c_str (),
2194 targetFilename
.c_str () );
2200 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2201 const string
& bootcdDirectory
)
2203 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2205 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2206 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2207 string targetFilename
= MingwModuleHandler::PassThruCacheDirectory (
2208 FixupTargetFilename ( targetFilenameNoFixup
),
2210 fprintf ( fMakefile
,
2212 fprintf ( fMakefile
,
2214 cdfile
.GetPath ().c_str (),
2215 targetFilename
.c_str () );
2220 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
2223 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2225 const Module
& m
= *module
.project
.modules
[i
];
2226 if ( m
.bootstrap
!= NULL
)
2228 string
targetDirectory ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
);
2229 if ( directories
.size () > 0 )
2231 directories
+= PassThruCacheDirectory (
2232 FixupTargetFilename ( targetDirectory
),
2240 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
2243 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2245 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2246 string
targetDirectory ( bootcdDirectory
+ SSEP
+ cdfile
.base
);
2247 if ( directories
.size () > 0 )
2249 directories
+= PassThruCacheDirectory (
2250 FixupTargetFilename ( targetDirectory
),
2257 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
2259 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
2260 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
2265 MingwIsoModuleHandler::GetBootstrapCdFiles (
2266 vector
<string
>& out
) const
2268 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2270 const Module
& m
= *module
.project
.modules
[i
];
2271 if ( m
.bootstrap
!= NULL
)
2272 out
.push_back ( FixupTargetFilename ( m
.GetPath () ) );
2277 MingwIsoModuleHandler::GetNonModuleCdFiles (
2278 vector
<string
>& out
) const
2280 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2282 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2283 out
.push_back ( NormalizeFilename ( cdfile
.GetPath () ) );
2288 MingwIsoModuleHandler::GetCdFiles (
2289 vector
<string
>& out
) const
2291 GetBootstrapCdFiles ( out
);
2292 GetNonModuleCdFiles ( out
);
2296 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2298 string bootcdDirectory
= "cd";
2299 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2300 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2301 string bootcdReactos
= PassThruCacheDirectory (
2302 FixupTargetFilename ( bootcdReactosNoFixup
),
2304 CLEAN_FILE ( bootcdReactos
);
2305 string reactosInf
= ros_temp
+ FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2306 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2307 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
2308 vector
<string
> vCdFiles
;
2309 GetCdFiles ( vCdFiles
);
2310 string cdFiles
= v2s ( vCdFiles
, 5 );
2312 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2313 module
.name
.c_str ());
2314 fprintf ( fMakefile
,
2315 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2316 module
.name
.c_str (),
2318 bootcdReactos
.c_str (),
2319 cdDirectories
.c_str (),
2321 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2322 fprintf ( fMakefile
,
2323 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I\n",
2324 reactosDff
.c_str (),
2325 bootcdReactos
.c_str () );
2326 fprintf ( fMakefile
,
2327 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2328 reactosDff
.c_str (),
2329 reactosInf
.c_str (),
2330 bootcdReactos
.c_str ());
2331 fprintf ( fMakefile
,
2332 "\t-@${rm} %s 2>$(NUL)\n",
2333 reactosInf
.c_str () );
2334 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
2335 OutputCdfileCopyCommands ( bootcdDirectory
);
2336 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2337 fprintf ( fMakefile
,
2338 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2340 bootcdDirectory
.c_str () );
2341 fprintf ( fMakefile
,
2346 MingwTestModuleHandler::MingwTestModuleHandler (
2347 const Module
& module_
)
2349 : MingwModuleHandler ( module_
)
2354 MingwTestModuleHandler::Process ()
2356 GenerateTestModuleTarget ();
2360 MingwTestModuleHandler::GenerateTestModuleTarget ()
2362 string
targetMacro ( GetTargetMacro (module
) );
2363 string workingDirectory
= GetWorkingDirectory ( );
2364 string objectsMacro
= GetObjectsMacro ( module
);
2365 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2366 string libsMacro
= GetLibsMacro ();
2368 GenerateImportLibraryTargetIfNeeded ();
2370 if ( module
.non_if_data
.files
.size () > 0 )
2374 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
2377 if ( module
.cplusplus
)
2382 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2383 module
.entrypoint
.c_str (),
2384 module
.baseaddress
.c_str () );
2385 GenerateLinkerCommand ( dependencies
,
2393 GeneratePhonyTarget();