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
) index
= 0;
35 string tmp
= filename
.substr( index
, filename
.size() - index
);
36 size_t ext_index
= tmp
.find_last_of( '.' );
37 if (ext_index
!= string::npos
)
38 return filename
.substr ( 0, index
+ ext_index
) + newExtension
;
39 return filename
+ newExtension
;
43 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype
)
46 handler_map
= new map
<ModuleType
,MingwModuleHandler
*>;
47 (*handler_map
)[moduletype
] = this;
50 MingwModuleHandler::~MingwModuleHandler()
60 MingwModuleHandler::PassThruCacheDirectory ( const string
&file
) const
62 directory_set
.insert ( GetDirectory ( file
) );
67 MingwModuleHandler::SetMakefile ( FILE* f
)
73 MingwModuleHandler::SetUsePch ( bool b
)
79 MingwModuleHandler::LookupHandler ( const string
& location
,
80 ModuleType moduletype
)
83 throw Exception ( "internal tool error: no registered module handlers" );
84 MingwModuleHandler
* h
= (*handler_map
)[moduletype
];
87 throw UnknownModuleTypeException ( location
, moduletype
);
94 MingwModuleHandler::GetWorkingDirectory () const
100 MingwModuleHandler::GetBasename ( const string
& filename
) const
102 size_t index
= filename
.find_last_of ( '.' );
103 if ( index
!= string::npos
)
104 return filename
.substr ( 0, index
);
109 MingwModuleHandler::GetActualSourceFilename ( const string
& filename
) const
111 string extension
= GetExtension ( filename
);
112 if ( extension
== ".spec" || extension
== "SPEC" )
114 string basename
= GetBasename ( filename
);
115 return basename
+ ".stubs.c";
122 MingwModuleHandler::GetModuleArchiveFilename ( const Module
& module
) const
124 return ReplaceExtension ( FixupTargetFilename ( module
.GetPath () ),
129 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
131 string extension
= GetExtension ( file
.name
);
132 if ( extension
== ".spec" || extension
== "SPEC" )
139 MingwModuleHandler::GetImportLibraryDependency ( const Module
& importedModule
) const
141 if ( importedModule
.type
== ObjectLibrary
)
142 return GetObjectsMacro ( importedModule
);
144 return PassThruCacheDirectory ( FixupTargetFilename ( importedModule
.GetDependencyPath () ) );
148 MingwModuleHandler::GetModuleDependencies ( const Module
& module
) const
150 if ( module
.dependencies
.size () == 0 )
153 string
dependencies ( "" );
154 for ( size_t i
= 0; i
< module
.dependencies
.size (); i
++ )
156 if ( dependencies
.size () > 0 )
158 const Dependency
* dependency
= module
.dependencies
[i
];
159 const Module
* dependencyModule
= dependency
->dependencyModule
;
160 dependencies
+= dependencyModule
->GetTargets ();
162 string definitionDependencies
= GetDefinitionDependencies ( module
);
163 if ( dependencies
.length () > 0 && definitionDependencies
.length () > 0 )
164 dependencies
+= " " + definitionDependencies
;
165 else if ( definitionDependencies
.length () > 0 )
166 dependencies
= definitionDependencies
;
171 MingwModuleHandler::GetAllDependencies ( const Module& module ) const
173 string dependencies = GetImportMacro ( module );
174 string s = GetModuleDependencies ( module );
175 if ( s.length () > 0 )
184 MingwModuleHandler::GetSourceFilenames ( const Module
& module
,
185 bool includeGeneratedFiles
) const
189 string
sourceFilenames ( "" );
190 const vector
<File
*>& files
= module
.non_if_data
.files
;
191 for ( i
= 0; i
< files
.size (); i
++ )
193 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *files
[i
] ) )
194 sourceFilenames
+= " " + GetActualSourceFilename ( files
[i
]->name
);
196 // intentionally make a copy so that we can append more work in
197 // the middle of processing without having to go recursive
198 vector
<If
*> v
= module
.non_if_data
.ifs
;
199 for ( i
= 0; i
< v
.size (); i
++ )
203 // check for sub-ifs to add to list
204 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
205 for ( j
= 0; j
< ifs
.size (); j
++ )
206 v
.push_back ( ifs
[j
] );
207 const vector
<File
*>& files
= rIf
.data
.files
;
208 for ( j
= 0; j
< files
.size (); j
++ )
210 File
& file
= *files
[j
];
211 if ( includeGeneratedFiles
|| !IsGeneratedFile ( file
) )
212 sourceFilenames
+= " " + GetActualSourceFilename ( file
.name
);
215 return sourceFilenames
;
219 MingwModuleHandler::GetSourceFilenames ( const Module
& module
) const
221 return GetSourceFilenames ( module
,
226 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module
& module
) const
228 return GetSourceFilenames ( module
,
233 MingwModuleHandler::GetObjectFilename ( const string
& sourceFilename
)
236 string extension
= GetExtension ( sourceFilename
);
237 if ( extension
== ".rc" || extension
== ".RC" )
238 newExtension
= ".coff";
239 else if ( extension
== ".spec" || extension
== ".SPEC" )
240 newExtension
= ".stubs.o";
243 return FixupTargetFilename ( ReplaceExtension ( sourceFilename
, newExtension
) );
247 MingwModuleHandler::GenerateCleanTarget (
248 const Module
& module
,
249 const string_list
& clean_files
) const
251 if ( 0 == clean_files
.size() )
253 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
254 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
255 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
258 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
259 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
261 fprintf ( fMakefile
, " 2>$(NUL)\n" );
262 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
266 MingwModuleHandler::GetObjectFilenames ( const Module
& module
) const
268 const vector
<File
*>& files
= module
.non_if_data
.files
;
269 if ( files
.size () == 0 )
272 string
objectFilenames ( "" );
273 for ( size_t i
= 0; i
< files
.size (); i
++ )
275 if ( objectFilenames
.size () > 0 )
276 objectFilenames
+= " ";
277 objectFilenames
+= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) );
279 return objectFilenames
;
283 MingwModuleHandler::IncludeDirectoryTarget ( const string
& directory
) const
285 if ( directory
== "$(ROS_INTERMEDIATE)." SSEP
"tools")
292 MingwModuleHandler::GenerateDirectoryTargets () const
294 if ( directory_set
.size () == 0 )
297 set_string::iterator it
;
298 size_t wrap_count
= 0;
300 fprintf ( fMakefile
, "ifneq ($(ROS_INTERMEDIATE),)\n" );
301 fprintf ( fMakefile
, "directories::" );
303 for ( it
= directory_set
.begin ();
304 it
!= directory_set
.end ();
307 if ( IncludeDirectoryTarget ( *it
) )
309 if ( wrap_count
++ == 5 )
310 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
317 fprintf ( fMakefile
, "\n\n" );
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;
335 "::\n\t${mkdir} $@\n" );
336 fprintf ( fMakefile
, "endif\n\n" );
338 directory_set
.clear ();
342 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector
<Define
*>& defines
) const
345 for ( size_t i
= 0; i
< defines
.size (); i
++ )
347 Define
& define
= *defines
[i
];
348 if (parameters
.length () > 0)
351 parameters
+= define
.name
;
352 if (define
.value
.length () > 0)
355 parameters
+= define
.value
;
362 MingwModuleHandler::GenerateGccDefineParameters ( const Module
& module
) const
364 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
365 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
366 if ( s
.length () > 0 )
375 MingwModuleHandler::ConcatenatePaths ( const string
& path1
,
376 const string
& path2
) const
378 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
380 if ( path1
[path1
.length ()] == CSEP
)
381 return path1
+ path2
;
383 return path1
+ CSEP
+ path2
;
387 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
390 for ( size_t i
= 0; i
< includes
.size (); i
++ )
392 Include
& include
= *includes
[i
];
393 if ( parameters
.length () > 0 )
395 parameters
+= "-I" + include
.directory
;
401 MingwModuleHandler::GenerateGccIncludeParameters ( const Module
& module
) const
403 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
404 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
405 if ( s
.length () > 0 )
415 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
418 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
420 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
421 if ( parameters
.length () > 0 )
423 parameters
+= compilerFlag
.flag
;
429 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
432 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
434 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
435 if ( parameters
.length () > 0 )
437 parameters
+= linkerFlag
.flag
;
443 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
444 const vector
<Library
*>& libraries
) const
446 string
dependencies ( "" );
448 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
450 if ( wrap_count
++ == 5 )
451 dependencies
+= " \\\n\t\t", wrap_count
= 0;
452 else if ( dependencies
.size () > 0 )
454 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->imported_module
);
460 MingwModuleHandler::GenerateLinkerParameters ( const Module
& module
) const
462 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
466 MingwModuleHandler::GenerateMacro (
467 const char* assignmentOperation
,
469 const IfableData
& data
,
470 const vector
<CompilerFlag
*>* compilerFlags
) const
478 assignmentOperation
);
480 if ( compilerFlags
!= NULL
)
482 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
483 if ( compilerParameters
.size () > 0 )
488 compilerParameters
.c_str () );
492 for ( i
= 0; i
< data
.includes
.size(); i
++ )
497 data
.includes
[i
]->directory
.c_str() );
499 for ( i
= 0; i
< data
.defines
.size(); i
++ )
501 Define
& d
= *data
.defines
[i
];
506 if ( d
.value
.size() )
512 fprintf ( fMakefile
, "\n" );
516 MingwModuleHandler::GenerateMacros (
517 const char* assignmentOperation
,
518 const IfableData
& data
,
519 const vector
<CompilerFlag
*>* compilerFlags
,
520 const vector
<LinkerFlag
*>* linkerFlags
,
521 const string
& cflags_macro
,
522 const string
& nasmflags_macro
,
523 const string
& windresflags_macro
,
524 const string
& linkerflags_macro
,
525 const string
& objs_macro
,
526 const string
& libs_macro
,
527 const string
& linkdeps_macro
) const
531 if ( data
.includes
.size () > 0 || data
.defines
.size () > 0 )
533 GenerateMacro ( assignmentOperation
,
537 GenerateMacro ( assignmentOperation
,
543 if ( linkerFlags
!= NULL
)
545 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
546 if ( linkerParameters
.size () > 0 )
551 linkerflags_macro
.c_str (),
553 linkerParameters
.c_str() );
557 if ( data
.libraries
.size () > 0 )
559 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
560 if ( deps
.size () > 0 )
571 const vector
<File
*>& files
= data
.files
;
572 if ( files
.size () > 0 )
574 for ( i
= 0; i
< files
.size (); i
++ )
576 File
& file
= *files
[i
];
582 PassThruCacheDirectory (
583 MingwModuleHandler::GetObjectFilename ( file
.name
) ).c_str (),
584 objs_macro
.c_str() );
591 assignmentOperation
);
592 for ( i
= 0; i
< files
.size(); i
++ )
594 File
& file
= *files
[i
];
600 ( i
%10 == 9 ? "\\\n\t" : " " ),
601 PassThruCacheDirectory (
602 MingwModuleHandler::GetObjectFilename ( file
.name
) ).c_str () );
605 fprintf ( fMakefile
, "\n" );
608 const vector
<If
*>& ifs
= data
.ifs
;
609 for ( i
= 0; i
< ifs
.size(); i
++ )
612 if ( rIf
.data
.defines
.size()
613 || rIf
.data
.includes
.size()
614 || rIf
.data
.libraries
.size()
615 || rIf
.data
.files
.size()
616 || rIf
.data
.ifs
.size() )
620 "ifeq (\"$(%s)\",\"%s\")\n",
621 rIf
.property
.c_str(),
643 MingwModuleHandler::GenerateMacros (
644 const Module
& module
,
645 const string
& cflags_macro
,
646 const string
& nasmflags_macro
,
647 const string
& windresflags_macro
,
648 const string
& linkerflags_macro
,
649 const string
& objs_macro
,
650 const string
& libs_macro
,
651 const string
& linkdeps_macro
) const
656 &module
.compilerFlags
,
666 if ( module
.importLibrary
)
669 const vector
<File
*>& files
= module
.non_if_data
.files
;
670 for ( size_t i
= 0; i
< files
.size (); i
++ )
672 File
& file
= *files
[i
];
673 string extension
= GetExtension ( file
.name
);
674 if ( extension
== ".spec" || extension
== ".SPEC" )
676 if ( s
.length () > 0 )
678 s
+= GetSpecObjectDependencies ( file
.name
);
681 if ( s
.length () > 0 )
686 linkdeps_macro
.c_str(),
693 "%s += $(PROJECT_CFLAGS)\n",
694 cflags_macro
.c_str () );
698 "%s += $(PROJECT_RCFLAGS)\n",
699 windresflags_macro
.c_str () );
703 "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
704 module
.name
.c_str () );
709 linkdeps_macro
.c_str (),
710 libs_macro
.c_str () );
712 fprintf ( fMakefile
, "\n" );
716 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
717 const string
& sourceFilename
,
719 const string
& cflagsMacro
) const
721 string deps
= sourceFilename
;
722 if ( module
.pch
&& use_pch
)
723 deps
+= " " + module
.pch
->header
+ ".gch";
724 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
727 objectFilename
.c_str (),
729 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
731 "\t%s -c %s -o %s %s\n",
733 sourceFilename
.c_str (),
734 objectFilename
.c_str (),
735 cflagsMacro
.c_str () );
739 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
740 const string
& sourceFilename
,
742 const string
& cflagsMacro
) const
744 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
747 objectFilename
.c_str (),
748 sourceFilename
.c_str () );
749 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
751 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
753 sourceFilename
.c_str (),
754 objectFilename
.c_str (),
755 cflagsMacro
.c_str () );
759 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
760 const string
& sourceFilename
,
761 const string
& nasmflagsMacro
) const
763 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
766 objectFilename
.c_str (),
767 sourceFilename
.c_str () );
768 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
770 "\t%s -f win32 %s -o %s %s\n",
772 sourceFilename
.c_str (),
773 objectFilename
.c_str (),
774 nasmflagsMacro
.c_str () );
778 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
779 const string
& sourceFilename
,
780 const string
& windresflagsMacro
) const
782 string objectFilename
= PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename
) );
783 string rciFilename
= ReplaceExtension ( sourceFilename
,
785 string resFilename
= ReplaceExtension ( sourceFilename
,
789 objectFilename
.c_str (),
790 sourceFilename
.c_str () );
791 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
793 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
794 windresflagsMacro
.c_str (),
795 sourceFilename
.c_str (),
796 rciFilename
.c_str () );
798 "\t${wrc} ${%s} %s %s\n",
799 windresflagsMacro
.c_str (),
800 rciFilename
.c_str (),
801 resFilename
.c_str () );
804 rciFilename
.c_str () );
806 "\t${windres} %s -o %s\n",
807 resFilename
.c_str (),
808 objectFilename
.c_str () );
811 resFilename
.c_str () );
815 MingwModuleHandler::GenerateWinebuildCommands (
816 const Module
& module
,
817 const string
& sourceFilename
,
818 string_list
& clean_files
) const
820 string basename
= GetBasename ( sourceFilename
);
822 string def_file
= basename
+ ".spec.def";
823 CLEAN_FILE ( def_file
);
825 string stub_file
= basename
+ ".stubs.c";
826 CLEAN_FILE ( stub_file
);
831 sourceFilename
.c_str () );
832 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
834 "\t%s --def=%s -o %s\n",
836 sourceFilename
.c_str (),
842 sourceFilename
.c_str () );
843 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
845 "\t%s --pedll=%s -o %s\n",
847 sourceFilename
.c_str (),
848 stub_file
.c_str () );
852 MingwModuleHandler::GenerateCommands (
853 const Module
& module
,
854 const string
& sourceFilename
,
857 const string
& cflagsMacro
,
858 const string
& nasmflagsMacro
,
859 const string
& windresflagsMacro
,
860 string_list
& clean_files
) const
862 CLEAN_FILE ( GetObjectFilename(sourceFilename
) );
863 string extension
= GetExtension ( sourceFilename
);
864 if ( extension
== ".c" || extension
== ".C" )
866 GenerateGccCommand ( module
,
872 else if ( extension
== ".cc" || extension
== ".CC" ||
873 extension
== ".cpp" || extension
== ".CPP" ||
874 extension
== ".cxx" || extension
== ".CXX" )
876 GenerateGccCommand ( module
,
882 else if ( extension
== ".s" || extension
== ".S" )
884 GenerateGccAssemblerCommand ( module
,
890 else if ( extension
== ".asm" || extension
== ".ASM" )
892 GenerateNasmCommand ( module
,
897 else if ( extension
== ".rc" || extension
== ".RC" )
899 GenerateWindresCommand ( module
,
904 else if ( extension
== ".spec" || extension
== ".SPEC" )
906 GenerateWinebuildCommands ( module
,
909 GenerateGccCommand ( module
,
910 GetActualSourceFilename ( sourceFilename
),
916 throw InvalidOperationException ( __FILE__
,
918 "Unsupported filename extension '%s' in file '%s'",
920 sourceFilename
.c_str () );
924 MingwModuleHandler::GenerateLinkerCommand (
925 const Module
& module
,
926 const string
& linker
,
927 const string
& linkerParameters
,
928 const string
& objectsMacro
,
929 const string
& libsMacro
,
930 string_list
& clean_files
) const
932 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
933 string
targetName ( module
.GetTargetName () );
934 string
target ( FixupTargetFilename ( module
.GetPath () ) );
935 if ( module
.importLibrary
!= NULL
)
937 static string
ros_junk ( "$(ROS_TEMPORARY)" );
938 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
939 CLEAN_FILE ( base_tmp
);
940 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
941 CLEAN_FILE ( junk_tmp
);
942 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
943 CLEAN_FILE ( temp_exp
);
944 string def_file
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
947 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
949 linkerParameters
.c_str (),
952 objectsMacro
.c_str (),
954 GetLinkerMacro ( module
).c_str () );
960 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
962 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
974 "\t%s %s %s -o %s %s %s %s\n",
976 linkerParameters
.c_str (),
979 objectsMacro
.c_str (),
981 GetLinkerMacro ( module
).c_str () );
990 "\t%s %s -o %s %s %s %s\n",
992 linkerParameters
.c_str (),
994 objectsMacro
.c_str (),
996 GetLinkerMacro ( module
).c_str () );
999 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1000 fprintf ( fMakefile
,
1001 "\t${rsym} %s %s\n\n",
1007 MingwModuleHandler::GenerateObjectFileTargets (
1008 const Module
& module
,
1009 const IfableData
& data
,
1012 const string
& cflagsMacro
,
1013 const string
& nasmflagsMacro
,
1014 const string
& windresflagsMacro
,
1015 string_list
& clean_files
) const
1019 const vector
<File
*>& files
= data
.files
;
1020 for ( i
= 0; i
< files
.size (); i
++ )
1022 string sourceFilename
= files
[i
]->name
;
1023 GenerateCommands ( module
,
1031 fprintf ( fMakefile
,
1035 const vector
<If
*>& ifs
= data
.ifs
;
1036 for ( i
= 0; i
< ifs
.size(); i
++ )
1038 GenerateObjectFileTargets ( module
,
1050 MingwModuleHandler::GenerateObjectFileTargets (
1051 const Module
& module
,
1054 const string
& cflagsMacro
,
1055 const string
& nasmflagsMacro
,
1056 const string
& windresflagsMacro
,
1057 string_list
& clean_files
) const
1061 const string
& pch_file
= module
.pch
->header
;
1062 string gch_file
= pch_file
+ ".gch";
1063 CLEAN_FILE(gch_file
);
1071 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1074 "\t%s -o %s %s -g %s\n\n",
1075 ( module
.cplusplus
? cppc
.c_str() : cc
.c_str() ),
1077 cflagsMacro
.c_str(),
1082 GenerateObjectFileTargets ( module
,
1090 fprintf ( fMakefile
, "\n" );
1094 MingwModuleHandler::GetCleanTargets (
1096 const IfableData
& data
) const
1100 const vector
<File
*>& files
= data
.files
;
1101 for ( i
= 0; i
< files
.size(); i
++ )
1102 out
.push_back ( PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) ) );
1104 const vector
<If
*>& ifs
= data
.ifs
;
1105 for ( i
= 0; i
< ifs
.size(); i
++ )
1106 GetCleanTargets ( out
, ifs
[i
]->data
);
1110 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
1112 const string
& objs_macro
) const
1114 string archiveFilename
= GetModuleArchiveFilename ( module
);
1116 fprintf ( fMakefile
,
1118 archiveFilename
.c_str (),
1119 objs_macro
.c_str ());
1121 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1123 fprintf ( fMakefile
,
1124 "\t%s -rc %s %s\n\n",
1126 archiveFilename
.c_str (),
1127 objs_macro
.c_str ());
1129 return archiveFilename
;
1133 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
1135 return ssprintf ( "$(%s_CFLAGS)",
1136 module
.name
.c_str () );
1140 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
1142 return ssprintf ( "$(%s_OBJS)",
1143 module
.name
.c_str () );
1147 MingwModuleHandler::GetLinkingDependenciesMacro ( const Module
& module
) const
1149 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1153 MingwModuleHandler::GetLibsMacro ( const Module
& module
) const
1155 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1159 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
1161 return ssprintf ( "$(%s_LFLAGS)",
1162 module
.name
.c_str () );
1166 MingwModuleHandler::GenerateMacrosAndTargets (
1167 const Module
& module
,
1171 const string
* cflags
,
1172 const string
* nasmflags
,
1173 string_list
& clean_files
) const
1175 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1176 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1177 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1178 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1179 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1180 string libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1181 string linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1183 GenerateMacros ( module
,
1192 if ( cflags
!= NULL
)
1194 fprintf ( fMakefile
,
1196 cflagsMacro
.c_str (),
1200 if ( nasmflags
!= NULL
)
1202 fprintf ( fMakefile
,
1204 nasmflagsMacro
.c_str (),
1205 nasmflags
->c_str () );
1208 // generate phony target for module name
1209 fprintf ( fMakefile
, ".PHONY: %s\n",
1210 module
.name
.c_str () );
1211 fprintf ( fMakefile
, "%s: %s\n\n",
1212 module
.name
.c_str (),
1213 FixupTargetFilename ( module
.GetPath () ).c_str () );
1215 // future references to the macros will be to get their values
1216 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1217 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1218 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1220 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1221 GenerateObjectFileTargets ( module
,
1229 CLEAN_FILE ( ar_target
);
1230 string tgt
= FixupTargetFilename(module
.GetPath());
1231 if ( tgt
!= ar_target
)
1238 MingwModuleHandler::GenerateMacrosAndTargetsHost (
1239 const Module
& module
,
1240 string_list
& clean_files
) const
1242 GenerateMacrosAndTargets (
1253 MingwModuleHandler::GenerateMacrosAndTargetsTarget (
1254 const Module
& module
,
1255 string_list
& clean_files
) const
1257 GenerateMacrosAndTargetsTarget (
1265 MingwModuleHandler::GenerateMacrosAndTargetsTarget (
1266 const Module
& module
,
1267 const string
* cflags
,
1268 const string
* nasmflags
,
1269 string_list
& clean_files
) const
1271 GenerateMacrosAndTargets (
1282 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
1284 string dependencies
;
1285 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1287 Invoke
& invoke
= *module
.invocations
[i
];
1288 if (invoke
.invokeModule
== &module
)
1289 /* Protect against circular dependencies */
1291 if ( dependencies
.length () > 0 )
1292 dependencies
+= " ";
1293 dependencies
+= invoke
.GetTargets ();
1295 return dependencies
;
1299 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1301 if ( module
.invocations
.size () == 0 )
1304 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1306 const Invoke
& invoke
= *module
.invocations
[i
];
1308 if ( invoke
.invokeModule
->type
!= BuildTool
)
1310 throw InvalidBuildFileException ( module
.node
.location
,
1311 "Only modules of type buildtool can be invoked." );
1314 string invokeTarget
= module
.GetInvocationTarget ( i
);
1315 fprintf ( fMakefile
,
1317 invokeTarget
.c_str () );
1318 fprintf ( fMakefile
,
1320 invokeTarget
.c_str (),
1321 invoke
.GetTargets ().c_str () );
1322 fprintf ( fMakefile
,
1324 invoke
.GetTargets ().c_str (),
1325 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1326 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1327 fprintf ( fMakefile
,
1329 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1330 invoke
.GetParameters ().c_str () );
1335 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1337 return ssprintf ( "%s_precondition",
1338 module
.name
.c_str () );
1342 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1344 /* Avoid circular dependency */
1345 if ( module
.type
== BuildTool
|| module
.name
== "zlib" )
1346 return "$(ROS_INTERMEDIATE)." SSEP
"tools $(ROS_INTERMEDIATE)." SSEP
"lib" SSEP
"zlib";
1352 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
1354 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1355 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1356 string dependencies
= GetDefaultDependencies ( module
);
1357 string s
= GetModuleDependencies ( module
);
1358 if ( s
.length () > 0 )
1360 if ( dependencies
.length () > 0 )
1361 dependencies
+= " ";
1365 s
= GetInvocationDependencies ( module
);
1366 if ( s
.length () > 0 )
1368 if ( dependencies
.length () > 0 )
1369 dependencies
+= " ";
1373 fprintf ( fMakefile
,
1375 preconditionDependenciesName
.c_str () );
1376 fprintf ( fMakefile
,
1378 preconditionDependenciesName
.c_str (),
1379 dependencies
.c_str () );
1380 const char* p
= sourceFilenames
.c_str();
1381 const char* end
= p
+ strlen(p
);
1384 const char* p2
= &p
[512];
1387 while ( p2
> p
&& !isspace(*p2
) )
1391 p2
= strpbrk ( p
, " \t" );
1395 fprintf ( fMakefile
,
1399 preconditionDependenciesName
.c_str ());
1401 p
+= strspn ( p
, " \t" );
1403 fprintf ( fMakefile
, "\n" );
1407 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded (
1408 const Module
& module
,
1409 string_list
& clean_files
) const
1411 if ( module
.importLibrary
!= NULL
)
1413 string library_target
= FixupTargetFilename( module
.GetDependencyPath () ).c_str ();
1414 CLEAN_FILE ( library_target
);
1416 string definitionDependencies
= GetDefinitionDependencies ( module
);
1417 fprintf ( fMakefile
, "%s: %s\n",
1418 library_target
.c_str (),
1419 definitionDependencies
.c_str () );
1421 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1423 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1424 fprintf ( fMakefile
,
1425 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1426 module
.GetTargetName ().c_str (),
1427 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1428 library_target
.c_str (),
1434 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1436 string basename
= GetBasename ( filename
);
1437 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1441 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
) const
1443 string dependencies
;
1444 string dkNkmLibNoFixup
= "dk/nkm/lib";
1445 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1446 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1447 const vector
<File
*>& files
= module
.non_if_data
.files
;
1448 for ( size_t i
= 0; i
< files
.size (); i
++ )
1450 File
& file
= *files
[i
];
1451 string extension
= GetExtension ( file
.name
);
1452 if ( extension
== ".spec" || extension
== ".SPEC" )
1454 if ( dependencies
.length () > 0 )
1455 dependencies
+= " ";
1456 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1459 return dependencies
;
1463 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
) const
1465 return module
.cplusplus
;
1469 static MingwBuildToolModuleHandler buildtool_handler
;
1471 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1472 : MingwModuleHandler ( BuildTool
)
1477 MingwBuildToolModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1479 GeneratePreconditionDependencies ( module
);
1480 GenerateBuildToolModuleTarget ( module
, clean_files
);
1481 GenerateInvocations ( module
);
1485 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
, string_list
& clean_files
)
1487 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1488 string objectsMacro
= GetObjectsMacro ( module
);
1489 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1490 string libsMacro
= GetLibsMacro ( module
);
1492 GenerateMacrosAndTargetsHost ( module
, clean_files
);
1495 if ( IsCPlusPlusModule ( module
) )
1496 linker
= "${host_gpp}";
1498 linker
= "${host_gcc}";
1500 fprintf ( fMakefile
, "%s: %s %s\n",
1502 objectsMacro
.c_str (),
1503 linkDepsMacro
.c_str () );
1504 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1505 fprintf ( fMakefile
,
1506 "\t%s %s -o %s %s %s\n\n",
1508 GetLinkerMacro ( module
).c_str (),
1510 objectsMacro
.c_str (),
1511 libsMacro
.c_str () );
1515 static MingwKernelModuleHandler kernelmodule_handler
;
1517 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1518 : MingwModuleHandler ( Kernel
)
1523 MingwKernelModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1525 GeneratePreconditionDependencies ( module
);
1526 GenerateKernelModuleTarget ( module
, clean_files
);
1527 GenerateInvocations ( module
);
1531 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
, string_list
& clean_files
)
1533 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1534 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1535 string
target ( FixupTargetFilename (module
.GetPath ()) ); // i.e. "$(ROS_INT).\ntoskrnl\ntoskrnl.exe"
1536 string workingDirectory
= GetWorkingDirectory ();
1537 string objectsMacro
= GetObjectsMacro ( module
);
1538 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1539 string libsMacro
= GetLibsMacro ( module
);
1540 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1541 CLEAN_FILE ( base_tmp
);
1542 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1543 CLEAN_FILE ( junk_tmp
);
1544 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1545 CLEAN_FILE ( temp_exp
);
1546 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",
1547 module
.GetBasePath ().c_str (),
1548 module
.entrypoint
.c_str (),
1549 module
.baseaddress
.c_str () );
1551 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1553 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1555 fprintf ( fMakefile
, "%s: %s %s\n",
1557 objectsMacro
.c_str (),
1558 linkDepsMacro
.c_str () );
1559 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1560 fprintf ( fMakefile
,
1561 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1562 GetLinkerMacro ( module
).c_str (),
1563 gccOptions
.c_str (),
1566 objectsMacro
.c_str (),
1567 linkDepsMacro
.c_str () );
1568 fprintf ( fMakefile
,
1570 junk_tmp
.c_str () );
1571 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1572 fprintf ( fMakefile
,
1573 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1574 targetName
.c_str (),
1578 fprintf ( fMakefile
,
1580 base_tmp
.c_str () );
1581 fprintf ( fMakefile
,
1582 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1583 GetLinkerMacro ( module
).c_str (),
1584 gccOptions
.c_str (),
1587 objectsMacro
.c_str (),
1588 linkDepsMacro
.c_str () );
1589 fprintf ( fMakefile
,
1591 temp_exp
.c_str () );
1592 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1593 fprintf ( fMakefile
,
1594 "\t${rsym} %s %s\n\n",
1600 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1602 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1603 : MingwModuleHandler ( StaticLibrary
)
1608 MingwStaticLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1610 GeneratePreconditionDependencies ( module
);
1611 GenerateStaticLibraryModuleTarget ( module
, clean_files
);
1612 GenerateInvocations ( module
);
1616 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1618 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1622 static MingwObjectLibraryModuleHandler objectlibrary_handler
;
1624 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()
1625 : MingwModuleHandler ( ObjectLibrary
)
1630 MingwObjectLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1632 GeneratePreconditionDependencies ( module
);
1633 GenerateObjectLibraryModuleTarget ( module
, clean_files
);
1634 GenerateInvocations ( module
);
1638 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1640 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1644 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1646 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1647 : MingwModuleHandler ( KernelModeDLL
)
1652 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1654 GeneratePreconditionDependencies ( module
);
1655 GenerateKernelModeDLLModuleTarget ( module
, clean_files
);
1656 GenerateInvocations ( module
);
1660 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget (
1661 const Module
& module
,
1662 string_list
& clean_files
)
1664 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1665 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1666 string workingDirectory
= GetWorkingDirectory ( );
1667 string objectsMacro
= GetObjectsMacro ( module
);
1668 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1669 string libsMacro
= GetLibsMacro ( module
);
1671 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1673 if ( module
.non_if_data
.files
.size () > 0 )
1675 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1677 fprintf ( fMakefile
, "%s: %s %s\n",
1679 objectsMacro
.c_str (),
1680 linkDepsMacro
.c_str () );
1682 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1683 module
.entrypoint
.c_str (),
1684 module
.baseaddress
.c_str () );
1685 GenerateLinkerCommand ( module
,
1694 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1696 fprintf ( fMakefile
, "%s:\n",
1702 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1704 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1705 : MingwModuleHandler ( KernelModeDriver
)
1710 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1712 GeneratePreconditionDependencies ( module
);
1713 GenerateKernelModeDriverModuleTarget ( module
, clean_files
);
1714 GenerateInvocations ( module
);
1719 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget (
1720 const Module
& module
,
1721 string_list
& clean_files
)
1723 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1724 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1725 string workingDirectory
= GetWorkingDirectory ();
1726 string objectsMacro
= GetObjectsMacro ( module
);
1727 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1728 string libsMacro
= GetLibsMacro ( module
);
1730 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1732 if ( module
.non_if_data
.files
.size () > 0 )
1734 string
cflags ( "-D__NTDRIVER__" );
1735 GenerateMacrosAndTargetsTarget ( module
,
1740 fprintf ( fMakefile
, "%s: %s %s\n",
1742 objectsMacro
.c_str (),
1743 linkDepsMacro
.c_str () );
1745 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1746 module
.entrypoint
.c_str (),
1747 module
.baseaddress
.c_str () );
1748 GenerateLinkerCommand ( module
,
1757 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1759 fprintf ( fMakefile
, "%s:\n",
1765 static MingwNativeDLLModuleHandler nativedll_handler
;
1767 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1768 : MingwModuleHandler ( NativeDLL
)
1773 MingwNativeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1775 GeneratePreconditionDependencies ( module
);
1776 GenerateNativeDLLModuleTarget ( module
, clean_files
);
1777 GenerateInvocations ( module
);
1781 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1783 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1784 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1785 string workingDirectory
= GetWorkingDirectory ( );
1786 string objectsMacro
= GetObjectsMacro ( module
);
1787 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1788 string libsMacro
= GetLibsMacro ( module
);
1790 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1792 if ( module
.non_if_data
.files
.size () > 0 )
1794 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1796 fprintf ( fMakefile
, "%s: %s %s\n",
1798 objectsMacro
.c_str (),
1799 linkDepsMacro
.c_str () );
1801 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1802 module
.entrypoint
.c_str (),
1803 module
.baseaddress
.c_str () );
1804 GenerateLinkerCommand ( module
,
1813 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1815 fprintf ( fMakefile
, "%s:\n\n",
1821 static MingwNativeCUIModuleHandler nativecui_handler
;
1823 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ()
1824 : MingwModuleHandler ( NativeCUI
)
1829 MingwNativeCUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1831 GeneratePreconditionDependencies ( module
);
1832 GenerateNativeCUIModuleTarget ( module
, clean_files
);
1833 GenerateInvocations ( module
);
1837 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1839 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1840 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1841 string workingDirectory
= GetWorkingDirectory ( );
1842 string objectsMacro
= GetObjectsMacro ( module
);
1843 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1844 string libsMacro
= GetLibsMacro ( module
);
1846 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1848 if ( module
.non_if_data
.files
.size () > 0 )
1850 string
cflags ( "-D__NTAPP__" );
1851 GenerateMacrosAndTargetsTarget ( module
,
1856 fprintf ( fMakefile
, "%s: %s %s\n",
1858 objectsMacro
.c_str (),
1859 linkDepsMacro
.c_str () );
1861 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1862 module
.entrypoint
.c_str (),
1863 module
.baseaddress
.c_str () );
1864 GenerateLinkerCommand ( module
,
1873 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1875 fprintf ( fMakefile
, "%s:\n\n",
1881 static MingwWin32DLLModuleHandler win32dll_handler
;
1883 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1884 : MingwModuleHandler ( Win32DLL
)
1889 MingwWin32DLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1891 GenerateExtractWineDLLResourcesTarget ( module
, clean_files
);
1892 GeneratePreconditionDependencies ( module
);
1893 GenerateWin32DLLModuleTarget ( module
, clean_files
);
1894 GenerateInvocations ( module
);
1898 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
, string_list
& clean_files
)
1900 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1901 module
.name
.c_str () );
1902 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1903 module
.name
.c_str () );
1904 const vector
<File
*>& files
= module
.non_if_data
.files
;
1905 for ( size_t i
= 0; i
< files
.size (); i
++ )
1907 File
& file
= *files
[i
];
1908 string extension
= GetExtension ( file
.name
);
1909 if ( extension
== ".rc" || extension
== ".RC" )
1911 string resource
= FixupTargetFilename ( file
.name
);
1912 fprintf ( fMakefile
, "\t$(ECHO_BIN2RES)\n" );
1913 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1914 resource
.c_str () );
1917 fprintf ( fMakefile
, "\n");
1921 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1923 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1924 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1925 string workingDirectory
= GetWorkingDirectory ( );
1926 string objectsMacro
= GetObjectsMacro ( module
);
1927 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1928 string libsMacro
= GetLibsMacro ( module
);
1930 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1932 if ( module
.non_if_data
.files
.size () > 0 )
1934 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1936 fprintf ( fMakefile
, "%s: %s %s\n",
1938 objectsMacro
.c_str (),
1939 linkDepsMacro
.c_str () );
1942 if ( IsCPlusPlusModule ( module
) )
1947 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1948 module
.entrypoint
.c_str (),
1949 module
.baseaddress
.c_str () );
1950 GenerateLinkerCommand ( module
,
1959 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1961 fprintf ( fMakefile
, "%s:\n\n",
1967 static MingwWin32CUIModuleHandler win32cui_handler
;
1969 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ()
1970 : MingwModuleHandler ( Win32CUI
)
1975 MingwWin32CUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1977 GeneratePreconditionDependencies ( module
);
1978 GenerateWin32CUIModuleTarget ( module
, clean_files
);
1979 GenerateInvocations ( module
);
1983 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1985 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1986 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1987 string workingDirectory
= GetWorkingDirectory ( );
1988 string objectsMacro
= GetObjectsMacro ( module
);
1989 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1990 string libsMacro
= GetLibsMacro ( module
);
1992 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1994 if ( module
.non_if_data
.files
.size () > 0 )
1996 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1998 fprintf ( fMakefile
, "%s: %s %s\n",
2000 objectsMacro
.c_str (),
2001 linkDepsMacro
.c_str () );
2004 if ( IsCPlusPlusModule ( module
) )
2009 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2010 module
.entrypoint
.c_str (),
2011 module
.baseaddress
.c_str () );
2012 GenerateLinkerCommand ( module
,
2021 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2023 fprintf ( fMakefile
, "%s:\n\n",
2029 static MingwWin32GUIModuleHandler win32gui_handler
;
2031 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
2032 : MingwModuleHandler ( Win32GUI
)
2037 MingwWin32GUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2039 GeneratePreconditionDependencies ( module
);
2040 GenerateWin32GUIModuleTarget ( module
, clean_files
);
2041 GenerateInvocations ( module
);
2045 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
2047 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2048 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2049 string workingDirectory
= GetWorkingDirectory ( );
2050 string objectsMacro
= GetObjectsMacro ( module
);
2051 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2052 string libsMacro
= GetLibsMacro ( module
);
2054 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
2056 if ( module
.non_if_data
.files
.size () > 0 )
2058 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
2060 fprintf ( fMakefile
, "%s: %s %s\n",
2062 objectsMacro
.c_str (),
2063 linkDepsMacro
.c_str () );
2066 if ( IsCPlusPlusModule ( module
) )
2071 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2072 module
.entrypoint
.c_str (),
2073 module
.baseaddress
.c_str () );
2074 GenerateLinkerCommand ( module
,
2083 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2085 fprintf ( fMakefile
, "%s:\n\n",
2091 static MingwBootLoaderModuleHandler bootloadermodule_handler
;
2093 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()
2094 : MingwModuleHandler ( BootLoader
)
2099 MingwBootLoaderModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2101 GeneratePreconditionDependencies ( module
);
2102 GenerateBootLoaderModuleTarget ( module
, clean_files
);
2103 GenerateInvocations ( module
);
2107 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget (
2108 const Module
& module
,
2109 string_list
& clean_files
)
2111 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2112 string
targetName ( module
.GetTargetName () );
2113 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2114 string workingDirectory
= GetWorkingDirectory ();
2115 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
2116 CLEAN_FILE ( junk_tmp
);
2117 string objectsMacro
= GetObjectsMacro ( module
);
2118 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2119 string libsMacro
= GetLibsMacro ( module
);
2121 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
2123 fprintf ( fMakefile
, "%s: %s %s\n",
2125 objectsMacro
.c_str (),
2126 linkDepsMacro
.c_str () );
2128 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2130 fprintf ( fMakefile
,
2131 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2132 GetLinkerMacro ( module
).c_str (),
2134 objectsMacro
.c_str (),
2135 linkDepsMacro
.c_str () );
2136 fprintf ( fMakefile
,
2137 "\t${objcopy} -O binary %s %s\n",
2140 fprintf ( fMakefile
,
2142 junk_tmp
.c_str () );
2146 static MingwBootSectorModuleHandler bootsectormodule_handler
;
2148 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ()
2149 : MingwModuleHandler ( BootSector
)
2154 MingwBootSectorModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2156 GeneratePreconditionDependencies ( module
);
2157 GenerateBootSectorModuleTarget ( module
, clean_files
);
2158 GenerateInvocations ( module
);
2162 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
, string_list
& clean_files
)
2164 string objectsMacro
= GetObjectsMacro ( module
);
2166 string
* nasmflags
= new string ( "-f bin" );
2167 GenerateMacrosAndTargetsTarget ( module
,
2172 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2173 module
.name
.c_str ());
2174 fprintf ( fMakefile
,
2176 module
.name
.c_str (),
2177 objectsMacro
.c_str () );
2181 static MingwIsoModuleHandler isomodule_handler
;
2183 MingwIsoModuleHandler::MingwIsoModuleHandler ()
2184 : MingwModuleHandler ( Iso
)
2189 MingwIsoModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2191 GeneratePreconditionDependencies ( module
);
2192 GenerateIsoModuleTarget ( module
, clean_files
);
2193 GenerateInvocations ( module
);
2197 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string bootcdDirectory
,
2198 const Module
& module
) const
2200 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2202 const Module
& m
= *module
.project
.modules
[i
];
2203 if ( m
.bootstrap
!= NULL
)
2205 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
2206 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2207 fprintf ( fMakefile
,
2209 m
.GetPath ().c_str (),
2210 targetFilename
.c_str () );
2216 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string bootcdDirectory
,
2217 const Module
& module
) const
2219 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2221 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2222 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2223 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2224 fprintf ( fMakefile
,
2226 cdfile
.GetPath ().c_str (),
2227 targetFilename
.c_str () );
2232 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string bootcdDirectory
,
2233 const Module
& module
) const
2236 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2238 const Module
& m
= *module
.project
.modules
[i
];
2239 if ( m
.bootstrap
!= NULL
)
2241 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2242 if ( directories
.size () > 0 )
2244 directories
+= FixupTargetFilename ( targetDirecctory
);
2251 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string bootcdDirectory
,
2252 const Module
& module
) const
2255 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2257 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2258 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2259 if ( directories
.size () > 0 )
2261 directories
+= FixupTargetFilename ( targetDirecctory
);
2267 MingwIsoModuleHandler::GetCdDirectories ( const string bootcdDirectory
,
2268 const Module
& module
) const
2270 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2272 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2278 MingwIsoModuleHandler::GetBootstrapCdFiles ( const string bootcdDirectory
,
2279 const Module
& module
) const
2282 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2284 const Module
& m
= *module
.project
.modules
[i
];
2285 if ( m
.bootstrap
!= NULL
)
2287 if ( cdfiles
.size () > 0 )
2289 cdfiles
+= FixupTargetFilename ( m
.GetPath () );
2296 MingwIsoModuleHandler::GetNonModuleCdFiles ( const string bootcdDirectory
,
2297 const Module
& module
) const
2300 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2302 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2303 if ( cdfiles
.size () > 0 )
2305 cdfiles
+= NormalizeFilename ( cdfile
.GetPath () );
2311 MingwIsoModuleHandler::GetCdFiles ( const string bootcdDirectory
,
2312 const Module
& module
) const
2314 string cdfiles
= GetBootstrapCdFiles ( bootcdDirectory
,
2316 cdfiles
+= " " + GetNonModuleCdFiles ( bootcdDirectory
,
2322 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
, string_list
& clean_files
)
2324 string bootcdDirectory
= "cd";
2325 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2326 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2327 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2328 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2329 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2330 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2331 string cdDirectories
= bootcdReactos
+ " " + GetCdDirectories ( bootcdDirectory
,
2333 string cdFiles
= GetCdFiles ( bootcdDirectory
,
2336 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2337 module
.name
.c_str ());
2338 fprintf ( fMakefile
,
2339 "%s: all %s %s %s\n",
2340 module
.name
.c_str (),
2342 cdDirectories
.c_str (),
2344 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2345 fprintf ( fMakefile
,
2346 "\t${cabman} -C %s -L %s -I\n",
2347 reactosDff
.c_str (),
2348 bootcdReactos
.c_str () );
2349 fprintf ( fMakefile
,
2350 "\t${cabman} -C %s -RC %s -L %s -N\n",
2351 reactosDff
.c_str (),
2352 reactosInf
.c_str (),
2353 bootcdReactos
.c_str () );
2354 fprintf ( fMakefile
,
2356 reactosInf
.c_str () );
2357 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2359 OutputCdfileCopyCommands ( bootcdDirectory
,
2361 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2362 fprintf ( fMakefile
,
2363 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2365 bootcdDirectory
.c_str () );
2366 fprintf ( fMakefile
,