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
;
27 MingwModuleHandler::use_pch
= false;
30 ReplaceExtension ( const string
& filename
,
31 const string
& newExtension
)
33 size_t index
= filename
.find_last_of ( '/' );
34 if ( index
== string::npos
)
36 size_t index2
= filename
.find_last_of ( '\\' );
37 if ( index2
!= string::npos
&& index2
> index
)
39 string tmp
= filename
.substr( index
/*, filename.size() - index*/ );
40 size_t ext_index
= tmp
.find_last_of( '.' );
41 if ( ext_index
!= string::npos
)
42 return filename
.substr ( 0, index
+ ext_index
) + newExtension
;
43 return filename
+ newExtension
;
48 const string
& filename
,
49 const string
& prefix
)
51 if ( !prefix
.length() )
54 const char* pfilename
= filename
.c_str();
55 const char* p1
= strrchr ( pfilename
, '/' );
56 const char* p2
= strrchr ( pfilename
, '\\' );
61 out
+= string(pfilename
,p1
-pfilename
) + CSEP
;
64 out
+= prefix
+ pfilename
;
68 string
v2s ( const vector
<string
>& v
, int wrap_at
)
74 for ( size_t i
= 0; i
< v
.size(); i
++ )
78 if ( wrap_at
> 0 && wrap_count
++ == wrap_at
)
87 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype
)
90 handler_map
= new map
<ModuleType
,MingwModuleHandler
*>;
91 (*handler_map
)[moduletype
] = this;
94 MingwModuleHandler::~MingwModuleHandler()
104 MingwModuleHandler::PassThruCacheDirectory ( const string
&file
) const
106 directory_set
.insert ( GetDirectory ( file
) );
111 MingwModuleHandler::SetMakefile ( FILE* f
)
117 MingwModuleHandler::SetUsePch ( bool b
)
123 MingwModuleHandler::LookupHandler ( const string
& location
,
124 ModuleType moduletype
)
127 throw Exception ( "internal tool error: no registered module handlers" );
128 MingwModuleHandler
* h
= (*handler_map
)[moduletype
];
131 throw UnknownModuleTypeException ( location
, moduletype
);
138 MingwModuleHandler::GetWorkingDirectory () const
144 MingwModuleHandler::GetBasename ( const string
& filename
) const
146 size_t index
= filename
.find_last_of ( '.' );
147 if ( index
!= string::npos
)
148 return filename
.substr ( 0, index
);
153 MingwModuleHandler::GetActualSourceFilename ( const string
& filename
) const
155 string extension
= GetExtension ( filename
);
156 if ( extension
== ".spec" || extension
== "SPEC" )
158 string basename
= GetBasename ( filename
);
159 return basename
+ ".stubs.c";
166 MingwModuleHandler::GetModuleArchiveFilename ( const Module
& module
) const
168 return ReplaceExtension ( FixupTargetFilename ( module
.GetPath () ),
173 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
175 string extension
= GetExtension ( file
.name
);
176 if ( extension
== ".spec" || extension
== "SPEC" )
183 MingwModuleHandler::GetImportLibraryDependency ( const Module
& importedModule
) const
185 if ( importedModule
.type
== ObjectLibrary
)
186 return GetObjectsMacro ( importedModule
);
188 return PassThruCacheDirectory ( FixupTargetFilename ( importedModule
.GetDependencyPath () ) );
192 MingwModuleHandler::GetModuleDependencies ( const Module
& module
) const
194 if ( module
.dependencies
.size () == 0 )
197 string
dependencies ( "" );
198 for ( size_t i
= 0; i
< module
.dependencies
.size (); i
++ )
200 if ( dependencies
.size () > 0 )
202 const Dependency
* dependency
= module
.dependencies
[i
];
203 const Module
* dependencyModule
= dependency
->dependencyModule
;
204 dependencies
+= dependencyModule
->GetTargets ();
206 string definitionDependencies
= GetDefinitionDependencies ( module
);
207 if ( dependencies
.length () > 0 && definitionDependencies
.length () > 0 )
208 dependencies
+= " " + definitionDependencies
;
209 else if ( definitionDependencies
.length () > 0 )
210 dependencies
= definitionDependencies
;
215 MingwModuleHandler::GetSourceFilenames ( const Module
& module
,
216 bool includeGeneratedFiles
) const
220 string
sourceFilenames ( "" );
221 const vector
<File
*>& files
= module
.non_if_data
.files
;
222 for ( i
= 0; i
< files
.size (); i
++ )
224 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *files
[i
] ) )
225 sourceFilenames
+= " " + GetActualSourceFilename ( files
[i
]->name
);
227 // intentionally make a copy so that we can append more work in
228 // the middle of processing without having to go recursive
229 vector
<If
*> v
= module
.non_if_data
.ifs
;
230 for ( i
= 0; i
< v
.size (); i
++ )
234 // check for sub-ifs to add to list
235 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
236 for ( j
= 0; j
< ifs
.size (); j
++ )
237 v
.push_back ( ifs
[j
] );
238 const vector
<File
*>& files
= rIf
.data
.files
;
239 for ( j
= 0; j
< files
.size (); j
++ )
241 File
& file
= *files
[j
];
242 if ( includeGeneratedFiles
|| !IsGeneratedFile ( file
) )
243 sourceFilenames
+= " " + GetActualSourceFilename ( file
.name
);
246 return sourceFilenames
;
250 MingwModuleHandler::GetSourceFilenames ( const Module
& module
) const
252 return GetSourceFilenames ( module
,
257 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module
& module
) const
259 return GetSourceFilenames ( module
,
264 GetObjectFilename ( const Module
& module
, const string
& sourceFilename
)
267 string extension
= GetExtension ( sourceFilename
);
268 if ( extension
== ".rc" || extension
== ".RC" )
269 newExtension
= ".coff";
270 else if ( extension
== ".spec" || extension
== ".SPEC" )
271 newExtension
= ".stubs.o";
274 return FixupTargetFilename (
276 PrefixFilename(sourceFilename
,module
.prefix
),
281 MingwModuleHandler::GenerateCleanTarget (
282 const Module
& module
,
283 const string_list
& clean_files
) const
285 if ( 0 == clean_files
.size() )
287 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
288 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
289 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
292 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
293 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
295 fprintf ( fMakefile
, " 2>$(NUL)\n" );
296 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
300 MingwModuleHandler::GetObjectFilenames ( const Module
& module
) const
302 const vector
<File
*>& files
= module
.non_if_data
.files
;
303 if ( files
.size () == 0 )
306 string
objectFilenames ( "" );
307 for ( size_t i
= 0; i
< files
.size (); i
++ )
309 if ( objectFilenames
.size () > 0 )
310 objectFilenames
+= " ";
311 objectFilenames
+= PassThruCacheDirectory (
312 GetObjectFilename ( module
, files
[i
]->name
) );
314 return objectFilenames
;
318 MingwModuleHandler::IncludeDirectoryTarget ( const string
& directory
) const
320 if ( directory
== "$(ROS_INTERMEDIATE)." SSEP
"tools")
327 MingwModuleHandler::GenerateDirectoryTargets () const
329 if ( directory_set
.size () == 0 )
332 set_string::iterator it
;
333 size_t wrap_count
= 0;
335 fprintf ( fMakefile
, "ifneq ($(ROS_INTERMEDIATE),)\n" );
336 fprintf ( fMakefile
, "directories::" );
338 for ( it
= directory_set
.begin ();
339 it
!= directory_set
.end ();
342 if ( IncludeDirectoryTarget ( *it
) )
344 if ( wrap_count
++ == 5 )
345 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
352 fprintf ( fMakefile
, "\n\n" );
355 for ( it
= directory_set
.begin ();
356 it
!= directory_set
.end ();
359 if ( IncludeDirectoryTarget ( *it
) )
361 if ( wrap_count
++ == 5 )
362 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
370 "::\n\t${mkdir} $@\n" );
371 fprintf ( fMakefile
, "endif\n\n" );
373 directory_set
.clear ();
377 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector
<Define
*>& defines
) const
380 for ( size_t i
= 0; i
< defines
.size (); i
++ )
382 Define
& define
= *defines
[i
];
383 if (parameters
.length () > 0)
386 parameters
+= define
.name
;
387 if (define
.value
.length () > 0)
390 parameters
+= define
.value
;
397 MingwModuleHandler::GenerateGccDefineParameters ( const Module
& module
) const
399 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
400 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
401 if ( s
.length () > 0 )
410 MingwModuleHandler::ConcatenatePaths ( const string
& path1
,
411 const string
& path2
) const
413 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
415 if ( path1
[path1
.length ()] == CSEP
)
416 return path1
+ path2
;
418 return path1
+ CSEP
+ path2
;
422 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
425 for ( size_t i
= 0; i
< includes
.size (); i
++ )
427 Include
& include
= *includes
[i
];
428 if ( parameters
.length () > 0 )
430 parameters
+= "-I" + include
.directory
;
436 MingwModuleHandler::GenerateGccIncludeParameters ( const Module
& module
) const
438 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
439 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
440 if ( s
.length () > 0 )
450 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
453 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
455 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
456 if ( parameters
.length () > 0 )
458 parameters
+= compilerFlag
.flag
;
464 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
467 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
469 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
470 if ( parameters
.length () > 0 )
472 parameters
+= linkerFlag
.flag
;
478 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
479 const vector
<Library
*>& libraries
) const
481 string
dependencies ( "" );
483 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
485 if ( wrap_count
++ == 5 )
486 dependencies
+= " \\\n\t\t", wrap_count
= 0;
487 else if ( dependencies
.size () > 0 )
489 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->imported_module
);
495 MingwModuleHandler::GenerateLinkerParameters ( const Module
& module
) const
497 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
501 MingwModuleHandler::GenerateMacro (
502 const char* assignmentOperation
,
504 const IfableData
& data
,
505 const vector
<CompilerFlag
*>* compilerFlags
) const
513 assignmentOperation
);
515 if ( compilerFlags
!= NULL
)
517 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
518 if ( compilerParameters
.size () > 0 )
523 compilerParameters
.c_str () );
527 for ( i
= 0; i
< data
.includes
.size(); i
++ )
532 data
.includes
[i
]->directory
.c_str() );
534 for ( i
= 0; i
< data
.defines
.size(); i
++ )
536 Define
& d
= *data
.defines
[i
];
541 if ( d
.value
.size() )
547 fprintf ( fMakefile
, "\n" );
551 MingwModuleHandler::GenerateMacros (
552 const Module
& module
,
553 const char* assignmentOperation
,
554 const IfableData
& data
,
555 const vector
<CompilerFlag
*>* compilerFlags
,
556 const vector
<LinkerFlag
*>* linkerFlags
,
557 const string
& cflags_macro
,
558 const string
& nasmflags_macro
,
559 const string
& windresflags_macro
,
560 const string
& linkerflags_macro
,
561 const string
& objs_macro
,
562 const string
& libs_macro
,
563 const string
& linkdeps_macro
) const
567 if ( data
.includes
.size () > 0 || data
.defines
.size () > 0 )
569 GenerateMacro ( assignmentOperation
,
573 GenerateMacro ( assignmentOperation
,
579 if ( linkerFlags
!= NULL
)
581 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
582 if ( linkerParameters
.size () > 0 )
587 linkerflags_macro
.c_str (),
589 linkerParameters
.c_str() );
593 if ( data
.libraries
.size () > 0 )
595 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
596 if ( deps
.size () > 0 )
607 const vector
<File
*>& files
= data
.files
;
608 if ( files
.size () > 0 )
610 for ( i
= 0; i
< files
.size (); i
++ )
612 File
& file
= *files
[i
];
618 PassThruCacheDirectory (
619 GetObjectFilename ( module
, file
.name
) ).c_str (),
620 objs_macro
.c_str() );
627 assignmentOperation
);
628 for ( i
= 0; i
< files
.size(); i
++ )
630 File
& file
= *files
[i
];
636 ( i
%10 == 9 ? "\\\n\t" : " " ),
637 PassThruCacheDirectory (
638 GetObjectFilename ( module
, file
.name
) ).c_str () );
641 fprintf ( fMakefile
, "\n" );
644 const vector
<If
*>& ifs
= data
.ifs
;
645 for ( i
= 0; i
< ifs
.size(); i
++ )
648 if ( rIf
.data
.defines
.size()
649 || rIf
.data
.includes
.size()
650 || rIf
.data
.libraries
.size()
651 || rIf
.data
.files
.size()
652 || rIf
.data
.ifs
.size() )
656 "ifeq (\"$(%s)\",\"%s\")\n",
657 rIf
.property
.c_str(),
680 MingwModuleHandler::GenerateMacros (
681 const Module
& module
,
682 const string
& cflags_macro
,
683 const string
& nasmflags_macro
,
684 const string
& windresflags_macro
,
685 const string
& linkerflags_macro
,
686 const string
& objs_macro
,
687 const string
& libs_macro
,
688 const string
& linkdeps_macro
) const
694 &module
.compilerFlags
,
704 if ( module
.importLibrary
)
707 const vector
<File
*>& files
= module
.non_if_data
.files
;
708 for ( size_t i
= 0; i
< files
.size (); i
++ )
710 File
& file
= *files
[i
];
711 string extension
= GetExtension ( file
.name
);
712 if ( extension
== ".spec" || extension
== ".SPEC" )
714 if ( s
.length () > 0 )
716 s
+= GetSpecObjectDependencies ( file
.name
);
719 if ( s
.length () > 0 )
724 linkdeps_macro
.c_str(),
731 "%s += $(PROJECT_CFLAGS)\n",
732 cflags_macro
.c_str () );
736 "%s += $(PROJECT_RCFLAGS)\n",
737 windresflags_macro
.c_str () );
741 "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
742 module
.name
.c_str () );
747 linkdeps_macro
.c_str (),
748 libs_macro
.c_str () );
750 fprintf ( fMakefile
, "\n" );
754 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
755 const string
& sourceFilename
,
757 const string
& cflagsMacro
) const
759 string deps
= sourceFilename
;
760 if ( module
.pch
&& use_pch
)
761 deps
+= " " + module
.pch
->header
+ ".gch";
762 string objectFilename
= PassThruCacheDirectory (
763 GetObjectFilename ( module
, sourceFilename
) );
766 objectFilename
.c_str (),
768 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
770 "\t%s -c %s -o %s %s\n",
772 sourceFilename
.c_str (),
773 objectFilename
.c_str (),
774 cflagsMacro
.c_str () );
778 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
779 const string
& sourceFilename
,
781 const string
& cflagsMacro
) const
783 string objectFilename
= PassThruCacheDirectory (
784 GetObjectFilename ( module
, sourceFilename
) );
787 objectFilename
.c_str (),
788 sourceFilename
.c_str () );
789 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
791 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
793 sourceFilename
.c_str (),
794 objectFilename
.c_str (),
795 cflagsMacro
.c_str () );
799 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
800 const string
& sourceFilename
,
801 const string
& nasmflagsMacro
) const
803 string objectFilename
= PassThruCacheDirectory (
804 GetObjectFilename ( module
, sourceFilename
) );
807 objectFilename
.c_str (),
808 sourceFilename
.c_str () );
809 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
811 "\t%s -f win32 %s -o %s %s\n",
813 sourceFilename
.c_str (),
814 objectFilename
.c_str (),
815 nasmflagsMacro
.c_str () );
819 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
820 const string
& sourceFilename
,
821 const string
& windresflagsMacro
) const
823 string objectFilename
= PassThruCacheDirectory (
824 GetObjectFilename ( module
, sourceFilename
) );
825 string rciFilename
= ReplaceExtension ( sourceFilename
,
827 string resFilename
= ReplaceExtension ( sourceFilename
,
830 "%s: %s $(WRC_TARGET)\n",
831 objectFilename
.c_str (),
832 sourceFilename
.c_str () );
833 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
835 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
836 windresflagsMacro
.c_str (),
837 sourceFilename
.c_str (),
838 rciFilename
.c_str () );
840 "\t${wrc} ${%s} %s %s\n",
841 windresflagsMacro
.c_str (),
842 rciFilename
.c_str (),
843 resFilename
.c_str () );
846 rciFilename
.c_str () );
848 "\t${windres} %s -o %s\n",
849 resFilename
.c_str (),
850 objectFilename
.c_str () );
853 resFilename
.c_str () );
857 MingwModuleHandler::GenerateWinebuildCommands (
858 const Module
& module
,
859 const string
& sourceFilename
,
860 string_list
& clean_files
) const
862 string basename
= GetBasename ( sourceFilename
);
864 string def_file
= basename
+ ".spec.def";
865 CLEAN_FILE ( def_file
);
867 string stub_file
= basename
+ ".stubs.c";
868 CLEAN_FILE ( stub_file
);
873 sourceFilename
.c_str () );
874 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
876 "\t%s --def=%s -o %s\n",
878 sourceFilename
.c_str (),
884 sourceFilename
.c_str () );
885 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
887 "\t%s --pedll=%s -o %s\n",
889 sourceFilename
.c_str (),
890 stub_file
.c_str () );
894 MingwModuleHandler::GenerateCommands (
895 const Module
& module
,
896 const string
& sourceFilename
,
899 const string
& cflagsMacro
,
900 const string
& nasmflagsMacro
,
901 const string
& windresflagsMacro
,
902 string_list
& clean_files
) const
904 CLEAN_FILE ( GetObjectFilename(module
,sourceFilename
) );
905 string extension
= GetExtension ( sourceFilename
);
906 if ( extension
== ".c" || extension
== ".C" )
908 GenerateGccCommand ( module
,
914 else if ( extension
== ".cc" || extension
== ".CC" ||
915 extension
== ".cpp" || extension
== ".CPP" ||
916 extension
== ".cxx" || extension
== ".CXX" )
918 GenerateGccCommand ( module
,
924 else if ( extension
== ".s" || extension
== ".S" )
926 GenerateGccAssemblerCommand ( module
,
932 else if ( extension
== ".asm" || extension
== ".ASM" )
934 GenerateNasmCommand ( module
,
939 else if ( extension
== ".rc" || extension
== ".RC" )
941 GenerateWindresCommand ( module
,
946 else if ( extension
== ".spec" || extension
== ".SPEC" )
948 GenerateWinebuildCommands ( module
,
951 GenerateGccCommand ( module
,
952 GetActualSourceFilename ( sourceFilename
),
958 throw InvalidOperationException ( __FILE__
,
960 "Unsupported filename extension '%s' in file '%s'",
962 sourceFilename
.c_str () );
966 MingwModuleHandler::GenerateLinkerCommand (
967 const Module
& module
,
968 const string
& target
,
969 const string
& dependencies
,
970 const string
& linker
,
971 const string
& linkerParameters
,
972 const string
& objectsMacro
,
973 const string
& libsMacro
,
974 string_list
& clean_files
) const
977 "%s: %s ${RSYM_TARGET}\n",
979 dependencies
.c_str () );
980 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
981 string
targetName ( module
.GetTargetName () );
982 if ( module
.importLibrary
!= NULL
)
984 static string
ros_junk ( "$(ROS_TEMPORARY)" );
985 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
986 CLEAN_FILE ( base_tmp
);
987 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
988 CLEAN_FILE ( junk_tmp
);
989 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
990 CLEAN_FILE ( temp_exp
);
991 string def_file
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
994 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
996 linkerParameters
.c_str (),
999 objectsMacro
.c_str (),
1001 GetLinkerMacro ( module
).c_str () );
1003 fprintf ( fMakefile
,
1005 junk_tmp
.c_str () );
1007 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1008 fprintf ( fMakefile
,
1009 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
1010 targetName
.c_str (),
1016 fprintf ( fMakefile
,
1018 base_tmp
.c_str () );
1020 fprintf ( fMakefile
,
1021 "\t%s %s %s -o %s %s %s %s\n",
1023 linkerParameters
.c_str (),
1026 objectsMacro
.c_str (),
1028 GetLinkerMacro ( module
).c_str () );
1030 fprintf ( fMakefile
,
1032 temp_exp
.c_str () );
1036 fprintf ( fMakefile
,
1037 "\t%s %s -o %s %s %s %s\n",
1039 linkerParameters
.c_str (),
1041 objectsMacro
.c_str (),
1043 GetLinkerMacro ( module
).c_str () );
1046 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1047 fprintf ( fMakefile
,
1048 "\t${rsym} %s %s\n\n",
1054 MingwModuleHandler::GenerateObjectFileTargets (
1055 const Module
& module
,
1056 const IfableData
& data
,
1059 const string
& cflagsMacro
,
1060 const string
& nasmflagsMacro
,
1061 const string
& windresflagsMacro
,
1062 string_list
& clean_files
) const
1066 const vector
<File
*>& files
= data
.files
;
1067 for ( i
= 0; i
< files
.size (); i
++ )
1069 string sourceFilename
= files
[i
]->name
;
1070 GenerateCommands ( module
,
1078 fprintf ( fMakefile
,
1082 const vector
<If
*>& ifs
= data
.ifs
;
1083 for ( i
= 0; i
< ifs
.size(); i
++ )
1085 GenerateObjectFileTargets ( module
,
1097 MingwModuleHandler::GenerateObjectFileTargets (
1098 const Module
& module
,
1101 const string
& cflagsMacro
,
1102 const string
& nasmflagsMacro
,
1103 const string
& windresflagsMacro
,
1104 string_list
& clean_files
) const
1108 const string
& pch_file
= module
.pch
->header
;
1109 string gch_file
= pch_file
+ ".gch";
1110 CLEAN_FILE(gch_file
);
1118 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1121 "\t%s -o %s %s -g %s\n\n",
1122 ( module
.cplusplus
? cppc
.c_str() : cc
.c_str() ),
1124 cflagsMacro
.c_str(),
1129 GenerateObjectFileTargets ( module
,
1137 fprintf ( fMakefile
, "\n" );
1141 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
1143 const string
& objs_macro
) const
1145 string archiveFilename
= GetModuleArchiveFilename ( module
);
1147 fprintf ( fMakefile
,
1149 archiveFilename
.c_str (),
1150 objs_macro
.c_str ());
1152 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1154 fprintf ( fMakefile
,
1155 "\t%s -rc %s %s\n\n",
1157 archiveFilename
.c_str (),
1158 objs_macro
.c_str ());
1160 return archiveFilename
;
1164 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
1166 return ssprintf ( "$(%s_CFLAGS)",
1167 module
.name
.c_str () );
1171 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
1173 return ssprintf ( "$(%s_OBJS)",
1174 module
.name
.c_str () );
1178 MingwModuleHandler::GetLinkingDependenciesMacro ( const Module
& module
) const
1180 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1184 MingwModuleHandler::GetLibsMacro ( const Module
& module
) const
1186 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1190 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
1192 return ssprintf ( "$(%s_LFLAGS)",
1193 module
.name
.c_str () );
1197 MingwModuleHandler::GenerateMacrosAndTargets (
1198 const Module
& module
,
1199 const string
* cflags
,
1200 const string
* nasmflags
,
1201 string_list
& clean_files
) const
1203 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1204 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1205 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1207 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1208 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1209 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1210 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1211 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1212 string libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1213 string linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1215 GenerateMacros ( module
,
1224 if ( cflags
!= NULL
)
1226 fprintf ( fMakefile
,
1228 cflagsMacro
.c_str (),
1232 if ( nasmflags
!= NULL
)
1234 fprintf ( fMakefile
,
1236 nasmflagsMacro
.c_str (),
1237 nasmflags
->c_str () );
1240 // generate phony target for module name
1241 fprintf ( fMakefile
, ".PHONY: %s\n",
1242 module
.name
.c_str () );
1243 fprintf ( fMakefile
, "%s: %s\n\n",
1244 module
.name
.c_str (),
1245 FixupTargetFilename ( module
.GetPath () ).c_str () );
1247 // future references to the macros will be to get their values
1248 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1249 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1250 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1252 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1253 GenerateObjectFileTargets ( module
,
1261 CLEAN_FILE ( ar_target
);
1262 string tgt
= FixupTargetFilename(module
.GetPath());
1263 if ( tgt
!= ar_target
)
1270 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
1272 string dependencies
;
1273 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1275 Invoke
& invoke
= *module
.invocations
[i
];
1276 if (invoke
.invokeModule
== &module
)
1277 /* Protect against circular dependencies */
1279 if ( dependencies
.length () > 0 )
1280 dependencies
+= " ";
1281 dependencies
+= invoke
.GetTargets ();
1283 return dependencies
;
1287 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1289 if ( module
.invocations
.size () == 0 )
1292 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1294 const Invoke
& invoke
= *module
.invocations
[i
];
1296 if ( invoke
.invokeModule
->type
!= BuildTool
)
1298 throw InvalidBuildFileException ( module
.node
.location
,
1299 "Only modules of type buildtool can be invoked." );
1302 string invokeTarget
= module
.GetInvocationTarget ( i
);
1303 fprintf ( fMakefile
,
1305 invokeTarget
.c_str () );
1306 fprintf ( fMakefile
,
1308 invokeTarget
.c_str (),
1309 invoke
.GetTargets ().c_str () );
1310 fprintf ( fMakefile
,
1312 invoke
.GetTargets ().c_str (),
1313 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1314 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1315 fprintf ( fMakefile
,
1317 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1318 invoke
.GetParameters ().c_str () );
1323 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1325 return module
.name
+ "_precondition";
1329 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1331 /* Avoid circular dependency */
1332 if ( module
.type
== BuildTool
1333 || module
.name
== "zlib"
1334 || module
.name
== "hostzlib" )
1335 return "$(ROS_INTERMEDIATE)." SSEP
"tools $(ROS_INTERMEDIATE)." SSEP
"lib" SSEP
"zlib";
1341 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
1343 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1344 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1345 string dependencies
= GetDefaultDependencies ( module
);
1346 string s
= GetModuleDependencies ( module
);
1347 if ( s
.length () > 0 )
1349 if ( dependencies
.length () > 0 )
1350 dependencies
+= " ";
1354 s
= GetInvocationDependencies ( module
);
1355 if ( s
.length () > 0 )
1357 if ( dependencies
.length () > 0 )
1358 dependencies
+= " ";
1362 fprintf ( fMakefile
,
1364 preconditionDependenciesName
.c_str (),
1365 dependencies
.c_str () );
1366 const char* p
= sourceFilenames
.c_str();
1367 const char* end
= p
+ strlen(p
);
1370 const char* p2
= &p
[512];
1373 while ( p2
> p
&& !isspace(*p2
) )
1377 p2
= strpbrk ( p
, " \t" );
1381 fprintf ( fMakefile
,
1385 preconditionDependenciesName
.c_str ());
1387 p
+= strspn ( p
, " \t" );
1389 fprintf ( fMakefile
, "\n" );
1393 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded (
1394 const Module
& module
,
1395 string_list
& clean_files
) const
1397 if ( module
.importLibrary
!= NULL
)
1399 string library_target
= FixupTargetFilename( module
.GetDependencyPath () ).c_str ();
1400 CLEAN_FILE ( library_target
);
1402 string definitionDependencies
= GetDefinitionDependencies ( module
);
1403 fprintf ( fMakefile
, "%s: %s\n",
1404 library_target
.c_str (),
1405 definitionDependencies
.c_str () );
1407 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1409 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1410 fprintf ( fMakefile
,
1411 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1412 module
.GetTargetName ().c_str (),
1413 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1414 library_target
.c_str (),
1420 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1422 string basename
= GetBasename ( filename
);
1423 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1427 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
) const
1429 string dependencies
;
1430 string dkNkmLibNoFixup
= "dk/nkm/lib";
1431 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1432 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1433 const vector
<File
*>& files
= module
.non_if_data
.files
;
1434 for ( size_t i
= 0; i
< files
.size (); i
++ )
1436 File
& file
= *files
[i
];
1437 string extension
= GetExtension ( file
.name
);
1438 if ( extension
== ".spec" || extension
== ".SPEC" )
1440 if ( dependencies
.length () > 0 )
1441 dependencies
+= " ";
1442 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1445 return dependencies
;
1449 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
) const
1451 return module
.cplusplus
;
1455 static MingwBuildToolModuleHandler buildtool_handler
;
1457 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1458 : MingwModuleHandler ( BuildTool
)
1463 MingwBuildToolModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1465 GeneratePreconditionDependencies ( module
);
1466 GenerateBuildToolModuleTarget ( module
, clean_files
);
1467 GenerateInvocations ( module
);
1471 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
, string_list
& clean_files
)
1473 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1474 string objectsMacro
= GetObjectsMacro ( module
);
1475 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1476 string libsMacro
= GetLibsMacro ( module
);
1478 GenerateMacrosAndTargets (
1485 if ( IsCPlusPlusModule ( module
) )
1486 linker
= "${host_gpp}";
1488 linker
= "${host_gcc}";
1490 fprintf ( fMakefile
, "%s: %s %s\n",
1492 objectsMacro
.c_str (),
1493 linkDepsMacro
.c_str () );
1494 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1495 fprintf ( fMakefile
,
1496 "\t%s %s -o %s %s %s\n\n",
1498 GetLinkerMacro ( module
).c_str (),
1500 objectsMacro
.c_str (),
1501 libsMacro
.c_str () );
1505 static MingwKernelModuleHandler kernelmodule_handler
;
1507 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1508 : MingwModuleHandler ( Kernel
)
1513 MingwKernelModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1515 GeneratePreconditionDependencies ( module
);
1516 GenerateKernelModuleTarget ( module
, clean_files
);
1517 GenerateInvocations ( module
);
1521 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
, string_list
& clean_files
)
1523 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1524 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1525 string
target ( FixupTargetFilename (module
.GetPath ()) ); // i.e. "$(ROS_INT).\ntoskrnl\ntoskrnl.exe"
1526 string workingDirectory
= GetWorkingDirectory ();
1527 string objectsMacro
= GetObjectsMacro ( module
);
1528 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1529 string libsMacro
= GetLibsMacro ( module
);
1530 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1531 CLEAN_FILE ( base_tmp
);
1532 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1533 CLEAN_FILE ( junk_tmp
);
1534 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1535 CLEAN_FILE ( temp_exp
);
1536 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",
1537 module
.GetBasePath ().c_str (),
1538 module
.entrypoint
.c_str (),
1539 module
.baseaddress
.c_str () );
1541 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1543 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1545 fprintf ( fMakefile
, "%s: %s %s ${RSYM_TARGET}\n",
1547 objectsMacro
.c_str (),
1548 linkDepsMacro
.c_str () );
1549 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1550 fprintf ( fMakefile
,
1551 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1552 GetLinkerMacro ( module
).c_str (),
1553 gccOptions
.c_str (),
1556 objectsMacro
.c_str (),
1557 linkDepsMacro
.c_str () );
1558 fprintf ( fMakefile
,
1560 junk_tmp
.c_str () );
1561 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1562 fprintf ( fMakefile
,
1563 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1564 targetName
.c_str (),
1568 fprintf ( fMakefile
,
1570 base_tmp
.c_str () );
1571 fprintf ( fMakefile
,
1572 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1573 GetLinkerMacro ( module
).c_str (),
1574 gccOptions
.c_str (),
1577 objectsMacro
.c_str (),
1578 linkDepsMacro
.c_str () );
1579 fprintf ( fMakefile
,
1581 temp_exp
.c_str () );
1582 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1583 fprintf ( fMakefile
,
1584 "\t${rsym} %s %s\n\n",
1590 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1592 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1593 : MingwModuleHandler ( StaticLibrary
)
1598 MingwStaticLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1600 GeneratePreconditionDependencies ( module
);
1601 GenerateStaticLibraryModuleTarget ( module
, clean_files
);
1602 GenerateInvocations ( module
);
1606 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1608 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1612 static MingwObjectLibraryModuleHandler objectlibrary_handler
;
1614 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()
1615 : MingwModuleHandler ( ObjectLibrary
)
1620 MingwObjectLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1622 GeneratePreconditionDependencies ( module
);
1623 GenerateObjectLibraryModuleTarget ( module
, clean_files
);
1624 GenerateInvocations ( module
);
1628 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1630 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1634 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1636 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1637 : MingwModuleHandler ( KernelModeDLL
)
1642 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1644 GeneratePreconditionDependencies ( module
);
1645 GenerateKernelModeDLLModuleTarget ( module
, clean_files
);
1646 GenerateInvocations ( module
);
1650 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget (
1651 const Module
& module
,
1652 string_list
& clean_files
)
1654 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1655 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1656 string workingDirectory
= GetWorkingDirectory ( );
1657 string objectsMacro
= GetObjectsMacro ( module
);
1658 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1659 string libsMacro
= GetLibsMacro ( module
);
1661 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1663 if ( module
.non_if_data
.files
.size () > 0 )
1665 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1667 string dependencies
=
1668 objectsMacro
+ " " + linkDepsMacro
;
1670 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1671 module
.entrypoint
.c_str (),
1672 module
.baseaddress
.c_str () );
1673 GenerateLinkerCommand ( module
,
1684 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1686 fprintf ( fMakefile
, "%s:\n",
1692 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1694 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1695 : MingwModuleHandler ( KernelModeDriver
)
1700 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1702 GeneratePreconditionDependencies ( module
);
1703 GenerateKernelModeDriverModuleTarget ( module
, clean_files
);
1704 GenerateInvocations ( module
);
1709 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget (
1710 const Module
& module
,
1711 string_list
& clean_files
)
1713 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1714 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1715 string workingDirectory
= GetWorkingDirectory ();
1716 string objectsMacro
= GetObjectsMacro ( module
);
1717 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1718 string libsMacro
= GetLibsMacro ( module
);
1720 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1722 if ( module
.non_if_data
.files
.size () > 0 )
1724 string
cflags ( "-D__NTDRIVER__" );
1725 GenerateMacrosAndTargets ( module
,
1730 string dependencies
=
1731 objectsMacro
+ " " + linkDepsMacro
;
1733 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1734 module
.entrypoint
.c_str (),
1735 module
.baseaddress
.c_str () );
1736 GenerateLinkerCommand ( module
,
1747 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1749 fprintf ( fMakefile
, "%s:\n",
1755 static MingwNativeDLLModuleHandler nativedll_handler
;
1757 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1758 : MingwModuleHandler ( NativeDLL
)
1763 MingwNativeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1765 GeneratePreconditionDependencies ( module
);
1766 GenerateNativeDLLModuleTarget ( module
, clean_files
);
1767 GenerateInvocations ( module
);
1771 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1773 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1774 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1775 string workingDirectory
= GetWorkingDirectory ( );
1776 string objectsMacro
= GetObjectsMacro ( module
);
1777 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1778 string libsMacro
= GetLibsMacro ( module
);
1780 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1782 if ( module
.non_if_data
.files
.size () > 0 )
1784 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1786 string dependencies
=
1787 objectsMacro
+ " " + linkDepsMacro
;
1789 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1790 module
.entrypoint
.c_str (),
1791 module
.baseaddress
.c_str () );
1792 GenerateLinkerCommand ( module
,
1803 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1805 fprintf ( fMakefile
, "%s:\n\n",
1811 static MingwNativeCUIModuleHandler nativecui_handler
;
1813 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ()
1814 : MingwModuleHandler ( NativeCUI
)
1819 MingwNativeCUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1821 GeneratePreconditionDependencies ( module
);
1822 GenerateNativeCUIModuleTarget ( module
, clean_files
);
1823 GenerateInvocations ( module
);
1827 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1829 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1830 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1831 string workingDirectory
= GetWorkingDirectory ( );
1832 string objectsMacro
= GetObjectsMacro ( module
);
1833 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1834 string libsMacro
= GetLibsMacro ( module
);
1836 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1838 if ( module
.non_if_data
.files
.size () > 0 )
1840 string
cflags ( "-D__NTAPP__" );
1841 GenerateMacrosAndTargets ( module
,
1846 string dependencies
=
1847 objectsMacro
+ " " + linkDepsMacro
;
1849 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1850 module
.entrypoint
.c_str (),
1851 module
.baseaddress
.c_str () );
1852 GenerateLinkerCommand ( module
,
1863 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1865 fprintf ( fMakefile
, "%s:\n\n",
1871 static MingwWin32DLLModuleHandler win32dll_handler
;
1873 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1874 : MingwModuleHandler ( Win32DLL
)
1879 MingwWin32DLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1881 GenerateExtractWineDLLResourcesTarget ( module
, clean_files
);
1882 GeneratePreconditionDependencies ( module
);
1883 GenerateWin32DLLModuleTarget ( module
, clean_files
);
1884 GenerateInvocations ( module
);
1888 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
, string_list
& clean_files
)
1890 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1891 module
.name
.c_str () );
1892 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1893 module
.name
.c_str () );
1894 const vector
<File
*>& files
= module
.non_if_data
.files
;
1895 for ( size_t i
= 0; i
< files
.size (); i
++ )
1897 File
& file
= *files
[i
];
1898 string extension
= GetExtension ( file
.name
);
1899 if ( extension
== ".rc" || extension
== ".RC" )
1901 string resource
= FixupTargetFilename ( file
.name
);
1902 fprintf ( fMakefile
, "\t$(ECHO_BIN2RES)\n" );
1903 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1904 resource
.c_str () );
1907 fprintf ( fMakefile
, "\n");
1911 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1913 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1914 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1915 string workingDirectory
= GetWorkingDirectory ( );
1916 string objectsMacro
= GetObjectsMacro ( module
);
1917 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1918 string libsMacro
= GetLibsMacro ( module
);
1920 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1922 if ( module
.non_if_data
.files
.size () > 0 )
1924 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1926 string dependencies
=
1927 objectsMacro
+ " " + linkDepsMacro
;
1930 if ( module
.cplusplus
)
1935 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1936 module
.entrypoint
.c_str (),
1937 module
.baseaddress
.c_str () );
1938 GenerateLinkerCommand ( module
,
1949 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1951 fprintf ( fMakefile
, "%s:\n\n",
1957 static MingwWin32CUIModuleHandler win32cui_handler
;
1959 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ()
1960 : MingwModuleHandler ( Win32CUI
)
1965 MingwWin32CUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1967 GeneratePreconditionDependencies ( module
);
1968 GenerateWin32CUIModuleTarget ( module
, clean_files
);
1969 GenerateInvocations ( module
);
1973 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1975 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1976 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1977 string workingDirectory
= GetWorkingDirectory ( );
1978 string objectsMacro
= GetObjectsMacro ( module
);
1979 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1980 string libsMacro
= GetLibsMacro ( module
);
1982 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1984 if ( module
.non_if_data
.files
.size () > 0 )
1986 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1988 string dependencies
=
1989 objectsMacro
+ " " + linkDepsMacro
;
1992 if ( module
.cplusplus
)
1997 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1998 module
.entrypoint
.c_str (),
1999 module
.baseaddress
.c_str () );
2000 GenerateLinkerCommand ( module
,
2011 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2013 fprintf ( fMakefile
, "%s:\n\n",
2019 static MingwWin32GUIModuleHandler win32gui_handler
;
2021 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
2022 : MingwModuleHandler ( Win32GUI
)
2027 MingwWin32GUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2029 GeneratePreconditionDependencies ( module
);
2030 GenerateWin32GUIModuleTarget ( module
, clean_files
);
2031 GenerateInvocations ( module
);
2035 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
2037 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2038 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2039 string workingDirectory
= GetWorkingDirectory ( );
2040 string objectsMacro
= GetObjectsMacro ( module
);
2041 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2042 string libsMacro
= GetLibsMacro ( module
);
2044 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
2046 if ( module
.non_if_data
.files
.size () > 0 )
2048 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
2050 string dependencies
=
2051 objectsMacro
+ " " + linkDepsMacro
;
2054 if ( module
.cplusplus
)
2059 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2060 module
.entrypoint
.c_str (),
2061 module
.baseaddress
.c_str () );
2062 GenerateLinkerCommand ( module
,
2073 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2075 fprintf ( fMakefile
, "%s:\n\n",
2081 static MingwBootLoaderModuleHandler bootloadermodule_handler
;
2083 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()
2084 : MingwModuleHandler ( BootLoader
)
2089 MingwBootLoaderModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2091 GeneratePreconditionDependencies ( module
);
2092 GenerateBootLoaderModuleTarget ( module
, clean_files
);
2093 GenerateInvocations ( module
);
2097 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget (
2098 const Module
& module
,
2099 string_list
& clean_files
)
2101 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2102 string
targetName ( module
.GetTargetName () );
2103 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2104 string workingDirectory
= GetWorkingDirectory ();
2105 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
2106 CLEAN_FILE ( junk_tmp
);
2107 string objectsMacro
= GetObjectsMacro ( module
);
2108 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2109 string libsMacro
= GetLibsMacro ( module
);
2111 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
2113 fprintf ( fMakefile
, "%s: %s %s\n",
2115 objectsMacro
.c_str (),
2116 linkDepsMacro
.c_str () );
2118 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2120 fprintf ( fMakefile
,
2121 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2122 GetLinkerMacro ( module
).c_str (),
2124 objectsMacro
.c_str (),
2125 linkDepsMacro
.c_str () );
2126 fprintf ( fMakefile
,
2127 "\t${objcopy} -O binary %s %s\n",
2130 fprintf ( fMakefile
,
2132 junk_tmp
.c_str () );
2136 static MingwBootSectorModuleHandler bootsectormodule_handler
;
2138 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ()
2139 : MingwModuleHandler ( BootSector
)
2144 MingwBootSectorModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2146 GeneratePreconditionDependencies ( module
);
2147 GenerateBootSectorModuleTarget ( module
, clean_files
);
2148 GenerateInvocations ( module
);
2152 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
, string_list
& clean_files
)
2154 string objectsMacro
= GetObjectsMacro ( module
);
2156 string
* nasmflags
= new string ( "-f bin" );
2157 GenerateMacrosAndTargets ( module
,
2162 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2163 module
.name
.c_str ());
2164 fprintf ( fMakefile
,
2166 module
.name
.c_str (),
2167 objectsMacro
.c_str () );
2171 static MingwIsoModuleHandler isomodule_handler
;
2173 MingwIsoModuleHandler::MingwIsoModuleHandler ()
2174 : MingwModuleHandler ( Iso
)
2179 MingwIsoModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2181 GeneratePreconditionDependencies ( module
);
2182 GenerateIsoModuleTarget ( module
, clean_files
);
2183 GenerateInvocations ( module
);
2187 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string
& bootcdDirectory
,
2188 const Module
& module
) const
2190 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2192 const Module
& m
= *module
.project
.modules
[i
];
2193 if ( m
.bootstrap
!= NULL
)
2195 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
2196 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2197 fprintf ( fMakefile
,
2199 m
.GetPath ().c_str (),
2200 targetFilename
.c_str () );
2206 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string
& bootcdDirectory
,
2207 const Module
& module
) const
2209 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2211 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2212 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2213 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2214 fprintf ( fMakefile
,
2216 cdfile
.GetPath ().c_str (),
2217 targetFilename
.c_str () );
2222 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
,
2223 const Module
& module
) const
2226 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2228 const Module
& m
= *module
.project
.modules
[i
];
2229 if ( m
.bootstrap
!= NULL
)
2231 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2232 if ( directories
.size () > 0 )
2234 directories
+= FixupTargetFilename ( targetDirecctory
);
2241 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
,
2242 const Module
& module
) const
2245 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2247 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2248 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2249 if ( directories
.size () > 0 )
2251 directories
+= FixupTargetFilename ( targetDirecctory
);
2257 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
,
2258 const Module
& module
) const
2260 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2262 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2268 MingwIsoModuleHandler::GetBootstrapCdFiles (
2269 vector
<string
>& out
,
2270 const Module
& module
) const
2272 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2274 const Module
& m
= *module
.project
.modules
[i
];
2275 if ( m
.bootstrap
!= NULL
)
2276 out
.push_back ( FixupTargetFilename ( m
.GetPath () ) );
2281 MingwIsoModuleHandler::GetNonModuleCdFiles (
2282 vector
<string
>& out
,
2283 const Module
& module
) const
2285 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2287 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2288 out
.push_back ( NormalizeFilename ( cdfile
.GetPath () ) );
2293 MingwIsoModuleHandler::GetCdFiles (
2294 vector
<string
>& out
,
2295 const Module
& module
) const
2297 GetBootstrapCdFiles ( out
, module
);
2298 GetNonModuleCdFiles ( out
, module
);
2302 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
, string_list
& clean_files
)
2304 string bootcdDirectory
= "cd";
2305 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2306 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2307 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2308 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2309 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2310 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2311 string cdDirectories
= bootcdReactos
+ " " + GetCdDirectories ( bootcdDirectory
,
2313 vector
<string
> vCdFiles
;
2314 GetCdFiles ( vCdFiles
, module
);
2315 string cdFiles
= v2s ( vCdFiles
, 5 );
2317 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2318 module
.name
.c_str ());
2319 fprintf ( fMakefile
,
2320 "%s: all %s %s %s ${CABMAN_TARGET} ${CDMAKE_TARGET}\n",
2321 module
.name
.c_str (),
2323 cdDirectories
.c_str (),
2325 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2326 fprintf ( fMakefile
,
2327 "\t${cabman} -C %s -L %s -I\n",
2328 reactosDff
.c_str (),
2329 bootcdReactos
.c_str () );
2330 fprintf ( fMakefile
,
2331 "\t${cabman} -C %s -RC %s -L %s -N\n",
2332 reactosDff
.c_str (),
2333 reactosInf
.c_str (),
2334 bootcdReactos
.c_str () );
2335 fprintf ( fMakefile
,
2337 reactosInf
.c_str () );
2338 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2340 OutputCdfileCopyCommands ( bootcdDirectory
,
2342 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2343 fprintf ( fMakefile
,
2344 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2346 bootcdDirectory
.c_str () );
2347 fprintf ( fMakefile
,