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
<If
*>& ifs
= data
.ifs
;
618 for ( i
= 0; i
< ifs
.size(); i
++ )
621 if ( rIf
.data
.defines
.size()
622 || rIf
.data
.includes
.size()
623 || rIf
.data
.libraries
.size()
624 || rIf
.data
.files
.size()
625 || rIf
.data
.ifs
.size() )
629 "ifeq (\"$(%s)\",\"%s\")\n",
630 rIf
.property
.c_str(),
645 MingwModuleHandler::GenerateObjectMacros (
646 const char* assignmentOperation
,
647 const IfableData
& data
,
648 const vector
<CompilerFlag
*>* compilerFlags
,
649 const vector
<LinkerFlag
*>* linkerFlags
)
653 const vector
<File
*>& files
= data
.files
;
654 if ( files
.size () > 0 )
656 for ( i
= 0; i
< files
.size (); i
++ )
658 File
& file
= *files
[i
];
663 objectsMacro
.c_str(),
665 file
.name
, NULL
).c_str (),
666 objectsMacro
.c_str() );
672 objectsMacro
.c_str (),
673 assignmentOperation
);
674 for ( i
= 0; i
< files
.size(); i
++ )
676 File
& file
= *files
[i
];
682 ( i
%10 == 9 ? " \\\n\t" : " " ),
684 file
.name
, NULL
).c_str () );
687 fprintf ( fMakefile
, "\n" );
690 const vector
<If
*>& ifs
= data
.ifs
;
691 for ( i
= 0; i
< ifs
.size(); i
++ )
694 if ( rIf
.data
.defines
.size()
695 || rIf
.data
.includes
.size()
696 || rIf
.data
.libraries
.size()
697 || rIf
.data
.files
.size()
698 || rIf
.data
.ifs
.size() )
702 "ifeq (\"$(%s)\",\"%s\")\n",
703 rIf
.property
.c_str(),
705 GenerateObjectMacros (
718 MingwModuleHandler::GenerateGccCommand (
719 const string
& sourceFilename
,
721 const string
& cflagsMacro
)
723 string deps
= sourceFilename
;
724 if ( module
.pch
&& use_pch
)
725 deps
+= " " + module
.pch
->header
+ ".gch";
726 string objectFilename
= GetObjectFilename (
727 sourceFilename
, NULL
);
730 objectFilename
.c_str (),
732 GetDirectory ( objectFilename
).c_str () );
733 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
735 "\t%s -c $< -o $@ %s\n",
737 cflagsMacro
.c_str () );
741 MingwModuleHandler::GenerateGccAssemblerCommand (
742 const string
& sourceFilename
,
744 const string
& cflagsMacro
)
746 string objectFilename
= GetObjectFilename (
747 sourceFilename
, &clean_files
);
750 objectFilename
.c_str (),
751 sourceFilename
.c_str (),
752 GetDirectory ( objectFilename
).c_str () );
753 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
755 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
757 cflagsMacro
.c_str () );
761 MingwModuleHandler::GenerateNasmCommand (
762 const string
& sourceFilename
,
763 const string
& nasmflagsMacro
)
765 string objectFilename
= GetObjectFilename (
766 sourceFilename
, &clean_files
);
769 objectFilename
.c_str (),
770 sourceFilename
.c_str (),
771 GetDirectory ( objectFilename
).c_str () );
772 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
774 "\t%s -f win32 $< -o $@ %s\n",
776 nasmflagsMacro
.c_str () );
780 MingwModuleHandler::GenerateWindresCommand (
781 const string
& sourceFilename
,
782 const string
& windresflagsMacro
)
784 string objectFilename
=
785 GetObjectFilename ( sourceFilename
, &clean_files
);
786 string rciFilename
= ros_temp
+
787 ReplaceExtension ( sourceFilename
, ".rci" );
788 string resFilename
= ros_temp
+
789 ReplaceExtension ( sourceFilename
, ".res" );
791 "%s: %s %s $(WRC_TARGET)\n",
792 objectFilename
.c_str (),
793 sourceFilename
.c_str (),
794 GetDirectory ( objectFilename
).c_str () );
795 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
797 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
798 windresflagsMacro
.c_str (),
799 sourceFilename
.c_str (),
800 rciFilename
.c_str () );
802 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
803 windresflagsMacro
.c_str (),
804 rciFilename
.c_str (),
805 resFilename
.c_str () );
807 "\t-@${rm} %s 2>$(NUL)\n",
808 rciFilename
.c_str () );
810 "\t${windres} %s -o $@\n",
811 resFilename
.c_str () );
813 "\t-@${rm} %s 2>$(NUL)\n",
814 resFilename
.c_str () );
818 MingwModuleHandler::GenerateWinebuildCommands (
819 const string
& sourceFilename
)
821 string basename
= GetBasename ( sourceFilename
);
823 string def_file
= PassThruCacheDirectory (
824 basename
+ ".spec.def",
826 CLEAN_FILE(def_file
);
828 string stub_file
= PassThruCacheDirectory (
829 basename
+ ".stubs.c",
831 CLEAN_FILE(stub_file
)
834 "%s: %s $(WINEBUILD_TARGET)\n",
836 sourceFilename
.c_str () );
837 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
839 "\t%s --def=%s -o %s\n",
840 "$(Q)$(WINEBUILD_TARGET)",
841 sourceFilename
.c_str (),
847 sourceFilename
.c_str () );
848 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
850 "\t%s --pedll=%s -o %s\n",
851 "$(Q)$(WINEBUILD_TARGET)",
852 sourceFilename
.c_str (),
853 stub_file
.c_str () );
857 MingwModuleHandler::GenerateCommands (
858 const string
& sourceFilename
,
861 const string
& cflagsMacro
,
862 const string
& nasmflagsMacro
,
863 const string
& windresflagsMacro
)
865 string extension
= GetExtension ( sourceFilename
);
866 if ( extension
== ".c" || extension
== ".C" )
868 GenerateGccCommand ( sourceFilename
,
873 else if ( extension
== ".cc" || extension
== ".CC" ||
874 extension
== ".cpp" || extension
== ".CPP" ||
875 extension
== ".cxx" || extension
== ".CXX" )
877 GenerateGccCommand ( sourceFilename
,
882 else if ( extension
== ".s" || extension
== ".S" )
884 GenerateGccAssemblerCommand ( sourceFilename
,
889 else if ( extension
== ".asm" || extension
== ".ASM" )
891 GenerateNasmCommand ( sourceFilename
,
895 else if ( extension
== ".rc" || extension
== ".RC" )
897 GenerateWindresCommand ( sourceFilename
,
901 else if ( extension
== ".spec" || extension
== ".SPEC" )
903 GenerateWinebuildCommands ( sourceFilename
);
904 GenerateGccCommand ( GetActualSourceFilename ( sourceFilename
),
910 throw InvalidOperationException ( __FILE__
,
912 "Unsupported filename extension '%s' in file '%s'",
914 sourceFilename
.c_str () );
918 MingwModuleHandler::GenerateLinkerCommand (
919 const string
& dependencies
,
920 const string
& linker
,
921 const string
& linkerParameters
,
922 const string
& objectsMacro
,
923 const string
& libsMacro
)
925 string
target ( GetTargetMacro ( module
) );
926 string
target_folder ( GetDirectory ( GetTargetFilename ( module
, NULL
) ) );
929 "%s: %s %s $(RSYM_TARGET)\n",
931 dependencies
.c_str (),
932 target_folder
.c_str () );
933 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
934 string
targetName ( module
.GetTargetName () );
935 if ( module
.importLibrary
!= NULL
)
937 string base_tmp
= ros_temp
+ module
.name
+ ".base.tmp";
938 CLEAN_FILE ( base_tmp
);
939 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
940 CLEAN_FILE ( junk_tmp
);
941 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
942 CLEAN_FILE ( temp_exp
);
943 string def_file
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
946 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
948 linkerParameters
.c_str (),
951 objectsMacro
.c_str (),
953 GetLinkerMacro ().c_str () );
956 "\t-@${rm} %s 2>$(NUL)\n",
959 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
961 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
969 "\t-@${rm} %s 2>$(NUL)\n",
973 "\t%s %s %s -o %s %s %s %s\n",
975 linkerParameters
.c_str (),
978 objectsMacro
.c_str (),
980 GetLinkerMacro ().c_str () );
983 "\t-@${rm} %s 2>$(NUL)\n",
989 "\t%s %s -o %s %s %s %s\n",
991 linkerParameters
.c_str (),
993 objectsMacro
.c_str (),
995 GetLinkerMacro ().c_str () );
998 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1000 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1004 MingwModuleHandler::GeneratePhonyTarget() const
1006 string
targetMacro ( GetTargetMacro(module
) );
1007 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1008 targetMacro
.c_str ());
1009 fprintf ( fMakefile
, "%s: %s\n",
1010 targetMacro
.c_str (),
1011 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1015 MingwModuleHandler::GenerateObjectFileTargets (
1016 const IfableData
& data
,
1019 const string
& cflagsMacro
,
1020 const string
& nasmflagsMacro
,
1021 const string
& windresflagsMacro
)
1025 const vector
<File
*>& files
= data
.files
;
1026 for ( i
= 0; i
< files
.size (); i
++ )
1028 string sourceFilename
= files
[i
]->name
;
1029 GenerateCommands ( sourceFilename
,
1034 windresflagsMacro
);
1035 fprintf ( fMakefile
,
1039 const vector
<If
*>& ifs
= data
.ifs
;
1040 for ( i
= 0; i
< ifs
.size(); i
++ )
1042 GenerateObjectFileTargets ( ifs
[i
]->data
,
1047 windresflagsMacro
);
1052 MingwModuleHandler::GenerateObjectFileTargets (
1055 const string
& cflagsMacro
,
1056 const string
& nasmflagsMacro
,
1057 const string
& windresflagsMacro
)
1061 const string
& pch_file
= module
.pch
->header
;
1062 string gch_file
= pch_file
+ ".gch";
1063 CLEAN_FILE(gch_file
);
1071 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1074 "\t%s -o %s %s -g %s\n\n",
1075 ( module
.cplusplus
? cppc
.c_str() : cc
.c_str() ),
1077 cflagsMacro
.c_str(),
1082 GenerateObjectFileTargets ( module
.non_if_data
,
1087 windresflagsMacro
);
1088 fprintf ( fMakefile
, "\n" );
1092 MingwModuleHandler::GenerateArchiveTarget ( const string
& ar
,
1093 const string
& objs_macro
) const
1095 string
archiveFilename ( GetModuleArchiveFilename () );
1097 fprintf ( fMakefile
,
1099 archiveFilename
.c_str (),
1100 objs_macro
.c_str (),
1101 GetDirectory(archiveFilename
).c_str() );
1103 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1105 fprintf ( fMakefile
,
1106 "\t%s -rc $@ %s\n\n",
1108 objs_macro
.c_str ());
1110 return archiveFilename
;
1114 MingwModuleHandler::GetCFlagsMacro () const
1116 return ssprintf ( "$(%s_CFLAGS)",
1117 module
.name
.c_str () );
1121 MingwModuleHandler::GetObjectsMacro ( const Module
& module
)
1123 return ssprintf ( "$(%s_OBJS)",
1124 module
.name
.c_str () );
1128 MingwModuleHandler::GetLinkingDependenciesMacro () const
1130 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1134 MingwModuleHandler::GetLibsMacro () const
1136 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1140 MingwModuleHandler::GetLinkerMacro () const
1142 return ssprintf ( "$(%s_LFLAGS)",
1143 module
.name
.c_str () );
1147 MingwModuleHandler::GetModuleTargets ( const Module
& module
)
1149 if ( module
.type
== ObjectLibrary
)
1150 return GetObjectsMacro ( module
);
1152 return GetTargetFilename ( module
, NULL
);
1156 MingwModuleHandler::GenerateObjectMacro ()
1158 objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1160 GenerateObjectMacros (
1163 &module
.compilerFlags
,
1164 &module
.linkerFlags
);
1166 // future references to the macro will be to get its values
1167 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1171 MingwModuleHandler::GenerateTargetMacro ()
1173 fprintf ( fMakefile
,
1175 GetTargetMacro ( module
, false ).c_str (),
1176 GetModuleTargets ( module
).c_str () );
1180 MingwModuleHandler::GenerateOtherMacros ()
1182 cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1183 nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1184 windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1185 linkerflagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1186 libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1187 linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1192 &module
.compilerFlags
,
1193 &module
.linkerFlags
);
1195 if ( module
.importLibrary
)
1198 const vector
<File
*>& files
= module
.non_if_data
.files
;
1199 for ( size_t i
= 0; i
< files
.size (); i
++ )
1201 File
& file
= *files
[i
];
1202 string extension
= GetExtension ( file
.name
);
1203 if ( extension
== ".spec" || extension
== ".SPEC" )
1204 GetSpecObjectDependencies ( s
, file
.name
);
1206 if ( s
.size () > 0 )
1211 linkDepsMacro
.c_str() );
1212 for ( size_t i
= 0; i
< s
.size(); i
++ )
1213 fprintf ( fMakefile
,
1216 fprintf ( fMakefile
, "\n" );
1222 "%s += $(PROJECT_CFLAGS)\n",
1223 cflagsMacro
.c_str () );
1227 "%s += $(PROJECT_RCFLAGS)\n",
1228 windresflagsMacro
.c_str () );
1232 "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
1233 module
.name
.c_str () );
1238 linkDepsMacro
.c_str (),
1239 libsMacro
.c_str () );
1241 string cflags
= TypeSpecificCFlags();
1242 if ( cflags
.size() > 0 )
1244 fprintf ( fMakefile
,
1246 cflagsMacro
.c_str (),
1250 string nasmflags
= TypeSpecificNasmFlags();
1251 if ( nasmflags
.size () > 0 )
1253 fprintf ( fMakefile
,
1255 nasmflagsMacro
.c_str (),
1256 nasmflags
.c_str () );
1259 fprintf ( fMakefile
, "\n\n" );
1261 // future references to the macros will be to get their values
1262 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1263 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1267 MingwModuleHandler::GenerateRules ()
1269 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1270 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1271 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1273 string targetMacro
= GetTargetMacro ( module
);
1275 CLEAN_FILE ( targetMacro
);
1277 // generate phony target for module name
1278 fprintf ( fMakefile
, ".PHONY: %s\n",
1279 module
.name
.c_str () );
1280 fprintf ( fMakefile
, "%s: %s\n\n",
1281 module
.name
.c_str (),
1282 GetTargetMacro ( module
).c_str () );
1285 if ( module
.type
!= ObjectLibrary
)
1286 ar_target
= GenerateArchiveTarget ( ar
, objectsMacro
);
1288 GenerateObjectFileTargets ( cc
,
1292 windresflagsMacro
);
1294 if ( module
.type
!= ObjectLibrary
)
1296 if ( targetMacro
!= ar_target
)
1298 CLEAN_FILE ( ar_target
);
1304 MingwModuleHandler::GetInvocationDependencies (
1305 const Module
& module
,
1306 string_list
& dependencies
)
1308 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1310 Invoke
& invoke
= *module
.invocations
[i
];
1311 if ( invoke
.invokeModule
== &module
)
1312 /* Protect against circular dependencies */
1314 invoke
.GetTargets ( dependencies
);
1319 MingwModuleHandler::GenerateInvocations () const
1321 if ( module
.invocations
.size () == 0 )
1324 size_t iend
= module
.invocations
.size ();
1325 for ( size_t i
= 0; i
< iend
; i
++ )
1327 const Invoke
& invoke
= *module
.invocations
[i
];
1329 if ( invoke
.invokeModule
->type
!= BuildTool
)
1331 throw InvalidBuildFileException ( module
.node
.location
,
1332 "Only modules of type buildtool can be invoked." );
1335 string invokeTarget
= module
.GetInvocationTarget ( i
);
1336 string_list invoke_targets
;
1337 assert ( invoke_targets
.size() );
1338 invoke
.GetTargets ( invoke_targets
);
1339 fprintf ( fMakefile
,
1341 invokeTarget
.c_str () );
1342 fprintf ( fMakefile
,
1344 invokeTarget
.c_str () );
1345 size_t j
, jend
= invoke_targets
.size();
1346 for ( j
= 0; j
< jend
; j
++ )
1348 fprintf ( fMakefile
,
1350 invoke_targets
[i
].c_str () );
1352 fprintf ( fMakefile
, "\n\n%s", invoke_targets
[0].c_str () );
1353 for ( j
= 1; j
< jend
; j
++ )
1354 fprintf ( fMakefile
,
1356 invoke_targets
[i
].c_str () );
1357 fprintf ( fMakefile
,
1359 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1360 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1361 fprintf ( fMakefile
,
1363 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1364 invoke
.GetParameters ().c_str () );
1369 MingwModuleHandler::GetPreconditionDependenciesName () const
1371 return module
.name
+ "_precondition";
1375 MingwModuleHandler::GetDefaultDependencies (
1376 string_list
& dependencies
) const
1378 /* Avoid circular dependency */
1379 if ( module
.type
!= BuildTool
1380 && module
.name
!= "zlib"
1381 && module
.name
!= "hostzlib" )
1383 dependencies
.push_back ( "$(INIT)" );
1387 MingwModuleHandler::GeneratePreconditionDependencies ()
1389 string preconditionDependenciesName
= GetPreconditionDependenciesName ();
1390 string_list sourceFilenames
;
1391 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames
);
1392 string_list dependencies
;
1393 GetDefaultDependencies ( dependencies
);
1394 GetModuleDependencies ( dependencies
);
1396 GetInvocationDependencies ( module
, dependencies
);
1398 if ( dependencies
.size() )
1400 fprintf ( fMakefile
,
1402 preconditionDependenciesName
.c_str () );
1403 for ( size_t i
= 0; i
< dependencies
.size(); i
++ )
1404 fprintf ( fMakefile
,
1406 dependencies
[i
].c_str () );
1407 fprintf ( fMakefile
, "\n\n" );
1410 for ( size_t i
= 0; i
< sourceFilenames
.size(); i
++ )
1412 fprintf ( fMakefile
,
1414 sourceFilenames
[i
].c_str(),
1415 preconditionDependenciesName
.c_str ());
1417 fprintf ( fMakefile
, "\n" );
1421 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
1423 if ( module
.importLibrary
!= NULL
)
1425 string
library_target (
1426 GetImportLibraryFilename ( module
, &clean_files
) );
1429 GetDefinitionDependencies ( deps
);
1431 fprintf ( fMakefile
, "# IMPORT LIBRARY RULE:\n" );
1433 fprintf ( fMakefile
, "%s:",
1434 library_target
.c_str () );
1436 size_t i
, iend
= deps
.size();
1437 for ( i
= 0; i
< iend
; i
++ )
1438 fprintf ( fMakefile
, " %s",
1441 fprintf ( fMakefile
, " %s\n",
1442 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1444 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1446 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1447 fprintf ( fMakefile
,
1448 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1449 module
.GetTargetName ().c_str (),
1450 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1451 library_target
.c_str (),
1457 MingwModuleHandler::GetSpecObjectDependencies (
1458 string_list
& dependencies
,
1459 const string
& filename
) const
1461 string basename
= GetBasename ( filename
);
1462 dependencies
.push_back ( basename
+ ".spec.def" );
1463 dependencies
.push_back ( basename
+ ".stubs.c" );
1467 MingwModuleHandler::GetDefinitionDependencies (
1468 string_list
& dependencies
) const
1470 string dkNkmLibNoFixup
= "dk/nkm/lib";
1471 // TODO FIXME - verify this is the correct dependency...
1472 // easiest way to tell is to remove it and see what breaks
1473 /*dependencies += PassThruCacheDirectory (
1474 FixupTargetFilename ( dkNkmLibNoFixup ),
1476 const vector
<File
*>& files
= module
.non_if_data
.files
;
1477 for ( size_t i
= 0; i
< files
.size (); i
++ )
1479 File
& file
= *files
[i
];
1480 string extension
= GetExtension ( file
.name
);
1481 if ( extension
== ".spec" || extension
== ".SPEC" )
1483 GetSpecObjectDependencies ( dependencies
, file
.name
);
1488 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module
& module_
)
1489 : MingwModuleHandler ( module_
)
1494 MingwBuildToolModuleHandler::Process ()
1496 GenerateBuildToolModuleTarget ();
1500 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
1502 string
targetMacro ( GetTargetMacro (module
) );
1503 string objectsMacro
= GetObjectsMacro ( module
);
1504 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1505 string libsMacro
= GetLibsMacro ();
1510 if ( module
.cplusplus
)
1511 linker
= "${host_gpp}";
1513 linker
= "${host_gcc}";
1515 fprintf ( fMakefile
, "%s: %s %s %s\n",
1516 targetMacro
.c_str (),
1517 objectsMacro
.c_str (),
1518 linkDepsMacro
.c_str (),
1519 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1520 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1521 fprintf ( fMakefile
,
1522 "\t%s %s -o $@ %s %s\n\n",
1524 GetLinkerMacro ().c_str (),
1525 objectsMacro
.c_str (),
1526 libsMacro
.c_str () );
1530 MingwKernelModuleHandler::MingwKernelModuleHandler (
1531 const Module
& module_
)
1533 : MingwModuleHandler ( module_
)
1538 MingwKernelModuleHandler::Process ()
1540 GenerateKernelModuleTarget ();
1544 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
1546 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1547 string
targetMacro ( GetTargetMacro (module
) ); // i.e. "$(NTOSKRNL_TARGET)"
1548 string workingDirectory
= GetWorkingDirectory ();
1549 string objectsMacro
= GetObjectsMacro ( module
);
1550 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1551 string libsMacro
= GetLibsMacro ();
1552 string base_tmp
= ros_temp
+ module
.name
+ ".base.tmp";
1553 CLEAN_FILE ( base_tmp
);
1554 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
1555 CLEAN_FILE ( junk_tmp
);
1556 string temp_exp
= ros_temp
+ module
.name
+ ".temp.exp";
1557 CLEAN_FILE ( temp_exp
);
1558 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",
1559 module
.GetBasePath ().c_str (),
1560 module
.entrypoint
.c_str (),
1561 module
.baseaddress
.c_str () );
1565 GenerateImportLibraryTargetIfNeeded ();
1567 fprintf ( fMakefile
, "%s: %s %s %s $(RSYM_TARGET)\n",
1568 targetMacro
.c_str (),
1569 objectsMacro
.c_str (),
1570 linkDepsMacro
.c_str (),
1571 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
1572 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1573 fprintf ( fMakefile
,
1574 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1575 GetLinkerMacro ().c_str (),
1576 gccOptions
.c_str (),
1579 objectsMacro
.c_str (),
1580 linkDepsMacro
.c_str () );
1581 fprintf ( fMakefile
,
1582 "\t-@${rm} %s 2>$(NUL)\n",
1583 junk_tmp
.c_str () );
1584 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1585 fprintf ( fMakefile
,
1586 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1587 targetName
.c_str (),
1591 fprintf ( fMakefile
,
1592 "\t-@${rm} %s 2>$(NUL)\n",
1593 base_tmp
.c_str () );
1594 fprintf ( fMakefile
,
1595 "\t${gcc} %s %s -Wl,%s -o $@ %s %s\n",
1596 GetLinkerMacro ().c_str (),
1597 gccOptions
.c_str (),
1599 objectsMacro
.c_str (),
1600 linkDepsMacro
.c_str () );
1601 fprintf ( fMakefile
,
1602 "\t-@${rm} %s 2>$(NUL)\n",
1603 temp_exp
.c_str () );
1604 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1605 fprintf ( fMakefile
,
1606 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1610 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
1611 const Module
& module_
)
1613 : MingwModuleHandler ( module_
)
1618 MingwStaticLibraryModuleHandler::Process ()
1620 GenerateStaticLibraryModuleTarget ();
1624 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
1630 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
1631 const Module
& module_
)
1633 : MingwModuleHandler ( module_
)
1638 MingwObjectLibraryModuleHandler::Process ()
1640 GenerateObjectLibraryModuleTarget ();
1644 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
1650 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
1651 const Module
& module_
)
1653 : MingwModuleHandler ( module_
)
1658 MingwKernelModeDLLModuleHandler::Process ()
1660 GenerateKernelModeDLLModuleTarget ();
1664 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
1666 string
targetMacro ( GetTargetMacro (module
) );
1667 string workingDirectory
= GetWorkingDirectory ( );
1668 string objectsMacro
= GetObjectsMacro ( module
);
1669 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1670 string libsMacro
= GetLibsMacro ();
1672 GenerateImportLibraryTargetIfNeeded ();
1674 if ( module
.non_if_data
.files
.size () > 0 )
1678 string dependencies
=
1679 objectsMacro
+ " " + linkDepsMacro
;
1681 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1682 module
.entrypoint
.c_str (),
1683 module
.baseaddress
.c_str () );
1684 GenerateLinkerCommand ( dependencies
,
1692 GeneratePhonyTarget();
1697 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
1698 const Module
& module_
)
1700 : MingwModuleHandler ( module_
)
1705 MingwKernelModeDriverModuleHandler::Process ()
1707 GenerateKernelModeDriverModuleTarget ();
1712 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
1714 string
targetMacro ( GetTargetMacro (module
) );
1715 string workingDirectory
= GetWorkingDirectory ();
1716 string objectsMacro
= GetObjectsMacro ( module
);
1717 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1718 string libsMacro
= GetLibsMacro ();
1720 GenerateImportLibraryTargetIfNeeded ();
1722 if ( module
.non_if_data
.files
.size () > 0 )
1726 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
1728 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1729 module
.entrypoint
.c_str (),
1730 module
.baseaddress
.c_str () );
1731 GenerateLinkerCommand ( dependencies
,
1739 GeneratePhonyTarget();
1744 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
1745 const Module
& module_
)
1747 : MingwModuleHandler ( module_
)
1752 MingwNativeDLLModuleHandler::Process ()
1754 GenerateNativeDLLModuleTarget ();
1758 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
1760 string
targetMacro ( GetTargetMacro (module
) );
1761 string workingDirectory
= GetWorkingDirectory ( );
1762 string objectsMacro
= GetObjectsMacro ( module
);
1763 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1764 string libsMacro
= GetLibsMacro ();
1766 GenerateImportLibraryTargetIfNeeded ();
1768 if ( module
.non_if_data
.files
.size () > 0 )
1772 string dependencies
=
1773 objectsMacro
+ " " + linkDepsMacro
;
1775 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1776 module
.entrypoint
.c_str (),
1777 module
.baseaddress
.c_str () );
1778 GenerateLinkerCommand ( dependencies
,
1786 GeneratePhonyTarget();
1791 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
1792 const Module
& module_
)
1794 : MingwModuleHandler ( module_
)
1799 MingwNativeCUIModuleHandler::Process ()
1801 GenerateNativeCUIModuleTarget ();
1805 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
1807 string
targetMacro ( GetTargetMacro (module
) );
1808 string workingDirectory
= GetWorkingDirectory ( );
1809 string objectsMacro
= GetObjectsMacro ( module
);
1810 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1811 string libsMacro
= GetLibsMacro ();
1813 GenerateImportLibraryTargetIfNeeded ();
1815 if ( module
.non_if_data
.files
.size () > 0 )
1819 string dependencies
=
1820 objectsMacro
+ " " + linkDepsMacro
;
1822 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1823 module
.entrypoint
.c_str (),
1824 module
.baseaddress
.c_str () );
1825 GenerateLinkerCommand ( dependencies
,
1833 GeneratePhonyTarget();
1838 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
1839 const Module
& module_
)
1841 : MingwModuleHandler ( module_
)
1846 MingwWin32DLLModuleHandler::Process ()
1848 GenerateExtractWineDLLResourcesTarget ();
1849 GenerateWin32DLLModuleTarget ();
1853 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ()
1855 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1856 module
.name
.c_str () );
1857 fprintf ( fMakefile
, "%s_extractresources: $(BIN2RES_TARGET)\n",
1858 module
.name
.c_str () );
1859 const vector
<File
*>& files
= module
.non_if_data
.files
;
1860 for ( size_t i
= 0; i
< files
.size (); i
++ )
1862 File
& file
= *files
[i
];
1863 string extension
= GetExtension ( file
.name
);
1864 if ( extension
== ".rc" || extension
== ".RC" )
1866 string resource
= FixupTargetFilename ( file
.name
);
1867 fprintf ( fMakefile
, "\t$(ECHO_BIN2RES)\n" );
1868 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1869 resource
.c_str () );
1872 fprintf ( fMakefile
, "\n");
1876 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
1878 string
targetMacro ( GetTargetMacro (module
) );
1879 string workingDirectory
= GetWorkingDirectory ( );
1880 string objectsMacro
= GetObjectsMacro ( module
);
1881 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1882 string libsMacro
= GetLibsMacro ();
1884 GenerateImportLibraryTargetIfNeeded ();
1886 if ( module
.non_if_data
.files
.size () > 0 )
1890 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
1893 if ( module
.cplusplus
)
1898 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1899 module
.entrypoint
.c_str (),
1900 module
.baseaddress
.c_str () );
1901 GenerateLinkerCommand ( dependencies
,
1909 GeneratePhonyTarget();
1914 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
1915 const Module
& module_
)
1917 : MingwModuleHandler ( module_
)
1922 MingwWin32CUIModuleHandler::Process ()
1924 GenerateWin32CUIModuleTarget ();
1928 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
1930 string
targetMacro ( GetTargetMacro (module
) );
1931 string workingDirectory
= GetWorkingDirectory ( );
1932 string objectsMacro
= GetObjectsMacro ( module
);
1933 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1934 string libsMacro
= GetLibsMacro ();
1936 GenerateImportLibraryTargetIfNeeded ();
1938 if ( module
.non_if_data
.files
.size () > 0 )
1942 string dependencies
=
1943 objectsMacro
+ " " + linkDepsMacro
;
1946 if ( module
.cplusplus
)
1951 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1952 module
.entrypoint
.c_str (),
1953 module
.baseaddress
.c_str () );
1954 GenerateLinkerCommand ( dependencies
,
1962 GeneratePhonyTarget();
1967 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
1968 const Module
& module_
)
1970 : MingwModuleHandler ( module_
)
1975 MingwWin32GUIModuleHandler::Process ()
1977 GenerateWin32GUIModuleTarget ();
1981 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
1983 string
targetMacro ( GetTargetMacro (module
) );
1984 string workingDirectory
= GetWorkingDirectory ( );
1985 string objectsMacro
= GetObjectsMacro ( module
);
1986 string linkDepsMacro
= GetLinkingDependenciesMacro ();
1987 string libsMacro
= GetLibsMacro ();
1989 GenerateImportLibraryTargetIfNeeded ();
1991 if ( module
.non_if_data
.files
.size () > 0 )
1995 string dependencies
=
1996 objectsMacro
+ " " + linkDepsMacro
;
1999 if ( module
.cplusplus
)
2004 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2005 module
.entrypoint
.c_str (),
2006 module
.baseaddress
.c_str () );
2007 GenerateLinkerCommand ( dependencies
,
2015 GeneratePhonyTarget();
2020 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2021 const Module
& module_
)
2023 : MingwModuleHandler ( module_
)
2028 MingwBootLoaderModuleHandler::Process ()
2030 GenerateBootLoaderModuleTarget ();
2034 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2036 string
targetName ( module
.GetTargetName () );
2037 string
targetMacro ( GetTargetMacro (module
) );
2038 string workingDirectory
= GetWorkingDirectory ();
2039 string junk_tmp
= ros_temp
+ module
.name
+ ".junk.tmp";
2040 CLEAN_FILE ( junk_tmp
);
2041 string objectsMacro
= GetObjectsMacro ( module
);
2042 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2043 string libsMacro
= GetLibsMacro ();
2047 fprintf ( fMakefile
, "%s: %s %s %s\n",
2048 targetMacro
.c_str (),
2049 objectsMacro
.c_str (),
2050 linkDepsMacro
.c_str (),
2051 GetDirectory(GetTargetFilename(module
,NULL
)).c_str () );
2053 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2055 fprintf ( fMakefile
,
2056 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2057 GetLinkerMacro ().c_str (),
2059 objectsMacro
.c_str (),
2060 linkDepsMacro
.c_str () );
2061 fprintf ( fMakefile
,
2062 "\t${objcopy} -O binary %s $@\n",
2063 junk_tmp
.c_str () );
2064 fprintf ( fMakefile
,
2065 "\t-@${rm} %s 2>$(NUL)\n",
2066 junk_tmp
.c_str () );
2070 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2071 const Module
& module_
)
2073 : MingwModuleHandler ( module_
)
2078 MingwBootSectorModuleHandler::Process ()
2080 GenerateBootSectorModuleTarget ();
2084 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2086 string objectsMacro
= GetObjectsMacro ( module
);
2090 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2091 module
.name
.c_str ());
2092 fprintf ( fMakefile
,
2094 module
.name
.c_str (),
2095 objectsMacro
.c_str () );
2099 MingwIsoModuleHandler::MingwIsoModuleHandler (
2100 const Module
& module_
)
2102 : MingwModuleHandler ( module_
)
2107 MingwIsoModuleHandler::Process ()
2109 GenerateIsoModuleTarget ();
2113 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2114 const string
& bootcdDirectory
)
2116 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2118 const Module
& m
= *module
.project
.modules
[i
];
2119 if ( m
.bootstrap
!= NULL
)
2121 string
targetFilenameNoFixup ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
);
2122 string
targetFilename ( GetTargetMacro ( module
) );
2123 fprintf ( fMakefile
,
2125 m
.GetPath ().c_str (),
2126 targetFilename
.c_str () );
2132 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2133 const string
& bootcdDirectory
)
2135 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2137 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2138 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2139 string targetFilename
= GetTargetMacro(module
);
2140 fprintf ( fMakefile
,
2142 cdfile
.GetPath ().c_str (),
2143 targetFilename
.c_str () );
2148 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
)
2151 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2153 const Module
& m
= *module
.project
.modules
[i
];
2154 if ( m
.bootstrap
!= NULL
)
2156 string
targetDirectory ( bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
);
2157 if ( directories
.size () > 0 )
2159 directories
+= PassThruCacheDirectory (
2160 FixupTargetFilename ( targetDirectory
),
2168 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
)
2171 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2173 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2174 string
targetDirectory ( bootcdDirectory
+ SSEP
+ cdfile
.base
);
2175 if ( directories
.size () > 0 )
2177 directories
+= PassThruCacheDirectory (
2178 FixupTargetFilename ( targetDirectory
),
2185 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
)
2187 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
);
2188 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
);
2193 MingwIsoModuleHandler::GetBootstrapCdFiles (
2194 vector
<string
>& out
) const
2196 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2198 const Module
& m
= *module
.project
.modules
[i
];
2199 if ( m
.bootstrap
!= NULL
)
2200 out
.push_back ( FixupTargetFilename ( m
.GetPath () ) );
2205 MingwIsoModuleHandler::GetNonModuleCdFiles (
2206 vector
<string
>& out
) const
2208 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2210 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2211 out
.push_back ( NormalizeFilename ( cdfile
.GetPath () ) );
2216 MingwIsoModuleHandler::GetCdFiles (
2217 vector
<string
>& out
) const
2219 GetBootstrapCdFiles ( out
);
2220 GetNonModuleCdFiles ( out
);
2224 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2226 string bootcdDirectory
= "cd";
2227 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2228 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2229 string bootcdReactos
= PassThruCacheDirectory (
2230 FixupTargetFilename ( bootcdReactosNoFixup
),
2232 CLEAN_FILE ( bootcdReactos
);
2233 string reactosInf
= ros_temp
+ FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2234 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2235 string cdDirectories
= GetCdDirectories ( bootcdDirectory
);
2236 vector
<string
> vCdFiles
;
2237 GetCdFiles ( vCdFiles
);
2238 string cdFiles
= v2s ( vCdFiles
, 5 );
2240 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2241 module
.name
.c_str ());
2242 fprintf ( fMakefile
,
2243 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2244 module
.name
.c_str (),
2246 bootcdReactos
.c_str (),
2247 cdDirectories
.c_str (),
2249 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2250 fprintf ( fMakefile
,
2251 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I\n",
2252 reactosDff
.c_str (),
2253 bootcdReactos
.c_str () );
2254 fprintf ( fMakefile
,
2255 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2256 reactosDff
.c_str (),
2257 reactosInf
.c_str (),
2258 bootcdReactos
.c_str ());
2259 fprintf ( fMakefile
,
2260 "\t-@${rm} %s 2>$(NUL)\n",
2261 reactosInf
.c_str () );
2262 OutputBootstrapfileCopyCommands ( bootcdDirectory
);
2263 OutputCdfileCopyCommands ( bootcdDirectory
);
2264 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2265 fprintf ( fMakefile
,
2266 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2268 bootcdDirectory
.c_str () );
2269 fprintf ( fMakefile
,
2274 MingwTestModuleHandler::MingwTestModuleHandler (
2275 const Module
& module_
)
2277 : MingwModuleHandler ( module_
)
2282 MingwTestModuleHandler::Process ()
2284 GenerateTestModuleTarget ();
2288 MingwTestModuleHandler::GenerateTestModuleTarget ()
2290 string
targetMacro ( GetTargetMacro (module
) );
2291 string workingDirectory
= GetWorkingDirectory ( );
2292 string objectsMacro
= GetObjectsMacro ( module
);
2293 string linkDepsMacro
= GetLinkingDependenciesMacro ();
2294 string libsMacro
= GetLibsMacro ();
2296 GenerateImportLibraryTargetIfNeeded ();
2298 if ( module
.non_if_data
.files
.size () > 0 )
2302 string dependencies
= objectsMacro
+ " " + linkDepsMacro
;
2305 if ( module
.cplusplus
)
2310 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2311 module
.entrypoint
.c_str (),
2312 module
.baseaddress
.c_str () );
2313 GenerateLinkerCommand ( dependencies
,
2321 GeneratePhonyTarget();