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 v2s ( const string_list
& v
, int wrap_at
)
50 for ( size_t i
= 0; i
< v
.size(); i
++ )
54 if ( wrap_at
> 0 && wrap_count
++ == wrap_at
)
64 GetTargetMacro ( const Module
& module
, bool with_dollar
)
66 string
s ( module
.name
);
70 return ssprintf ( "$(%s)", s
.c_str() );
74 MingwModuleHandler::MingwModuleHandler (
75 const Module
& module_
)
81 MingwModuleHandler::~MingwModuleHandler()
86 MingwModuleHandler::SetBackend ( MingwBackend
* backend_
)
92 MingwModuleHandler::SetMakefile ( FILE* f
)
98 MingwModuleHandler::SetUsePch ( bool b
)
104 MingwModuleHandler::PassThruCacheDirectory (
105 const string
&file
, bool out
)
107 string
dir ( GetDirectory ( file
) );
108 return backend
->AddDirectoryTarget ( dir
, out
) + SSEP
+ file
;
112 MingwModuleHandler::GetTargetFilename (
113 const Module
& module
,
114 string_list
* pclean_files
)
116 string target
= PassThruCacheDirectory (
117 FixupTargetFilename ( module
.GetPath () ),
121 string_list
& clean_files
= *pclean_files
;
122 CLEAN_FILE ( target
);
128 MingwModuleHandler::GetImportLibraryFilename (
129 const Module
& module
,
130 string_list
* pclean_files
)
132 string target
= PassThruCacheDirectory (
133 FixupTargetFilename ( module
.GetDependencyPath () ),
137 string_list
& clean_files
= *pclean_files
;
138 CLEAN_FILE ( target
);
143 /*static*/ MingwModuleHandler
*
144 MingwModuleHandler::InstanciateHandler (
145 const Module
& module
,
146 MingwBackend
* backend
)
148 MingwModuleHandler
* handler
;
149 switch ( module
.type
)
152 handler
= new MingwBuildToolModuleHandler ( module
);
155 handler
= new MingwStaticLibraryModuleHandler ( module
);
158 handler
= new MingwObjectLibraryModuleHandler ( module
);
161 handler
= new MingwKernelModuleHandler ( module
);
164 handler
= new MingwNativeCUIModuleHandler ( module
);
167 handler
= new MingwWin32CUIModuleHandler ( module
);
170 handler
= new MingwWin32GUIModuleHandler ( module
);
173 handler
= new MingwKernelModeDLLModuleHandler ( module
);
176 handler
= new MingwNativeDLLModuleHandler ( module
);
179 handler
= new MingwWin32DLLModuleHandler ( module
);
181 case KernelModeDriver
:
182 handler
= new MingwKernelModeDriverModuleHandler ( module
);
185 handler
= new MingwBootLoaderModuleHandler ( module
);
188 handler
= new MingwBootSectorModuleHandler ( module
);
191 handler
= new MingwIsoModuleHandler ( module
);
194 handler
= new MingwTestModuleHandler ( module
);
197 throw UnknownModuleTypeException (
198 module
.node
.location
,
206 MingwModuleHandler::GetWorkingDirectory () const
212 MingwModuleHandler::GetBasename ( const string
& filename
) const
214 size_t index
= filename
.find_last_of ( '.' );
215 if ( index
!= string::npos
)
216 return filename
.substr ( 0, index
);
221 MingwModuleHandler::GetActualSourceFilename (
222 const string
& filename
) const
224 string extension
= GetExtension ( filename
);
225 if ( extension
== ".spec" || extension
== "SPEC" )
227 string basename
= GetBasename ( filename
);
228 return basename
+ ".stubs.c";
235 MingwModuleHandler::GetModuleArchiveFilename () const
237 if ( module
.type
== StaticLibrary
)
238 return GetTargetFilename(module
,NULL
);
239 return PassThruCacheDirectory ( ReplaceExtension (
240 FixupTargetFilename ( module
.GetPath () ),
241 ".temp.a" ), false );
245 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
247 string extension
= GetExtension ( file
.name
);
248 return ( extension
== ".spec" || extension
== "SPEC" );
252 MingwModuleHandler::GetImportLibraryDependency (
253 const Module
& importedModule
)
256 if ( importedModule
.type
== ObjectLibrary
)
257 dep
= GetTargetMacro ( importedModule
);
259 dep
= GetImportLibraryFilename ( importedModule
, NULL
);
264 MingwModuleHandler::GetModuleDependencies (
265 string_list
& dependencies
)
267 size_t iend
= module
.dependencies
.size ();
269 // TODO FIXME - do we *really* not want to call
270 // GetDefinitionDependencies() if dependencies.size() == 0 ???
274 for ( size_t i
= 0; i
< iend
; i
++ )
276 const Dependency
& dependency
= *module
.dependencies
[i
];
277 const Module
& dependencyModule
= *dependency
.dependencyModule
;
278 dependencyModule
.GetTargets ( dependencies
);
280 GetDefinitionDependencies ( dependencies
);
284 MingwModuleHandler::GetSourceFilenames (
286 bool includeGeneratedFiles
) const
290 const vector
<File
*>& files
= module
.non_if_data
.files
;
291 for ( i
= 0; i
< files
.size (); i
++ )
293 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *files
[i
] ) )
296 GetActualSourceFilename ( files
[i
]->name
) );
299 // intentionally make a copy so that we can append more work in
300 // the middle of processing without having to go recursive
301 vector
<If
*> v
= module
.non_if_data
.ifs
;
302 for ( i
= 0; i
< v
.size (); i
++ )
306 // check for sub-ifs to add to list
307 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
308 for ( j
= 0; j
< ifs
.size (); j
++ )
309 v
.push_back ( ifs
[j
] );
310 const vector
<File
*>& files
= rIf
.data
.files
;
311 for ( j
= 0; j
< files
.size (); j
++ )
313 File
& file
= *files
[j
];
314 if ( includeGeneratedFiles
|| !IsGeneratedFile ( file
) )
317 GetActualSourceFilename ( file
.name
) );
324 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
325 string_list
& list
) const
327 GetSourceFilenames ( list
, false );
331 MingwModuleHandler::GetObjectFilename (
332 const string
& sourceFilename
,
333 string_list
* pclean_files
) const
336 string extension
= GetExtension ( sourceFilename
);
337 if ( extension
== ".rc" || extension
== ".RC" )
338 newExtension
= ".coff";
339 else if ( extension
== ".spec" || extension
== ".SPEC" )
340 newExtension
= ".stubs.o";
343 string obj_file
= PassThruCacheDirectory (
344 FixupTargetFilename (
346 sourceFilename
, //PrefixFilename(sourceFilename,module.prefix),
351 string_list
& clean_files
= *pclean_files
;
352 CLEAN_FILE ( obj_file
);
358 MingwModuleHandler::GenerateCleanTarget () const
360 if ( 0 == clean_files
.size() )
362 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
363 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
364 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
367 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
368 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
370 fprintf ( fMakefile
, " 2>$(NUL)\n" );
371 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
375 MingwModuleHandler::GetObjectFilenames ()
377 const vector
<File
*>& files
= module
.non_if_data
.files
;
378 if ( files
.size () == 0 )
381 string
objectFilenames ( "" );
382 for ( size_t i
= 0; i
< files
.size (); i
++ )
384 if ( objectFilenames
.size () > 0 )
385 objectFilenames
+= " ";
387 GetObjectFilename ( files
[i
]->name
, NULL
);
389 return objectFilenames
;
393 MingwModuleHandler::GenerateGccDefineParametersFromVector (
394 const vector
<Define
*>& defines
) const
397 for ( size_t i
= 0; i
< defines
.size (); i
++ )
399 Define
& define
= *defines
[i
];
400 if (parameters
.length () > 0)
403 parameters
+= define
.name
;
404 if (define
.value
.length () > 0)
407 parameters
+= define
.value
;
414 MingwModuleHandler::GenerateGccDefineParameters () const
416 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
417 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
418 if ( s
.length () > 0 )
427 MingwModuleHandler::ConcatenatePaths (
429 const string
& path2
) const
431 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
433 if ( path1
[path1
.length ()] == CSEP
)
434 return path1
+ path2
;
436 return path1
+ CSEP
+ path2
;
440 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
443 for ( size_t i
= 0; i
< includes
.size (); i
++ )
445 Include
& include
= *includes
[i
];
446 if ( parameters
.length () > 0 )
448 parameters
+= "-I" + include
.directory
;
454 MingwModuleHandler::GenerateGccIncludeParameters () const
456 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
457 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
458 if ( s
.length () > 0 )
468 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
471 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
473 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
474 if ( parameters
.length () > 0 )
476 parameters
+= compilerFlag
.flag
;
482 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
485 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
487 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
488 if ( parameters
.length () > 0 )
490 parameters
+= linkerFlag
.flag
;
496 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
497 const vector
<Library
*>& libraries
)
499 string
dependencies ( "" );
501 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
503 if ( wrap_count
++ == 5 )
504 dependencies
+= " \\\n\t\t", wrap_count
= 0;
505 else if ( dependencies
.size () > 0 )
507 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->imported_module
);
513 MingwModuleHandler::GenerateLinkerParameters () const
515 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
519 MingwModuleHandler::GenerateMacro (
520 const char* assignmentOperation
,
522 const IfableData
& data
,
523 const vector
<CompilerFlag
*>* compilerFlags
)
531 assignmentOperation
);
533 if ( compilerFlags
!= NULL
)
535 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
536 if ( compilerParameters
.size () > 0 )
541 compilerParameters
.c_str () );
545 for ( i
= 0; i
< data
.includes
.size(); i
++ )
550 data
.includes
[i
]->directory
.c_str() );
552 for ( i
= 0; i
< data
.defines
.size(); i
++ )
554 Define
& d
= *data
.defines
[i
];
559 if ( d
.value
.size() )
565 fprintf ( fMakefile
, "\n" );
569 MingwModuleHandler::GenerateMacros (
570 const char* assignmentOperation
,
571 const IfableData
& data
,
572 const vector
<CompilerFlag
*>* compilerFlags
,
573 const vector
<LinkerFlag
*>* linkerFlags
)
577 if ( data
.includes
.size () > 0 || data
.defines
.size () > 0 )
579 GenerateMacro ( assignmentOperation
,
583 GenerateMacro ( assignmentOperation
,
589 if ( linkerFlags
!= NULL
)
591 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
592 if ( linkerParameters
.size () > 0 )
597 linkerflagsMacro
.c_str (),
599 linkerParameters
.c_str() );
603 if ( data
.libraries
.size () > 0 )
605 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
606 if ( deps
.size () > 0 )
617 const vector
<File
*>& files
= data
.files
;
618 if ( files
.size () > 0 )
620 for ( i
= 0; i
< files
.size (); i
++ )
622 File
& file
= *files
[i
];
627 objectsMacro
.c_str(),
629 file
.name
, NULL
).c_str (),
630 objectsMacro
.c_str() );
636 objectsMacro
.c_str (),
637 assignmentOperation
);
638 for ( i
= 0; i
< files
.size(); i
++ )
640 File
& file
= *files
[i
];
646 ( i
%10 == 9 ? " \\\n\t" : " " ),
648 file
.name
, NULL
).c_str () );
651 fprintf ( fMakefile
, "\n" );
654 const vector
<If
*>& ifs
= data
.ifs
;
655 for ( i
= 0; i
< ifs
.size(); i
++ )
658 if ( rIf
.data
.defines
.size()
659 || rIf
.data
.includes
.size()
660 || rIf
.data
.libraries
.size()
661 || rIf
.data
.files
.size()
662 || rIf
.data
.ifs
.size() )
666 "ifeq (\"$(%s)\",\"%s\")\n",
667 rIf
.property
.c_str(),
682 MingwModuleHandler::GenerateGccCommand (
683 const string
& sourceFilename
,
685 const string
& cflagsMacro
)
687 string deps
= sourceFilename
;
688 if ( module
.pch
&& use_pch
)
689 deps
+= " " + module
.pch
->header
+ ".gch";
690 string objectFilename
= GetObjectFilename (
691 sourceFilename
, NULL
);
694 objectFilename
.c_str (),
696 GetDirectory ( objectFilename
).c_str () );
697 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
699 "\t%s -c $< -o $@ %s\n",
701 cflagsMacro
.c_str () );
705 MingwModuleHandler::GenerateGccAssemblerCommand (
706 const string
& sourceFilename
,
708 const string
& cflagsMacro
)
710 string objectFilename
= GetObjectFilename (
711 sourceFilename
, &clean_files
);
714 objectFilename
.c_str (),
715 sourceFilename
.c_str (),
716 GetDirectory ( objectFilename
).c_str () );
717 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
719 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
721 cflagsMacro
.c_str () );
725 MingwModuleHandler::GenerateNasmCommand (
726 const string
& sourceFilename
,
727 const string
& nasmflagsMacro
)
729 string objectFilename
= GetObjectFilename (
730 sourceFilename
, &clean_files
);
733 objectFilename
.c_str (),
734 sourceFilename
.c_str (),
735 GetDirectory ( objectFilename
).c_str () );
736 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
738 "\t%s -f win32 $< -o $@ %s\n",
740 nasmflagsMacro
.c_str () );
744 MingwModuleHandler::GenerateWindresCommand (
745 const string
& sourceFilename
,
746 const string
& windresflagsMacro
)
748 string objectFilename
=
749 GetObjectFilename ( sourceFilename
, &clean_files
);
750 string rciFilename
= ros_temp
+
751 ReplaceExtension ( sourceFilename
, ".rci" );
752 string resFilename
= ros_temp
+
753 ReplaceExtension ( sourceFilename
, ".res" );
755 "%s: %s %s $(WRC_TARGET)\n",
756 objectFilename
.c_str (),
757 sourceFilename
.c_str (),
758 GetDirectory ( objectFilename
).c_str () );
759 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
761 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
762 windresflagsMacro
.c_str (),
763 sourceFilename
.c_str (),
764 rciFilename
.c_str () );
766 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
767 windresflagsMacro
.c_str (),
768 rciFilename
.c_str (),
769 resFilename
.c_str () );
771 "\t-@${rm} %s 2>$(NUL)\n",
772 rciFilename
.c_str () );
774 "\t${windres} %s -o $@\n",
775 resFilename
.c_str () );
777 "\t-@${rm} %s 2>$(NUL)\n",
778 resFilename
.c_str () );
782 MingwModuleHandler::GenerateWinebuildCommands (
783 const string
& sourceFilename
)
785 string basename
= GetBasename ( sourceFilename
);
787 string def_file
= PassThruCacheDirectory (
788 basename
+ ".spec.def",
790 CLEAN_FILE(def_file
);
792 string stub_file
= PassThruCacheDirectory (
793 basename
+ ".stubs.c",
795 CLEAN_FILE(stub_file
)
798 "%s: %s $(WINEBUILD_TARGET)\n",
800 sourceFilename
.c_str () );
801 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
803 "\t%s --def=%s -o %s\n",
804 "$(Q)$(WINEBUILD_TARGET)",
805 sourceFilename
.c_str (),
811 sourceFilename
.c_str () );
812 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
814 "\t%s --pedll=%s -o %s\n",
815 "$(Q)$(WINEBUILD_TARGET)",
816 sourceFilename
.c_str (),
817 stub_file
.c_str () );
821 MingwModuleHandler::GenerateCommands (
822 const string
& sourceFilename
,
825 const string
& cflagsMacro
,
826 const string
& nasmflagsMacro
,
827 const string
& windresflagsMacro
)
829 string extension
= GetExtension ( sourceFilename
);
830 if ( extension
== ".c" || extension
== ".C" )
832 GenerateGccCommand ( sourceFilename
,
837 else if ( extension
== ".cc" || extension
== ".CC" ||
838 extension
== ".cpp" || extension
== ".CPP" ||
839 extension
== ".cxx" || extension
== ".CXX" )
841 GenerateGccCommand ( sourceFilename
,
846 else if ( extension
== ".s" || extension
== ".S" )
848 GenerateGccAssemblerCommand ( sourceFilename
,
853 else if ( extension
== ".asm" || extension
== ".ASM" )
855 GenerateNasmCommand ( sourceFilename
,
859 else if ( extension
== ".rc" || extension
== ".RC" )
861 GenerateWindresCommand ( sourceFilename
,
865 else if ( extension
== ".spec" || extension
== ".SPEC" )
867 GenerateWinebuildCommands ( sourceFilename
);
868 GenerateGccCommand ( GetActualSourceFilename ( sourceFilename
),
874 throw InvalidOperationException ( __FILE__
,
876 "Unsupported filename extension '%s' in file '%s'",
878 sourceFilename
.c_str () );
882 MingwModuleHandler::GenerateLinkerCommand (
883 const string
& dependencies
,
884 const string
& linker
,
885 const string
& linkerParameters
,
886 const string
& objectsMacro
,
887 const string
& libsMacro
)
889 string
target ( GetTargetMacro ( module
) );
890 string
target_folder ( GetDirectory(GetTargetFilename(module
,NULL
)) );
893 "%s: %s %s $(RSYM_TARGET)\n",
895 dependencies
.c_str (),
896 target_folder
.c_str () );
897 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
898 string
targetName ( module
.GetTargetName () );
899 if ( module
.importLibrary
!= NULL
)
901 string base_tmp
= ros_temp
+ module
.name
+ ".base.tmp";
902 CLEAN_FILE ( base_tmp
);
903 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
904 CLEAN_FILE ( junk_tmp
);
905 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
906 CLEAN_FILE ( temp_exp
);
907 string def_file
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
910 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
912 linkerParameters
.c_str (),
915 objectsMacro
.c_str (),
917 GetLinkerMacro ().c_str () );
920 "\t-@${rm} %s 2>$(NUL)\n",
923 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
925 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
933 "\t-@${rm} %s 2>$(NUL)\n",
937 "\t%s %s %s -o %s %s %s %s\n",
939 linkerParameters
.c_str (),
942 objectsMacro
.c_str (),
944 GetLinkerMacro ().c_str () );
947 "\t-@${rm} %s 2>$(NUL)\n",
953 "\t%s %s -o %s %s %s %s\n",
955 linkerParameters
.c_str (),
957 objectsMacro
.c_str (),
959 GetLinkerMacro ().c_str () );
962 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
964 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
968 MingwModuleHandler::GeneratePhonyTarget() const
970 string
targetMacro ( GetTargetMacro(module
) );
971 fprintf ( fMakefile
, ".PHONY: %s\n\n",
972 targetMacro
.c_str ());
973 fprintf ( fMakefile
, "%s: %s\n",
974 targetMacro
.c_str (),
975 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
979 MingwModuleHandler::GenerateObjectFileTargets (
980 const IfableData
& data
,
983 const string
& cflagsMacro
,
984 const string
& nasmflagsMacro
,
985 const string
& windresflagsMacro
)
989 const vector
<File
*>& files
= data
.files
;
990 for ( i
= 0; i
< files
.size (); i
++ )
992 string sourceFilename
= files
[i
]->name
;
993 GenerateCommands ( sourceFilename
,
1003 const vector
<If
*>& ifs
= data
.ifs
;
1004 for ( i
= 0; i
< ifs
.size(); i
++ )
1006 GenerateObjectFileTargets ( ifs
[i
]->data
,
1011 windresflagsMacro
);
1016 MingwModuleHandler::GenerateObjectFileTargets (
1019 const string
& cflagsMacro
,
1020 const string
& nasmflagsMacro
,
1021 const string
& windresflagsMacro
)
1025 const string
& pch_file
= module
.pch
->header
;
1026 string gch_file
= pch_file
+ ".gch";
1027 CLEAN_FILE(gch_file
);
1035 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1038 "\t%s -o %s %s -g %s\n\n",
1039 ( module
.cplusplus
? cppc
.c_str() : cc
.c_str() ),
1041 cflagsMacro
.c_str(),
1046 GenerateObjectFileTargets ( module
.non_if_data
,
1051 windresflagsMacro
);
1052 fprintf ( fMakefile
, "\n" );
1056 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1057 const string
& objs_macro
) const
1059 string
archiveFilename ( GetModuleArchiveFilename () );
1061 fprintf ( fMakefile
,
1063 archiveFilename
.c_str (),
1064 objs_macro
.c_str (),
1065 GetDirectory(archiveFilename
).c_str() );
1067 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1069 fprintf ( fMakefile
,
1070 "\t%s -rc $@ %s\n\n",
1072 objs_macro
.c_str ());
1074 return archiveFilename
;
1078 MingwModuleHandler::GetCFlagsMacro () const
1080 return ssprintf ( "$(%s_CFLAGS)",
1081 module
.name
.c_str () );
1085 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1087 return ssprintf ( "$(%s_OBJS)",
1088 module
.name
.c_str () );
1092 MingwModuleHandler::GetLinkingDependenciesMacro () const
1094 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1098 MingwModuleHandler::GetLibsMacro () const
1100 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1104 MingwModuleHandler::GetLinkerMacro () const
1106 return ssprintf ( "$(%s_LFLAGS)",
1107 module
.name
.c_str () );
1111 MingwModuleHandler::GenerateTargetMacro ()
1113 fprintf ( fMakefile
,
1115 GetTargetMacro(module
,false).c_str (),
1116 GetTargetFilename(module
,NULL
).c_str () );
1120 MingwModuleHandler::GenerateOtherMacros ()
1122 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1123 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1124 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1125 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1126 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1127 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1128 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1133 &module
.compilerFlags
,
1134 &module
.linkerFlags
);
1136 if ( module
.importLibrary
)
1139 const vector
<File
*>& files
= module
.non_if_data
.files
;
1140 for ( size_t i
= 0; i
< files
.size (); i
++ )
1142 File
& file
= *files
[i
];
1143 string extension
= GetExtension ( file
.name
);
1144 if ( extension
== ".spec" || extension
== ".SPEC" )
1145 GetSpecObjectDependencies ( s
, file
.name
);
1147 if ( s
.size () > 0 )
1152 linkDepsMacro
.c_str() );
1153 for ( size_t i
= 0; i
< s
.size(); i
++ )
1154 fprintf ( fMakefile
,
1157 fprintf ( fMakefile
, "\n" );
1163 "%s += $(PROJECT_CFLAGS)\n",
1164 cflagsMacro
.c_str () );
1168 "%s += $(PROJECT_RCFLAGS)\n",
1169 windresflagsMacro
.c_str () );
1173 "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
1174 module
.name
.c_str () );
1179 linkDepsMacro
.c_str (),
1180 libsMacro
.c_str () );
1182 string cflags
= TypeSpecificCFlags();
1183 if ( cflags
.size() > 0 )
1185 fprintf ( fMakefile
,
1187 cflagsMacro
.c_str (),
1191 string nasmflags
= TypeSpecificNasmFlags();
1192 if ( nasmflags
.size () > 0 )
1194 fprintf ( fMakefile
,
1196 nasmflagsMacro
.c_str (),
1197 nasmflags
.c_str () );
1200 fprintf ( fMakefile
, "\n\n" );
1202 // future references to the macros will be to get their values
1203 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1204 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1205 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1209 MingwModuleHandler::GenerateRules ()
1211 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1212 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1213 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1215 string targetMacro
= GetTargetMacro ( module
);
1217 CLEAN_FILE ( targetMacro
);
1219 // generate phony target for module name
1220 fprintf ( fMakefile
, ".PHONY: %s\n",
1221 module
.name
.c_str () );
1222 fprintf ( fMakefile
, "%s: %s\n\n",
1223 module
.name
.c_str (),
1224 GetTargetMacro ( module
).c_str () );
1226 if ( module
.type
!= ObjectLibrary
)
1229 GenerateArchiveTarget ( ar
, objectsMacro
);
1231 GenerateObjectFileTargets ( cc
,
1235 windresflagsMacro
);
1237 if ( targetMacro
!= ar_target
)
1239 CLEAN_FILE ( ar_target
);
1245 MingwModuleHandler::GetInvocationDependencies (
1246 const Module
& module
,
1247 string_list
& dependencies
)
1249 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1251 Invoke
& invoke
= *module
.invocations
[i
];
1252 if ( invoke
.invokeModule
== &module
)
1253 /* Protect against circular dependencies */
1255 invoke
.GetTargets ( dependencies
);
1260 MingwModuleHandler::GenerateInvocations () const
1262 if ( module
.invocations
.size () == 0 )
1265 size_t iend
= module
.invocations
.size ();
1266 for ( size_t i
= 0; i
< iend
; i
++ )
1268 const Invoke
& invoke
= *module
.invocations
[i
];
1270 if ( invoke
.invokeModule
->type
!= BuildTool
)
1272 throw InvalidBuildFileException ( module
.node
.location
,
1273 "Only modules of type buildtool can be invoked." );
1276 string invokeTarget
= module
.GetInvocationTarget ( i
);
1277 string_list invoke_targets
;
1278 assert ( invoke_targets
.size() );
1279 invoke
.GetTargets ( invoke_targets
);
1280 fprintf ( fMakefile
,
1282 invokeTarget
.c_str () );
1283 fprintf ( fMakefile
,
1285 invokeTarget
.c_str () );
1286 size_t j
, jend
= invoke_targets
.size();
1287 for ( j
= 0; j
< jend
; j
++ )
1289 fprintf ( fMakefile
,
1291 invoke_targets
[i
].c_str () );
1293 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
1294 for ( j
= 1; j
< jend
; j
++ )
1295 fprintf ( fMakefile
,
1297 invoke_targets
[i
].c_str () );
1298 fprintf ( fMakefile
,
1300 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1301 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1302 fprintf ( fMakefile
,
1304 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1305 invoke
.GetParameters ().c_str () );
1310 MingwModuleHandler::GetPreconditionDependenciesName () const
1312 return module
.name
+ "_precondition";
1316 MingwModuleHandler::GetDefaultDependencies (
1317 string_list
& dependencies
) const
1319 /* Avoid circular dependency */
1320 if ( module
.type
!= BuildTool
1321 && module
.name
!= "zlib"
1322 && module
.name
!= "hostzlib" )
1324 dependencies
.push_back ( "$(INIT)" );
1328 MingwModuleHandler::GeneratePreconditionDependencies ()
1330 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
1331 string_list sourceFilenames
;
1332 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
1333 string_list dependencies
;
1334 GetDefaultDependencies ( dependencies
);
1335 GetModuleDependencies ( dependencies
);
1337 GetInvocationDependencies ( module
, dependencies
);
1339 if ( dependencies
.size() )
1341 fprintf ( fMakefile
,
1343 preconditionDependenciesName
.c_str () );
1344 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
1345 fprintf ( fMakefile
,
1347 dependencies
[i
].c_str () );
1348 fprintf ( fMakefile
, "\n\n" );
1351 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
1353 fprintf ( fMakefile
,
1355 sourceFilenames
[i
].c_str(),
1356 preconditionDependenciesName
.c_str ());
1358 fprintf ( fMakefile
, "\n" );
1362 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
1364 if ( module
.importLibrary
!= NULL
)
1366 string
library_target (
1367 GetImportLibraryFilename ( module
, &clean_files
) );
1370 GetDefinitionDependencies ( deps
);
1372 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
1374 fprintf ( fMakefile
, "%s:",
1375 library_target
.c_str () );
1377 size_t i
, iend
= deps
.size();
1378 for ( i
= 0; i
< iend
; i
++ )
1379 fprintf ( fMakefile
, " %s",
1382 fprintf ( fMakefile
, " %s\n",
1383 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1385 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1387 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1388 fprintf ( fMakefile
,
1389 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1390 module
.GetTargetName ().c_str (),
1391 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1392 library_target
.c_str (),
1398 MingwModuleHandler::GetSpecObjectDependencies (
1399 string_list
& dependencies
,
1400 const string
& filename
) const
1402 string basename
= GetBasename ( filename
);
1403 dependencies
.push_back ( basename
+ ".spec.def" );
1404 dependencies
.push_back ( basename
+ ".stubs.c" );
1408 MingwModuleHandler::GetDefinitionDependencies (
1409 string_list
& dependencies
) const
1411 string dkNkmLibNoFixup
= "dk/nkm/lib";
1412 // TODO FIXME - verify this is the correct dependency...
1413 // easiest way to tell is to remove it and see what breaks
1414 /*dependencies += PassThruCacheDirectory (
1415 FixupTargetFilename ( dkNkmLibNoFixup ),
1417 const vector
<File
*>& files
= module
.non_if_data
.files
;
1418 for ( size_t i
= 0; i
< files
.size (); i
++ )
1420 File
& file
= *files
[i
];
1421 string extension
= GetExtension ( file
.name
);
1422 if ( extension
== ".spec" || extension
== ".SPEC" )
1424 GetSpecObjectDependencies ( dependencies
, file
.name
);
1429 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
1430 : MingwModuleHandler ( module_
)
1435 MingwBuildToolModuleHandler::Process ()
1437 GenerateBuildToolModuleTarget ();
1441 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
1443 string
targetMacro ( GetTargetMacro (module
) );
1444 string objectsMacro
= GetObjectsMacro ( module
);
1445 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1446 string libsMacro
= GetLibsMacro ();
1451 if ( module
.cplusplus
)
1452 linker
= "${host_gpp}";
1454 linker
= "${host_gcc}";
1456 fprintf ( fMakefile
, "%s: %s %s %s\n",
1457 targetMacro
.c_str (),
1458 objectsMacro
.c_str (),
1459 linkDepsMacro
.c_str (),
1460 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1461 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1462 fprintf ( fMakefile
,
1463 "\t%s %s -o $@ %s %s\n\n",
1465 GetLinkerMacro ().c_str (),
1466 objectsMacro
.c_str (),
1467 libsMacro
.c_str () );
1471 MingwKernelModuleHandler::MingwKernelModuleHandler (
1472 const Module
& module_
)
1474 : MingwModuleHandler ( module_
)
1479 MingwKernelModuleHandler::Process ()
1481 GenerateKernelModuleTarget ();
1485 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
1487 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1488 string
targetMacro ( GetTargetMacro (module
) ); // i.e. "$(NTOSKRNL_TARGET)"
1489 string workingDirectory
= GetWorkingDirectory ();
1490 string objectsMacro
= GetObjectsMacro ( module
);
1491 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1492 string libsMacro
= GetLibsMacro ();
1493 string base_tmp
= ros_temp
+ module
.name
+ ".base.tmp";
1494 CLEAN_FILE ( base_tmp
);
1495 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
1496 CLEAN_FILE ( junk_tmp
);
1497 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1498 CLEAN_FILE ( temp_exp
);
1499 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",
1500 module
.GetBasePath ().c_str (),
1501 module
.entrypoint
.c_str (),
1502 module
.baseaddress
.c_str () );
1506 GenerateImportLibraryTargetIfNeeded ();
1508 fprintf ( fMakefile
, "%s: %s %s %s $(RSYM_TARGET)\n",
1509 targetMacro
.c_str (),
1510 objectsMacro
.c_str (),
1511 linkDepsMacro
.c_str (),
1512 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1513 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1514 fprintf ( fMakefile
,
1515 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1516 GetLinkerMacro ().c_str (),
1517 gccOptions
.c_str (),
1520 objectsMacro
.c_str (),
1521 linkDepsMacro
.c_str () );
1522 fprintf ( fMakefile
,
1523 "\t-@${rm} %s 2>$(NUL)\n",
1524 junk_tmp
.c_str () );
1525 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1526 fprintf ( fMakefile
,
1527 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1528 targetName
.c_str (),
1532 fprintf ( fMakefile
,
1533 "\t-@${rm} %s 2>$(NUL)\n",
1534 base_tmp
.c_str () );
1535 fprintf ( fMakefile
,
1536 "\t${gcc} %s %s -Wl,%s -o $@ %s %s\n",
1537 GetLinkerMacro ().c_str (),
1538 gccOptions
.c_str (),
1540 objectsMacro
.c_str (),
1541 linkDepsMacro
.c_str () );
1542 fprintf ( fMakefile
,
1543 "\t-@${rm} %s 2>$(NUL)\n",
1544 temp_exp
.c_str () );
1545 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1546 fprintf ( fMakefile
,
1547 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1551 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
1552 const Module
& module_
)
1554 : MingwModuleHandler ( module_
)
1559 MingwStaticLibraryModuleHandler::Process ()
1561 GenerateStaticLibraryModuleTarget ();
1565 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
1571 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
1572 const Module
& module_
)
1574 : MingwModuleHandler ( module_
)
1579 MingwObjectLibraryModuleHandler::Process ()
1581 GenerateObjectLibraryModuleTarget ();
1585 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
1591 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
1592 const Module
& module_
)
1594 : MingwModuleHandler ( module_
)
1599 MingwKernelModeDLLModuleHandler::Process ()
1601 GenerateKernelModeDLLModuleTarget ();
1605 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
1607 string
targetMacro ( GetTargetMacro (module
) );
1608 string workingDirectory
= GetWorkingDirectory ( );
1609 string objectsMacro
= GetObjectsMacro ( module
);
1610 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1611 string libsMacro
= GetLibsMacro ();
1613 GenerateImportLibraryTargetIfNeeded ();
1615 if ( module
.non_if_data
.files
.size () > 0 )
1619 string dependencies
=
1620 objectsMacro
+ " " + linkDepsMacro
;
1622 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1623 module
.entrypoint
.c_str (),
1624 module
.baseaddress
.c_str () );
1625 GenerateLinkerCommand ( dependencies
,
1633 GeneratePhonyTarget();
1638 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
1639 const Module
& module_
)
1641 : MingwModuleHandler ( module_
)
1646 MingwKernelModeDriverModuleHandler::Process ()
1648 GenerateKernelModeDriverModuleTarget ();
1653 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
1655 string
targetMacro ( GetTargetMacro (module
) );
1656 string workingDirectory
= GetWorkingDirectory ();
1657 string objectsMacro
= GetObjectsMacro ( module
);
1658 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1659 string libsMacro
= GetLibsMacro ();
1661 GenerateImportLibraryTargetIfNeeded ();
1663 if ( module
.non_if_data
.files
.size () > 0 )
1667 string dependencies
=
1668 objectsMacro
+ " " + linkDepsMacro
;
1670 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1671 module
.entrypoint
.c_str (),
1672 module
.baseaddress
.c_str () );
1673 GenerateLinkerCommand ( dependencies
,
1681 GeneratePhonyTarget();
1686 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
1687 const Module
& module_
)
1689 : MingwModuleHandler ( module_
)
1694 MingwNativeDLLModuleHandler::Process ()
1696 GenerateNativeDLLModuleTarget ();
1700 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
1702 string
targetMacro ( GetTargetMacro (module
) );
1703 string workingDirectory
= GetWorkingDirectory ( );
1704 string objectsMacro
= GetObjectsMacro ( module
);
1705 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1706 string libsMacro
= GetLibsMacro ();
1708 GenerateImportLibraryTargetIfNeeded ();
1710 if ( module
.non_if_data
.files
.size () > 0 )
1714 string dependencies
=
1715 objectsMacro
+ " " + linkDepsMacro
;
1717 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1718 module
.entrypoint
.c_str (),
1719 module
.baseaddress
.c_str () );
1720 GenerateLinkerCommand ( dependencies
,
1728 GeneratePhonyTarget();
1733 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
1734 const Module
& module_
)
1736 : MingwModuleHandler ( module_
)
1741 MingwNativeCUIModuleHandler::Process ()
1743 GenerateNativeCUIModuleTarget ();
1747 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
1749 string
targetMacro ( GetTargetMacro (module
) );
1750 string workingDirectory
= GetWorkingDirectory ( );
1751 string objectsMacro
= GetObjectsMacro ( module
);
1752 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1753 string libsMacro
= GetLibsMacro ();
1755 GenerateImportLibraryTargetIfNeeded ();
1757 if ( module
.non_if_data
.files
.size () > 0 )
1761 string dependencies
=
1762 objectsMacro
+ " " + linkDepsMacro
;
1764 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1765 module
.entrypoint
.c_str (),
1766 module
.baseaddress
.c_str () );
1767 GenerateLinkerCommand ( dependencies
,
1775 GeneratePhonyTarget();
1780 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
1781 const Module
& module_
)
1783 : MingwModuleHandler ( module_
)
1788 MingwWin32DLLModuleHandler::Process ()
1790 GenerateExtractWineDLLResourcesTarget ();
1791 GenerateWin32DLLModuleTarget ();
1795 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ()
1797 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1798 module
.name
.c_str () );
1799 fprintf ( fMakefile
, "%s_extractresources: $(BIN2RES_TARGET)\n",
1800 module
.name
.c_str () );
1801 const vector
<File
*>& files
= module
.non_if_data
.files
;
1802 for ( size_t i
= 0; i
< files
.size (); i
++ )
1804 File
& file
= *files
[i
];
1805 string extension
= GetExtension ( file
.name
);
1806 if ( extension
== ".rc" || extension
== ".RC" )
1808 string resource
= FixupTargetFilename ( file
.name
);
1809 fprintf ( fMakefile
, "\t$(ECHO_BIN2RES)\n" );
1810 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1811 resource
.c_str () );
1814 fprintf ( fMakefile
, "\n");
1818 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
1820 string
targetMacro ( GetTargetMacro (module
) );
1821 string workingDirectory
= GetWorkingDirectory ( );
1822 string objectsMacro
= GetObjectsMacro ( module
);
1823 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1824 string libsMacro
= GetLibsMacro ();
1826 GenerateImportLibraryTargetIfNeeded ();
1828 if ( module
.non_if_data
.files
.size () > 0 )
1832 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
1835 if ( module
.cplusplus
)
1840 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1841 module
.entrypoint
.c_str (),
1842 module
.baseaddress
.c_str () );
1843 GenerateLinkerCommand ( dependencies
,
1851 GeneratePhonyTarget();
1856 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
1857 const Module
& module_
)
1859 : MingwModuleHandler ( module_
)
1864 MingwWin32CUIModuleHandler::Process ()
1866 GenerateWin32CUIModuleTarget ();
1870 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
1872 string
targetMacro ( GetTargetMacro (module
) );
1873 string workingDirectory
= GetWorkingDirectory ( );
1874 string objectsMacro
= GetObjectsMacro ( module
);
1875 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1876 string libsMacro
= GetLibsMacro ();
1878 GenerateImportLibraryTargetIfNeeded ();
1880 if ( module
.non_if_data
.files
.size () > 0 )
1884 string dependencies
=
1885 objectsMacro
+ " " + linkDepsMacro
;
1888 if ( module
.cplusplus
)
1893 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1894 module
.entrypoint
.c_str (),
1895 module
.baseaddress
.c_str () );
1896 GenerateLinkerCommand ( dependencies
,
1904 GeneratePhonyTarget();
1909 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
1910 const Module
& module_
)
1912 : MingwModuleHandler ( module_
)
1917 MingwWin32GUIModuleHandler::Process ()
1919 GenerateWin32GUIModuleTarget ();
1923 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
1925 string
targetMacro ( GetTargetMacro (module
) );
1926 string workingDirectory
= GetWorkingDirectory ( );
1927 string objectsMacro
= GetObjectsMacro ( module
);
1928 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1929 string libsMacro
= GetLibsMacro ();
1931 GenerateImportLibraryTargetIfNeeded ();
1933 if ( module
.non_if_data
.files
.size () > 0 )
1937 string dependencies
=
1938 objectsMacro
+ " " + linkDepsMacro
;
1941 if ( module
.cplusplus
)
1946 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1947 module
.entrypoint
.c_str (),
1948 module
.baseaddress
.c_str () );
1949 GenerateLinkerCommand ( dependencies
,
1957 GeneratePhonyTarget();
1962 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
1963 const Module
& module_
)
1965 : MingwModuleHandler ( module_
)
1970 MingwBootLoaderModuleHandler::Process ()
1972 GenerateBootLoaderModuleTarget ();
1976 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
1978 string
targetName ( module
.GetTargetName () );
1979 string
targetMacro ( GetTargetMacro (module
) );
1980 string workingDirectory
= GetWorkingDirectory ();
1981 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
1982 CLEAN_FILE ( junk_tmp
);
1983 string objectsMacro
= GetObjectsMacro ( module
);
1984 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1985 string libsMacro
= GetLibsMacro ();
1989 fprintf ( fMakefile
, "%s: %s %s %s\n",
1990 targetMacro
.c_str (),
1991 objectsMacro
.c_str (),
1992 linkDepsMacro
.c_str (),
1993 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1995 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1997 fprintf ( fMakefile
,
1998 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
1999 GetLinkerMacro ().c_str (),
2001 objectsMacro
.c_str (),
2002 linkDepsMacro
.c_str () );
2003 fprintf ( fMakefile
,
2004 "\t${objcopy} -O binary %s $@\n",
2005 junk_tmp
.c_str () );
2006 fprintf ( fMakefile
,
2007 "\t-@${rm} %s 2>$(NUL)\n",
2008 junk_tmp
.c_str () );
2012 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2013 const Module
& module_
)
2015 : MingwModuleHandler ( module_
)
2020 MingwBootSectorModuleHandler::Process ()
2022 GenerateBootSectorModuleTarget ();
2026 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2028 string objectsMacro
= GetObjectsMacro ( module
);
2032 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2033 module
.name
.c_str ());
2034 fprintf ( fMakefile
,
2036 module
.name
.c_str (),
2037 objectsMacro
.c_str () );
2041 MingwIsoModuleHandler::MingwIsoModuleHandler (
2042 const Module
& module_
)
2044 : MingwModuleHandler ( module_
)
2049 MingwIsoModuleHandler::Process ()
2051 GenerateIsoModuleTarget ();
2055 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2056 const string
& bootcdDirectory
)
2058 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2060 const Module
& m
= *module
.project
.modules
[i
];
2061 if ( m
.bootstrap
!= NULL
)
2063 string
targetFilenameNoFixup ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
);
2064 string
targetFilename ( GetTargetMacro ( module
) );
2065 fprintf ( fMakefile
,
2067 m
.GetPath ().c_str (),
2068 targetFilename
.c_str () );
2074 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2075 const string
& bootcdDirectory
)
2077 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2079 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2080 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2081 string targetFilename
= GetTargetMacro(module
);
2082 fprintf ( fMakefile
,
2084 cdfile
.GetPath ().c_str (),
2085 targetFilename
.c_str () );
2090 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
2093 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2095 const Module
& m
= *module
.project
.modules
[i
];
2096 if ( m
.bootstrap
!= NULL
)
2098 string
targetDirectory ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
);
2099 if ( directories
.size () > 0 )
2101 directories
+= PassThruCacheDirectory (
2102 FixupTargetFilename ( targetDirectory
),
2110 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
2113 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2115 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2116 string
targetDirectory ( bootcdDirectory
+ SSEP
+ cdfile
.base
);
2117 if ( directories
.size () > 0 )
2119 directories
+= PassThruCacheDirectory (
2120 FixupTargetFilename ( targetDirectory
),
2127 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
2129 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
2130 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
2135 MingwIsoModuleHandler::GetBootstrapCdFiles (
2136 vector
<string
>& out
) const
2138 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2140 const Module
& m
= *module
.project
.modules
[i
];
2141 if ( m
.bootstrap
!= NULL
)
2142 out
.push_back ( FixupTargetFilename ( m
.GetPath () ) );
2147 MingwIsoModuleHandler::GetNonModuleCdFiles (
2148 vector
<string
>& out
) const
2150 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2152 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2153 out
.push_back ( NormalizeFilename ( cdfile
.GetPath () ) );
2158 MingwIsoModuleHandler::GetCdFiles (
2159 vector
<string
>& out
) const
2161 GetBootstrapCdFiles ( out
);
2162 GetNonModuleCdFiles ( out
);
2166 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2168 string bootcdDirectory
= "cd";
2169 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2170 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2171 string bootcdReactos
= PassThruCacheDirectory (
2172 FixupTargetFilename ( bootcdReactosNoFixup
),
2174 CLEAN_FILE ( bootcdReactos
);
2175 string reactosInf
= ros_temp
+ FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2176 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2177 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
2178 vector
<string
> vCdFiles
;
2179 GetCdFiles ( vCdFiles
);
2180 string cdFiles
= v2s ( vCdFiles
, 5 );
2182 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2183 module
.name
.c_str ());
2184 fprintf ( fMakefile
,
2185 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2186 module
.name
.c_str (),
2188 bootcdReactos
.c_str (),
2189 cdDirectories
.c_str (),
2191 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2192 fprintf ( fMakefile
,
2193 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I\n",
2194 reactosDff
.c_str (),
2195 bootcdReactos
.c_str () );
2196 fprintf ( fMakefile
,
2197 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2198 reactosDff
.c_str (),
2199 reactosInf
.c_str (),
2200 bootcdReactos
.c_str ());
2201 fprintf ( fMakefile
,
2202 "\t-@${rm} %s 2>$(NUL)\n",
2203 reactosInf
.c_str () );
2204 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
2205 OutputCdfileCopyCommands ( bootcdDirectory
);
2206 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2207 fprintf ( fMakefile
,
2208 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2210 bootcdDirectory
.c_str () );
2211 fprintf ( fMakefile
,
2216 MingwTestModuleHandler::MingwTestModuleHandler (
2217 const Module
& module_
)
2219 : MingwModuleHandler ( module_
)
2224 MingwTestModuleHandler::Process ()
2226 GenerateTestModuleTarget ();
2230 MingwTestModuleHandler::GenerateTestModuleTarget ()
2232 string
targetMacro ( GetTargetMacro (module
) );
2233 string workingDirectory
= GetWorkingDirectory ( );
2234 string objectsMacro
= GetObjectsMacro ( module
);
2235 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2236 string libsMacro
= GetLibsMacro ();
2238 GenerateImportLibraryTargetIfNeeded ();
2240 if ( module
.non_if_data
.files
.size () > 0 )
2244 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
2247 if ( module
.cplusplus
)
2252 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2253 module
.entrypoint
.c_str (),
2254 module
.baseaddress
.c_str () );
2255 GenerateLinkerCommand ( dependencies
,
2263 GeneratePhonyTarget();