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
) );
679 string rciFilename
= ReplaceExtension ( sourceFilename
,
681 string resFilename
= ReplaceExtension ( sourceFilename
,
685 objectFilename
.c_str (),
686 sourceFilename
.c_str () );
688 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
689 windresflagsMacro
.c_str (),
690 sourceFilename
.c_str (),
691 rciFilename
.c_str () );
693 "\t${wrc} ${%s} %s %s\n",
694 windresflagsMacro
.c_str (),
695 rciFilename
.c_str (),
696 resFilename
.c_str () );
699 rciFilename
.c_str () );
701 "\t${windres} %s -o %s\n",
702 resFilename
.c_str (),
703 objectFilename
.c_str () );
706 resFilename
.c_str () );
710 MingwModuleHandler::GenerateWinebuildCommands ( const Module
& module
,
711 const string
& sourceFilename
) const
713 string basename
= GetBasename ( sourceFilename
);
717 sourceFilename
.c_str () );
719 "\t%s --def=%s -o %s.spec.def\n",
721 sourceFilename
.c_str (),
727 sourceFilename
.c_str () );
729 "\t%s --pedll=%s -o %s.stubs.c\n",
731 sourceFilename
.c_str (),
736 MingwModuleHandler::GenerateCommands ( const Module
& module
,
737 const string
& sourceFilename
,
740 const string
& cflagsMacro
,
741 const string
& nasmflagsMacro
,
742 const string
& windresflagsMacro
) const
744 string extension
= GetExtension ( sourceFilename
);
745 if ( extension
== ".c" || extension
== ".C" )
747 GenerateGccCommand ( module
,
753 else if ( extension
== ".cc" || extension
== ".CC" ||
754 extension
== ".cpp" || extension
== ".CPP" ||
755 extension
== ".cxx" || extension
== ".CXX" )
757 GenerateGccCommand ( module
,
763 else if ( extension
== ".s" || extension
== ".S" )
765 GenerateGccAssemblerCommand ( module
,
771 else if ( extension
== ".asm" || extension
== ".ASM" )
773 GenerateNasmCommand ( module
,
778 else if ( extension
== ".rc" || extension
== ".RC" )
780 GenerateWindresCommand ( module
,
785 else if ( extension
== ".spec" || extension
== ".SPEC" )
787 GenerateWinebuildCommands ( module
,
789 GenerateGccCommand ( module
,
790 GetActualSourceFilename ( sourceFilename
),
796 throw InvalidOperationException ( __FILE__
,
798 "Unsupported filename extension '%s' in file '%s'",
800 sourceFilename
.c_str () );
804 MingwModuleHandler::GenerateLinkerCommand ( const Module
& module
,
805 const string
& linker
,
806 const string
& linkerParameters
,
807 const string
& objectFilenames
) const
809 string
targetName ( module
.GetTargetName () );
810 string
target ( FixupTargetFilename ( module
.GetPath () ) );
811 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
812 if ( module
.importLibrary
!= NULL
)
814 static string
ros_junk ( "$(ROS_TEMPORARY)" );
815 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
816 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
817 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
820 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
822 linkerParameters
.c_str (),
825 objectFilenames
.c_str (),
826 importLibraryDependencies
.c_str (),
827 GetLinkerMacro ( module
).c_str () );
833 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
835 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
838 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
847 "\t%s %s %s -o %s %s %s %s\n\n",
849 linkerParameters
.c_str (),
852 objectFilenames
.c_str (),
853 importLibraryDependencies
.c_str (),
854 GetLinkerMacro ( module
).c_str () );
863 "\t%s %s -o %s %s %s %s\n\n",
865 linkerParameters
.c_str (),
867 objectFilenames
.c_str (),
868 importLibraryDependencies
.c_str (),
869 GetLinkerMacro ( module
).c_str () );
874 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
875 const vector
<File
*>& files
,
876 const vector
<If
*>& ifs
,
879 const string
& cflagsMacro
,
880 const string
& nasmflagsMacro
,
881 const string
& windresflagsMacro
) const
885 for ( i
= 0; i
< files
.size (); i
++ )
887 string sourceFilename
= files
[i
]->name
;
888 GenerateCommands ( module
,
899 for ( i
= 0; i
< ifs
.size(); i
++ )
901 GenerateObjectFileTargets ( module
,
913 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
916 const string
& cflagsMacro
,
917 const string
& nasmflagsMacro
,
918 const string
& windresflagsMacro
) const
920 GenerateObjectFileTargets ( module
,
928 fprintf ( fMakefile
, "\n" );
932 MingwModuleHandler::GetCleanTargets ( vector
<string
>& out
,
933 const vector
<File
*>& files
,
934 const vector
<If
*>& ifs
) const
938 for ( i
= 0; i
< files
.size(); i
++ )
939 out
.push_back ( PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) ) );
941 for ( i
= 0; i
< ifs
.size(); i
++ )
942 GetCleanTargets ( out
, ifs
[i
]->files
, ifs
[i
]->ifs
);
946 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
948 const string
& objs_macro
) const
950 string archiveFilename
= GetModuleArchiveFilename ( module
);
954 archiveFilename
.c_str (),
955 objs_macro
.c_str ());
958 "\t%s -rc %s %s\n\n",
960 archiveFilename
.c_str (),
961 objs_macro
.c_str ());
963 return archiveFilename
;
967 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
969 return ssprintf ( "$(%s_CFLAGS)",
970 module
.name
.c_str () );
974 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
976 return ssprintf ( "$(%s_OBJS)",
977 module
.name
.c_str () );
981 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
983 return ssprintf ( "$(%s_LFLAGS)",
984 module
.name
.c_str () );
988 MingwModuleHandler::GenerateMacrosAndTargets (
989 const Module
& module
,
993 const string
* cflags
,
994 const string
* nasmflags
) const
996 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
997 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
998 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
999 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1000 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1002 GenerateMacros ( module
,
1009 if ( cflags
!= NULL
)
1011 fprintf ( fMakefile
,
1013 cflagsMacro
.c_str (),
1017 if ( nasmflags
!= NULL
)
1019 fprintf ( fMakefile
,
1021 nasmflagsMacro
.c_str (),
1022 nasmflags
->c_str () );
1025 // generate phony target for module name
1026 fprintf ( fMakefile
, ".PHONY: %s\n",
1027 module
.name
.c_str () );
1028 fprintf ( fMakefile
, "%s: %s\n\n",
1029 module
.name
.c_str (),
1030 FixupTargetFilename ( module
.GetPath () ).c_str () );
1032 // future references to the macros will be to get their values
1033 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1034 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1035 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1037 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1038 GenerateObjectFileTargets ( module
,
1043 windresflagsMacro
);
1045 vector
<string
> clean_files
;
1046 clean_files
.push_back ( FixupTargetFilename(module
.GetPath()) );
1047 clean_files
.push_back ( ar_target
);
1048 GetCleanTargets ( clean_files
, module
.files
, module
.ifs
);
1050 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
1051 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
1052 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
1055 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
1056 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
1058 fprintf ( fMakefile
, " 2>$(NUL)\n" );
1059 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
1063 MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module
& module
) const
1065 GenerateMacrosAndTargets ( module
,
1074 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
) const
1076 GenerateMacrosAndTargetsTarget ( module
,
1082 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
,
1083 const string
* cflags
,
1084 const string
* nasmflags
) const
1086 GenerateMacrosAndTargets ( module
,
1095 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
1097 string dependencies
;
1098 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1100 Invoke
& invoke
= *module
.invocations
[i
];
1101 if (invoke
.invokeModule
== &module
)
1102 /* Protect against circular dependencies */
1104 if ( dependencies
.length () > 0 )
1105 dependencies
+= " ";
1106 dependencies
+= invoke
.GetTargets ();
1108 return dependencies
;
1112 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1114 if ( module
.invocations
.size () == 0 )
1117 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1119 const Invoke
& invoke
= *module
.invocations
[i
];
1121 if ( invoke
.invokeModule
->type
!= BuildTool
)
1123 throw InvalidBuildFileException ( module
.node
.location
,
1124 "Only modules of type buildtool can be invoked." );
1127 string invokeTarget
= module
.GetInvocationTarget ( i
);
1128 fprintf ( fMakefile
,
1130 invokeTarget
.c_str () );
1131 fprintf ( fMakefile
,
1133 invokeTarget
.c_str (),
1134 invoke
.GetTargets ().c_str () );
1135 fprintf ( fMakefile
,
1137 invoke
.GetTargets ().c_str (),
1138 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1139 fprintf ( fMakefile
,
1141 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1142 invoke
.GetParameters ().c_str () );
1147 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1149 return ssprintf ( "%s_precondition",
1150 module
.name
.c_str () );
1154 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1156 /* Avoid circular dependency */
1157 if ( module
.type
== BuildTool
|| module
.name
== "zlib" )
1158 return "$(ROS_INTERMEDIATE)." SSEP
"tools $(ROS_INTERMEDIATE)." SSEP
"lib" SSEP
"zlib";
1164 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
1166 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1167 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1168 string dependencies
= GetDefaultDependencies ( module
);
1169 string s
= GetModuleDependencies ( module
);
1170 if ( s
.length () > 0 )
1172 if ( dependencies
.length () > 0 )
1173 dependencies
+= " ";
1177 s
= GetInvocationDependencies ( module
);
1178 if ( s
.length () > 0 )
1180 if ( dependencies
.length () > 0 )
1181 dependencies
+= " ";
1185 fprintf ( fMakefile
,
1187 preconditionDependenciesName
.c_str () );
1188 fprintf ( fMakefile
,
1190 preconditionDependenciesName
.c_str (),
1191 dependencies
.c_str () );
1192 const char* p
= sourceFilenames
.c_str();
1193 const char* end
= p
+ strlen(p
);
1196 const char* p2
= &p
[512];
1199 while ( p2
> p
&& !isspace(*p2
) )
1203 p2
= strpbrk ( p
, " \t" );
1207 fprintf ( fMakefile
,
1211 preconditionDependenciesName
.c_str ());
1213 p
+= strspn ( p
, " \t" );
1215 fprintf ( fMakefile
, "\n" );
1219 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module
& module
) const
1221 if ( module
.importLibrary
!= NULL
)
1223 string definitionDependencies
= GetDefinitionDependencies ( module
);
1224 fprintf ( fMakefile
, "%s: %s\n",
1225 FixupTargetFilename( module
.GetDependencyPath () ).c_str (),
1226 definitionDependencies
.c_str () );
1228 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1229 fprintf ( fMakefile
,
1230 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1231 module
.GetTargetName ().c_str (),
1232 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1233 FixupTargetFilename ( module
.GetDependencyPath () ).c_str (),
1239 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1241 string basename
= GetBasename ( filename
);
1242 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1246 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
) const
1248 string dependencies
;
1249 string dkNkmLibNoFixup
= "dk/nkm/lib";
1250 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1251 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1252 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
1254 File
& file
= *module
.files
[i
];
1255 string extension
= GetExtension ( file
.name
);
1256 if ( extension
== ".spec" || extension
== ".SPEC" )
1258 if ( dependencies
.length () > 0 )
1259 dependencies
+= " ";
1260 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1263 return dependencies
;
1267 MingwModuleHandler::GetLinkingDependencies ( const Module
& module
) const
1269 string dependencies
= GetImportLibraryDependencies ( module
);
1270 string s
= GetDefinitionDependencies ( module
);
1271 if ( s
.length () > 0 )
1273 dependencies
+= " ";
1276 return dependencies
;
1280 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
) const
1282 if ( module
.HasFileWithExtensions ( ".cc", ".CC" ) )
1284 if ( module
.HasFileWithExtensions ( ".cxx", ".CXX" ) )
1286 if ( module
.HasFileWithExtensions ( ".cpp", ".CPP" ) )
1292 static MingwBuildToolModuleHandler buildtool_handler
;
1294 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1295 : MingwModuleHandler ( BuildTool
)
1300 MingwBuildToolModuleHandler::Process ( const Module
& module
)
1302 GeneratePreconditionDependencies ( module
);
1303 GenerateBuildToolModuleTarget ( module
);
1304 GenerateInvocations ( module
);
1308 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
)
1310 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1311 string archiveFilename
= GetModuleArchiveFilename ( module
);
1312 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1314 GenerateMacrosAndTargetsHost ( module
);
1317 if ( IsCPlusPlusModule ( module
) )
1318 linker
= "${host_gpp}";
1320 linker
= "${host_gcc}";
1322 fprintf ( fMakefile
, "%s: %s %s\n",
1324 archiveFilename
.c_str (),
1325 importLibraryDependencies
.c_str () );
1326 fprintf ( fMakefile
,
1327 "\t%s %s -o %s %s %s\n\n",
1329 GetLinkerMacro ( module
).c_str (),
1331 archiveFilename
.c_str (),
1332 importLibraryDependencies
.c_str () );
1336 static MingwKernelModuleHandler kernelmodule_handler
;
1338 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1339 : MingwModuleHandler ( Kernel
)
1344 MingwKernelModuleHandler::Process ( const Module
& module
)
1346 GeneratePreconditionDependencies ( module
);
1347 GenerateKernelModuleTarget ( module
);
1348 GenerateInvocations ( module
);
1352 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
)
1354 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1355 string
targetName ( module
.GetTargetName () );
1356 string
target ( FixupTargetFilename (module
.GetPath ()) );
1357 string workingDirectory
= GetWorkingDirectory ();
1358 string objectsMacro
= GetObjectsMacro ( module
);
1359 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1360 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1361 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1362 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1363 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",
1364 module
.GetBasePath ().c_str (),
1365 module
.entrypoint
.c_str (),
1366 module
.baseaddress
.c_str () );
1368 GenerateMacrosAndTargetsTarget ( module
);
1370 GenerateImportLibraryTargetIfNeeded ( module
);
1372 fprintf ( fMakefile
, "%s: %s %s\n",
1374 objectsMacro
.c_str (),
1375 importLibraryDependencies
.c_str () );
1376 fprintf ( fMakefile
,
1377 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1378 GetLinkerMacro ( module
).c_str (),
1379 gccOptions
.c_str (),
1382 objectsMacro
.c_str (),
1383 importLibraryDependencies
.c_str () );
1384 fprintf ( fMakefile
,
1386 junk_tmp
.c_str () );
1387 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1388 fprintf ( fMakefile
,
1389 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1390 targetName
.c_str (),
1394 fprintf ( fMakefile
,
1396 base_tmp
.c_str () );
1397 fprintf ( fMakefile
,
1398 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1399 GetLinkerMacro ( module
).c_str (),
1400 gccOptions
.c_str (),
1403 objectsMacro
.c_str (),
1404 importLibraryDependencies
.c_str () );
1405 fprintf ( fMakefile
,
1407 temp_exp
.c_str () );
1411 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1413 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1414 : MingwModuleHandler ( StaticLibrary
)
1419 MingwStaticLibraryModuleHandler::Process ( const Module
& module
)
1421 GeneratePreconditionDependencies ( module
);
1422 GenerateStaticLibraryModuleTarget ( module
);
1423 GenerateInvocations ( module
);
1427 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
)
1429 GenerateMacrosAndTargetsTarget ( module
);
1433 static MingwObjectLibraryModuleHandler objectlibrary_handler
;
1435 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()
1436 : MingwModuleHandler ( ObjectLibrary
)
1441 MingwObjectLibraryModuleHandler::Process ( const Module
& module
)
1443 GeneratePreconditionDependencies ( module
);
1444 GenerateObjectLibraryModuleTarget ( module
);
1445 GenerateInvocations ( module
);
1449 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
)
1451 GenerateMacrosAndTargetsTarget ( module
);
1455 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1457 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1458 : MingwModuleHandler ( KernelModeDLL
)
1463 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
)
1465 GeneratePreconditionDependencies ( module
);
1466 GenerateKernelModeDLLModuleTarget ( module
);
1467 GenerateInvocations ( module
);
1471 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Module
& module
)
1473 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1474 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1475 string workingDirectory
= GetWorkingDirectory ( );
1476 string archiveFilename
= GetModuleArchiveFilename ( module
);
1477 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1479 GenerateImportLibraryTargetIfNeeded ( module
);
1481 if ( module
.files
.size () > 0 )
1483 GenerateMacrosAndTargetsTarget ( module
);
1485 fprintf ( fMakefile
, "%s: %s %s\n",
1487 archiveFilename
.c_str (),
1488 importLibraryDependencies
.c_str () );
1490 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1491 module
.entrypoint
.c_str (),
1492 module
.baseaddress
.c_str () );
1493 GenerateLinkerCommand ( module
,
1500 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1502 fprintf ( fMakefile
, "%s:\n",
1508 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1510 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1511 : MingwModuleHandler ( KernelModeDriver
)
1516 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
)
1518 GeneratePreconditionDependencies ( module
);
1519 GenerateKernelModeDriverModuleTarget ( module
);
1520 GenerateInvocations ( module
);
1525 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module
& module
)
1527 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1528 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1529 string workingDirectory
= GetWorkingDirectory ( );
1530 string archiveFilename
= GetModuleArchiveFilename ( module
);
1531 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1533 GenerateImportLibraryTargetIfNeeded ( module
);
1535 if ( module
.files
.size () > 0 )
1537 string
* cflags
= new string ( "-D__NTDRIVER__" );
1538 GenerateMacrosAndTargetsTarget ( module
,
1543 fprintf ( fMakefile
, "%s: %s %s\n",
1545 archiveFilename
.c_str (),
1546 importLibraryDependencies
.c_str () );
1548 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1549 module
.entrypoint
.c_str (),
1550 module
.baseaddress
.c_str () );
1551 GenerateLinkerCommand ( module
,
1558 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1560 fprintf ( fMakefile
, "%s:\n",
1566 static MingwNativeDLLModuleHandler nativedll_handler
;
1568 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1569 : MingwModuleHandler ( NativeDLL
)
1574 MingwNativeDLLModuleHandler::Process ( const Module
& module
)
1576 GeneratePreconditionDependencies ( module
);
1577 GenerateNativeDLLModuleTarget ( module
);
1578 GenerateInvocations ( module
);
1582 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
)
1584 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1585 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1586 string workingDirectory
= GetWorkingDirectory ( );
1587 string objectFilenames
= GetObjectFilenames ( module
);
1588 string archiveFilename
= GetModuleArchiveFilename ( module
);
1589 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1591 GenerateImportLibraryTargetIfNeeded ( module
);
1593 if ( module
.files
.size () > 0 )
1595 GenerateMacrosAndTargetsTarget ( module
);
1597 fprintf ( fMakefile
, "%s: %s %s\n",
1599 archiveFilename
.c_str (),
1600 importLibraryDependencies
.c_str () );
1602 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1603 module
.entrypoint
.c_str (),
1604 module
.baseaddress
.c_str () );
1605 GenerateLinkerCommand ( module
,
1612 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1614 fprintf ( fMakefile
, "%s:\n\n",
1620 static MingwNativeCUIModuleHandler nativecui_handler
;
1622 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ()
1623 : MingwModuleHandler ( NativeCUI
)
1628 MingwNativeCUIModuleHandler::Process ( const Module
& module
)
1630 GeneratePreconditionDependencies ( module
);
1631 GenerateNativeCUIModuleTarget ( module
);
1632 GenerateInvocations ( module
);
1636 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module
& module
)
1638 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1639 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1640 string workingDirectory
= GetWorkingDirectory ( );
1641 string objectFilenames
= GetObjectFilenames ( module
);
1642 string archiveFilename
= GetModuleArchiveFilename ( module
);
1643 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1645 GenerateImportLibraryTargetIfNeeded ( module
);
1647 if ( module
.files
.size () > 0 )
1649 string
* cflags
= new string ( "-D__NTAPP__" );
1650 GenerateMacrosAndTargetsTarget ( module
,
1655 fprintf ( fMakefile
, "%s: %s %s\n",
1657 archiveFilename
.c_str (),
1658 importLibraryDependencies
.c_str () );
1660 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1661 module
.entrypoint
.c_str (),
1662 module
.baseaddress
.c_str () );
1663 GenerateLinkerCommand ( module
,
1670 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1672 fprintf ( fMakefile
, "%s:\n\n",
1678 static MingwWin32DLLModuleHandler win32dll_handler
;
1680 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1681 : MingwModuleHandler ( Win32DLL
)
1686 MingwWin32DLLModuleHandler::Process ( const Module
& module
)
1688 GenerateExtractWineDLLResourcesTarget ( module
);
1689 GeneratePreconditionDependencies ( module
);
1690 GenerateWin32DLLModuleTarget ( module
);
1691 GenerateInvocations ( module
);
1695 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
)
1697 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1698 module
.name
.c_str () );
1699 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1700 module
.name
.c_str () );
1701 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
1703 File
& file
= *module
.files
[i
];
1704 string extension
= GetExtension ( file
.name
);
1705 if ( extension
== ".rc" || extension
== ".RC" )
1707 string resource
= FixupTargetFilename ( file
.name
);
1708 fprintf ( fMakefile
, "\t@echo ${bin2res} -f -x %s\n",
1709 resource
.c_str () );
1712 fprintf ( fMakefile
, "\n");
1716 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
)
1718 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1719 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1720 string workingDirectory
= GetWorkingDirectory ( );
1721 string objectFilenames
= GetObjectFilenames ( module
);
1722 string linkingDependencies
= GetLinkingDependencies ( module
);
1724 GenerateImportLibraryTargetIfNeeded ( module
);
1725 if ( module
.files
.size () > 0 )
1727 GenerateMacrosAndTargetsTarget ( module
);
1729 fprintf ( fMakefile
, "%s: %s %s\n",
1731 objectFilenames
.c_str (),
1732 linkingDependencies
.c_str () );
1735 if ( IsCPlusPlusModule ( module
) )
1740 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1741 module
.entrypoint
.c_str (),
1742 module
.baseaddress
.c_str () );
1743 GenerateLinkerCommand ( module
,
1750 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1752 fprintf ( fMakefile
, "%s:\n\n",
1758 static MingwWin32CUIModuleHandler win32cui_handler
;
1760 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ()
1761 : MingwModuleHandler ( Win32CUI
)
1766 MingwWin32CUIModuleHandler::Process ( const Module
& module
)
1768 GeneratePreconditionDependencies ( module
);
1769 GenerateWin32CUIModuleTarget ( module
);
1770 GenerateInvocations ( module
);
1774 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
)
1776 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1777 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1778 string workingDirectory
= GetWorkingDirectory ( );
1779 string objectFilenames
= GetObjectFilenames ( module
);
1780 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1782 GenerateImportLibraryTargetIfNeeded ( module
);
1784 if ( module
.files
.size () > 0 )
1786 GenerateMacrosAndTargetsTarget ( module
);
1788 fprintf ( fMakefile
, "%s: %s %s\n",
1790 objectFilenames
.c_str (),
1791 importLibraryDependencies
.c_str () );
1794 if ( IsCPlusPlusModule ( module
) )
1799 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1800 module
.entrypoint
.c_str (),
1801 module
.baseaddress
.c_str () );
1802 GenerateLinkerCommand ( module
,
1809 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1811 fprintf ( fMakefile
, "%s:\n\n",
1817 static MingwWin32GUIModuleHandler win32gui_handler
;
1819 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
1820 : MingwModuleHandler ( Win32GUI
)
1825 MingwWin32GUIModuleHandler::Process ( const Module
& module
)
1827 GeneratePreconditionDependencies ( module
);
1828 GenerateWin32GUIModuleTarget ( module
);
1829 GenerateInvocations ( module
);
1833 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
)
1835 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1836 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1837 string workingDirectory
= GetWorkingDirectory ( );
1838 string objectFilenames
= GetObjectFilenames ( module
);
1839 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1841 GenerateImportLibraryTargetIfNeeded ( module
);
1843 if ( module
.files
.size () > 0 )
1845 GenerateMacrosAndTargetsTarget ( module
);
1847 fprintf ( fMakefile
, "%s: %s %s\n",
1849 objectFilenames
.c_str (),
1850 importLibraryDependencies
.c_str () );
1853 if ( IsCPlusPlusModule ( module
) )
1858 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1859 module
.entrypoint
.c_str (),
1860 module
.baseaddress
.c_str () );
1861 GenerateLinkerCommand ( module
,
1868 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1870 fprintf ( fMakefile
, "%s:\n\n",
1876 static MingwBootLoaderModuleHandler bootloadermodule_handler
;
1878 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()
1879 : MingwModuleHandler ( BootLoader
)
1884 MingwBootLoaderModuleHandler::Process ( const Module
& module
)
1886 GeneratePreconditionDependencies ( module
);
1887 GenerateBootLoaderModuleTarget ( module
);
1888 GenerateInvocations ( module
);
1892 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ( const Module
& module
)
1894 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1895 string
targetName ( module
.GetTargetName () );
1896 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1897 string workingDirectory
= GetWorkingDirectory ();
1898 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1899 string objectsMacro
= GetObjectsMacro ( module
);
1900 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1902 GenerateMacrosAndTargetsTarget ( module
);
1904 fprintf ( fMakefile
, "%s: %s %s\n",
1906 objectsMacro
.c_str (),
1907 importLibraryDependencies
.c_str () );
1909 fprintf ( fMakefile
,
1910 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
1911 GetLinkerMacro ( module
).c_str (),
1913 objectsMacro
.c_str (),
1914 importLibraryDependencies
.c_str () );
1915 fprintf ( fMakefile
,
1916 "\t${objcopy} -O binary %s %s\n",
1919 fprintf ( fMakefile
,
1921 junk_tmp
.c_str () );
1925 static MingwBootSectorModuleHandler bootsectormodule_handler
;
1927 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ()
1928 : MingwModuleHandler ( BootSector
)
1933 MingwBootSectorModuleHandler::Process ( const Module
& module
)
1935 GeneratePreconditionDependencies ( module
);
1936 GenerateBootSectorModuleTarget ( module
);
1937 GenerateInvocations ( module
);
1941 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
)
1943 string objectsMacro
= GetObjectsMacro ( module
);
1945 string
* nasmflags
= new string ( "-f bin" );
1946 GenerateMacrosAndTargetsTarget ( module
,
1950 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1951 module
.name
.c_str ());
1952 fprintf ( fMakefile
,
1954 module
.name
.c_str (),
1955 objectsMacro
.c_str () );
1959 static MingwIsoModuleHandler isomodule_handler
;
1961 MingwIsoModuleHandler::MingwIsoModuleHandler ()
1962 : MingwModuleHandler ( Iso
)
1967 MingwIsoModuleHandler::Process ( const Module
& module
)
1969 GeneratePreconditionDependencies ( module
);
1970 GenerateIsoModuleTarget ( module
);
1971 GenerateInvocations ( module
);
1975 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string bootcdDirectory
,
1976 const Module
& module
) const
1978 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
1980 const Module
& m
= *module
.project
.modules
[i
];
1981 if ( m
.bootstrap
!= NULL
)
1983 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
1984 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
1985 fprintf ( fMakefile
,
1987 m
.GetPath ().c_str (),
1988 targetFilename
.c_str () );
1994 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string bootcdDirectory
,
1995 const Module
& module
) const
1997 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
1999 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2000 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2001 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2002 fprintf ( fMakefile
,
2004 cdfile
.GetPath ().c_str (),
2005 targetFilename
.c_str () );
2010 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string bootcdDirectory
,
2011 const Module
& module
) const
2014 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2016 const Module
& m
= *module
.project
.modules
[i
];
2017 if ( m
.bootstrap
!= NULL
)
2019 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2020 if ( directories
.size () > 0 )
2022 directories
+= FixupTargetFilename ( targetDirecctory
);
2029 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string bootcdDirectory
,
2030 const Module
& module
) const
2033 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2035 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2036 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2037 if ( directories
.size () > 0 )
2039 directories
+= FixupTargetFilename ( targetDirecctory
);
2045 MingwIsoModuleHandler::GetCdDirectories ( const string bootcdDirectory
,
2046 const Module
& module
) const
2048 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2050 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2056 MingwIsoModuleHandler::GetBootstrapCdFiles ( const string bootcdDirectory
,
2057 const Module
& module
) const
2060 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2062 const Module
& m
= *module
.project
.modules
[i
];
2063 if ( m
.bootstrap
!= NULL
)
2065 if ( cdfiles
.size () > 0 )
2067 cdfiles
+= FixupTargetFilename ( m
.GetPath () );
2074 MingwIsoModuleHandler::GetNonModuleCdFiles ( const string bootcdDirectory
,
2075 const Module
& module
) const
2078 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2080 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2081 if ( cdfiles
.size () > 0 )
2083 cdfiles
+= NormalizeFilename ( cdfile
.GetPath () );
2089 MingwIsoModuleHandler::GetCdFiles ( const string bootcdDirectory
,
2090 const Module
& module
) const
2092 string cdfiles
= GetBootstrapCdFiles ( bootcdDirectory
,
2094 cdfiles
+= " " + GetNonModuleCdFiles ( bootcdDirectory
,
2100 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
)
2102 string bootcdDirectory
= "cd";
2103 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2104 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2105 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2106 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2107 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2108 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2109 string cdDirectories
= bootcdReactos
+ " " + GetCdDirectories ( bootcdDirectory
,
2111 string cdFiles
= GetCdFiles ( bootcdDirectory
,
2114 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2115 module
.name
.c_str ());
2116 fprintf ( fMakefile
,
2117 "%s: all %s %s %s\n",
2118 module
.name
.c_str (),
2120 cdDirectories
.c_str (),
2122 fprintf ( fMakefile
,
2123 "\t${cabman} -C %s -L %s -I\n",
2124 reactosDff
.c_str (),
2125 bootcdReactos
.c_str () );
2126 fprintf ( fMakefile
,
2127 "\t${cabman} -C %s -RC %s -L %s -N\n",
2128 reactosDff
.c_str (),
2129 reactosInf
.c_str (),
2130 bootcdReactos
.c_str () );
2131 fprintf ( fMakefile
,
2133 reactosInf
.c_str () );
2134 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2136 OutputCdfileCopyCommands ( bootcdDirectory
,
2138 fprintf ( fMakefile
,
2139 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2141 bootcdDirectory
.c_str () );
2142 fprintf ( fMakefile
,