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 () > 0 || defines
.size () > 0 )
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() );
512 if ( files
.size () > 0 )
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 if ( !files
[i
]->first
)
537 ( i
%10 == 9 ? "\\\n\t" : " " ),
538 PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) ).c_str () );
541 fprintf ( fMakefile
, "\n" );
544 for ( i
= 0; i
< ifs
.size(); i
++ )
547 if ( rIf
.defines
.size() || rIf
.includes
.size() || rIf
.files
.size() || rIf
.ifs
.size() )
551 "ifeq (\"$(%s)\",\"%s\")\n",
552 rIf
.property
.c_str(),
575 MingwModuleHandler::GenerateMacros (
576 const Module
& module
,
577 const string
& cflags_macro
,
578 const string
& nasmflags_macro
,
579 const string
& windresflags_macro
,
580 const string
& linkerflags_macro
,
581 const string
& objs_macro
) const
588 &module
.compilerFlags
,
596 fprintf ( fMakefile
, "\n" );
600 "%s += $(PROJECT_CFLAGS)\n\n",
601 cflags_macro
.c_str () );
605 "%s += $(PROJECT_RCFLAGS)\n\n",
606 windresflags_macro
.c_str () );
610 "%s_LFLAGS += $(PROJECT_LFLAGS)\n\n",
611 module
.name
.c_str () );
615 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
616 const string
& sourceFilename
,
618 const string
& cflagsMacro
) const
620 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
623 objectFilename
.c_str (),
624 sourceFilename
.c_str () );
626 "\t%s -c %s -o %s %s\n",
628 sourceFilename
.c_str (),
629 objectFilename
.c_str (),
630 cflagsMacro
.c_str () );
634 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
635 const string
& sourceFilename
,
637 const string
& cflagsMacro
) const
639 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
642 objectFilename
.c_str (),
643 sourceFilename
.c_str () );
645 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
647 sourceFilename
.c_str (),
648 objectFilename
.c_str (),
649 cflagsMacro
.c_str () );
653 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
654 const string
& sourceFilename
,
655 const string
& nasmflagsMacro
) const
657 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
660 objectFilename
.c_str (),
661 sourceFilename
.c_str () );
663 "\t%s -f win32 %s -o %s %s\n",
665 sourceFilename
.c_str (),
666 objectFilename
.c_str (),
667 nasmflagsMacro
.c_str () );
671 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
672 const string
& sourceFilename
,
673 const string
& windresflagsMacro
) const
675 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
676 string rciFilename
= ReplaceExtension ( sourceFilename
,
678 string resFilename
= ReplaceExtension ( sourceFilename
,
682 objectFilename
.c_str (),
683 sourceFilename
.c_str () );
685 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
686 windresflagsMacro
.c_str (),
687 sourceFilename
.c_str (),
688 rciFilename
.c_str () );
690 "\t${wrc} ${%s} %s %s\n",
691 windresflagsMacro
.c_str (),
692 rciFilename
.c_str (),
693 resFilename
.c_str () );
696 rciFilename
.c_str () );
698 "\t${windres} %s -o %s\n",
699 resFilename
.c_str (),
700 objectFilename
.c_str () );
703 resFilename
.c_str () );
707 MingwModuleHandler::GenerateWinebuildCommands ( const Module
& module
,
708 const string
& sourceFilename
) const
710 string basename
= GetBasename ( sourceFilename
);
714 sourceFilename
.c_str () );
716 "\t%s --def=%s -o %s.spec.def\n",
718 sourceFilename
.c_str (),
724 sourceFilename
.c_str () );
726 "\t%s --pedll=%s -o %s.stubs.c\n",
728 sourceFilename
.c_str (),
733 MingwModuleHandler::GenerateCommands ( const Module
& module
,
734 const string
& sourceFilename
,
737 const string
& cflagsMacro
,
738 const string
& nasmflagsMacro
,
739 const string
& windresflagsMacro
) const
741 string extension
= GetExtension ( sourceFilename
);
742 if ( extension
== ".c" || extension
== ".C" )
744 GenerateGccCommand ( module
,
750 else if ( extension
== ".cc" || extension
== ".CC" ||
751 extension
== ".cpp" || extension
== ".CPP" ||
752 extension
== ".cxx" || extension
== ".CXX" )
754 GenerateGccCommand ( module
,
760 else if ( extension
== ".s" || extension
== ".S" )
762 GenerateGccAssemblerCommand ( module
,
768 else if ( extension
== ".asm" || extension
== ".ASM" )
770 GenerateNasmCommand ( module
,
775 else if ( extension
== ".rc" || extension
== ".RC" )
777 GenerateWindresCommand ( module
,
782 else if ( extension
== ".spec" || extension
== ".SPEC" )
784 GenerateWinebuildCommands ( module
,
786 GenerateGccCommand ( module
,
787 GetActualSourceFilename ( sourceFilename
),
793 throw InvalidOperationException ( __FILE__
,
795 "Unsupported filename extension '%s' in file '%s'",
797 sourceFilename
.c_str () );
801 MingwModuleHandler::GenerateLinkerCommand ( const Module
& module
,
802 const string
& linker
,
803 const string
& linkerParameters
,
804 const string
& objectFilenames
) const
806 string
targetName ( module
.GetTargetName () );
807 string
target ( FixupTargetFilename ( module
.GetPath () ) );
808 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
809 if ( module
.importLibrary
!= NULL
)
811 static string
ros_junk ( "$(ROS_TEMPORARY)" );
812 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
813 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
814 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
817 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
819 linkerParameters
.c_str (),
822 objectFilenames
.c_str (),
823 importLibraryDependencies
.c_str (),
824 GetLinkerMacro ( module
).c_str () );
830 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
832 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
835 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
844 "\t%s %s %s -o %s %s %s %s\n\n",
846 linkerParameters
.c_str (),
849 objectFilenames
.c_str (),
850 importLibraryDependencies
.c_str (),
851 GetLinkerMacro ( module
).c_str () );
860 "\t%s %s -o %s %s %s %s\n\n",
862 linkerParameters
.c_str (),
864 objectFilenames
.c_str (),
865 importLibraryDependencies
.c_str (),
866 GetLinkerMacro ( module
).c_str () );
876 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
877 const vector
<File
*>& files
,
878 const vector
<If
*>& ifs
,
881 const string
& cflagsMacro
,
882 const string
& nasmflagsMacro
,
883 const string
& windresflagsMacro
) const
887 for ( i
= 0; i
< files
.size (); i
++ )
889 string sourceFilename
= files
[i
]->name
;
890 GenerateCommands ( module
,
901 for ( i
= 0; i
< ifs
.size(); i
++ )
903 GenerateObjectFileTargets ( module
,
915 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
918 const string
& cflagsMacro
,
919 const string
& nasmflagsMacro
,
920 const string
& windresflagsMacro
) const
922 GenerateObjectFileTargets ( module
,
930 fprintf ( fMakefile
, "\n" );
934 MingwModuleHandler::GetCleanTargets ( vector
<string
>& out
,
935 const vector
<File
*>& files
,
936 const vector
<If
*>& ifs
) const
940 for ( i
= 0; i
< files
.size(); i
++ )
941 out
.push_back ( PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) ) );
943 for ( i
= 0; i
< ifs
.size(); i
++ )
944 GetCleanTargets ( out
, ifs
[i
]->files
, ifs
[i
]->ifs
);
948 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
950 const string
& objs_macro
) const
952 string archiveFilename
= GetModuleArchiveFilename ( module
);
956 archiveFilename
.c_str (),
957 objs_macro
.c_str ());
960 "\t%s -rc %s %s\n\n",
962 archiveFilename
.c_str (),
963 objs_macro
.c_str ());
965 return archiveFilename
;
969 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
971 return ssprintf ( "$(%s_CFLAGS)",
972 module
.name
.c_str () );
976 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
978 return ssprintf ( "$(%s_OBJS)",
979 module
.name
.c_str () );
983 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
985 return ssprintf ( "$(%s_LFLAGS)",
986 module
.name
.c_str () );
990 MingwModuleHandler::GenerateMacrosAndTargets (
991 const Module
& module
,
995 const string
* cflags
,
996 const string
* nasmflags
) const
998 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
999 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1000 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1001 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1002 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1004 GenerateMacros ( module
,
1011 if ( cflags
!= NULL
)
1013 fprintf ( fMakefile
,
1015 cflagsMacro
.c_str (),
1019 if ( nasmflags
!= NULL
)
1021 fprintf ( fMakefile
,
1023 nasmflagsMacro
.c_str (),
1024 nasmflags
->c_str () );
1027 // generate phony target for module name
1028 fprintf ( fMakefile
, ".PHONY: %s\n",
1029 module
.name
.c_str () );
1030 fprintf ( fMakefile
, "%s: %s\n\n",
1031 module
.name
.c_str (),
1032 FixupTargetFilename ( module
.GetPath () ).c_str () );
1034 // future references to the macros will be to get their values
1035 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1036 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1037 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1039 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1040 GenerateObjectFileTargets ( module
,
1045 windresflagsMacro
);
1047 vector
<string
> clean_files
;
1048 clean_files
.push_back ( FixupTargetFilename(module
.GetPath()) );
1049 clean_files
.push_back ( ar_target
);
1050 GetCleanTargets ( clean_files
, module
.files
, module
.ifs
);
1052 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
1053 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
1054 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
1057 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
1058 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
1060 fprintf ( fMakefile
, " 2>$(NUL)\n" );
1061 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
1065 MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module
& module
) const
1067 GenerateMacrosAndTargets ( module
,
1076 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
) const
1078 GenerateMacrosAndTargetsTarget ( module
,
1084 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
,
1085 const string
* cflags
,
1086 const string
* nasmflags
) const
1088 GenerateMacrosAndTargets ( module
,
1097 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
1099 string dependencies
;
1100 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1102 Invoke
& invoke
= *module
.invocations
[i
];
1103 if (invoke
.invokeModule
== &module
)
1104 /* Protect against circular dependencies */
1106 if ( dependencies
.length () > 0 )
1107 dependencies
+= " ";
1108 dependencies
+= invoke
.GetTargets ();
1110 return dependencies
;
1114 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1116 if ( module
.invocations
.size () == 0 )
1119 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1121 const Invoke
& invoke
= *module
.invocations
[i
];
1123 if ( invoke
.invokeModule
->type
!= BuildTool
)
1125 throw InvalidBuildFileException ( module
.node
.location
,
1126 "Only modules of type buildtool can be invoked." );
1129 string invokeTarget
= module
.GetInvocationTarget ( i
);
1130 fprintf ( fMakefile
,
1132 invokeTarget
.c_str () );
1133 fprintf ( fMakefile
,
1135 invokeTarget
.c_str (),
1136 invoke
.GetTargets ().c_str () );
1137 fprintf ( fMakefile
,
1139 invoke
.GetTargets ().c_str (),
1140 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1141 fprintf ( fMakefile
,
1143 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1144 invoke
.GetParameters ().c_str () );
1149 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1151 return ssprintf ( "%s_precondition",
1152 module
.name
.c_str () );
1156 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1158 /* Avoid circular dependency */
1159 if ( module
.type
== BuildTool
|| module
.name
== "zlib" )
1160 return "$(ROS_INTERMEDIATE)." SSEP
"tools $(ROS_INTERMEDIATE)." SSEP
"lib" SSEP
"zlib";
1166 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
1168 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1169 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1170 string dependencies
= GetDefaultDependencies ( module
);
1171 string s
= GetModuleDependencies ( module
);
1172 if ( s
.length () > 0 )
1174 if ( dependencies
.length () > 0 )
1175 dependencies
+= " ";
1179 s
= GetInvocationDependencies ( module
);
1180 if ( s
.length () > 0 )
1182 if ( dependencies
.length () > 0 )
1183 dependencies
+= " ";
1187 fprintf ( fMakefile
,
1189 preconditionDependenciesName
.c_str () );
1190 fprintf ( fMakefile
,
1192 preconditionDependenciesName
.c_str (),
1193 dependencies
.c_str () );
1194 const char* p
= sourceFilenames
.c_str();
1195 const char* end
= p
+ strlen(p
);
1198 const char* p2
= &p
[512];
1201 while ( p2
> p
&& !isspace(*p2
) )
1205 p2
= strpbrk ( p
, " \t" );
1209 fprintf ( fMakefile
,
1213 preconditionDependenciesName
.c_str ());
1215 p
+= strspn ( p
, " \t" );
1217 fprintf ( fMakefile
, "\n" );
1221 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module
& module
) const
1223 if ( module
.importLibrary
!= NULL
)
1225 string definitionDependencies
= GetDefinitionDependencies ( module
);
1226 fprintf ( fMakefile
, "%s: %s\n",
1227 FixupTargetFilename( module
.GetDependencyPath () ).c_str (),
1228 definitionDependencies
.c_str () );
1230 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1231 fprintf ( fMakefile
,
1232 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1233 module
.GetTargetName ().c_str (),
1234 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1235 FixupTargetFilename ( module
.GetDependencyPath () ).c_str (),
1241 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1243 string basename
= GetBasename ( filename
);
1244 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1248 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
) const
1250 string dependencies
;
1251 string dkNkmLibNoFixup
= "dk/nkm/lib";
1252 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1253 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1254 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
1256 File
& file
= *module
.files
[i
];
1257 string extension
= GetExtension ( file
.name
);
1258 if ( extension
== ".spec" || extension
== ".SPEC" )
1260 if ( dependencies
.length () > 0 )
1261 dependencies
+= " ";
1262 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1265 return dependencies
;
1269 MingwModuleHandler::GetLinkingDependencies ( const Module
& module
) const
1271 string dependencies
= GetImportLibraryDependencies ( module
);
1272 string s
= GetDefinitionDependencies ( module
);
1273 if ( s
.length () > 0 )
1275 dependencies
+= " ";
1278 return dependencies
;
1282 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
) const
1284 if ( module
.HasFileWithExtensions ( ".cc", ".CC" ) )
1286 if ( module
.HasFileWithExtensions ( ".cxx", ".CXX" ) )
1288 if ( module
.HasFileWithExtensions ( ".cpp", ".CPP" ) )
1294 static MingwBuildToolModuleHandler buildtool_handler
;
1296 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1297 : MingwModuleHandler ( BuildTool
)
1302 MingwBuildToolModuleHandler::Process ( const Module
& module
)
1304 GeneratePreconditionDependencies ( module
);
1305 GenerateBuildToolModuleTarget ( module
);
1306 GenerateInvocations ( module
);
1310 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
)
1312 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1313 string objectsMacro
= GetObjectsMacro ( module
);
1314 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1316 GenerateMacrosAndTargetsHost ( module
);
1319 if ( IsCPlusPlusModule ( module
) )
1320 linker
= "${host_gpp}";
1322 linker
= "${host_gcc}";
1324 fprintf ( fMakefile
, "%s: %s %s\n",
1326 objectsMacro
.c_str (),
1327 importLibraryDependencies
.c_str () );
1328 fprintf ( fMakefile
,
1329 "\t%s %s -o %s %s %s\n\n",
1331 GetLinkerMacro ( module
).c_str (),
1333 objectsMacro
.c_str (),
1334 importLibraryDependencies
.c_str () );
1338 static MingwKernelModuleHandler kernelmodule_handler
;
1340 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1341 : MingwModuleHandler ( Kernel
)
1346 MingwKernelModuleHandler::Process ( const Module
& module
)
1348 GeneratePreconditionDependencies ( module
);
1349 GenerateKernelModuleTarget ( module
);
1350 GenerateInvocations ( module
);
1354 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
)
1356 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1357 string
targetName ( module
.GetTargetName () );
1358 string
target ( FixupTargetFilename (module
.GetPath ()) );
1359 string workingDirectory
= GetWorkingDirectory ();
1360 string objectsMacro
= GetObjectsMacro ( module
);
1361 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1362 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1363 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1364 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1365 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",
1366 module
.GetBasePath ().c_str (),
1367 module
.entrypoint
.c_str (),
1368 module
.baseaddress
.c_str () );
1370 GenerateMacrosAndTargetsTarget ( module
);
1372 GenerateImportLibraryTargetIfNeeded ( module
);
1374 fprintf ( fMakefile
, "%s: %s %s\n",
1376 objectsMacro
.c_str (),
1377 importLibraryDependencies
.c_str () );
1378 fprintf ( fMakefile
,
1379 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1380 GetLinkerMacro ( module
).c_str (),
1381 gccOptions
.c_str (),
1384 objectsMacro
.c_str (),
1385 importLibraryDependencies
.c_str () );
1386 fprintf ( fMakefile
,
1388 junk_tmp
.c_str () );
1389 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1390 fprintf ( fMakefile
,
1391 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1392 targetName
.c_str (),
1396 fprintf ( fMakefile
,
1398 base_tmp
.c_str () );
1399 fprintf ( fMakefile
,
1400 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1401 GetLinkerMacro ( module
).c_str (),
1402 gccOptions
.c_str (),
1405 objectsMacro
.c_str (),
1406 importLibraryDependencies
.c_str () );
1407 fprintf ( fMakefile
,
1409 temp_exp
.c_str () );
1410 fprintf ( fMakefile
,
1411 "\t${rsym} %s %s\n",
1417 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1419 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1420 : MingwModuleHandler ( StaticLibrary
)
1425 MingwStaticLibraryModuleHandler::Process ( const Module
& module
)
1427 GeneratePreconditionDependencies ( module
);
1428 GenerateStaticLibraryModuleTarget ( module
);
1429 GenerateInvocations ( module
);
1433 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
)
1435 GenerateMacrosAndTargetsTarget ( module
);
1439 static MingwObjectLibraryModuleHandler objectlibrary_handler
;
1441 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()
1442 : MingwModuleHandler ( ObjectLibrary
)
1447 MingwObjectLibraryModuleHandler::Process ( const Module
& module
)
1449 GeneratePreconditionDependencies ( module
);
1450 GenerateObjectLibraryModuleTarget ( module
);
1451 GenerateInvocations ( module
);
1455 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
)
1457 GenerateMacrosAndTargetsTarget ( module
);
1461 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1463 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1464 : MingwModuleHandler ( KernelModeDLL
)
1469 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
)
1471 GeneratePreconditionDependencies ( module
);
1472 GenerateKernelModeDLLModuleTarget ( module
);
1473 GenerateInvocations ( module
);
1477 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Module
& module
)
1479 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1480 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1481 string workingDirectory
= GetWorkingDirectory ( );
1482 string objectsMacro
= GetObjectsMacro ( module
);
1483 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1485 GenerateImportLibraryTargetIfNeeded ( module
);
1487 if ( module
.files
.size () > 0 )
1489 GenerateMacrosAndTargetsTarget ( module
);
1491 fprintf ( fMakefile
, "%s: %s %s\n",
1493 objectsMacro
.c_str (),
1494 importLibraryDependencies
.c_str () );
1496 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1497 module
.entrypoint
.c_str (),
1498 module
.baseaddress
.c_str () );
1499 GenerateLinkerCommand ( module
,
1506 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1508 fprintf ( fMakefile
, "%s:\n",
1514 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1516 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1517 : MingwModuleHandler ( KernelModeDriver
)
1522 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
)
1524 GeneratePreconditionDependencies ( module
);
1525 GenerateKernelModeDriverModuleTarget ( module
);
1526 GenerateInvocations ( module
);
1531 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module
& module
)
1533 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1534 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1535 string workingDirectory
= GetWorkingDirectory ();
1536 string objectsMacro
= GetObjectsMacro ( module
);
1537 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1539 GenerateImportLibraryTargetIfNeeded ( module
);
1541 if ( module
.files
.size () > 0 )
1543 string
* cflags
= new string ( "-D__NTDRIVER__" );
1544 GenerateMacrosAndTargetsTarget ( module
,
1549 fprintf ( fMakefile
, "%s: %s %s\n",
1551 objectsMacro
.c_str (),
1552 importLibraryDependencies
.c_str () );
1554 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1555 module
.entrypoint
.c_str (),
1556 module
.baseaddress
.c_str () );
1557 GenerateLinkerCommand ( module
,
1564 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1566 fprintf ( fMakefile
, "%s:\n",
1572 static MingwNativeDLLModuleHandler nativedll_handler
;
1574 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1575 : MingwModuleHandler ( NativeDLL
)
1580 MingwNativeDLLModuleHandler::Process ( const Module
& module
)
1582 GeneratePreconditionDependencies ( module
);
1583 GenerateNativeDLLModuleTarget ( module
);
1584 GenerateInvocations ( module
);
1588 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
)
1590 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1591 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1592 string workingDirectory
= GetWorkingDirectory ( );
1593 string objectsMacro
= GetObjectsMacro ( module
);
1594 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1596 GenerateImportLibraryTargetIfNeeded ( module
);
1598 if ( module
.files
.size () > 0 )
1600 GenerateMacrosAndTargetsTarget ( module
);
1602 fprintf ( fMakefile
, "%s: %s %s\n",
1604 objectsMacro
.c_str (),
1605 importLibraryDependencies
.c_str () );
1607 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1608 module
.entrypoint
.c_str (),
1609 module
.baseaddress
.c_str () );
1610 GenerateLinkerCommand ( module
,
1617 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1619 fprintf ( fMakefile
, "%s:\n\n",
1625 static MingwNativeCUIModuleHandler nativecui_handler
;
1627 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ()
1628 : MingwModuleHandler ( NativeCUI
)
1633 MingwNativeCUIModuleHandler::Process ( const Module
& module
)
1635 GeneratePreconditionDependencies ( module
);
1636 GenerateNativeCUIModuleTarget ( module
);
1637 GenerateInvocations ( module
);
1641 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module
& module
)
1643 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1644 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1645 string workingDirectory
= GetWorkingDirectory ( );
1646 string objectsMacro
= GetObjectsMacro ( module
);
1647 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1649 GenerateImportLibraryTargetIfNeeded ( module
);
1651 if ( module
.files
.size () > 0 )
1653 string
* cflags
= new string ( "-D__NTAPP__" );
1654 GenerateMacrosAndTargetsTarget ( module
,
1659 fprintf ( fMakefile
, "%s: %s %s\n",
1661 objectsMacro
.c_str (),
1662 importLibraryDependencies
.c_str () );
1664 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1665 module
.entrypoint
.c_str (),
1666 module
.baseaddress
.c_str () );
1667 GenerateLinkerCommand ( module
,
1674 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1676 fprintf ( fMakefile
, "%s:\n\n",
1682 static MingwWin32DLLModuleHandler win32dll_handler
;
1684 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1685 : MingwModuleHandler ( Win32DLL
)
1690 MingwWin32DLLModuleHandler::Process ( const Module
& module
)
1692 GenerateExtractWineDLLResourcesTarget ( module
);
1693 GeneratePreconditionDependencies ( module
);
1694 GenerateWin32DLLModuleTarget ( module
);
1695 GenerateInvocations ( module
);
1699 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
)
1701 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1702 module
.name
.c_str () );
1703 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1704 module
.name
.c_str () );
1705 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
1707 File
& file
= *module
.files
[i
];
1708 string extension
= GetExtension ( file
.name
);
1709 if ( extension
== ".rc" || extension
== ".RC" )
1711 string resource
= FixupTargetFilename ( file
.name
);
1712 fprintf ( fMakefile
, "\t@echo ${bin2res} -f -x %s\n",
1713 resource
.c_str () );
1716 fprintf ( fMakefile
, "\n");
1720 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
)
1722 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1723 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1724 string workingDirectory
= GetWorkingDirectory ( );
1725 string objectsMacro
= GetObjectsMacro ( module
);
1726 string linkingDependencies
= GetLinkingDependencies ( module
);
1728 GenerateImportLibraryTargetIfNeeded ( module
);
1729 if ( module
.files
.size () > 0 )
1731 GenerateMacrosAndTargetsTarget ( module
);
1733 fprintf ( fMakefile
, "%s: %s %s\n",
1735 objectsMacro
.c_str (),
1736 linkingDependencies
.c_str () );
1739 if ( IsCPlusPlusModule ( module
) )
1744 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1745 module
.entrypoint
.c_str (),
1746 module
.baseaddress
.c_str () );
1747 GenerateLinkerCommand ( module
,
1754 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1756 fprintf ( fMakefile
, "%s:\n\n",
1762 static MingwWin32CUIModuleHandler win32cui_handler
;
1764 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ()
1765 : MingwModuleHandler ( Win32CUI
)
1770 MingwWin32CUIModuleHandler::Process ( const Module
& module
)
1772 GeneratePreconditionDependencies ( module
);
1773 GenerateWin32CUIModuleTarget ( module
);
1774 GenerateInvocations ( module
);
1778 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
)
1780 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1781 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1782 string workingDirectory
= GetWorkingDirectory ( );
1783 string objectsMacro
= GetObjectsMacro ( module
);
1784 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1786 GenerateImportLibraryTargetIfNeeded ( module
);
1788 if ( module
.files
.size () > 0 )
1790 GenerateMacrosAndTargetsTarget ( module
);
1792 fprintf ( fMakefile
, "%s: %s %s\n",
1794 objectsMacro
.c_str (),
1795 importLibraryDependencies
.c_str () );
1798 if ( IsCPlusPlusModule ( module
) )
1803 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1804 module
.entrypoint
.c_str (),
1805 module
.baseaddress
.c_str () );
1806 GenerateLinkerCommand ( module
,
1813 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1815 fprintf ( fMakefile
, "%s:\n\n",
1821 static MingwWin32GUIModuleHandler win32gui_handler
;
1823 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
1824 : MingwModuleHandler ( Win32GUI
)
1829 MingwWin32GUIModuleHandler::Process ( const Module
& module
)
1831 GeneratePreconditionDependencies ( module
);
1832 GenerateWin32GUIModuleTarget ( module
);
1833 GenerateInvocations ( module
);
1837 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
)
1839 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1840 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1841 string workingDirectory
= GetWorkingDirectory ( );
1842 string objectsMacro
= GetObjectsMacro ( module
);
1843 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1845 GenerateImportLibraryTargetIfNeeded ( module
);
1847 if ( module
.files
.size () > 0 )
1849 GenerateMacrosAndTargetsTarget ( module
);
1851 fprintf ( fMakefile
, "%s: %s %s\n",
1853 objectsMacro
.c_str (),
1854 importLibraryDependencies
.c_str () );
1857 if ( IsCPlusPlusModule ( module
) )
1862 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1863 module
.entrypoint
.c_str (),
1864 module
.baseaddress
.c_str () );
1865 GenerateLinkerCommand ( module
,
1872 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1874 fprintf ( fMakefile
, "%s:\n\n",
1880 static MingwBootLoaderModuleHandler bootloadermodule_handler
;
1882 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()
1883 : MingwModuleHandler ( BootLoader
)
1888 MingwBootLoaderModuleHandler::Process ( const Module
& module
)
1890 GeneratePreconditionDependencies ( module
);
1891 GenerateBootLoaderModuleTarget ( module
);
1892 GenerateInvocations ( module
);
1896 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ( const Module
& module
)
1898 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1899 string
targetName ( module
.GetTargetName () );
1900 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1901 string workingDirectory
= GetWorkingDirectory ();
1902 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1903 string objectsMacro
= GetObjectsMacro ( module
);
1904 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1906 GenerateMacrosAndTargetsTarget ( module
);
1908 fprintf ( fMakefile
, "%s: %s %s\n",
1910 objectsMacro
.c_str (),
1911 importLibraryDependencies
.c_str () );
1913 fprintf ( fMakefile
,
1914 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
1915 GetLinkerMacro ( module
).c_str (),
1917 objectsMacro
.c_str (),
1918 importLibraryDependencies
.c_str () );
1919 fprintf ( fMakefile
,
1920 "\t${objcopy} -O binary %s %s\n",
1923 fprintf ( fMakefile
,
1925 junk_tmp
.c_str () );
1929 static MingwBootSectorModuleHandler bootsectormodule_handler
;
1931 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ()
1932 : MingwModuleHandler ( BootSector
)
1937 MingwBootSectorModuleHandler::Process ( const Module
& module
)
1939 GeneratePreconditionDependencies ( module
);
1940 GenerateBootSectorModuleTarget ( module
);
1941 GenerateInvocations ( module
);
1945 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
)
1947 string objectsMacro
= GetObjectsMacro ( module
);
1949 string
* nasmflags
= new string ( "-f bin" );
1950 GenerateMacrosAndTargetsTarget ( module
,
1954 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1955 module
.name
.c_str ());
1956 fprintf ( fMakefile
,
1958 module
.name
.c_str (),
1959 objectsMacro
.c_str () );
1963 static MingwIsoModuleHandler isomodule_handler
;
1965 MingwIsoModuleHandler::MingwIsoModuleHandler ()
1966 : MingwModuleHandler ( Iso
)
1971 MingwIsoModuleHandler::Process ( const Module
& module
)
1973 GeneratePreconditionDependencies ( module
);
1974 GenerateIsoModuleTarget ( module
);
1975 GenerateInvocations ( module
);
1979 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string bootcdDirectory
,
1980 const Module
& module
) const
1982 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
1984 const Module
& m
= *module
.project
.modules
[i
];
1985 if ( m
.bootstrap
!= NULL
)
1987 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
1988 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
1989 fprintf ( fMakefile
,
1991 m
.GetPath ().c_str (),
1992 targetFilename
.c_str () );
1998 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string bootcdDirectory
,
1999 const Module
& module
) const
2001 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2003 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2004 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2005 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2006 fprintf ( fMakefile
,
2008 cdfile
.GetPath ().c_str (),
2009 targetFilename
.c_str () );
2014 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string bootcdDirectory
,
2015 const Module
& module
) const
2018 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2020 const Module
& m
= *module
.project
.modules
[i
];
2021 if ( m
.bootstrap
!= NULL
)
2023 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2024 if ( directories
.size () > 0 )
2026 directories
+= FixupTargetFilename ( targetDirecctory
);
2033 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string bootcdDirectory
,
2034 const Module
& module
) const
2037 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2039 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2040 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2041 if ( directories
.size () > 0 )
2043 directories
+= FixupTargetFilename ( targetDirecctory
);
2049 MingwIsoModuleHandler::GetCdDirectories ( const string bootcdDirectory
,
2050 const Module
& module
) const
2052 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2054 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2060 MingwIsoModuleHandler::GetBootstrapCdFiles ( const string bootcdDirectory
,
2061 const Module
& module
) const
2064 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2066 const Module
& m
= *module
.project
.modules
[i
];
2067 if ( m
.bootstrap
!= NULL
)
2069 if ( cdfiles
.size () > 0 )
2071 cdfiles
+= FixupTargetFilename ( m
.GetPath () );
2078 MingwIsoModuleHandler::GetNonModuleCdFiles ( const string bootcdDirectory
,
2079 const Module
& module
) const
2082 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2084 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2085 if ( cdfiles
.size () > 0 )
2087 cdfiles
+= NormalizeFilename ( cdfile
.GetPath () );
2093 MingwIsoModuleHandler::GetCdFiles ( const string bootcdDirectory
,
2094 const Module
& module
) const
2096 string cdfiles
= GetBootstrapCdFiles ( bootcdDirectory
,
2098 cdfiles
+= " " + GetNonModuleCdFiles ( bootcdDirectory
,
2104 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
)
2106 string bootcdDirectory
= "cd";
2107 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2108 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2109 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2110 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2111 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2112 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2113 string cdDirectories
= bootcdReactos
+ " " + GetCdDirectories ( bootcdDirectory
,
2115 string cdFiles
= GetCdFiles ( bootcdDirectory
,
2118 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2119 module
.name
.c_str ());
2120 fprintf ( fMakefile
,
2121 "%s: all %s %s %s\n",
2122 module
.name
.c_str (),
2124 cdDirectories
.c_str (),
2126 fprintf ( fMakefile
,
2127 "\t${cabman} -C %s -L %s -I\n",
2128 reactosDff
.c_str (),
2129 bootcdReactos
.c_str () );
2130 fprintf ( fMakefile
,
2131 "\t${cabman} -C %s -RC %s -L %s -N\n",
2132 reactosDff
.c_str (),
2133 reactosInf
.c_str (),
2134 bootcdReactos
.c_str () );
2135 fprintf ( fMakefile
,
2137 reactosInf
.c_str () );
2138 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2140 OutputCdfileCopyCommands ( bootcdDirectory
,
2142 fprintf ( fMakefile
,
2143 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2145 bootcdDirectory
.c_str () );
2146 fprintf ( fMakefile
,