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
;
69 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype
)
72 handler_map
= new map
<ModuleType
,MingwModuleHandler
*>;
73 (*handler_map
)[moduletype
] = this;
76 MingwModuleHandler::~MingwModuleHandler()
86 MingwModuleHandler::PassThruCacheDirectory ( const string
&file
) const
88 directory_set
.insert ( GetDirectory ( file
) );
93 MingwModuleHandler::SetMakefile ( FILE* f
)
99 MingwModuleHandler::SetUsePch ( bool b
)
105 MingwModuleHandler::LookupHandler ( const string
& location
,
106 ModuleType moduletype
)
109 throw Exception ( "internal tool error: no registered module handlers" );
110 MingwModuleHandler
* h
= (*handler_map
)[moduletype
];
113 throw UnknownModuleTypeException ( location
, moduletype
);
120 MingwModuleHandler::GetWorkingDirectory () const
126 MingwModuleHandler::GetBasename ( const string
& filename
) const
128 size_t index
= filename
.find_last_of ( '.' );
129 if ( index
!= string::npos
)
130 return filename
.substr ( 0, index
);
135 MingwModuleHandler::GetActualSourceFilename ( const string
& filename
) const
137 string extension
= GetExtension ( filename
);
138 if ( extension
== ".spec" || extension
== "SPEC" )
140 string basename
= GetBasename ( filename
);
141 return basename
+ ".stubs.c";
148 MingwModuleHandler::GetModuleArchiveFilename ( const Module
& module
) const
150 return ReplaceExtension ( FixupTargetFilename ( module
.GetPath () ),
155 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
157 string extension
= GetExtension ( file
.name
);
158 if ( extension
== ".spec" || extension
== "SPEC" )
165 MingwModuleHandler::GetImportLibraryDependency ( const Module
& importedModule
) const
167 if ( importedModule
.type
== ObjectLibrary
)
168 return GetObjectsMacro ( importedModule
);
170 return PassThruCacheDirectory ( FixupTargetFilename ( importedModule
.GetDependencyPath () ) );
174 MingwModuleHandler::GetModuleDependencies ( const Module
& module
) const
176 if ( module
.dependencies
.size () == 0 )
179 string
dependencies ( "" );
180 for ( size_t i
= 0; i
< module
.dependencies
.size (); i
++ )
182 if ( dependencies
.size () > 0 )
184 const Dependency
* dependency
= module
.dependencies
[i
];
185 const Module
* dependencyModule
= dependency
->dependencyModule
;
186 dependencies
+= dependencyModule
->GetTargets ();
188 string definitionDependencies
= GetDefinitionDependencies ( module
);
189 if ( dependencies
.length () > 0 && definitionDependencies
.length () > 0 )
190 dependencies
+= " " + definitionDependencies
;
191 else if ( definitionDependencies
.length () > 0 )
192 dependencies
= definitionDependencies
;
197 MingwModuleHandler::GetSourceFilenames ( const Module
& module
,
198 bool includeGeneratedFiles
) const
202 string
sourceFilenames ( "" );
203 const vector
<File
*>& files
= module
.non_if_data
.files
;
204 for ( i
= 0; i
< files
.size (); i
++ )
206 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *files
[i
] ) )
207 sourceFilenames
+= " " + GetActualSourceFilename ( files
[i
]->name
);
209 // intentionally make a copy so that we can append more work in
210 // the middle of processing without having to go recursive
211 vector
<If
*> v
= module
.non_if_data
.ifs
;
212 for ( i
= 0; i
< v
.size (); i
++ )
216 // check for sub-ifs to add to list
217 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
218 for ( j
= 0; j
< ifs
.size (); j
++ )
219 v
.push_back ( ifs
[j
] );
220 const vector
<File
*>& files
= rIf
.data
.files
;
221 for ( j
= 0; j
< files
.size (); j
++ )
223 File
& file
= *files
[j
];
224 if ( includeGeneratedFiles
|| !IsGeneratedFile ( file
) )
225 sourceFilenames
+= " " + GetActualSourceFilename ( file
.name
);
228 return sourceFilenames
;
232 MingwModuleHandler::GetSourceFilenames ( const Module
& module
) const
234 return GetSourceFilenames ( module
,
239 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module
& module
) const
241 return GetSourceFilenames ( module
,
246 GetObjectFilename ( const Module
& module
, const string
& sourceFilename
)
249 string extension
= GetExtension ( sourceFilename
);
250 if ( extension
== ".rc" || extension
== ".RC" )
251 newExtension
= ".coff";
252 else if ( extension
== ".spec" || extension
== ".SPEC" )
253 newExtension
= ".stubs.o";
256 return FixupTargetFilename (
258 PrefixFilename(sourceFilename
,module
.prefix
),
263 MingwModuleHandler::GenerateCleanTarget (
264 const Module
& module
,
265 const string_list
& clean_files
) const
267 if ( 0 == clean_files
.size() )
269 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
270 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
271 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
274 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
275 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
277 fprintf ( fMakefile
, " 2>$(NUL)\n" );
278 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
282 MingwModuleHandler::GetObjectFilenames ( const Module
& module
) const
284 const vector
<File
*>& files
= module
.non_if_data
.files
;
285 if ( files
.size () == 0 )
288 string
objectFilenames ( "" );
289 for ( size_t i
= 0; i
< files
.size (); i
++ )
291 if ( objectFilenames
.size () > 0 )
292 objectFilenames
+= " ";
293 objectFilenames
+= PassThruCacheDirectory (
294 GetObjectFilename ( module
, files
[i
]->name
) );
296 return objectFilenames
;
300 MingwModuleHandler::IncludeDirectoryTarget ( const string
& directory
) const
302 if ( directory
== "$(ROS_INTERMEDIATE)." SSEP
"tools")
309 MingwModuleHandler::GenerateDirectoryTargets () const
311 if ( directory_set
.size () == 0 )
314 set_string::iterator it
;
315 size_t wrap_count
= 0;
317 fprintf ( fMakefile
, "ifneq ($(ROS_INTERMEDIATE),)\n" );
318 fprintf ( fMakefile
, "directories::" );
320 for ( it
= directory_set
.begin ();
321 it
!= directory_set
.end ();
324 if ( IncludeDirectoryTarget ( *it
) )
326 if ( wrap_count
++ == 5 )
327 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
334 fprintf ( fMakefile
, "\n\n" );
337 for ( it
= directory_set
.begin ();
338 it
!= directory_set
.end ();
341 if ( IncludeDirectoryTarget ( *it
) )
343 if ( wrap_count
++ == 5 )
344 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
352 "::\n\t${mkdir} $@\n" );
353 fprintf ( fMakefile
, "endif\n\n" );
355 directory_set
.clear ();
359 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector
<Define
*>& defines
) const
362 for ( size_t i
= 0; i
< defines
.size (); i
++ )
364 Define
& define
= *defines
[i
];
365 if (parameters
.length () > 0)
368 parameters
+= define
.name
;
369 if (define
.value
.length () > 0)
372 parameters
+= define
.value
;
379 MingwModuleHandler::GenerateGccDefineParameters ( const Module
& module
) const
381 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
382 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
383 if ( s
.length () > 0 )
392 MingwModuleHandler::ConcatenatePaths ( const string
& path1
,
393 const string
& path2
) const
395 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
397 if ( path1
[path1
.length ()] == CSEP
)
398 return path1
+ path2
;
400 return path1
+ CSEP
+ path2
;
404 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
407 for ( size_t i
= 0; i
< includes
.size (); i
++ )
409 Include
& include
= *includes
[i
];
410 if ( parameters
.length () > 0 )
412 parameters
+= "-I" + include
.directory
;
418 MingwModuleHandler::GenerateGccIncludeParameters ( const Module
& module
) const
420 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
421 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
422 if ( s
.length () > 0 )
432 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
435 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
437 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
438 if ( parameters
.length () > 0 )
440 parameters
+= compilerFlag
.flag
;
446 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
449 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
451 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
452 if ( parameters
.length () > 0 )
454 parameters
+= linkerFlag
.flag
;
460 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
461 const vector
<Library
*>& libraries
) const
463 string
dependencies ( "" );
465 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
467 if ( wrap_count
++ == 5 )
468 dependencies
+= " \\\n\t\t", wrap_count
= 0;
469 else if ( dependencies
.size () > 0 )
471 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->imported_module
);
477 MingwModuleHandler::GenerateLinkerParameters ( const Module
& module
) const
479 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
483 MingwModuleHandler::GenerateMacro (
484 const char* assignmentOperation
,
486 const IfableData
& data
,
487 const vector
<CompilerFlag
*>* compilerFlags
) const
495 assignmentOperation
);
497 if ( compilerFlags
!= NULL
)
499 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
500 if ( compilerParameters
.size () > 0 )
505 compilerParameters
.c_str () );
509 for ( i
= 0; i
< data
.includes
.size(); i
++ )
514 data
.includes
[i
]->directory
.c_str() );
516 for ( i
= 0; i
< data
.defines
.size(); i
++ )
518 Define
& d
= *data
.defines
[i
];
523 if ( d
.value
.size() )
529 fprintf ( fMakefile
, "\n" );
533 MingwModuleHandler::GenerateMacros (
534 const Module
& module
,
535 const char* assignmentOperation
,
536 const IfableData
& data
,
537 const vector
<CompilerFlag
*>* compilerFlags
,
538 const vector
<LinkerFlag
*>* linkerFlags
,
539 const string
& cflags_macro
,
540 const string
& nasmflags_macro
,
541 const string
& windresflags_macro
,
542 const string
& linkerflags_macro
,
543 const string
& objs_macro
,
544 const string
& libs_macro
,
545 const string
& linkdeps_macro
) const
549 if ( data
.includes
.size () > 0 || data
.defines
.size () > 0 )
551 GenerateMacro ( assignmentOperation
,
555 GenerateMacro ( assignmentOperation
,
561 if ( linkerFlags
!= NULL
)
563 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
564 if ( linkerParameters
.size () > 0 )
569 linkerflags_macro
.c_str (),
571 linkerParameters
.c_str() );
575 if ( data
.libraries
.size () > 0 )
577 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
578 if ( deps
.size () > 0 )
589 const vector
<File
*>& files
= data
.files
;
590 if ( files
.size () > 0 )
592 for ( i
= 0; i
< files
.size (); i
++ )
594 File
& file
= *files
[i
];
600 PassThruCacheDirectory (
601 GetObjectFilename ( module
, file
.name
) ).c_str (),
602 objs_macro
.c_str() );
609 assignmentOperation
);
610 for ( i
= 0; i
< files
.size(); i
++ )
612 File
& file
= *files
[i
];
618 ( i
%10 == 9 ? "\\\n\t" : " " ),
619 PassThruCacheDirectory (
620 GetObjectFilename ( module
, file
.name
) ).c_str () );
623 fprintf ( fMakefile
, "\n" );
626 const vector
<If
*>& ifs
= data
.ifs
;
627 for ( i
= 0; i
< ifs
.size(); i
++ )
630 if ( rIf
.data
.defines
.size()
631 || rIf
.data
.includes
.size()
632 || rIf
.data
.libraries
.size()
633 || rIf
.data
.files
.size()
634 || rIf
.data
.ifs
.size() )
638 "ifeq (\"$(%s)\",\"%s\")\n",
639 rIf
.property
.c_str(),
662 MingwModuleHandler::GenerateMacros (
663 const Module
& module
,
664 const string
& cflags_macro
,
665 const string
& nasmflags_macro
,
666 const string
& windresflags_macro
,
667 const string
& linkerflags_macro
,
668 const string
& objs_macro
,
669 const string
& libs_macro
,
670 const string
& linkdeps_macro
) const
676 &module
.compilerFlags
,
686 if ( module
.importLibrary
)
689 const vector
<File
*>& files
= module
.non_if_data
.files
;
690 for ( size_t i
= 0; i
< files
.size (); i
++ )
692 File
& file
= *files
[i
];
693 string extension
= GetExtension ( file
.name
);
694 if ( extension
== ".spec" || extension
== ".SPEC" )
696 if ( s
.length () > 0 )
698 s
+= GetSpecObjectDependencies ( file
.name
);
701 if ( s
.length () > 0 )
706 linkdeps_macro
.c_str(),
713 "%s += $(PROJECT_CFLAGS)\n",
714 cflags_macro
.c_str () );
718 "%s += $(PROJECT_RCFLAGS)\n",
719 windresflags_macro
.c_str () );
723 "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
724 module
.name
.c_str () );
729 linkdeps_macro
.c_str (),
730 libs_macro
.c_str () );
732 fprintf ( fMakefile
, "\n" );
736 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
737 const string
& sourceFilename
,
739 const string
& cflagsMacro
) const
741 string deps
= sourceFilename
;
742 if ( module
.pch
&& use_pch
)
743 deps
+= " " + module
.pch
->header
+ ".gch";
744 string objectFilename
= PassThruCacheDirectory (
745 GetObjectFilename ( module
, sourceFilename
) );
748 objectFilename
.c_str (),
750 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
752 "\t%s -c %s -o %s %s\n",
754 sourceFilename
.c_str (),
755 objectFilename
.c_str (),
756 cflagsMacro
.c_str () );
760 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
761 const string
& sourceFilename
,
763 const string
& cflagsMacro
) const
765 string objectFilename
= PassThruCacheDirectory (
766 GetObjectFilename ( module
, sourceFilename
) );
769 objectFilename
.c_str (),
770 sourceFilename
.c_str () );
771 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
773 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
775 sourceFilename
.c_str (),
776 objectFilename
.c_str (),
777 cflagsMacro
.c_str () );
781 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
782 const string
& sourceFilename
,
783 const string
& nasmflagsMacro
) const
785 string objectFilename
= PassThruCacheDirectory (
786 GetObjectFilename ( module
, sourceFilename
) );
789 objectFilename
.c_str (),
790 sourceFilename
.c_str () );
791 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
793 "\t%s -f win32 %s -o %s %s\n",
795 sourceFilename
.c_str (),
796 objectFilename
.c_str (),
797 nasmflagsMacro
.c_str () );
801 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
802 const string
& sourceFilename
,
803 const string
& windresflagsMacro
) const
805 string objectFilename
= PassThruCacheDirectory (
806 GetObjectFilename ( module
, sourceFilename
) );
807 string rciFilename
= ReplaceExtension ( sourceFilename
,
809 string resFilename
= ReplaceExtension ( sourceFilename
,
813 objectFilename
.c_str (),
814 sourceFilename
.c_str () );
815 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
817 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
818 windresflagsMacro
.c_str (),
819 sourceFilename
.c_str (),
820 rciFilename
.c_str () );
822 "\t${wrc} ${%s} %s %s\n",
823 windresflagsMacro
.c_str (),
824 rciFilename
.c_str (),
825 resFilename
.c_str () );
828 rciFilename
.c_str () );
830 "\t${windres} %s -o %s\n",
831 resFilename
.c_str (),
832 objectFilename
.c_str () );
835 resFilename
.c_str () );
839 MingwModuleHandler::GenerateWinebuildCommands (
840 const Module
& module
,
841 const string
& sourceFilename
,
842 string_list
& clean_files
) const
844 string basename
= GetBasename ( sourceFilename
);
846 string def_file
= basename
+ ".spec.def";
847 CLEAN_FILE ( def_file
);
849 string stub_file
= basename
+ ".stubs.c";
850 CLEAN_FILE ( stub_file
);
855 sourceFilename
.c_str () );
856 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
858 "\t%s --def=%s -o %s\n",
860 sourceFilename
.c_str (),
866 sourceFilename
.c_str () );
867 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
869 "\t%s --pedll=%s -o %s\n",
871 sourceFilename
.c_str (),
872 stub_file
.c_str () );
876 MingwModuleHandler::GenerateCommands (
877 const Module
& module
,
878 const string
& sourceFilename
,
881 const string
& cflagsMacro
,
882 const string
& nasmflagsMacro
,
883 const string
& windresflagsMacro
,
884 string_list
& clean_files
) const
886 CLEAN_FILE ( GetObjectFilename(module
,sourceFilename
) );
887 string extension
= GetExtension ( sourceFilename
);
888 if ( extension
== ".c" || extension
== ".C" )
890 GenerateGccCommand ( module
,
896 else if ( extension
== ".cc" || extension
== ".CC" ||
897 extension
== ".cpp" || extension
== ".CPP" ||
898 extension
== ".cxx" || extension
== ".CXX" )
900 GenerateGccCommand ( module
,
906 else if ( extension
== ".s" || extension
== ".S" )
908 GenerateGccAssemblerCommand ( module
,
914 else if ( extension
== ".asm" || extension
== ".ASM" )
916 GenerateNasmCommand ( module
,
921 else if ( extension
== ".rc" || extension
== ".RC" )
923 GenerateWindresCommand ( module
,
928 else if ( extension
== ".spec" || extension
== ".SPEC" )
930 GenerateWinebuildCommands ( module
,
933 GenerateGccCommand ( module
,
934 GetActualSourceFilename ( sourceFilename
),
940 throw InvalidOperationException ( __FILE__
,
942 "Unsupported filename extension '%s' in file '%s'",
944 sourceFilename
.c_str () );
948 MingwModuleHandler::GenerateLinkerCommand (
949 const Module
& module
,
950 const string
& linker
,
951 const string
& linkerParameters
,
952 const string
& objectsMacro
,
953 const string
& libsMacro
,
954 string_list
& clean_files
) const
956 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
957 string
targetName ( module
.GetTargetName () );
958 string
target ( FixupTargetFilename ( module
.GetPath () ) );
959 if ( module
.importLibrary
!= NULL
)
961 static string
ros_junk ( "$(ROS_TEMPORARY)" );
962 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
963 CLEAN_FILE ( base_tmp
);
964 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
965 CLEAN_FILE ( junk_tmp
);
966 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
967 CLEAN_FILE ( temp_exp
);
968 string def_file
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
971 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
973 linkerParameters
.c_str (),
976 objectsMacro
.c_str (),
978 GetLinkerMacro ( module
).c_str () );
984 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
986 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
998 "\t%s %s %s -o %s %s %s %s\n",
1000 linkerParameters
.c_str (),
1003 objectsMacro
.c_str (),
1005 GetLinkerMacro ( module
).c_str () );
1007 fprintf ( fMakefile
,
1009 temp_exp
.c_str () );
1013 fprintf ( fMakefile
,
1014 "\t%s %s -o %s %s %s %s\n",
1016 linkerParameters
.c_str (),
1018 objectsMacro
.c_str (),
1020 GetLinkerMacro ( module
).c_str () );
1023 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1024 fprintf ( fMakefile
,
1025 "\t${rsym} %s %s\n\n",
1031 MingwModuleHandler::GenerateObjectFileTargets (
1032 const Module
& module
,
1033 const IfableData
& data
,
1036 const string
& cflagsMacro
,
1037 const string
& nasmflagsMacro
,
1038 const string
& windresflagsMacro
,
1039 string_list
& clean_files
) const
1043 const vector
<File
*>& files
= data
.files
;
1044 for ( i
= 0; i
< files
.size (); i
++ )
1046 string sourceFilename
= files
[i
]->name
;
1047 GenerateCommands ( module
,
1055 fprintf ( fMakefile
,
1059 const vector
<If
*>& ifs
= data
.ifs
;
1060 for ( i
= 0; i
< ifs
.size(); i
++ )
1062 GenerateObjectFileTargets ( module
,
1074 MingwModuleHandler::GenerateObjectFileTargets (
1075 const Module
& module
,
1078 const string
& cflagsMacro
,
1079 const string
& nasmflagsMacro
,
1080 const string
& windresflagsMacro
,
1081 string_list
& clean_files
) const
1085 const string
& pch_file
= module
.pch
->header
;
1086 string gch_file
= pch_file
+ ".gch";
1087 CLEAN_FILE(gch_file
);
1095 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1098 "\t%s -o %s %s -g %s\n\n",
1099 ( module
.cplusplus
? cppc
.c_str() : cc
.c_str() ),
1101 cflagsMacro
.c_str(),
1106 GenerateObjectFileTargets ( module
,
1114 fprintf ( fMakefile
, "\n" );
1118 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
1120 const string
& objs_macro
) const
1122 string archiveFilename
= GetModuleArchiveFilename ( module
);
1124 fprintf ( fMakefile
,
1126 archiveFilename
.c_str (),
1127 objs_macro
.c_str ());
1129 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1131 fprintf ( fMakefile
,
1132 "\t%s -rc %s %s\n\n",
1134 archiveFilename
.c_str (),
1135 objs_macro
.c_str ());
1137 return archiveFilename
;
1141 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
1143 return ssprintf ( "$(%s_CFLAGS)",
1144 module
.name
.c_str () );
1148 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
1150 return ssprintf ( "$(%s_OBJS)",
1151 module
.name
.c_str () );
1155 MingwModuleHandler::GetLinkingDependenciesMacro ( const Module
& module
) const
1157 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1161 MingwModuleHandler::GetLibsMacro ( const Module
& module
) const
1163 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1167 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
1169 return ssprintf ( "$(%s_LFLAGS)",
1170 module
.name
.c_str () );
1174 MingwModuleHandler::GenerateMacrosAndTargets (
1175 const Module
& module
,
1176 const string
* cflags
,
1177 const string
* nasmflags
,
1178 string_list
& clean_files
) const
1180 string cc
= ( module
.host
? "${host_gcc}" : "${gcc}" );
1181 string cppc
= ( module
.host
? "${host_gpp}" : "${gpp}" );
1182 string ar
= ( module
.host
? "${host_ar}" : "${ar}" );
1184 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1185 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1186 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1187 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1188 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1189 string libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1190 string linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1192 GenerateMacros ( module
,
1201 if ( cflags
!= NULL
)
1203 fprintf ( fMakefile
,
1205 cflagsMacro
.c_str (),
1209 if ( nasmflags
!= NULL
)
1211 fprintf ( fMakefile
,
1213 nasmflagsMacro
.c_str (),
1214 nasmflags
->c_str () );
1217 // generate phony target for module name
1218 fprintf ( fMakefile
, ".PHONY: %s\n",
1219 module
.name
.c_str () );
1220 fprintf ( fMakefile
, "%s: %s\n\n",
1221 module
.name
.c_str (),
1222 FixupTargetFilename ( module
.GetPath () ).c_str () );
1224 // future references to the macros will be to get their values
1225 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1226 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1227 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1229 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1230 GenerateObjectFileTargets ( module
,
1238 CLEAN_FILE ( ar_target
);
1239 string tgt
= FixupTargetFilename(module
.GetPath());
1240 if ( tgt
!= ar_target
)
1247 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
1249 string dependencies
;
1250 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1252 Invoke
& invoke
= *module
.invocations
[i
];
1253 if (invoke
.invokeModule
== &module
)
1254 /* Protect against circular dependencies */
1256 if ( dependencies
.length () > 0 )
1257 dependencies
+= " ";
1258 dependencies
+= invoke
.GetTargets ();
1260 return dependencies
;
1264 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1266 if ( module
.invocations
.size () == 0 )
1269 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1271 const Invoke
& invoke
= *module
.invocations
[i
];
1273 if ( invoke
.invokeModule
->type
!= BuildTool
)
1275 throw InvalidBuildFileException ( module
.node
.location
,
1276 "Only modules of type buildtool can be invoked." );
1279 string invokeTarget
= module
.GetInvocationTarget ( i
);
1280 fprintf ( fMakefile
,
1282 invokeTarget
.c_str () );
1283 fprintf ( fMakefile
,
1285 invokeTarget
.c_str (),
1286 invoke
.GetTargets ().c_str () );
1287 fprintf ( fMakefile
,
1289 invoke
.GetTargets ().c_str (),
1290 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1291 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1292 fprintf ( fMakefile
,
1294 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1295 invoke
.GetParameters ().c_str () );
1300 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1302 return ssprintf ( "%s_precondition",
1303 module
.name
.c_str () );
1307 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1309 /* Avoid circular dependency */
1310 if ( module
.type
== BuildTool
|| module
.name
== "zlib" )
1311 return "$(ROS_INTERMEDIATE)." SSEP
"tools $(ROS_INTERMEDIATE)." SSEP
"lib" SSEP
"zlib";
1317 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
1319 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1320 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1321 string dependencies
= GetDefaultDependencies ( module
);
1322 string s
= GetModuleDependencies ( module
);
1323 if ( s
.length () > 0 )
1325 if ( dependencies
.length () > 0 )
1326 dependencies
+= " ";
1330 s
= GetInvocationDependencies ( module
);
1331 if ( s
.length () > 0 )
1333 if ( dependencies
.length () > 0 )
1334 dependencies
+= " ";
1338 fprintf ( fMakefile
,
1340 preconditionDependenciesName
.c_str () );
1341 fprintf ( fMakefile
,
1343 preconditionDependenciesName
.c_str (),
1344 dependencies
.c_str () );
1345 const char* p
= sourceFilenames
.c_str();
1346 const char* end
= p
+ strlen(p
);
1349 const char* p2
= &p
[512];
1352 while ( p2
> p
&& !isspace(*p2
) )
1356 p2
= strpbrk ( p
, " \t" );
1360 fprintf ( fMakefile
,
1364 preconditionDependenciesName
.c_str ());
1366 p
+= strspn ( p
, " \t" );
1368 fprintf ( fMakefile
, "\n" );
1372 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded (
1373 const Module
& module
,
1374 string_list
& clean_files
) const
1376 if ( module
.importLibrary
!= NULL
)
1378 string library_target
= FixupTargetFilename( module
.GetDependencyPath () ).c_str ();
1379 CLEAN_FILE ( library_target
);
1381 string definitionDependencies
= GetDefinitionDependencies ( module
);
1382 fprintf ( fMakefile
, "%s: %s\n",
1383 library_target
.c_str (),
1384 definitionDependencies
.c_str () );
1386 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1388 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1389 fprintf ( fMakefile
,
1390 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1391 module
.GetTargetName ().c_str (),
1392 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1393 library_target
.c_str (),
1399 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1401 string basename
= GetBasename ( filename
);
1402 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1406 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
) const
1408 string dependencies
;
1409 string dkNkmLibNoFixup
= "dk/nkm/lib";
1410 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1411 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1412 const vector
<File
*>& files
= module
.non_if_data
.files
;
1413 for ( size_t i
= 0; i
< files
.size (); i
++ )
1415 File
& file
= *files
[i
];
1416 string extension
= GetExtension ( file
.name
);
1417 if ( extension
== ".spec" || extension
== ".SPEC" )
1419 if ( dependencies
.length () > 0 )
1420 dependencies
+= " ";
1421 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1424 return dependencies
;
1428 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
) const
1430 return module
.cplusplus
;
1434 static MingwBuildToolModuleHandler buildtool_handler
;
1436 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1437 : MingwModuleHandler ( BuildTool
)
1442 MingwBuildToolModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1444 GeneratePreconditionDependencies ( module
);
1445 GenerateBuildToolModuleTarget ( module
, clean_files
);
1446 GenerateInvocations ( module
);
1450 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
, string_list
& clean_files
)
1452 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1453 string objectsMacro
= GetObjectsMacro ( module
);
1454 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1455 string libsMacro
= GetLibsMacro ( module
);
1457 GenerateMacrosAndTargets (
1464 if ( IsCPlusPlusModule ( module
) )
1465 linker
= "${host_gpp}";
1467 linker
= "${host_gcc}";
1469 fprintf ( fMakefile
, "%s: %s %s\n",
1471 objectsMacro
.c_str (),
1472 linkDepsMacro
.c_str () );
1473 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1474 fprintf ( fMakefile
,
1475 "\t%s %s -o %s %s %s\n\n",
1477 GetLinkerMacro ( module
).c_str (),
1479 objectsMacro
.c_str (),
1480 libsMacro
.c_str () );
1484 static MingwKernelModuleHandler kernelmodule_handler
;
1486 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1487 : MingwModuleHandler ( Kernel
)
1492 MingwKernelModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1494 GeneratePreconditionDependencies ( module
);
1495 GenerateKernelModuleTarget ( module
, clean_files
);
1496 GenerateInvocations ( module
);
1500 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
, string_list
& clean_files
)
1502 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1503 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1504 string
target ( FixupTargetFilename (module
.GetPath ()) ); // i.e. "$(ROS_INT).\ntoskrnl\ntoskrnl.exe"
1505 string workingDirectory
= GetWorkingDirectory ();
1506 string objectsMacro
= GetObjectsMacro ( module
);
1507 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1508 string libsMacro
= GetLibsMacro ( module
);
1509 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1510 CLEAN_FILE ( base_tmp
);
1511 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1512 CLEAN_FILE ( junk_tmp
);
1513 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1514 CLEAN_FILE ( temp_exp
);
1515 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",
1516 module
.GetBasePath ().c_str (),
1517 module
.entrypoint
.c_str (),
1518 module
.baseaddress
.c_str () );
1520 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1522 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1524 fprintf ( fMakefile
, "%s: %s %s\n",
1526 objectsMacro
.c_str (),
1527 linkDepsMacro
.c_str () );
1528 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1529 fprintf ( fMakefile
,
1530 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1531 GetLinkerMacro ( module
).c_str (),
1532 gccOptions
.c_str (),
1535 objectsMacro
.c_str (),
1536 linkDepsMacro
.c_str () );
1537 fprintf ( fMakefile
,
1539 junk_tmp
.c_str () );
1540 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1541 fprintf ( fMakefile
,
1542 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1543 targetName
.c_str (),
1547 fprintf ( fMakefile
,
1549 base_tmp
.c_str () );
1550 fprintf ( fMakefile
,
1551 "\t${gcc} %s %s -Wl,%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 temp_exp
.c_str () );
1561 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1562 fprintf ( fMakefile
,
1563 "\t${rsym} %s %s\n\n",
1569 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1571 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1572 : MingwModuleHandler ( StaticLibrary
)
1577 MingwStaticLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1579 GeneratePreconditionDependencies ( module
);
1580 GenerateStaticLibraryModuleTarget ( module
, clean_files
);
1581 GenerateInvocations ( module
);
1585 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1587 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1591 static MingwObjectLibraryModuleHandler objectlibrary_handler
;
1593 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()
1594 : MingwModuleHandler ( ObjectLibrary
)
1599 MingwObjectLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1601 GeneratePreconditionDependencies ( module
);
1602 GenerateObjectLibraryModuleTarget ( module
, clean_files
);
1603 GenerateInvocations ( module
);
1607 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1609 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1613 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1615 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1616 : MingwModuleHandler ( KernelModeDLL
)
1621 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1623 GeneratePreconditionDependencies ( module
);
1624 GenerateKernelModeDLLModuleTarget ( module
, clean_files
);
1625 GenerateInvocations ( module
);
1629 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget (
1630 const Module
& module
,
1631 string_list
& clean_files
)
1633 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1634 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1635 string workingDirectory
= GetWorkingDirectory ( );
1636 string objectsMacro
= GetObjectsMacro ( module
);
1637 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1638 string libsMacro
= GetLibsMacro ( module
);
1640 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1642 if ( module
.non_if_data
.files
.size () > 0 )
1644 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1646 fprintf ( fMakefile
, "%s: %s %s\n",
1648 objectsMacro
.c_str (),
1649 linkDepsMacro
.c_str () );
1651 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1652 module
.entrypoint
.c_str (),
1653 module
.baseaddress
.c_str () );
1654 GenerateLinkerCommand ( module
,
1663 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1665 fprintf ( fMakefile
, "%s:\n",
1671 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1673 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1674 : MingwModuleHandler ( KernelModeDriver
)
1679 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1681 GeneratePreconditionDependencies ( module
);
1682 GenerateKernelModeDriverModuleTarget ( module
, clean_files
);
1683 GenerateInvocations ( module
);
1688 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget (
1689 const Module
& module
,
1690 string_list
& clean_files
)
1692 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1693 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1694 string workingDirectory
= GetWorkingDirectory ();
1695 string objectsMacro
= GetObjectsMacro ( module
);
1696 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1697 string libsMacro
= GetLibsMacro ( module
);
1699 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1701 if ( module
.non_if_data
.files
.size () > 0 )
1703 string
cflags ( "-D__NTDRIVER__" );
1704 GenerateMacrosAndTargets ( module
,
1709 fprintf ( fMakefile
, "%s: %s %s\n",
1711 objectsMacro
.c_str (),
1712 linkDepsMacro
.c_str () );
1714 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1715 module
.entrypoint
.c_str (),
1716 module
.baseaddress
.c_str () );
1717 GenerateLinkerCommand ( module
,
1726 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1728 fprintf ( fMakefile
, "%s:\n",
1734 static MingwNativeDLLModuleHandler nativedll_handler
;
1736 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1737 : MingwModuleHandler ( NativeDLL
)
1742 MingwNativeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1744 GeneratePreconditionDependencies ( module
);
1745 GenerateNativeDLLModuleTarget ( module
, clean_files
);
1746 GenerateInvocations ( module
);
1750 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1752 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1753 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1754 string workingDirectory
= GetWorkingDirectory ( );
1755 string objectsMacro
= GetObjectsMacro ( module
);
1756 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1757 string libsMacro
= GetLibsMacro ( module
);
1759 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1761 if ( module
.non_if_data
.files
.size () > 0 )
1763 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1765 fprintf ( fMakefile
, "%s: %s %s\n",
1767 objectsMacro
.c_str (),
1768 linkDepsMacro
.c_str () );
1770 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1771 module
.entrypoint
.c_str (),
1772 module
.baseaddress
.c_str () );
1773 GenerateLinkerCommand ( module
,
1782 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1784 fprintf ( fMakefile
, "%s:\n\n",
1790 static MingwNativeCUIModuleHandler nativecui_handler
;
1792 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ()
1793 : MingwModuleHandler ( NativeCUI
)
1798 MingwNativeCUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1800 GeneratePreconditionDependencies ( module
);
1801 GenerateNativeCUIModuleTarget ( module
, clean_files
);
1802 GenerateInvocations ( module
);
1806 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1808 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1809 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1810 string workingDirectory
= GetWorkingDirectory ( );
1811 string objectsMacro
= GetObjectsMacro ( module
);
1812 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1813 string libsMacro
= GetLibsMacro ( module
);
1815 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1817 if ( module
.non_if_data
.files
.size () > 0 )
1819 string
cflags ( "-D__NTAPP__" );
1820 GenerateMacrosAndTargets ( module
,
1825 fprintf ( fMakefile
, "%s: %s %s\n",
1827 objectsMacro
.c_str (),
1828 linkDepsMacro
.c_str () );
1830 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1831 module
.entrypoint
.c_str (),
1832 module
.baseaddress
.c_str () );
1833 GenerateLinkerCommand ( module
,
1842 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1844 fprintf ( fMakefile
, "%s:\n\n",
1850 static MingwWin32DLLModuleHandler win32dll_handler
;
1852 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1853 : MingwModuleHandler ( Win32DLL
)
1858 MingwWin32DLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1860 GenerateExtractWineDLLResourcesTarget ( module
, clean_files
);
1861 GeneratePreconditionDependencies ( module
);
1862 GenerateWin32DLLModuleTarget ( module
, clean_files
);
1863 GenerateInvocations ( module
);
1867 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
, string_list
& clean_files
)
1869 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1870 module
.name
.c_str () );
1871 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1872 module
.name
.c_str () );
1873 const vector
<File
*>& files
= module
.non_if_data
.files
;
1874 for ( size_t i
= 0; i
< files
.size (); i
++ )
1876 File
& file
= *files
[i
];
1877 string extension
= GetExtension ( file
.name
);
1878 if ( extension
== ".rc" || extension
== ".RC" )
1880 string resource
= FixupTargetFilename ( file
.name
);
1881 fprintf ( fMakefile
, "\t$(ECHO_BIN2RES)\n" );
1882 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1883 resource
.c_str () );
1886 fprintf ( fMakefile
, "\n");
1890 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1892 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1893 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1894 string workingDirectory
= GetWorkingDirectory ( );
1895 string objectsMacro
= GetObjectsMacro ( module
);
1896 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1897 string libsMacro
= GetLibsMacro ( module
);
1899 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1901 if ( module
.non_if_data
.files
.size () > 0 )
1903 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1905 fprintf ( fMakefile
, "%s: %s %s\n",
1907 objectsMacro
.c_str (),
1908 linkDepsMacro
.c_str () );
1911 if ( module
.cplusplus
)
1916 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1917 module
.entrypoint
.c_str (),
1918 module
.baseaddress
.c_str () );
1919 GenerateLinkerCommand ( module
,
1928 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1930 fprintf ( fMakefile
, "%s:\n\n",
1936 static MingwWin32CUIModuleHandler win32cui_handler
;
1938 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ()
1939 : MingwModuleHandler ( Win32CUI
)
1944 MingwWin32CUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1946 GeneratePreconditionDependencies ( module
);
1947 GenerateWin32CUIModuleTarget ( module
, clean_files
);
1948 GenerateInvocations ( module
);
1952 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1954 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1955 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1956 string workingDirectory
= GetWorkingDirectory ( );
1957 string objectsMacro
= GetObjectsMacro ( module
);
1958 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1959 string libsMacro
= GetLibsMacro ( module
);
1961 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1963 if ( module
.non_if_data
.files
.size () > 0 )
1965 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1967 fprintf ( fMakefile
, "%s: %s %s\n",
1969 objectsMacro
.c_str (),
1970 linkDepsMacro
.c_str () );
1973 if ( module
.cplusplus
)
1978 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1979 module
.entrypoint
.c_str (),
1980 module
.baseaddress
.c_str () );
1981 GenerateLinkerCommand ( module
,
1990 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1992 fprintf ( fMakefile
, "%s:\n\n",
1998 static MingwWin32GUIModuleHandler win32gui_handler
;
2000 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
2001 : MingwModuleHandler ( Win32GUI
)
2006 MingwWin32GUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2008 GeneratePreconditionDependencies ( module
);
2009 GenerateWin32GUIModuleTarget ( module
, clean_files
);
2010 GenerateInvocations ( module
);
2014 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
2016 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2017 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2018 string workingDirectory
= GetWorkingDirectory ( );
2019 string objectsMacro
= GetObjectsMacro ( module
);
2020 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2021 string libsMacro
= GetLibsMacro ( module
);
2023 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
2025 if ( module
.non_if_data
.files
.size () > 0 )
2027 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
2029 fprintf ( fMakefile
, "%s: %s %s\n",
2031 objectsMacro
.c_str (),
2032 linkDepsMacro
.c_str () );
2035 if ( module
.cplusplus
)
2040 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2041 module
.entrypoint
.c_str (),
2042 module
.baseaddress
.c_str () );
2043 GenerateLinkerCommand ( module
,
2052 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2054 fprintf ( fMakefile
, "%s:\n\n",
2060 static MingwBootLoaderModuleHandler bootloadermodule_handler
;
2062 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()
2063 : MingwModuleHandler ( BootLoader
)
2068 MingwBootLoaderModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2070 GeneratePreconditionDependencies ( module
);
2071 GenerateBootLoaderModuleTarget ( module
, clean_files
);
2072 GenerateInvocations ( module
);
2076 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget (
2077 const Module
& module
,
2078 string_list
& clean_files
)
2080 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2081 string
targetName ( module
.GetTargetName () );
2082 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2083 string workingDirectory
= GetWorkingDirectory ();
2084 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
2085 CLEAN_FILE ( junk_tmp
);
2086 string objectsMacro
= GetObjectsMacro ( module
);
2087 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2088 string libsMacro
= GetLibsMacro ( module
);
2090 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
2092 fprintf ( fMakefile
, "%s: %s %s\n",
2094 objectsMacro
.c_str (),
2095 linkDepsMacro
.c_str () );
2097 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2099 fprintf ( fMakefile
,
2100 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2101 GetLinkerMacro ( module
).c_str (),
2103 objectsMacro
.c_str (),
2104 linkDepsMacro
.c_str () );
2105 fprintf ( fMakefile
,
2106 "\t${objcopy} -O binary %s %s\n",
2109 fprintf ( fMakefile
,
2111 junk_tmp
.c_str () );
2115 static MingwBootSectorModuleHandler bootsectormodule_handler
;
2117 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ()
2118 : MingwModuleHandler ( BootSector
)
2123 MingwBootSectorModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2125 GeneratePreconditionDependencies ( module
);
2126 GenerateBootSectorModuleTarget ( module
, clean_files
);
2127 GenerateInvocations ( module
);
2131 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
, string_list
& clean_files
)
2133 string objectsMacro
= GetObjectsMacro ( module
);
2135 string
* nasmflags
= new string ( "-f bin" );
2136 GenerateMacrosAndTargets ( module
,
2141 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2142 module
.name
.c_str ());
2143 fprintf ( fMakefile
,
2145 module
.name
.c_str (),
2146 objectsMacro
.c_str () );
2150 static MingwIsoModuleHandler isomodule_handler
;
2152 MingwIsoModuleHandler::MingwIsoModuleHandler ()
2153 : MingwModuleHandler ( Iso
)
2158 MingwIsoModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2160 GeneratePreconditionDependencies ( module
);
2161 GenerateIsoModuleTarget ( module
, clean_files
);
2162 GenerateInvocations ( module
);
2166 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string bootcdDirectory
,
2167 const Module
& module
) const
2169 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2171 const Module
& m
= *module
.project
.modules
[i
];
2172 if ( m
.bootstrap
!= NULL
)
2174 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
2175 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2176 fprintf ( fMakefile
,
2178 m
.GetPath ().c_str (),
2179 targetFilename
.c_str () );
2185 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string bootcdDirectory
,
2186 const Module
& module
) const
2188 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2190 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2191 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2192 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2193 fprintf ( fMakefile
,
2195 cdfile
.GetPath ().c_str (),
2196 targetFilename
.c_str () );
2201 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string bootcdDirectory
,
2202 const Module
& module
) const
2205 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2207 const Module
& m
= *module
.project
.modules
[i
];
2208 if ( m
.bootstrap
!= NULL
)
2210 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2211 if ( directories
.size () > 0 )
2213 directories
+= FixupTargetFilename ( targetDirecctory
);
2220 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string bootcdDirectory
,
2221 const Module
& module
) const
2224 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2226 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2227 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2228 if ( directories
.size () > 0 )
2230 directories
+= FixupTargetFilename ( targetDirecctory
);
2236 MingwIsoModuleHandler::GetCdDirectories ( const string bootcdDirectory
,
2237 const Module
& module
) const
2239 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2241 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2247 MingwIsoModuleHandler::GetBootstrapCdFiles ( const string bootcdDirectory
,
2248 const Module
& module
) const
2251 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2253 const Module
& m
= *module
.project
.modules
[i
];
2254 if ( m
.bootstrap
!= NULL
)
2256 if ( cdfiles
.size () > 0 )
2258 cdfiles
+= FixupTargetFilename ( m
.GetPath () );
2265 MingwIsoModuleHandler::GetNonModuleCdFiles ( const string bootcdDirectory
,
2266 const Module
& module
) const
2269 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2271 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2272 if ( cdfiles
.size () > 0 )
2274 cdfiles
+= NormalizeFilename ( cdfile
.GetPath () );
2280 MingwIsoModuleHandler::GetCdFiles ( const string bootcdDirectory
,
2281 const Module
& module
) const
2283 string cdfiles
= GetBootstrapCdFiles ( bootcdDirectory
,
2285 cdfiles
+= " " + GetNonModuleCdFiles ( bootcdDirectory
,
2291 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
, string_list
& clean_files
)
2293 string bootcdDirectory
= "cd";
2294 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2295 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2296 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2297 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2298 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2299 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2300 string cdDirectories
= bootcdReactos
+ " " + GetCdDirectories ( bootcdDirectory
,
2302 string cdFiles
= GetCdFiles ( bootcdDirectory
,
2305 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2306 module
.name
.c_str ());
2307 fprintf ( fMakefile
,
2308 "%s: all %s %s %s\n",
2309 module
.name
.c_str (),
2311 cdDirectories
.c_str (),
2313 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2314 fprintf ( fMakefile
,
2315 "\t${cabman} -C %s -L %s -I\n",
2316 reactosDff
.c_str (),
2317 bootcdReactos
.c_str () );
2318 fprintf ( fMakefile
,
2319 "\t${cabman} -C %s -RC %s -L %s -N\n",
2320 reactosDff
.c_str (),
2321 reactosInf
.c_str (),
2322 bootcdReactos
.c_str () );
2323 fprintf ( fMakefile
,
2325 reactosInf
.c_str () );
2326 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2328 OutputCdfileCopyCommands ( bootcdDirectory
,
2330 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2331 fprintf ( fMakefile
,
2332 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2334 bootcdDirectory
.c_str () );
2335 fprintf ( fMakefile
,