4 #include "../../rbuild.h"
6 #include "modulehandler.h"
13 typedef set
<string
> set_string
;
15 map
<ModuleType
,MingwModuleHandler
*>*
16 MingwModuleHandler::handler_map
= NULL
;
18 MingwModuleHandler::directory_set
;
20 MingwModuleHandler::ref
= 0;
23 MingwModuleHandler::fMakefile
= NULL
;
26 ReplaceExtension ( const string
& filename
,
27 const string
& newExtension
)
29 size_t index
= filename
.find_last_of ( '/' );
30 if (index
== string::npos
) index
= 0;
31 string tmp
= filename
.substr( index
, filename
.size() - index
);
32 size_t ext_index
= tmp
.find_last_of( '.' );
33 if (ext_index
!= string::npos
)
34 return filename
.substr ( 0, index
+ ext_index
) + newExtension
;
35 return filename
+ newExtension
;
39 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype
)
42 handler_map
= new map
<ModuleType
,MingwModuleHandler
*>;
43 (*handler_map
)[moduletype
] = this;
46 MingwModuleHandler::~MingwModuleHandler()
56 MingwModuleHandler::PassThruCacheDirectory ( const string
&file
) const
58 directory_set
.insert ( GetDirectory ( file
) );
63 MingwModuleHandler::SetMakefile ( FILE* f
)
69 MingwModuleHandler::LookupHandler ( const string
& location
,
70 ModuleType moduletype
)
73 throw Exception ( "internal tool error: no registered module handlers" );
74 MingwModuleHandler
* h
= (*handler_map
)[moduletype
];
77 throw UnknownModuleTypeException ( location
, moduletype
);
84 MingwModuleHandler::GetWorkingDirectory () const
90 MingwModuleHandler::GetBasename ( const string
& filename
) const
92 size_t index
= filename
.find_last_of ( '.' );
93 if ( index
!= string::npos
)
94 return filename
.substr ( 0, index
);
99 MingwModuleHandler::GetActualSourceFilename ( const string
& filename
) const
101 string extension
= GetExtension ( filename
);
102 if ( extension
== ".spec" || extension
== "SPEC" )
104 string basename
= GetBasename ( filename
);
105 return basename
+ ".stubs.c";
112 MingwModuleHandler::GetModuleArchiveFilename ( const Module
& module
) const
114 return ReplaceExtension ( FixupTargetFilename ( module
.GetPath () ),
119 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
121 string extension
= GetExtension ( file
.name
);
122 if ( extension
== ".spec" || extension
== "SPEC" )
129 MingwModuleHandler::GetImportLibraryDependency ( const Module
& importedModule
) const
131 if ( importedModule
.type
== ObjectLibrary
)
132 return GetObjectsMacro ( importedModule
);
134 return PassThruCacheDirectory ( FixupTargetFilename ( importedModule
.GetDependencyPath () ) );
138 MingwModuleHandler::GetImportLibraryDependencies ( const Module
& module
) const
140 string
dependencies ( "" );
141 for ( size_t i
= 0; i
< module
.libraries
.size (); i
++ )
143 if ( dependencies
.size () > 0 )
145 const Module
* importedModule
= module
.project
.LocateModule ( module
.libraries
[i
]->name
);
146 assert ( importedModule
!= NULL
);
147 dependencies
+= GetImportLibraryDependency ( *importedModule
);
153 MingwModuleHandler::GetModuleDependencies ( const Module
& module
) const
155 if ( module
.dependencies
.size () == 0 )
158 string
dependencies ( "" );
159 for ( size_t i
= 0; i
< module
.dependencies
.size (); i
++ )
161 if ( dependencies
.size () > 0 )
163 const Dependency
* dependency
= module
.dependencies
[i
];
164 const Module
* dependencyModule
= dependency
->dependencyModule
;
165 dependencies
+= dependencyModule
->GetTargets ();
167 string definitionDependencies
= GetDefinitionDependencies ( module
);
168 if ( dependencies
.length () > 0 && definitionDependencies
.length () > 0 )
169 dependencies
+= " " + definitionDependencies
;
170 else if ( definitionDependencies
.length () > 0 )
171 dependencies
= definitionDependencies
;
176 MingwModuleHandler::GetAllDependencies ( const Module
& module
) const
178 string dependencies
= GetImportLibraryDependencies ( module
);
179 string s
= GetModuleDependencies ( module
);
180 if ( s
.length () > 0 )
189 MingwModuleHandler::GetSourceFilenames ( const Module
& module
,
190 bool includeGeneratedFiles
) const
194 string
sourceFilenames ( "" );
195 for ( i
= 0; i
< module
.files
.size (); i
++ )
197 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *module
.files
[i
] ) )
198 sourceFilenames
+= " " + GetActualSourceFilename ( module
.files
[i
]->name
);
200 vector
<If
*> ifs
= module
.ifs
;
201 for ( i
= 0; i
< ifs
.size (); i
++ )
205 for ( j
= 0; j
< rIf
.ifs
.size (); j
++ )
206 ifs
.push_back ( rIf
.ifs
[j
] );
207 for ( j
= 0; j
< rIf
.files
.size (); j
++ )
209 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *rIf
.files
[j
] ) )
210 sourceFilenames
+= " " + GetActualSourceFilename ( rIf
.files
[j
]->name
);
213 return sourceFilenames
;
217 MingwModuleHandler::GetSourceFilenames ( const Module
& module
) const
219 return GetSourceFilenames ( module
,
224 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module
& module
) const
226 return GetSourceFilenames ( module
,
231 MingwModuleHandler::GetObjectFilename ( const string
& sourceFilename
)
234 string extension
= GetExtension ( sourceFilename
);
235 if ( extension
== ".rc" || extension
== ".RC" )
236 newExtension
= ".coff";
237 else if ( extension
== ".spec" || extension
== ".SPEC" )
238 newExtension
= ".stubs.o";
241 return FixupTargetFilename ( ReplaceExtension ( sourceFilename
, newExtension
) );
245 MingwModuleHandler::GetObjectFilenames ( const Module
& module
) const
247 if ( module
.files
.size () == 0 )
250 string
objectFilenames ( "" );
251 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
253 if ( objectFilenames
.size () > 0 )
254 objectFilenames
+= " ";
255 objectFilenames
+= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( module
.files
[i
]->name
) );
257 return objectFilenames
;
261 MingwModuleHandler::IncludeDirectoryTarget ( const string
& directory
) const
263 if ( directory
== "$(ROS_INTERMEDIATE)." SSEP
"tools")
270 MingwModuleHandler::GenerateDirectoryTargets () const
272 if ( directory_set
.size () == 0 )
275 set_string::iterator i
;
276 fprintf ( fMakefile
, "directories::" );
278 for ( i
= directory_set
.begin ();
279 i
!= directory_set
.end ();
282 if ( IncludeDirectoryTarget ( *i
) )
290 fprintf ( fMakefile
, "\n\n" );
292 for ( i
= directory_set
.begin ();
293 i
!= directory_set
.end ();
296 if ( IncludeDirectoryTarget ( *i
) )
305 "::\n\t${mkdir} $@\n\n" );
307 directory_set
.clear ();
311 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector
<Define
*>& defines
) const
314 for ( size_t i
= 0; i
< defines
.size (); i
++ )
316 Define
& define
= *defines
[i
];
317 if (parameters
.length () > 0)
320 parameters
+= define
.name
;
321 if (define
.value
.length () > 0)
324 parameters
+= define
.value
;
331 MingwModuleHandler::GenerateGccDefineParameters ( const Module
& module
) const
333 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.defines
);
334 string s
= GenerateGccDefineParametersFromVector ( module
.defines
);
335 if ( s
.length () > 0 )
344 MingwModuleHandler::ConcatenatePaths ( const string
& path1
,
345 const string
& path2
) const
347 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
349 if ( path1
[path1
.length ()] == CSEP
)
350 return path1
+ path2
;
352 return path1
+ CSEP
+ path2
;
356 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
359 for ( size_t i
= 0; i
< includes
.size (); i
++ )
361 Include
& include
= *includes
[i
];
362 if ( parameters
.length () > 0 )
364 parameters
+= "-I" + include
.directory
;
370 MingwModuleHandler::GenerateGccIncludeParameters ( const Module
& module
) const
372 string parameters
= GenerateGccIncludeParametersFromVector ( module
.includes
);
373 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.includes
);
374 if ( s
.length () > 0 )
384 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
387 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
389 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
390 if ( parameters
.length () > 0 )
392 parameters
+= compilerFlag
.flag
;
398 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
401 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
403 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
404 if ( parameters
.length () > 0 )
406 parameters
+= linkerFlag
.flag
;
412 MingwModuleHandler::GenerateLinkerParameters ( const Module
& module
) const
414 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
418 MingwModuleHandler::GenerateMacro ( const char* assignmentOperation
,
420 const vector
<Include
*>& includes
,
421 const vector
<Define
*>& defines
,
422 const vector
<CompilerFlag
*>* compilerFlags
) const
430 assignmentOperation
);
432 if ( compilerFlags
!= NULL
)
434 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
435 if ( compilerParameters
.size () > 0 )
440 compilerParameters
.c_str () );
444 for ( i
= 0; i
< includes
.size(); i
++ )
449 includes
[i
]->directory
.c_str() );
451 for ( i
= 0; i
< defines
.size(); i
++ )
453 Define
& d
= *defines
[i
];
458 if ( d
.value
.size() )
464 fprintf ( fMakefile
, "\n" );
468 MingwModuleHandler::GenerateMacros (
469 const char* assignmentOperation
,
470 const vector
<File
*>& files
,
471 const vector
<Include
*>& includes
,
472 const vector
<Define
*>& defines
,
473 const vector
<CompilerFlag
*>* compilerFlags
,
474 const vector
<LinkerFlag
*>* linkerFlags
,
475 const vector
<If
*>& ifs
,
476 const string
& cflags_macro
,
477 const string
& nasmflags_macro
,
478 const string
& windresflags_macro
,
479 const string
& linkerflags_macro
,
480 const string
& objs_macro
) const
484 if ( includes
.size() || defines
.size() )
486 GenerateMacro ( assignmentOperation
,
491 GenerateMacro ( assignmentOperation
,
498 if ( linkerFlags
!= NULL
)
500 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
501 if ( linkerParameters
.size () > 0 )
506 linkerflags_macro
.c_str (),
508 linkerParameters
.c_str() );
514 for ( i
= 0; i
< files
.size(); i
++ )
516 if ( files
[i
]->first
)
521 PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) ).c_str (),
522 objs_macro
.c_str() );
529 assignmentOperation
);
530 for ( i
= 0; i
< files
.size(); i
++ )
532 string extension
= GetExtension ( files
[i
]->name
);
533 if ( extension
!= ".spec"
534 && extension
!= ".SPEC"
535 && !files
[i
]->first
)
540 ( i
%10 == 9 ? "\\\n\t" : " " ),
541 PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) ).c_str () );
544 fprintf ( fMakefile
, "\n" );
547 for ( i
= 0; i
< ifs
.size(); i
++ )
550 if ( rIf
.defines
.size() || rIf
.includes
.size() || rIf
.files
.size() || rIf
.ifs
.size() )
554 "ifeq (\"$(%s)\",\"%s\")\n",
555 rIf
.property
.c_str(),
578 MingwModuleHandler::GenerateMacros (
579 const Module
& module
,
580 const string
& cflags_macro
,
581 const string
& nasmflags_macro
,
582 const string
& windresflags_macro
,
583 const string
& linkerflags_macro
,
584 const string
& objs_macro
) const
591 &module
.compilerFlags
,
599 fprintf ( fMakefile
, "\n" );
603 "%s += $(PROJECT_CFLAGS)\n\n",
604 cflags_macro
.c_str () );
608 "%s += $(PROJECT_RCFLAGS)\n\n",
609 windresflags_macro
.c_str () );
613 "%s_LFLAGS += $(PROJECT_LFLAGS)\n\n",
614 module
.name
.c_str () );
618 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
619 const string
& sourceFilename
,
621 const string
& cflagsMacro
) const
623 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
626 objectFilename
.c_str (),
627 sourceFilename
.c_str () );
629 "\t%s -c %s -o %s %s\n",
631 sourceFilename
.c_str (),
632 objectFilename
.c_str (),
633 cflagsMacro
.c_str () );
637 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
638 const string
& sourceFilename
,
640 const string
& cflagsMacro
) const
642 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
645 objectFilename
.c_str (),
646 sourceFilename
.c_str () );
648 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
650 sourceFilename
.c_str (),
651 objectFilename
.c_str (),
652 cflagsMacro
.c_str () );
656 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
657 const string
& sourceFilename
,
658 const string
& nasmflagsMacro
) const
660 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
663 objectFilename
.c_str (),
664 sourceFilename
.c_str () );
666 "\t%s -f win32 %s -o %s %s\n",
668 sourceFilename
.c_str (),
669 objectFilename
.c_str (),
670 nasmflagsMacro
.c_str () );
674 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
675 const string
& sourceFilename
,
676 const string
& windresflagsMacro
) const
678 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
681 objectFilename
.c_str (),
682 sourceFilename
.c_str () );
684 "\t%s %s -o %s ${%s}\n",
686 sourceFilename
.c_str (),
687 objectFilename
.c_str (),
688 windresflagsMacro
.c_str () );
692 MingwModuleHandler::GenerateWinebuildCommands ( const Module
& module
,
693 const string
& sourceFilename
) const
695 string basename
= GetBasename ( sourceFilename
);
699 sourceFilename
.c_str () );
701 "\t%s --def=%s -o %s.spec.def\n",
703 sourceFilename
.c_str (),
709 sourceFilename
.c_str () );
711 "\t%s --pedll=%s -o %s.stubs.c\n",
713 sourceFilename
.c_str (),
718 MingwModuleHandler::GenerateCommands ( const Module
& module
,
719 const string
& sourceFilename
,
722 const string
& cflagsMacro
,
723 const string
& nasmflagsMacro
,
724 const string
& windresflagsMacro
) const
726 string extension
= GetExtension ( sourceFilename
);
727 if ( extension
== ".c" || extension
== ".C" )
729 GenerateGccCommand ( module
,
735 else if ( extension
== ".cc" || extension
== ".CC" ||
736 extension
== ".cpp" || extension
== ".CPP" ||
737 extension
== ".cxx" || extension
== ".CXX" )
739 GenerateGccCommand ( module
,
745 else if ( extension
== ".s" || extension
== ".S" )
747 GenerateGccAssemblerCommand ( module
,
753 else if ( extension
== ".asm" || extension
== ".ASM" )
755 GenerateNasmCommand ( module
,
760 else if ( extension
== ".rc" || extension
== ".RC" )
762 GenerateWindresCommand ( module
,
767 else if ( extension
== ".spec" || extension
== ".SPEC" )
769 GenerateWinebuildCommands ( module
,
771 GenerateGccCommand ( module
,
772 GetActualSourceFilename ( sourceFilename
),
778 throw InvalidOperationException ( __FILE__
,
780 "Unsupported filename extension '%s' in file '%s'",
782 sourceFilename
.c_str () );
786 MingwModuleHandler::GenerateLinkerCommand ( const Module
& module
,
787 const string
& linker
,
788 const string
& linkerParameters
,
789 const string
& objectFilenames
) const
791 string
targetName ( module
.GetTargetName () );
792 string
target ( FixupTargetFilename ( module
.GetPath () ) );
793 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
794 if ( module
.importLibrary
!= NULL
)
796 static string
ros_junk ( "$(ROS_TEMPORARY)" );
797 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
798 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
799 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
802 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
804 linkerParameters
.c_str (),
807 objectFilenames
.c_str (),
808 importLibraryDependencies
.c_str (),
809 GetLinkerMacro ( module
).c_str () );
815 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
817 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
820 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
829 "\t%s %s %s -o %s %s %s %s\n\n",
831 linkerParameters
.c_str (),
834 objectFilenames
.c_str (),
835 importLibraryDependencies
.c_str (),
836 GetLinkerMacro ( module
).c_str () );
845 "\t%s %s -o %s %s %s %s\n\n",
847 linkerParameters
.c_str (),
849 objectFilenames
.c_str (),
850 importLibraryDependencies
.c_str (),
851 GetLinkerMacro ( module
).c_str () );
856 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
857 const vector
<File
*>& files
,
858 const vector
<If
*>& ifs
,
861 const string
& cflagsMacro
,
862 const string
& nasmflagsMacro
,
863 const string
& windresflagsMacro
) const
867 for ( i
= 0; i
< files
.size (); i
++ )
869 string sourceFilename
= files
[i
]->name
;
870 GenerateCommands ( module
,
881 for ( i
= 0; i
< ifs
.size(); i
++ )
883 GenerateObjectFileTargets ( module
,
895 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
898 const string
& cflagsMacro
,
899 const string
& nasmflagsMacro
,
900 const string
& windresflagsMacro
) const
902 GenerateObjectFileTargets ( module
,
910 fprintf ( fMakefile
, "\n" );
914 MingwModuleHandler::GetCleanTargets ( vector
<string
>& out
,
915 const vector
<File
*>& files
,
916 const vector
<If
*>& ifs
) const
920 for ( i
= 0; i
< files
.size(); i
++ )
921 out
.push_back ( PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) ) );
923 for ( i
= 0; i
< ifs
.size(); i
++ )
924 GetCleanTargets ( out
, ifs
[i
]->files
, ifs
[i
]->ifs
);
928 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
930 const string
& objs_macro
) const
932 string archiveFilename
= GetModuleArchiveFilename ( module
);
936 archiveFilename
.c_str (),
937 objs_macro
.c_str ());
940 "\t%s -rc %s %s\n\n",
942 archiveFilename
.c_str (),
943 objs_macro
.c_str ());
945 return archiveFilename
;
949 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
951 return ssprintf ( "$(%s_CFLAGS)",
952 module
.name
.c_str () );
956 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
958 return ssprintf ( "$(%s_OBJS)",
959 module
.name
.c_str () );
963 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
965 return ssprintf ( "$(%s_LFLAGS)",
966 module
.name
.c_str () );
970 MingwModuleHandler::GenerateMacrosAndTargets (
971 const Module
& module
,
975 const string
* cflags
,
976 const string
* nasmflags
) const
978 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
979 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
980 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
981 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
982 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
984 GenerateMacros ( module
,
991 if ( cflags
!= NULL
)
995 cflagsMacro
.c_str (),
999 if ( nasmflags
!= NULL
)
1001 fprintf ( fMakefile
,
1003 nasmflagsMacro
.c_str (),
1004 nasmflags
->c_str () );
1007 // generate phony target for module name
1008 fprintf ( fMakefile
, ".PHONY: %s\n",
1009 module
.name
.c_str () );
1010 fprintf ( fMakefile
, "%s: %s\n\n",
1011 module
.name
.c_str (),
1012 FixupTargetFilename ( module
.GetPath () ).c_str () );
1014 // future references to the macros will be to get their values
1015 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1016 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1017 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1019 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1020 GenerateObjectFileTargets ( module
,
1025 windresflagsMacro
);
1027 vector
<string
> clean_files
;
1028 clean_files
.push_back ( FixupTargetFilename(module
.GetPath()) );
1029 clean_files
.push_back ( ar_target
);
1030 GetCleanTargets ( clean_files
, module
.files
, module
.ifs
);
1032 fprintf ( fMakefile
, "clean::\n\t-@$(rm)" );
1033 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
1036 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
1037 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
1039 fprintf ( fMakefile
, " 2>$(NUL)\n\n" );
1043 MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module
& module
) const
1045 GenerateMacrosAndTargets ( module
,
1054 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
) const
1056 GenerateMacrosAndTargetsTarget ( module
,
1062 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
,
1063 const string
* cflags
,
1064 const string
* nasmflags
) const
1066 GenerateMacrosAndTargets ( module
,
1075 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
1077 string dependencies
;
1078 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1080 Invoke
& invoke
= *module
.invocations
[i
];
1081 if (invoke
.invokeModule
== &module
)
1082 /* Protect against circular dependencies */
1084 if ( dependencies
.length () > 0 )
1085 dependencies
+= " ";
1086 dependencies
+= invoke
.GetTargets ();
1088 return dependencies
;
1092 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1094 if ( module
.invocations
.size () == 0 )
1097 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1099 const Invoke
& invoke
= *module
.invocations
[i
];
1101 if ( invoke
.invokeModule
->type
!= BuildTool
)
1103 throw InvalidBuildFileException ( module
.node
.location
,
1104 "Only modules of type buildtool can be invoked." );
1107 string invokeTarget
= module
.GetInvocationTarget ( i
);
1108 fprintf ( fMakefile
,
1110 invokeTarget
.c_str () );
1111 fprintf ( fMakefile
,
1113 invokeTarget
.c_str (),
1114 invoke
.GetTargets ().c_str () );
1115 fprintf ( fMakefile
,
1117 invoke
.GetTargets ().c_str (),
1118 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1119 fprintf ( fMakefile
,
1121 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1122 invoke
.GetParameters ().c_str () );
1127 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1129 return ssprintf ( "%s_precondition",
1130 module
.name
.c_str () );
1134 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1136 /* Avoid circular dependency */
1137 if ( module
.type
== BuildTool
|| module
.name
== "zlib" )
1138 return "$(ROS_INTERMEDIATE)." SSEP
"tools $(ROS_INTERMEDIATE)." SSEP
"lib" SSEP
"zlib";
1144 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
1146 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1147 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1148 string dependencies
= GetDefaultDependencies ( module
);
1149 string s
= GetModuleDependencies ( module
);
1150 if ( s
.length () > 0 )
1152 if ( dependencies
.length () > 0 )
1153 dependencies
+= " ";
1157 s
= GetInvocationDependencies ( module
);
1158 if ( s
.length () > 0 )
1160 if ( dependencies
.length () > 0 )
1161 dependencies
+= " ";
1165 fprintf ( fMakefile
,
1167 preconditionDependenciesName
.c_str () );
1168 fprintf ( fMakefile
,
1170 preconditionDependenciesName
.c_str (),
1171 dependencies
.c_str () );
1172 const char* p
= sourceFilenames
.c_str();
1173 const char* end
= p
+ strlen(p
);
1176 const char* p2
= &p
[512];
1179 while ( p2
> p
&& !isspace(*p2
) )
1183 p2
= strpbrk ( p
, " \t" );
1187 fprintf ( fMakefile
,
1191 preconditionDependenciesName
.c_str ());
1193 p
+= strspn ( p
, " \t" );
1195 fprintf ( fMakefile
, "\n" );
1199 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module
& module
) const
1201 if ( module
.importLibrary
!= NULL
)
1203 string definitionDependencies
= GetDefinitionDependencies ( module
);
1204 fprintf ( fMakefile
, "%s: %s\n",
1205 FixupTargetFilename( module
.GetDependencyPath () ).c_str (),
1206 definitionDependencies
.c_str () );
1208 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1209 fprintf ( fMakefile
,
1210 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1211 module
.GetTargetName ().c_str (),
1212 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1213 FixupTargetFilename ( module
.GetDependencyPath () ).c_str (),
1219 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1221 string basename
= GetBasename ( filename
);
1222 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1226 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
) const
1228 string dependencies
;
1229 string dkNkmLibNoFixup
= "dk/nkm/lib";
1230 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1231 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1232 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
1234 File
& file
= *module
.files
[i
];
1235 string extension
= GetExtension ( file
.name
);
1236 if ( extension
== ".spec" || extension
== ".SPEC" )
1238 if ( dependencies
.length () > 0 )
1239 dependencies
+= " ";
1240 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1243 return dependencies
;
1247 MingwModuleHandler::GetLinkingDependencies ( const Module
& module
) const
1249 string dependencies
= GetImportLibraryDependencies ( module
);
1250 string s
= GetDefinitionDependencies ( module
);
1251 if ( s
.length () > 0 )
1253 dependencies
+= " ";
1256 return dependencies
;
1260 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
) const
1262 if ( module
.HasFileWithExtensions ( ".cc", ".CC" ) )
1264 if ( module
.HasFileWithExtensions ( ".cxx", ".CXX" ) )
1266 if ( module
.HasFileWithExtensions ( ".cpp", ".CPP" ) )
1272 static MingwBuildToolModuleHandler buildtool_handler
;
1274 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1275 : MingwModuleHandler ( BuildTool
)
1280 MingwBuildToolModuleHandler::Process ( const Module
& module
)
1282 GeneratePreconditionDependencies ( module
);
1283 GenerateBuildToolModuleTarget ( module
);
1284 GenerateInvocations ( module
);
1288 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
)
1290 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1291 string archiveFilename
= GetModuleArchiveFilename ( module
);
1292 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1294 GenerateMacrosAndTargetsHost ( module
);
1297 if ( IsCPlusPlusModule ( module
) )
1298 linker
= "${host_gpp}";
1300 linker
= "${host_gcc}";
1302 fprintf ( fMakefile
, "%s: %s %s\n",
1304 archiveFilename
.c_str (),
1305 importLibraryDependencies
.c_str () );
1306 fprintf ( fMakefile
,
1307 "\t%s %s -o %s %s %s\n\n",
1309 GetLinkerMacro ( module
).c_str (),
1311 archiveFilename
.c_str (),
1312 importLibraryDependencies
.c_str () );
1316 static MingwKernelModuleHandler kernelmodule_handler
;
1318 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1319 : MingwModuleHandler ( Kernel
)
1324 MingwKernelModuleHandler::Process ( const Module
& module
)
1326 GeneratePreconditionDependencies ( module
);
1327 GenerateKernelModuleTarget ( module
);
1328 GenerateInvocations ( module
);
1332 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
)
1334 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1335 string
targetName ( module
.GetTargetName () );
1336 string
target ( FixupTargetFilename (module
.GetPath ()) );
1337 string workingDirectory
= GetWorkingDirectory ();
1338 string objectsMacro
= GetObjectsMacro ( module
);
1339 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1340 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1341 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1342 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1343 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",
1344 module
.GetBasePath ().c_str (),
1345 module
.entrypoint
.c_str (),
1346 module
.baseaddress
.c_str () );
1348 GenerateMacrosAndTargetsTarget ( module
);
1350 GenerateImportLibraryTargetIfNeeded ( module
);
1352 fprintf ( fMakefile
, "%s: %s %s\n",
1354 objectsMacro
.c_str (),
1355 importLibraryDependencies
.c_str () );
1356 fprintf ( fMakefile
,
1357 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1358 GetLinkerMacro ( module
).c_str (),
1359 gccOptions
.c_str (),
1362 objectsMacro
.c_str (),
1363 importLibraryDependencies
.c_str () );
1364 fprintf ( fMakefile
,
1366 junk_tmp
.c_str () );
1367 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1368 fprintf ( fMakefile
,
1369 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1370 targetName
.c_str (),
1374 fprintf ( fMakefile
,
1376 base_tmp
.c_str () );
1377 fprintf ( fMakefile
,
1378 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1379 GetLinkerMacro ( module
).c_str (),
1380 gccOptions
.c_str (),
1383 objectsMacro
.c_str (),
1384 importLibraryDependencies
.c_str () );
1385 fprintf ( fMakefile
,
1387 temp_exp
.c_str () );
1391 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1393 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1394 : MingwModuleHandler ( StaticLibrary
)
1399 MingwStaticLibraryModuleHandler::Process ( const Module
& module
)
1401 GeneratePreconditionDependencies ( module
);
1402 GenerateStaticLibraryModuleTarget ( module
);
1403 GenerateInvocations ( module
);
1407 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
)
1409 GenerateMacrosAndTargetsTarget ( module
);
1413 static MingwObjectLibraryModuleHandler objectlibrary_handler
;
1415 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()
1416 : MingwModuleHandler ( ObjectLibrary
)
1421 MingwObjectLibraryModuleHandler::Process ( const Module
& module
)
1423 GeneratePreconditionDependencies ( module
);
1424 GenerateObjectLibraryModuleTarget ( module
);
1425 GenerateInvocations ( module
);
1429 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
)
1431 GenerateMacrosAndTargetsTarget ( module
);
1435 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1437 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1438 : MingwModuleHandler ( KernelModeDLL
)
1443 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
)
1445 GeneratePreconditionDependencies ( module
);
1446 GenerateKernelModeDLLModuleTarget ( module
);
1447 GenerateInvocations ( module
);
1451 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Module
& module
)
1453 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1454 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1455 string workingDirectory
= GetWorkingDirectory ( );
1456 string archiveFilename
= GetModuleArchiveFilename ( module
);
1457 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1459 GenerateImportLibraryTargetIfNeeded ( module
);
1461 if ( module
.files
.size () > 0 )
1463 GenerateMacrosAndTargetsTarget ( module
);
1465 fprintf ( fMakefile
, "%s: %s %s\n",
1467 archiveFilename
.c_str (),
1468 importLibraryDependencies
.c_str () );
1470 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1471 module
.entrypoint
.c_str (),
1472 module
.baseaddress
.c_str () );
1473 GenerateLinkerCommand ( module
,
1480 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1482 fprintf ( fMakefile
, "%s:\n",
1488 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1490 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1491 : MingwModuleHandler ( KernelModeDriver
)
1496 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
)
1498 GeneratePreconditionDependencies ( module
);
1499 GenerateKernelModeDriverModuleTarget ( module
);
1500 GenerateInvocations ( module
);
1505 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module
& module
)
1507 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1508 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1509 string workingDirectory
= GetWorkingDirectory ( );
1510 string archiveFilename
= GetModuleArchiveFilename ( module
);
1511 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1513 GenerateImportLibraryTargetIfNeeded ( module
);
1515 if ( module
.files
.size () > 0 )
1517 string
* cflags
= new string ( "-D__NTDRIVER__" );
1518 GenerateMacrosAndTargetsTarget ( module
,
1523 fprintf ( fMakefile
, "%s: %s %s\n",
1525 archiveFilename
.c_str (),
1526 importLibraryDependencies
.c_str () );
1528 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1529 module
.entrypoint
.c_str (),
1530 module
.baseaddress
.c_str () );
1531 GenerateLinkerCommand ( module
,
1538 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1540 fprintf ( fMakefile
, "%s:\n",
1546 static MingwNativeDLLModuleHandler nativedll_handler
;
1548 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1549 : MingwModuleHandler ( NativeDLL
)
1554 MingwNativeDLLModuleHandler::Process ( const Module
& module
)
1556 GeneratePreconditionDependencies ( module
);
1557 GenerateNativeDLLModuleTarget ( module
);
1558 GenerateInvocations ( module
);
1562 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
)
1564 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1565 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1566 string workingDirectory
= GetWorkingDirectory ( );
1567 string objectFilenames
= GetObjectFilenames ( module
);
1568 string archiveFilename
= GetModuleArchiveFilename ( module
);
1569 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1571 GenerateImportLibraryTargetIfNeeded ( module
);
1573 if ( module
.files
.size () > 0 )
1575 GenerateMacrosAndTargetsTarget ( module
);
1577 fprintf ( fMakefile
, "%s: %s %s\n",
1579 archiveFilename
.c_str (),
1580 importLibraryDependencies
.c_str () );
1582 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1583 module
.entrypoint
.c_str (),
1584 module
.baseaddress
.c_str () );
1585 GenerateLinkerCommand ( module
,
1592 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1594 fprintf ( fMakefile
, "%s:\n\n",
1600 static MingwNativeCUIModuleHandler nativecui_handler
;
1602 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ()
1603 : MingwModuleHandler ( NativeCUI
)
1608 MingwNativeCUIModuleHandler::Process ( const Module
& module
)
1610 GeneratePreconditionDependencies ( module
);
1611 GenerateNativeCUIModuleTarget ( module
);
1612 GenerateInvocations ( module
);
1616 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module
& module
)
1618 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1619 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1620 string workingDirectory
= GetWorkingDirectory ( );
1621 string objectFilenames
= GetObjectFilenames ( module
);
1622 string archiveFilename
= GetModuleArchiveFilename ( module
);
1623 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1625 GenerateImportLibraryTargetIfNeeded ( module
);
1627 if ( module
.files
.size () > 0 )
1629 string
* cflags
= new string ( "-D__NTAPP__" );
1630 GenerateMacrosAndTargetsTarget ( module
,
1635 fprintf ( fMakefile
, "%s: %s %s\n",
1637 archiveFilename
.c_str (),
1638 importLibraryDependencies
.c_str () );
1640 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1641 module
.entrypoint
.c_str (),
1642 module
.baseaddress
.c_str () );
1643 GenerateLinkerCommand ( module
,
1650 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1652 fprintf ( fMakefile
, "%s:\n\n",
1658 static MingwWin32DLLModuleHandler win32dll_handler
;
1660 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1661 : MingwModuleHandler ( Win32DLL
)
1666 MingwWin32DLLModuleHandler::Process ( const Module
& module
)
1668 GenerateExtractWineDLLResourcesTarget ( module
);
1669 GeneratePreconditionDependencies ( module
);
1670 GenerateWin32DLLModuleTarget ( module
);
1671 GenerateInvocations ( module
);
1675 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
)
1677 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1678 module
.name
.c_str () );
1679 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1680 module
.name
.c_str () );
1681 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
1683 File
& file
= *module
.files
[i
];
1684 string extension
= GetExtension ( file
.name
);
1685 if ( extension
== ".rc" || extension
== ".RC" )
1687 string resource
= FixupTargetFilename ( file
.name
);
1688 fprintf ( fMakefile
, "\t@echo ${bin2res} -f -x %s\n",
1689 resource
.c_str () );
1692 fprintf ( fMakefile
, "\n");
1696 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
)
1698 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1699 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1700 string workingDirectory
= GetWorkingDirectory ( );
1701 string objectFilenames
= GetObjectFilenames ( module
);
1702 string linkingDependencies
= GetLinkingDependencies ( module
);
1704 GenerateImportLibraryTargetIfNeeded ( module
);
1705 if ( module
.files
.size () > 0 )
1707 GenerateMacrosAndTargetsTarget ( module
);
1709 fprintf ( fMakefile
, "%s: %s %s\n",
1711 objectFilenames
.c_str (),
1712 linkingDependencies
.c_str () );
1715 if ( IsCPlusPlusModule ( module
) )
1720 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1721 module
.entrypoint
.c_str (),
1722 module
.baseaddress
.c_str () );
1723 GenerateLinkerCommand ( module
,
1730 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1732 fprintf ( fMakefile
, "%s:\n\n",
1738 static MingwWin32CUIModuleHandler win32cui_handler
;
1740 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ()
1741 : MingwModuleHandler ( Win32CUI
)
1746 MingwWin32CUIModuleHandler::Process ( const Module
& module
)
1748 GeneratePreconditionDependencies ( module
);
1749 GenerateWin32CUIModuleTarget ( module
);
1750 GenerateInvocations ( module
);
1754 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
)
1756 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1757 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1758 string workingDirectory
= GetWorkingDirectory ( );
1759 string objectFilenames
= GetObjectFilenames ( module
);
1760 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1762 GenerateImportLibraryTargetIfNeeded ( module
);
1764 if ( module
.files
.size () > 0 )
1766 GenerateMacrosAndTargetsTarget ( module
);
1768 fprintf ( fMakefile
, "%s: %s %s\n",
1770 objectFilenames
.c_str (),
1771 importLibraryDependencies
.c_str () );
1774 if ( IsCPlusPlusModule ( module
) )
1779 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1780 module
.entrypoint
.c_str (),
1781 module
.baseaddress
.c_str () );
1782 GenerateLinkerCommand ( module
,
1789 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1791 fprintf ( fMakefile
, "%s:\n\n",
1797 static MingwWin32GUIModuleHandler win32gui_handler
;
1799 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
1800 : MingwModuleHandler ( Win32GUI
)
1805 MingwWin32GUIModuleHandler::Process ( const Module
& module
)
1807 GeneratePreconditionDependencies ( module
);
1808 GenerateWin32GUIModuleTarget ( module
);
1809 GenerateInvocations ( module
);
1813 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
)
1815 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1816 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1817 string workingDirectory
= GetWorkingDirectory ( );
1818 string objectFilenames
= GetObjectFilenames ( module
);
1819 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1821 GenerateImportLibraryTargetIfNeeded ( module
);
1823 if ( module
.files
.size () > 0 )
1825 GenerateMacrosAndTargetsTarget ( module
);
1827 fprintf ( fMakefile
, "%s: %s %s\n",
1829 objectFilenames
.c_str (),
1830 importLibraryDependencies
.c_str () );
1833 if ( IsCPlusPlusModule ( module
) )
1838 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1839 module
.entrypoint
.c_str (),
1840 module
.baseaddress
.c_str () );
1841 GenerateLinkerCommand ( module
,
1848 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1850 fprintf ( fMakefile
, "%s:\n\n",
1856 static MingwBootLoaderModuleHandler bootloadermodule_handler
;
1858 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()
1859 : MingwModuleHandler ( BootLoader
)
1864 MingwBootLoaderModuleHandler::Process ( const Module
& module
)
1866 GeneratePreconditionDependencies ( module
);
1867 GenerateBootLoaderModuleTarget ( module
);
1868 GenerateInvocations ( module
);
1872 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ( const Module
& module
)
1874 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1875 string
targetName ( module
.GetTargetName () );
1876 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1877 string workingDirectory
= GetWorkingDirectory ();
1878 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1879 string objectsMacro
= GetObjectsMacro ( module
);
1880 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1882 GenerateMacrosAndTargetsTarget ( module
);
1884 fprintf ( fMakefile
, "%s: %s %s\n",
1886 objectsMacro
.c_str (),
1887 importLibraryDependencies
.c_str () );
1889 fprintf ( fMakefile
,
1890 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
1891 GetLinkerMacro ( module
).c_str (),
1893 objectsMacro
.c_str (),
1894 importLibraryDependencies
.c_str () );
1895 fprintf ( fMakefile
,
1896 "\t${objcopy} -O binary %s %s\n",
1899 fprintf ( fMakefile
,
1901 junk_tmp
.c_str () );
1905 static MingwBootSectorModuleHandler bootsectormodule_handler
;
1907 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ()
1908 : MingwModuleHandler ( BootSector
)
1913 MingwBootSectorModuleHandler::Process ( const Module
& module
)
1915 GeneratePreconditionDependencies ( module
);
1916 GenerateBootSectorModuleTarget ( module
);
1917 GenerateInvocations ( module
);
1921 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
)
1923 string objectsMacro
= GetObjectsMacro ( module
);
1925 string
* nasmflags
= new string ( "-f bin" );
1926 GenerateMacrosAndTargetsTarget ( module
,
1930 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1931 module
.name
.c_str ());
1932 fprintf ( fMakefile
,
1934 module
.name
.c_str (),
1935 objectsMacro
.c_str () );
1939 static MingwIsoModuleHandler isomodule_handler
;
1941 MingwIsoModuleHandler::MingwIsoModuleHandler ()
1942 : MingwModuleHandler ( Iso
)
1947 MingwIsoModuleHandler::Process ( const Module
& module
)
1949 GeneratePreconditionDependencies ( module
);
1950 GenerateIsoModuleTarget ( module
);
1951 GenerateInvocations ( module
);
1955 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string bootcdDirectory
,
1956 const Module
& module
) const
1958 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
1960 const Module
& m
= *module
.project
.modules
[i
];
1961 if ( m
.bootstrap
!= NULL
)
1963 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
1964 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
1965 fprintf ( fMakefile
,
1967 m
.GetPath ().c_str (),
1968 targetFilename
.c_str () );
1974 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string bootcdDirectory
,
1975 const Module
& module
) const
1977 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
1979 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
1980 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
1981 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
1982 fprintf ( fMakefile
,
1984 cdfile
.GetPath ().c_str (),
1985 targetFilename
.c_str () );
1990 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string bootcdDirectory
,
1991 const Module
& module
) const
1994 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
1996 const Module
& m
= *module
.project
.modules
[i
];
1997 if ( m
.bootstrap
!= NULL
)
1999 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2000 if ( directories
.size () > 0 )
2002 directories
+= FixupTargetFilename ( targetDirecctory
);
2009 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string bootcdDirectory
,
2010 const Module
& module
) const
2013 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2015 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2016 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2017 if ( directories
.size () > 0 )
2019 directories
+= FixupTargetFilename ( targetDirecctory
);
2025 MingwIsoModuleHandler::GetCdDirectories ( const string bootcdDirectory
,
2026 const Module
& module
) const
2028 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2030 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2036 MingwIsoModuleHandler::GetBootstrapCdFiles ( const string bootcdDirectory
,
2037 const Module
& module
) const
2040 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2042 const Module
& m
= *module
.project
.modules
[i
];
2043 if ( m
.bootstrap
!= NULL
)
2045 if ( cdfiles
.size () > 0 )
2047 cdfiles
+= FixupTargetFilename ( m
.GetPath () );
2054 MingwIsoModuleHandler::GetNonModuleCdFiles ( const string bootcdDirectory
,
2055 const Module
& module
) const
2058 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2060 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2061 if ( cdfiles
.size () > 0 )
2063 cdfiles
+= NormalizeFilename ( cdfile
.GetPath () );
2069 MingwIsoModuleHandler::GetCdFiles ( const string bootcdDirectory
,
2070 const Module
& module
) const
2072 string cdfiles
= GetBootstrapCdFiles ( bootcdDirectory
,
2074 cdfiles
+= " " + GetNonModuleCdFiles ( bootcdDirectory
,
2080 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
)
2082 string bootcdDirectory
= "cd";
2083 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2084 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2085 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2086 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2087 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2088 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2089 string cdDirectories
= bootcdReactos
+ " " + GetCdDirectories ( bootcdDirectory
,
2091 string cdFiles
= GetCdFiles ( bootcdDirectory
,
2094 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2095 module
.name
.c_str ());
2096 fprintf ( fMakefile
,
2097 "%s: all %s %s %s\n",
2098 module
.name
.c_str (),
2100 cdDirectories
.c_str (),
2102 fprintf ( fMakefile
,
2103 "\t${cabman} /C %s /L %s /I\n",
2104 reactosDff
.c_str (),
2105 bootcdReactos
.c_str () );
2106 fprintf ( fMakefile
,
2107 "\t${cabman} /C %s /RC %s /L %s /N\n",
2108 reactosDff
.c_str (),
2109 reactosInf
.c_str (),
2110 bootcdReactos
.c_str () );
2111 fprintf ( fMakefile
,
2113 reactosInf
.c_str () );
2114 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2116 OutputCdfileCopyCommands ( bootcdDirectory
,
2118 fprintf ( fMakefile
,
2119 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2121 bootcdDirectory
.c_str () );
2122 fprintf ( fMakefile
,