4 #include "../../rbuild.h"
6 #include "modulehandler.h"
13 typedef set
<string
> set_string
;
15 #define CLEAN_FILE(f) clean_files.push_back ( f ); /*if ( module.name == "crt" ) printf ( "%s(%i): clean: %s\n", __FILE__, __LINE__, f.c_str() )*/
17 map
<ModuleType
,MingwModuleHandler
*>*
18 MingwModuleHandler::handler_map
= NULL
;
20 MingwModuleHandler::directory_set
;
22 MingwModuleHandler::ref
= 0;
25 MingwModuleHandler::fMakefile
= NULL
;
28 ReplaceExtension ( const string
& filename
,
29 const string
& newExtension
)
31 size_t index
= filename
.find_last_of ( '/' );
32 if (index
== string::npos
) index
= 0;
33 string tmp
= filename
.substr( index
, filename
.size() - index
);
34 size_t ext_index
= tmp
.find_last_of( '.' );
35 if (ext_index
!= string::npos
)
36 return filename
.substr ( 0, index
+ ext_index
) + newExtension
;
37 return filename
+ newExtension
;
41 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype
)
44 handler_map
= new map
<ModuleType
,MingwModuleHandler
*>;
45 (*handler_map
)[moduletype
] = this;
48 MingwModuleHandler::~MingwModuleHandler()
58 MingwModuleHandler::PassThruCacheDirectory ( const string
&file
) const
60 directory_set
.insert ( GetDirectory ( file
) );
65 MingwModuleHandler::SetMakefile ( FILE* f
)
71 MingwModuleHandler::LookupHandler ( const string
& location
,
72 ModuleType moduletype
)
75 throw Exception ( "internal tool error: no registered module handlers" );
76 MingwModuleHandler
* h
= (*handler_map
)[moduletype
];
79 throw UnknownModuleTypeException ( location
, moduletype
);
86 MingwModuleHandler::GetWorkingDirectory () const
92 MingwModuleHandler::GetBasename ( const string
& filename
) const
94 size_t index
= filename
.find_last_of ( '.' );
95 if ( index
!= string::npos
)
96 return filename
.substr ( 0, index
);
101 MingwModuleHandler::GetActualSourceFilename ( const string
& filename
) const
103 string extension
= GetExtension ( filename
);
104 if ( extension
== ".spec" || extension
== "SPEC" )
106 string basename
= GetBasename ( filename
);
107 return basename
+ ".stubs.c";
114 MingwModuleHandler::GetModuleArchiveFilename ( const Module
& module
) const
116 return ReplaceExtension ( FixupTargetFilename ( module
.GetPath () ),
121 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
123 string extension
= GetExtension ( file
.name
);
124 if ( extension
== ".spec" || extension
== "SPEC" )
131 MingwModuleHandler::GetImportLibraryDependency ( const Module
& importedModule
) const
133 if ( importedModule
.type
== ObjectLibrary
)
134 return GetObjectsMacro ( importedModule
);
136 return PassThruCacheDirectory ( FixupTargetFilename ( importedModule
.GetDependencyPath () ) );
140 MingwModuleHandler::GetModuleDependencies ( const Module
& module
) const
142 if ( module
.dependencies
.size () == 0 )
145 string
dependencies ( "" );
146 for ( size_t i
= 0; i
< module
.dependencies
.size (); i
++ )
148 if ( dependencies
.size () > 0 )
150 const Dependency
* dependency
= module
.dependencies
[i
];
151 const Module
* dependencyModule
= dependency
->dependencyModule
;
152 dependencies
+= dependencyModule
->GetTargets ();
154 string definitionDependencies
= GetDefinitionDependencies ( module
);
155 if ( dependencies
.length () > 0 && definitionDependencies
.length () > 0 )
156 dependencies
+= " " + definitionDependencies
;
157 else if ( definitionDependencies
.length () > 0 )
158 dependencies
= definitionDependencies
;
163 MingwModuleHandler::GetAllDependencies ( const Module& module ) const
165 string dependencies = GetImportMacro ( module );
166 string s = GetModuleDependencies ( module );
167 if ( s.length () > 0 )
176 MingwModuleHandler::GetSourceFilenames ( const Module
& module
,
177 bool includeGeneratedFiles
) const
181 string
sourceFilenames ( "" );
182 const vector
<File
*>& files
= module
.non_if_data
.files
;
183 for ( i
= 0; i
< files
.size (); i
++ )
185 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *files
[i
] ) )
186 sourceFilenames
+= " " + GetActualSourceFilename ( files
[i
]->name
);
188 // intentionally make a copy so that we can append more work in
189 // the middle of processing without having to go recursive
190 vector
<If
*> v
= module
.non_if_data
.ifs
;
191 for ( i
= 0; i
< v
.size (); i
++ )
195 // check for sub-ifs to add to list
196 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
197 for ( j
= 0; j
< ifs
.size (); j
++ )
198 v
.push_back ( ifs
[j
] );
199 const vector
<File
*>& files
= rIf
.data
.files
;
200 for ( j
= 0; j
< files
.size (); j
++ )
202 File
& file
= *files
[j
];
203 if ( includeGeneratedFiles
|| !IsGeneratedFile ( file
) )
204 sourceFilenames
+= " " + GetActualSourceFilename ( file
.name
);
207 return sourceFilenames
;
211 MingwModuleHandler::GetSourceFilenames ( const Module
& module
) const
213 return GetSourceFilenames ( module
,
218 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module
& module
) const
220 return GetSourceFilenames ( module
,
225 MingwModuleHandler::GetObjectFilename ( const string
& sourceFilename
)
228 string extension
= GetExtension ( sourceFilename
);
229 if ( extension
== ".rc" || extension
== ".RC" )
230 newExtension
= ".coff";
231 else if ( extension
== ".spec" || extension
== ".SPEC" )
232 newExtension
= ".stubs.o";
235 return FixupTargetFilename ( ReplaceExtension ( sourceFilename
, newExtension
) );
239 MingwModuleHandler::GenerateCleanTarget (
240 const Module
& module
,
241 const string_list
& clean_files
) const
243 if ( 0 == clean_files
.size() )
245 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
246 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
247 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
250 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
251 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
253 fprintf ( fMakefile
, " 2>$(NUL)\n" );
254 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
258 MingwModuleHandler::GetObjectFilenames ( const Module
& module
) const
260 const vector
<File
*>& files
= module
.non_if_data
.files
;
261 if ( files
.size () == 0 )
264 string
objectFilenames ( "" );
265 for ( size_t i
= 0; i
< files
.size (); i
++ )
267 if ( objectFilenames
.size () > 0 )
268 objectFilenames
+= " ";
269 objectFilenames
+= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) );
271 return objectFilenames
;
275 MingwModuleHandler::IncludeDirectoryTarget ( const string
& directory
) const
277 if ( directory
== "$(ROS_INTERMEDIATE)." SSEP
"tools")
284 MingwModuleHandler::GenerateDirectoryTargets () const
286 if ( directory_set
.size () == 0 )
289 set_string::iterator it
;
290 size_t wrap_count
= 0;
292 fprintf ( fMakefile
, "ifneq ($(ROS_INTERMEDIATE),)\n" );
293 fprintf ( fMakefile
, "directories::" );
295 for ( it
= directory_set
.begin ();
296 it
!= directory_set
.end ();
299 if ( IncludeDirectoryTarget ( *it
) )
301 if ( wrap_count
++ == 5 )
302 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
309 fprintf ( fMakefile
, "\n\n" );
312 for ( it
= directory_set
.begin ();
313 it
!= directory_set
.end ();
316 if ( IncludeDirectoryTarget ( *it
) )
318 if ( wrap_count
++ == 5 )
319 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
327 "::\n\t${mkdir} $@\n" );
328 fprintf ( fMakefile
, "endif\n\n" );
330 directory_set
.clear ();
334 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector
<Define
*>& defines
) const
337 for ( size_t i
= 0; i
< defines
.size (); i
++ )
339 Define
& define
= *defines
[i
];
340 if (parameters
.length () > 0)
343 parameters
+= define
.name
;
344 if (define
.value
.length () > 0)
347 parameters
+= define
.value
;
354 MingwModuleHandler::GenerateGccDefineParameters ( const Module
& module
) const
356 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
357 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
358 if ( s
.length () > 0 )
367 MingwModuleHandler::ConcatenatePaths ( const string
& path1
,
368 const string
& path2
) const
370 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
372 if ( path1
[path1
.length ()] == CSEP
)
373 return path1
+ path2
;
375 return path1
+ CSEP
+ path2
;
379 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
382 for ( size_t i
= 0; i
< includes
.size (); i
++ )
384 Include
& include
= *includes
[i
];
385 if ( parameters
.length () > 0 )
387 parameters
+= "-I" + include
.directory
;
393 MingwModuleHandler::GenerateGccIncludeParameters ( const Module
& module
) const
395 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
396 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
397 if ( s
.length () > 0 )
407 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
410 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
412 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
413 if ( parameters
.length () > 0 )
415 parameters
+= compilerFlag
.flag
;
421 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
424 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
426 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
427 if ( parameters
.length () > 0 )
429 parameters
+= linkerFlag
.flag
;
435 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
436 const vector
<Library
*>& libraries
) const
438 string
dependencies ( "" );
440 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
442 if ( wrap_count
++ == 5 )
443 dependencies
+= " \\\n\t\t", wrap_count
= 0;
444 else if ( dependencies
.size () > 0 )
446 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->imported_module
);
452 MingwModuleHandler::GenerateLinkerParameters ( const Module
& module
) const
454 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
458 MingwModuleHandler::GenerateMacro (
459 const char* assignmentOperation
,
461 const IfableData
& data
,
462 const vector
<CompilerFlag
*>* compilerFlags
) const
470 assignmentOperation
);
472 if ( compilerFlags
!= NULL
)
474 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
475 if ( compilerParameters
.size () > 0 )
480 compilerParameters
.c_str () );
484 for ( i
= 0; i
< data
.includes
.size(); i
++ )
489 data
.includes
[i
]->directory
.c_str() );
491 for ( i
= 0; i
< data
.defines
.size(); i
++ )
493 Define
& d
= *data
.defines
[i
];
498 if ( d
.value
.size() )
504 fprintf ( fMakefile
, "\n" );
508 MingwModuleHandler::GenerateMacros (
509 const char* assignmentOperation
,
510 const IfableData
& data
,
511 const vector
<CompilerFlag
*>* compilerFlags
,
512 const vector
<LinkerFlag
*>* linkerFlags
,
513 const string
& cflags_macro
,
514 const string
& nasmflags_macro
,
515 const string
& windresflags_macro
,
516 const string
& linkerflags_macro
,
517 const string
& objs_macro
,
518 const string
& libs_macro
,
519 const string
& linkdeps_macro
) const
523 if ( data
.includes
.size () > 0 || data
.defines
.size () > 0 )
525 GenerateMacro ( assignmentOperation
,
529 GenerateMacro ( assignmentOperation
,
535 if ( linkerFlags
!= NULL
)
537 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
538 if ( linkerParameters
.size () > 0 )
543 linkerflags_macro
.c_str (),
545 linkerParameters
.c_str() );
549 if ( data
.libraries
.size () > 0 )
551 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
552 if ( deps
.size () > 0 )
563 const vector
<File
*>& files
= data
.files
;
564 if ( files
.size () > 0 )
566 for ( i
= 0; i
< files
.size (); i
++ )
568 File
& file
= *files
[i
];
574 PassThruCacheDirectory (
575 MingwModuleHandler::GetObjectFilename ( file
.name
) ).c_str (),
576 objs_macro
.c_str() );
583 assignmentOperation
);
584 for ( i
= 0; i
< files
.size(); i
++ )
586 File
& file
= *files
[i
];
592 ( i
%10 == 9 ? "\\\n\t" : " " ),
593 PassThruCacheDirectory (
594 MingwModuleHandler::GetObjectFilename ( file
.name
) ).c_str () );
597 fprintf ( fMakefile
, "\n" );
600 const vector
<If
*>& ifs
= data
.ifs
;
601 for ( i
= 0; i
< ifs
.size(); i
++ )
604 if ( rIf
.data
.defines
.size()
605 || rIf
.data
.includes
.size()
606 || rIf
.data
.libraries
.size()
607 || rIf
.data
.files
.size()
608 || rIf
.data
.ifs
.size() )
612 "ifeq (\"$(%s)\",\"%s\")\n",
613 rIf
.property
.c_str(),
635 MingwModuleHandler::GenerateMacros (
636 const Module
& module
,
637 const string
& cflags_macro
,
638 const string
& nasmflags_macro
,
639 const string
& windresflags_macro
,
640 const string
& linkerflags_macro
,
641 const string
& objs_macro
,
642 const string
& libs_macro
,
643 const string
& linkdeps_macro
) const
648 &module
.compilerFlags
,
658 if ( module
.importLibrary
)
661 const vector
<File
*>& files
= module
.non_if_data
.files
;
662 for ( size_t i
= 0; i
< files
.size (); i
++ )
664 File
& file
= *files
[i
];
665 string extension
= GetExtension ( file
.name
);
666 if ( extension
== ".spec" || extension
== ".SPEC" )
668 if ( s
.length () > 0 )
670 s
+= GetSpecObjectDependencies ( file
.name
);
673 if ( s
.length () > 0 )
678 linkdeps_macro
.c_str(),
685 "%s += $(PROJECT_CFLAGS)\n",
686 cflags_macro
.c_str () );
690 "%s += $(PROJECT_RCFLAGS)\n",
691 windresflags_macro
.c_str () );
695 "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
696 module
.name
.c_str () );
701 linkdeps_macro
.c_str (),
702 libs_macro
.c_str () );
704 fprintf ( fMakefile
, "\n" );
708 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
709 const string
& sourceFilename
,
711 const string
& cflagsMacro
) const
713 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
716 objectFilename
.c_str (),
717 sourceFilename
.c_str () );
718 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [CC] $<\n" );
720 "\t%s -c %s -o %s %s\n",
722 sourceFilename
.c_str (),
723 objectFilename
.c_str (),
724 cflagsMacro
.c_str () );
728 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
729 const string
& sourceFilename
,
731 const string
& cflagsMacro
) const
733 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
736 objectFilename
.c_str (),
737 sourceFilename
.c_str () );
738 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [GAS] $<\n" );
740 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
742 sourceFilename
.c_str (),
743 objectFilename
.c_str (),
744 cflagsMacro
.c_str () );
748 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
749 const string
& sourceFilename
,
750 const string
& nasmflagsMacro
) const
752 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
755 objectFilename
.c_str (),
756 sourceFilename
.c_str () );
757 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [NASM] $<\n" );
759 "\t%s -f win32 %s -o %s %s\n",
761 sourceFilename
.c_str (),
762 objectFilename
.c_str (),
763 nasmflagsMacro
.c_str () );
767 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
768 const string
& sourceFilename
,
769 const string
& windresflagsMacro
) const
771 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
772 string rciFilename
= ReplaceExtension ( sourceFilename
,
774 string resFilename
= ReplaceExtension ( sourceFilename
,
778 objectFilename
.c_str (),
779 sourceFilename
.c_str () );
780 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [WRC] $@\n" );
782 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
783 windresflagsMacro
.c_str (),
784 sourceFilename
.c_str (),
785 rciFilename
.c_str () );
787 "\t${wrc} ${%s} %s %s\n",
788 windresflagsMacro
.c_str (),
789 rciFilename
.c_str (),
790 resFilename
.c_str () );
793 rciFilename
.c_str () );
795 "\t${windres} %s -o %s\n",
796 resFilename
.c_str (),
797 objectFilename
.c_str () );
800 resFilename
.c_str () );
804 MingwModuleHandler::GenerateWinebuildCommands (
805 const Module
& module
,
806 const string
& sourceFilename
,
807 string_list
& clean_files
) const
809 string basename
= GetBasename ( sourceFilename
);
811 string def_file
= basename
+ ".spec.def";
812 CLEAN_FILE ( def_file
);
814 string stub_file
= basename
+ ".stubs.c";
815 CLEAN_FILE ( stub_file
);
820 sourceFilename
.c_str () );
821 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [WINEBLD] $@\n" );
823 "\t%s --def=%s -o %s\n",
825 sourceFilename
.c_str (),
831 sourceFilename
.c_str () );
832 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [WINEBLD] $@\n" );
834 "\t%s --pedll=%s -o %s\n",
836 sourceFilename
.c_str (),
837 stub_file
.c_str () );
841 MingwModuleHandler::GenerateCommands (
842 const Module
& module
,
843 const string
& sourceFilename
,
846 const string
& cflagsMacro
,
847 const string
& nasmflagsMacro
,
848 const string
& windresflagsMacro
,
849 string_list
& clean_files
) const
851 CLEAN_FILE ( GetObjectFilename(sourceFilename
) );
852 string extension
= GetExtension ( sourceFilename
);
853 if ( extension
== ".c" || extension
== ".C" )
855 GenerateGccCommand ( module
,
861 else if ( extension
== ".cc" || extension
== ".CC" ||
862 extension
== ".cpp" || extension
== ".CPP" ||
863 extension
== ".cxx" || extension
== ".CXX" )
865 GenerateGccCommand ( module
,
871 else if ( extension
== ".s" || extension
== ".S" )
873 GenerateGccAssemblerCommand ( module
,
879 else if ( extension
== ".asm" || extension
== ".ASM" )
881 GenerateNasmCommand ( module
,
886 else if ( extension
== ".rc" || extension
== ".RC" )
888 GenerateWindresCommand ( module
,
893 else if ( extension
== ".spec" || extension
== ".SPEC" )
895 GenerateWinebuildCommands ( module
,
898 GenerateGccCommand ( module
,
899 GetActualSourceFilename ( sourceFilename
),
905 throw InvalidOperationException ( __FILE__
,
907 "Unsupported filename extension '%s' in file '%s'",
909 sourceFilename
.c_str () );
913 MingwModuleHandler::GenerateLinkerCommand (
914 const Module
& module
,
915 const string
& linker
,
916 const string
& linkerParameters
,
917 const string
& objectsMacro
,
918 const string
& libsMacro
,
919 string_list
& clean_files
) const
921 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [LD] $@\n" );
922 string
targetName ( module
.GetTargetName () );
923 string
target ( FixupTargetFilename ( module
.GetPath () ) );
924 if ( module
.importLibrary
!= NULL
)
926 static string
ros_junk ( "$(ROS_TEMPORARY)" );
927 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
928 CLEAN_FILE ( base_tmp
);
929 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
930 CLEAN_FILE ( junk_tmp
);
931 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
932 CLEAN_FILE ( temp_exp
);
933 string def_file
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
936 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
938 linkerParameters
.c_str (),
941 objectsMacro
.c_str (),
943 GetLinkerMacro ( module
).c_str () );
949 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
951 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
963 "\t%s %s %s -o %s %s %s %s\n",
965 linkerParameters
.c_str (),
968 objectsMacro
.c_str (),
970 GetLinkerMacro ( module
).c_str () );
979 "\t%s %s -o %s %s %s %s\n",
981 linkerParameters
.c_str (),
983 objectsMacro
.c_str (),
985 GetLinkerMacro ( module
).c_str () );
988 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [RSYM] $@\n" );
990 "\t${rsym} %s %s\n\n",
996 MingwModuleHandler::GenerateObjectFileTargets (
997 const Module
& module
,
998 const IfableData
& data
,
1001 const string
& cflagsMacro
,
1002 const string
& nasmflagsMacro
,
1003 const string
& windresflagsMacro
,
1004 string_list
& clean_files
) const
1008 const vector
<File
*>& files
= data
.files
;
1009 for ( i
= 0; i
< files
.size (); i
++ )
1011 string sourceFilename
= files
[i
]->name
;
1012 GenerateCommands ( module
,
1020 fprintf ( fMakefile
,
1024 const vector
<If
*>& ifs
= data
.ifs
;
1025 for ( i
= 0; i
< ifs
.size(); i
++ )
1027 GenerateObjectFileTargets ( module
,
1039 MingwModuleHandler::GenerateObjectFileTargets (
1040 const Module
& module
,
1043 const string
& cflagsMacro
,
1044 const string
& nasmflagsMacro
,
1045 const string
& windresflagsMacro
,
1046 string_list
& clean_files
) const
1048 GenerateObjectFileTargets ( module
,
1056 fprintf ( fMakefile
, "\n" );
1060 MingwModuleHandler::GetCleanTargets (
1062 const IfableData
& data
) const
1066 const vector
<File
*>& files
= data
.files
;
1067 for ( i
= 0; i
< files
.size(); i
++ )
1068 out
.push_back ( PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) ) );
1070 const vector
<If
*>& ifs
= data
.ifs
;
1071 for ( i
= 0; i
< ifs
.size(); i
++ )
1072 GetCleanTargets ( out
, ifs
[i
]->data
);
1076 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
1078 const string
& objs_macro
) const
1080 string archiveFilename
= GetModuleArchiveFilename ( module
);
1082 fprintf ( fMakefile
,
1084 archiveFilename
.c_str (),
1085 objs_macro
.c_str ());
1087 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [AR] $@\n" );
1089 fprintf ( fMakefile
,
1090 "\t%s -rc %s %s\n\n",
1092 archiveFilename
.c_str (),
1093 objs_macro
.c_str ());
1095 return archiveFilename
;
1099 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
1101 return ssprintf ( "$(%s_CFLAGS)",
1102 module
.name
.c_str () );
1106 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
1108 return ssprintf ( "$(%s_OBJS)",
1109 module
.name
.c_str () );
1113 MingwModuleHandler::GetLinkingDependenciesMacro ( const Module
& module
) const
1115 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1119 MingwModuleHandler::GetLibsMacro ( const Module
& module
) const
1121 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1125 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
1127 return ssprintf ( "$(%s_LFLAGS)",
1128 module
.name
.c_str () );
1132 MingwModuleHandler::GenerateMacrosAndTargets (
1133 const Module
& module
,
1137 const string
* cflags
,
1138 const string
* nasmflags
,
1139 string_list
& clean_files
) const
1141 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1142 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1143 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1144 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1145 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1146 string libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1147 string linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1149 GenerateMacros ( module
,
1158 if ( cflags
!= NULL
)
1160 fprintf ( fMakefile
,
1162 cflagsMacro
.c_str (),
1166 if ( nasmflags
!= NULL
)
1168 fprintf ( fMakefile
,
1170 nasmflagsMacro
.c_str (),
1171 nasmflags
->c_str () );
1174 // generate phony target for module name
1175 fprintf ( fMakefile
, ".PHONY: %s\n",
1176 module
.name
.c_str () );
1177 fprintf ( fMakefile
, "%s: %s\n\n",
1178 module
.name
.c_str (),
1179 FixupTargetFilename ( module
.GetPath () ).c_str () );
1181 // future references to the macros will be to get their values
1182 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1183 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1184 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1186 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1187 GenerateObjectFileTargets ( module
,
1195 CLEAN_FILE ( ar_target
);
1196 string tgt
= FixupTargetFilename(module
.GetPath());
1197 if ( tgt
!= ar_target
)
1204 MingwModuleHandler::GenerateMacrosAndTargetsHost (
1205 const Module
& module
,
1206 string_list
& clean_files
) const
1208 GenerateMacrosAndTargets (
1219 MingwModuleHandler::GenerateMacrosAndTargetsTarget (
1220 const Module
& module
,
1221 string_list
& clean_files
) const
1223 GenerateMacrosAndTargetsTarget (
1231 MingwModuleHandler::GenerateMacrosAndTargetsTarget (
1232 const Module
& module
,
1233 const string
* cflags
,
1234 const string
* nasmflags
,
1235 string_list
& clean_files
) const
1237 GenerateMacrosAndTargets (
1248 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
1250 string dependencies
;
1251 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1253 Invoke
& invoke
= *module
.invocations
[i
];
1254 if (invoke
.invokeModule
== &module
)
1255 /* Protect against circular dependencies */
1257 if ( dependencies
.length () > 0 )
1258 dependencies
+= " ";
1259 dependencies
+= invoke
.GetTargets ();
1261 return dependencies
;
1265 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1267 if ( module
.invocations
.size () == 0 )
1270 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1272 const Invoke
& invoke
= *module
.invocations
[i
];
1274 if ( invoke
.invokeModule
->type
!= BuildTool
)
1276 throw InvalidBuildFileException ( module
.node
.location
,
1277 "Only modules of type buildtool can be invoked." );
1280 string invokeTarget
= module
.GetInvocationTarget ( i
);
1281 fprintf ( fMakefile
,
1283 invokeTarget
.c_str () );
1284 fprintf ( fMakefile
,
1286 invokeTarget
.c_str (),
1287 invoke
.GetTargets ().c_str () );
1288 fprintf ( fMakefile
,
1290 invoke
.GetTargets ().c_str (),
1291 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1292 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [INVOKE] $<\n" );
1293 fprintf ( fMakefile
,
1295 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1296 invoke
.GetParameters ().c_str () );
1301 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1303 return ssprintf ( "%s_precondition",
1304 module
.name
.c_str () );
1308 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1310 /* Avoid circular dependency */
1311 if ( module
.type
== BuildTool
|| module
.name
== "zlib" )
1312 return "$(ROS_INTERMEDIATE)." SSEP
"tools $(ROS_INTERMEDIATE)." SSEP
"lib" SSEP
"zlib";
1318 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
1320 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1321 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1322 string dependencies
= GetDefaultDependencies ( module
);
1323 string s
= GetModuleDependencies ( module
);
1324 if ( s
.length () > 0 )
1326 if ( dependencies
.length () > 0 )
1327 dependencies
+= " ";
1331 s
= GetInvocationDependencies ( module
);
1332 if ( s
.length () > 0 )
1334 if ( dependencies
.length () > 0 )
1335 dependencies
+= " ";
1339 fprintf ( fMakefile
,
1341 preconditionDependenciesName
.c_str () );
1342 fprintf ( fMakefile
,
1344 preconditionDependenciesName
.c_str (),
1345 dependencies
.c_str () );
1346 const char* p
= sourceFilenames
.c_str();
1347 const char* end
= p
+ strlen(p
);
1350 const char* p2
= &p
[512];
1353 while ( p2
> p
&& !isspace(*p2
) )
1357 p2
= strpbrk ( p
, " \t" );
1361 fprintf ( fMakefile
,
1365 preconditionDependenciesName
.c_str ());
1367 p
+= strspn ( p
, " \t" );
1369 fprintf ( fMakefile
, "\n" );
1373 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded (
1374 const Module
& module
,
1375 string_list
& clean_files
) const
1377 if ( module
.importLibrary
!= NULL
)
1379 string library_target
= FixupTargetFilename( module
.GetDependencyPath () ).c_str ();
1380 CLEAN_FILE ( library_target
);
1382 string definitionDependencies
= GetDefinitionDependencies ( module
);
1383 fprintf ( fMakefile
, "%s: %s\n",
1384 library_target
.c_str (),
1385 definitionDependencies
.c_str () );
1387 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [DLLTOOL] $@\n" );
1389 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1390 fprintf ( fMakefile
,
1391 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1392 module
.GetTargetName ().c_str (),
1393 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1394 library_target
.c_str (),
1400 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1402 string basename
= GetBasename ( filename
);
1403 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1407 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
) const
1409 string dependencies
;
1410 string dkNkmLibNoFixup
= "dk/nkm/lib";
1411 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1412 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1413 const vector
<File
*>& files
= module
.non_if_data
.files
;
1414 for ( size_t i
= 0; i
< files
.size (); i
++ )
1416 File
& file
= *files
[i
];
1417 string extension
= GetExtension ( file
.name
);
1418 if ( extension
== ".spec" || extension
== ".SPEC" )
1420 if ( dependencies
.length () > 0 )
1421 dependencies
+= " ";
1422 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1425 return dependencies
;
1429 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
) const
1431 if ( module
.HasFileWithExtension ( module
.non_if_data
, ".cc" ) )
1433 if ( module
.HasFileWithExtension ( module
.non_if_data
, ".cxx" ) )
1435 if ( module
.HasFileWithExtension ( module
.non_if_data
, ".cpp" ) )
1441 static MingwBuildToolModuleHandler buildtool_handler
;
1443 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1444 : MingwModuleHandler ( BuildTool
)
1449 MingwBuildToolModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1451 GeneratePreconditionDependencies ( module
);
1452 GenerateBuildToolModuleTarget ( module
, clean_files
);
1453 GenerateInvocations ( module
);
1457 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
, string_list
& clean_files
)
1459 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1460 string objectsMacro
= GetObjectsMacro ( module
);
1461 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1462 string libsMacro
= GetLibsMacro ( module
);
1464 GenerateMacrosAndTargetsHost ( module
, clean_files
);
1467 if ( IsCPlusPlusModule ( module
) )
1468 linker
= "${host_gpp}";
1470 linker
= "${host_gcc}";
1472 fprintf ( fMakefile
, "%s: %s %s\n",
1474 objectsMacro
.c_str (),
1475 linkDepsMacro
.c_str () );
1476 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [LD] $@\n" );
1477 fprintf ( fMakefile
,
1478 "\t%s %s -o %s %s %s\n\n",
1480 GetLinkerMacro ( module
).c_str (),
1482 objectsMacro
.c_str (),
1483 libsMacro
.c_str () );
1487 static MingwKernelModuleHandler kernelmodule_handler
;
1489 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1490 : MingwModuleHandler ( Kernel
)
1495 MingwKernelModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1497 GeneratePreconditionDependencies ( module
);
1498 GenerateKernelModuleTarget ( module
, clean_files
);
1499 GenerateInvocations ( module
);
1503 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
, string_list
& clean_files
)
1505 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1506 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1507 string
target ( FixupTargetFilename (module
.GetPath ()) ); // i.e. "$(ROS_INT).\ntoskrnl\ntoskrnl.exe"
1508 string workingDirectory
= GetWorkingDirectory ();
1509 string objectsMacro
= GetObjectsMacro ( module
);
1510 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1511 string libsMacro
= GetLibsMacro ( module
);
1512 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1513 CLEAN_FILE ( base_tmp
);
1514 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1515 CLEAN_FILE ( junk_tmp
);
1516 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1517 CLEAN_FILE ( temp_exp
);
1518 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",
1519 module
.GetBasePath ().c_str (),
1520 module
.entrypoint
.c_str (),
1521 module
.baseaddress
.c_str () );
1523 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1525 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1527 fprintf ( fMakefile
, "%s: %s %s\n",
1529 objectsMacro
.c_str (),
1530 linkDepsMacro
.c_str () );
1531 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [LD] $@\n" );
1532 fprintf ( fMakefile
,
1533 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1534 GetLinkerMacro ( module
).c_str (),
1535 gccOptions
.c_str (),
1538 objectsMacro
.c_str (),
1539 linkDepsMacro
.c_str () );
1540 fprintf ( fMakefile
,
1542 junk_tmp
.c_str () );
1543 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1544 fprintf ( fMakefile
,
1545 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1546 targetName
.c_str (),
1550 fprintf ( fMakefile
,
1552 base_tmp
.c_str () );
1553 fprintf ( fMakefile
,
1554 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1555 GetLinkerMacro ( module
).c_str (),
1556 gccOptions
.c_str (),
1559 objectsMacro
.c_str (),
1560 linkDepsMacro
.c_str () );
1561 fprintf ( fMakefile
,
1563 temp_exp
.c_str () );
1564 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [RSYM] $@\n" );
1565 fprintf ( fMakefile
,
1566 "\t${rsym} %s %s\n\n",
1572 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1574 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1575 : MingwModuleHandler ( StaticLibrary
)
1580 MingwStaticLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1582 GeneratePreconditionDependencies ( module
);
1583 GenerateStaticLibraryModuleTarget ( module
, clean_files
);
1584 GenerateInvocations ( module
);
1588 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1590 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1594 static MingwObjectLibraryModuleHandler objectlibrary_handler
;
1596 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()
1597 : MingwModuleHandler ( ObjectLibrary
)
1602 MingwObjectLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1604 GeneratePreconditionDependencies ( module
);
1605 GenerateObjectLibraryModuleTarget ( module
, clean_files
);
1606 GenerateInvocations ( module
);
1610 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1612 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1616 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1618 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1619 : MingwModuleHandler ( KernelModeDLL
)
1624 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1626 GeneratePreconditionDependencies ( module
);
1627 GenerateKernelModeDLLModuleTarget ( module
, clean_files
);
1628 GenerateInvocations ( module
);
1632 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget (
1633 const Module
& module
,
1634 string_list
& clean_files
)
1636 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1637 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1638 string workingDirectory
= GetWorkingDirectory ( );
1639 string objectsMacro
= GetObjectsMacro ( module
);
1640 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1641 string libsMacro
= GetLibsMacro ( module
);
1643 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1645 if ( module
.non_if_data
.files
.size () > 0 )
1647 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1649 fprintf ( fMakefile
, "%s: %s %s\n",
1651 objectsMacro
.c_str (),
1652 linkDepsMacro
.c_str () );
1654 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1655 module
.entrypoint
.c_str (),
1656 module
.baseaddress
.c_str () );
1657 GenerateLinkerCommand ( module
,
1666 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1668 fprintf ( fMakefile
, "%s:\n",
1674 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1676 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1677 : MingwModuleHandler ( KernelModeDriver
)
1682 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1684 GeneratePreconditionDependencies ( module
);
1685 GenerateKernelModeDriverModuleTarget ( module
, clean_files
);
1686 GenerateInvocations ( module
);
1691 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget (
1692 const Module
& module
,
1693 string_list
& clean_files
)
1695 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1696 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1697 string workingDirectory
= GetWorkingDirectory ();
1698 string objectsMacro
= GetObjectsMacro ( module
);
1699 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1700 string libsMacro
= GetLibsMacro ( module
);
1702 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1704 if ( module
.non_if_data
.files
.size () > 0 )
1706 string
cflags ( "-D__NTDRIVER__" );
1707 GenerateMacrosAndTargetsTarget ( module
,
1712 fprintf ( fMakefile
, "%s: %s %s\n",
1714 objectsMacro
.c_str (),
1715 linkDepsMacro
.c_str () );
1717 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1718 module
.entrypoint
.c_str (),
1719 module
.baseaddress
.c_str () );
1720 GenerateLinkerCommand ( module
,
1729 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1731 fprintf ( fMakefile
, "%s:\n",
1737 static MingwNativeDLLModuleHandler nativedll_handler
;
1739 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1740 : MingwModuleHandler ( NativeDLL
)
1745 MingwNativeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1747 GeneratePreconditionDependencies ( module
);
1748 GenerateNativeDLLModuleTarget ( module
, clean_files
);
1749 GenerateInvocations ( module
);
1753 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1755 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1756 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1757 string workingDirectory
= GetWorkingDirectory ( );
1758 string objectsMacro
= GetObjectsMacro ( module
);
1759 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1760 string libsMacro
= GetLibsMacro ( module
);
1762 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1764 if ( module
.non_if_data
.files
.size () > 0 )
1766 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1768 fprintf ( fMakefile
, "%s: %s %s\n",
1770 objectsMacro
.c_str (),
1771 linkDepsMacro
.c_str () );
1773 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1774 module
.entrypoint
.c_str (),
1775 module
.baseaddress
.c_str () );
1776 GenerateLinkerCommand ( module
,
1785 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1787 fprintf ( fMakefile
, "%s:\n\n",
1793 static MingwNativeCUIModuleHandler nativecui_handler
;
1795 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ()
1796 : MingwModuleHandler ( NativeCUI
)
1801 MingwNativeCUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1803 GeneratePreconditionDependencies ( module
);
1804 GenerateNativeCUIModuleTarget ( module
, clean_files
);
1805 GenerateInvocations ( module
);
1809 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1811 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1812 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1813 string workingDirectory
= GetWorkingDirectory ( );
1814 string objectsMacro
= GetObjectsMacro ( module
);
1815 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1816 string libsMacro
= GetLibsMacro ( module
);
1818 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1820 if ( module
.non_if_data
.files
.size () > 0 )
1822 string
cflags ( "-D__NTAPP__" );
1823 GenerateMacrosAndTargetsTarget ( module
,
1828 fprintf ( fMakefile
, "%s: %s %s\n",
1830 objectsMacro
.c_str (),
1831 linkDepsMacro
.c_str () );
1833 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1834 module
.entrypoint
.c_str (),
1835 module
.baseaddress
.c_str () );
1836 GenerateLinkerCommand ( module
,
1845 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1847 fprintf ( fMakefile
, "%s:\n\n",
1853 static MingwWin32DLLModuleHandler win32dll_handler
;
1855 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1856 : MingwModuleHandler ( Win32DLL
)
1861 MingwWin32DLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1863 GenerateExtractWineDLLResourcesTarget ( module
, clean_files
);
1864 GeneratePreconditionDependencies ( module
);
1865 GenerateWin32DLLModuleTarget ( module
, clean_files
);
1866 GenerateInvocations ( module
);
1870 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
, string_list
& clean_files
)
1872 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1873 module
.name
.c_str () );
1874 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1875 module
.name
.c_str () );
1876 const vector
<File
*>& files
= module
.non_if_data
.files
;
1877 for ( size_t i
= 0; i
< files
.size (); i
++ )
1879 File
& file
= *files
[i
];
1880 string extension
= GetExtension ( file
.name
);
1881 if ( extension
== ".rc" || extension
== ".RC" )
1883 string resource
= FixupTargetFilename ( file
.name
);
1884 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [BIN2RES] $<\n" );
1885 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1886 resource
.c_str () );
1889 fprintf ( fMakefile
, "\n");
1893 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1895 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1896 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1897 string workingDirectory
= GetWorkingDirectory ( );
1898 string objectsMacro
= GetObjectsMacro ( module
);
1899 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1900 string libsMacro
= GetLibsMacro ( module
);
1902 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1904 if ( module
.non_if_data
.files
.size () > 0 )
1906 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1908 fprintf ( fMakefile
, "%s: %s %s\n",
1910 objectsMacro
.c_str (),
1911 linkDepsMacro
.c_str () );
1914 if ( IsCPlusPlusModule ( module
) )
1919 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1920 module
.entrypoint
.c_str (),
1921 module
.baseaddress
.c_str () );
1922 GenerateLinkerCommand ( module
,
1931 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1933 fprintf ( fMakefile
, "%s:\n\n",
1939 static MingwWin32CUIModuleHandler win32cui_handler
;
1941 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ()
1942 : MingwModuleHandler ( Win32CUI
)
1947 MingwWin32CUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1949 GeneratePreconditionDependencies ( module
);
1950 GenerateWin32CUIModuleTarget ( module
, clean_files
);
1951 GenerateInvocations ( module
);
1955 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1957 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1958 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1959 string workingDirectory
= GetWorkingDirectory ( );
1960 string objectsMacro
= GetObjectsMacro ( module
);
1961 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1962 string libsMacro
= GetLibsMacro ( module
);
1964 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1966 if ( module
.non_if_data
.files
.size () > 0 )
1968 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1970 fprintf ( fMakefile
, "%s: %s %s\n",
1972 objectsMacro
.c_str (),
1973 linkDepsMacro
.c_str () );
1976 if ( IsCPlusPlusModule ( module
) )
1981 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1982 module
.entrypoint
.c_str (),
1983 module
.baseaddress
.c_str () );
1984 GenerateLinkerCommand ( module
,
1993 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1995 fprintf ( fMakefile
, "%s:\n\n",
2001 static MingwWin32GUIModuleHandler win32gui_handler
;
2003 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
2004 : MingwModuleHandler ( Win32GUI
)
2009 MingwWin32GUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2011 GeneratePreconditionDependencies ( module
);
2012 GenerateWin32GUIModuleTarget ( module
, clean_files
);
2013 GenerateInvocations ( module
);
2017 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
2019 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2020 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2021 string workingDirectory
= GetWorkingDirectory ( );
2022 string objectsMacro
= GetObjectsMacro ( module
);
2023 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2024 string libsMacro
= GetLibsMacro ( module
);
2026 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
2028 if ( module
.non_if_data
.files
.size () > 0 )
2030 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
2032 fprintf ( fMakefile
, "%s: %s %s\n",
2034 objectsMacro
.c_str (),
2035 linkDepsMacro
.c_str () );
2038 if ( IsCPlusPlusModule ( module
) )
2043 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2044 module
.entrypoint
.c_str (),
2045 module
.baseaddress
.c_str () );
2046 GenerateLinkerCommand ( module
,
2055 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2057 fprintf ( fMakefile
, "%s:\n\n",
2063 static MingwBootLoaderModuleHandler bootloadermodule_handler
;
2065 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()
2066 : MingwModuleHandler ( BootLoader
)
2071 MingwBootLoaderModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2073 GeneratePreconditionDependencies ( module
);
2074 GenerateBootLoaderModuleTarget ( module
, clean_files
);
2075 GenerateInvocations ( module
);
2079 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget (
2080 const Module
& module
,
2081 string_list
& clean_files
)
2083 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2084 string
targetName ( module
.GetTargetName () );
2085 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2086 string workingDirectory
= GetWorkingDirectory ();
2087 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
2088 CLEAN_FILE ( junk_tmp
);
2089 string objectsMacro
= GetObjectsMacro ( module
);
2090 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2091 string libsMacro
= GetLibsMacro ( module
);
2093 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
2095 fprintf ( fMakefile
, "%s: %s %s\n",
2097 objectsMacro
.c_str (),
2098 linkDepsMacro
.c_str () );
2100 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [LD] $@\n" );
2102 fprintf ( fMakefile
,
2103 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2104 GetLinkerMacro ( module
).c_str (),
2106 objectsMacro
.c_str (),
2107 linkDepsMacro
.c_str () );
2108 fprintf ( fMakefile
,
2109 "\t${objcopy} -O binary %s %s\n",
2112 fprintf ( fMakefile
,
2114 junk_tmp
.c_str () );
2118 static MingwBootSectorModuleHandler bootsectormodule_handler
;
2120 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ()
2121 : MingwModuleHandler ( BootSector
)
2126 MingwBootSectorModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2128 GeneratePreconditionDependencies ( module
);
2129 GenerateBootSectorModuleTarget ( module
, clean_files
);
2130 GenerateInvocations ( module
);
2134 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
, string_list
& clean_files
)
2136 string objectsMacro
= GetObjectsMacro ( module
);
2138 string
* nasmflags
= new string ( "-f bin" );
2139 GenerateMacrosAndTargetsTarget ( module
,
2144 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2145 module
.name
.c_str ());
2146 fprintf ( fMakefile
,
2148 module
.name
.c_str (),
2149 objectsMacro
.c_str () );
2153 static MingwIsoModuleHandler isomodule_handler
;
2155 MingwIsoModuleHandler::MingwIsoModuleHandler ()
2156 : MingwModuleHandler ( Iso
)
2161 MingwIsoModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2163 GeneratePreconditionDependencies ( module
);
2164 GenerateIsoModuleTarget ( module
, clean_files
);
2165 GenerateInvocations ( module
);
2169 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string bootcdDirectory
,
2170 const Module
& module
) const
2172 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2174 const Module
& m
= *module
.project
.modules
[i
];
2175 if ( m
.bootstrap
!= NULL
)
2177 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
2178 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2179 fprintf ( fMakefile
,
2181 m
.GetPath ().c_str (),
2182 targetFilename
.c_str () );
2188 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string bootcdDirectory
,
2189 const Module
& module
) const
2191 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2193 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2194 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2195 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2196 fprintf ( fMakefile
,
2198 cdfile
.GetPath ().c_str (),
2199 targetFilename
.c_str () );
2204 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string bootcdDirectory
,
2205 const Module
& module
) const
2208 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2210 const Module
& m
= *module
.project
.modules
[i
];
2211 if ( m
.bootstrap
!= NULL
)
2213 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2214 if ( directories
.size () > 0 )
2216 directories
+= FixupTargetFilename ( targetDirecctory
);
2223 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string bootcdDirectory
,
2224 const Module
& module
) const
2227 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2229 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2230 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2231 if ( directories
.size () > 0 )
2233 directories
+= FixupTargetFilename ( targetDirecctory
);
2239 MingwIsoModuleHandler::GetCdDirectories ( const string bootcdDirectory
,
2240 const Module
& module
) const
2242 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2244 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2250 MingwIsoModuleHandler::GetBootstrapCdFiles ( const string bootcdDirectory
,
2251 const Module
& module
) const
2254 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2256 const Module
& m
= *module
.project
.modules
[i
];
2257 if ( m
.bootstrap
!= NULL
)
2259 if ( cdfiles
.size () > 0 )
2261 cdfiles
+= FixupTargetFilename ( m
.GetPath () );
2268 MingwIsoModuleHandler::GetNonModuleCdFiles ( const string bootcdDirectory
,
2269 const Module
& module
) const
2272 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2274 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2275 if ( cdfiles
.size () > 0 )
2277 cdfiles
+= NormalizeFilename ( cdfile
.GetPath () );
2283 MingwIsoModuleHandler::GetCdFiles ( const string bootcdDirectory
,
2284 const Module
& module
) const
2286 string cdfiles
= GetBootstrapCdFiles ( bootcdDirectory
,
2288 cdfiles
+= " " + GetNonModuleCdFiles ( bootcdDirectory
,
2294 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
, string_list
& clean_files
)
2296 string bootcdDirectory
= "cd";
2297 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2298 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2299 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2300 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2301 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2302 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2303 string cdDirectories
= bootcdReactos
+ " " + GetCdDirectories ( bootcdDirectory
,
2305 string cdFiles
= GetCdFiles ( bootcdDirectory
,
2308 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2309 module
.name
.c_str ());
2310 fprintf ( fMakefile
,
2311 "%s: all %s %s %s\n",
2312 module
.name
.c_str (),
2314 cdDirectories
.c_str (),
2316 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [CABMAN] $<\n" );
2317 fprintf ( fMakefile
,
2318 "\t${cabman} -C %s -L %s -I\n",
2319 reactosDff
.c_str (),
2320 bootcdReactos
.c_str () );
2321 fprintf ( fMakefile
,
2322 "\t${cabman} -C %s -RC %s -L %s -N\n",
2323 reactosDff
.c_str (),
2324 reactosInf
.c_str (),
2325 bootcdReactos
.c_str () );
2326 fprintf ( fMakefile
,
2328 reactosInf
.c_str () );
2329 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2331 OutputCdfileCopyCommands ( bootcdDirectory
,
2333 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [CDMAKE] $@\n" );
2334 fprintf ( fMakefile
,
2335 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2337 bootcdDirectory
.c_str () );
2338 fprintf ( fMakefile
,