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$(HALFVERBOSEECHO) [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$(HALFVERBOSEECHO) [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$(HALFVERBOSEECHO) [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$(HALFVERBOSEECHO) [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$(HALFVERBOSEECHO) [WINEBLD] $@\n" );
834 "\t%s --def=%s -o %s\n",
836 sourceFilename
.c_str (),
842 sourceFilename
.c_str () );
843 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [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$(HALFVERBOSEECHO) [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$(HALFVERBOSEECHO) [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
1059 if ( module
.pch
&& use_pch
)
1061 const string
& pch_file
= module
.pch
->header
;
1062 string gch_file
= pch_file
+ ".gch";
1063 CLEAN_FILE(gch_file
);
1069 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [PCH] $@\n" );
1072 "\t%s -c %s -o %s %s\n\n",
1076 cflagsMacro
.c_str() );
1079 GenerateObjectFileTargets ( module
,
1087 fprintf ( fMakefile
, "\n" );
1091 MingwModuleHandler::GetCleanTargets (
1093 const IfableData
& data
) const
1097 const vector
<File
*>& files
= data
.files
;
1098 for ( i
= 0; i
< files
.size(); i
++ )
1099 out
.push_back ( PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( files
[i
]->name
) ) );
1101 const vector
<If
*>& ifs
= data
.ifs
;
1102 for ( i
= 0; i
< ifs
.size(); i
++ )
1103 GetCleanTargets ( out
, ifs
[i
]->data
);
1107 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
1109 const string
& objs_macro
) const
1111 string archiveFilename
= GetModuleArchiveFilename ( module
);
1113 fprintf ( fMakefile
,
1115 archiveFilename
.c_str (),
1116 objs_macro
.c_str ());
1118 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [AR] $@\n" );
1120 fprintf ( fMakefile
,
1121 "\t%s -rc %s %s\n\n",
1123 archiveFilename
.c_str (),
1124 objs_macro
.c_str ());
1126 return archiveFilename
;
1130 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
1132 return ssprintf ( "$(%s_CFLAGS)",
1133 module
.name
.c_str () );
1137 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
1139 return ssprintf ( "$(%s_OBJS)",
1140 module
.name
.c_str () );
1144 MingwModuleHandler::GetLinkingDependenciesMacro ( const Module
& module
) const
1146 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1150 MingwModuleHandler::GetLibsMacro ( const Module
& module
) const
1152 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1156 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
1158 return ssprintf ( "$(%s_LFLAGS)",
1159 module
.name
.c_str () );
1163 MingwModuleHandler::GenerateMacrosAndTargets (
1164 const Module
& module
,
1168 const string
* cflags
,
1169 const string
* nasmflags
,
1170 string_list
& clean_files
) const
1172 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1173 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1174 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1175 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1176 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1177 string libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1178 string linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1180 GenerateMacros ( module
,
1189 if ( cflags
!= NULL
)
1191 fprintf ( fMakefile
,
1193 cflagsMacro
.c_str (),
1197 if ( nasmflags
!= NULL
)
1199 fprintf ( fMakefile
,
1201 nasmflagsMacro
.c_str (),
1202 nasmflags
->c_str () );
1205 // generate phony target for module name
1206 fprintf ( fMakefile
, ".PHONY: %s\n",
1207 module
.name
.c_str () );
1208 fprintf ( fMakefile
, "%s: %s\n\n",
1209 module
.name
.c_str (),
1210 FixupTargetFilename ( module
.GetPath () ).c_str () );
1212 // future references to the macros will be to get their values
1213 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1214 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1215 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1217 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1218 GenerateObjectFileTargets ( module
,
1226 CLEAN_FILE ( ar_target
);
1227 string tgt
= FixupTargetFilename(module
.GetPath());
1228 if ( tgt
!= ar_target
)
1235 MingwModuleHandler::GenerateMacrosAndTargetsHost (
1236 const Module
& module
,
1237 string_list
& clean_files
) const
1239 GenerateMacrosAndTargets (
1250 MingwModuleHandler::GenerateMacrosAndTargetsTarget (
1251 const Module
& module
,
1252 string_list
& clean_files
) const
1254 GenerateMacrosAndTargetsTarget (
1262 MingwModuleHandler::GenerateMacrosAndTargetsTarget (
1263 const Module
& module
,
1264 const string
* cflags
,
1265 const string
* nasmflags
,
1266 string_list
& clean_files
) const
1268 GenerateMacrosAndTargets (
1279 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
1281 string dependencies
;
1282 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1284 Invoke
& invoke
= *module
.invocations
[i
];
1285 if (invoke
.invokeModule
== &module
)
1286 /* Protect against circular dependencies */
1288 if ( dependencies
.length () > 0 )
1289 dependencies
+= " ";
1290 dependencies
+= invoke
.GetTargets ();
1292 return dependencies
;
1296 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1298 if ( module
.invocations
.size () == 0 )
1301 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1303 const Invoke
& invoke
= *module
.invocations
[i
];
1305 if ( invoke
.invokeModule
->type
!= BuildTool
)
1307 throw InvalidBuildFileException ( module
.node
.location
,
1308 "Only modules of type buildtool can be invoked." );
1311 string invokeTarget
= module
.GetInvocationTarget ( i
);
1312 fprintf ( fMakefile
,
1314 invokeTarget
.c_str () );
1315 fprintf ( fMakefile
,
1317 invokeTarget
.c_str (),
1318 invoke
.GetTargets ().c_str () );
1319 fprintf ( fMakefile
,
1321 invoke
.GetTargets ().c_str (),
1322 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1323 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [INVOKE] $<\n" );
1324 fprintf ( fMakefile
,
1326 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1327 invoke
.GetParameters ().c_str () );
1332 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1334 return ssprintf ( "%s_precondition",
1335 module
.name
.c_str () );
1339 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1341 /* Avoid circular dependency */
1342 if ( module
.type
== BuildTool
|| module
.name
== "zlib" )
1343 return "$(ROS_INTERMEDIATE)." SSEP
"tools $(ROS_INTERMEDIATE)." SSEP
"lib" SSEP
"zlib";
1349 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
1351 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1352 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1353 string dependencies
= GetDefaultDependencies ( module
);
1354 string s
= GetModuleDependencies ( module
);
1355 if ( s
.length () > 0 )
1357 if ( dependencies
.length () > 0 )
1358 dependencies
+= " ";
1362 s
= GetInvocationDependencies ( module
);
1363 if ( s
.length () > 0 )
1365 if ( dependencies
.length () > 0 )
1366 dependencies
+= " ";
1370 fprintf ( fMakefile
,
1372 preconditionDependenciesName
.c_str () );
1373 fprintf ( fMakefile
,
1375 preconditionDependenciesName
.c_str (),
1376 dependencies
.c_str () );
1377 const char* p
= sourceFilenames
.c_str();
1378 const char* end
= p
+ strlen(p
);
1381 const char* p2
= &p
[512];
1384 while ( p2
> p
&& !isspace(*p2
) )
1388 p2
= strpbrk ( p
, " \t" );
1392 fprintf ( fMakefile
,
1396 preconditionDependenciesName
.c_str ());
1398 p
+= strspn ( p
, " \t" );
1400 fprintf ( fMakefile
, "\n" );
1404 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded (
1405 const Module
& module
,
1406 string_list
& clean_files
) const
1408 if ( module
.importLibrary
!= NULL
)
1410 string library_target
= FixupTargetFilename( module
.GetDependencyPath () ).c_str ();
1411 CLEAN_FILE ( library_target
);
1413 string definitionDependencies
= GetDefinitionDependencies ( module
);
1414 fprintf ( fMakefile
, "%s: %s\n",
1415 library_target
.c_str (),
1416 definitionDependencies
.c_str () );
1418 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [DLLTOOL] $@\n" );
1420 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1421 fprintf ( fMakefile
,
1422 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1423 module
.GetTargetName ().c_str (),
1424 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1425 library_target
.c_str (),
1431 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1433 string basename
= GetBasename ( filename
);
1434 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1438 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
) const
1440 string dependencies
;
1441 string dkNkmLibNoFixup
= "dk/nkm/lib";
1442 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1443 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1444 const vector
<File
*>& files
= module
.non_if_data
.files
;
1445 for ( size_t i
= 0; i
< files
.size (); i
++ )
1447 File
& file
= *files
[i
];
1448 string extension
= GetExtension ( file
.name
);
1449 if ( extension
== ".spec" || extension
== ".SPEC" )
1451 if ( dependencies
.length () > 0 )
1452 dependencies
+= " ";
1453 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1456 return dependencies
;
1459 // TODO FIXME - check for C++ extensions when parsing XML, and set a
1460 // bool in the Module class
1462 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
) const
1464 if ( module
.HasFileWithExtension ( module
.non_if_data
, ".cc" ) )
1466 if ( module
.HasFileWithExtension ( module
.non_if_data
, ".cxx" ) )
1468 if ( module
.HasFileWithExtension ( module
.non_if_data
, ".cpp" ) )
1474 static MingwBuildToolModuleHandler buildtool_handler
;
1476 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1477 : MingwModuleHandler ( BuildTool
)
1482 MingwBuildToolModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1484 GeneratePreconditionDependencies ( module
);
1485 GenerateBuildToolModuleTarget ( module
, clean_files
);
1486 GenerateInvocations ( module
);
1490 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
, string_list
& clean_files
)
1492 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1493 string objectsMacro
= GetObjectsMacro ( module
);
1494 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1495 string libsMacro
= GetLibsMacro ( module
);
1497 GenerateMacrosAndTargetsHost ( module
, clean_files
);
1500 if ( IsCPlusPlusModule ( module
) )
1501 linker
= "${host_gpp}";
1503 linker
= "${host_gcc}";
1505 fprintf ( fMakefile
, "%s: %s %s\n",
1507 objectsMacro
.c_str (),
1508 linkDepsMacro
.c_str () );
1509 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [LD] $@\n" );
1510 fprintf ( fMakefile
,
1511 "\t%s %s -o %s %s %s\n\n",
1513 GetLinkerMacro ( module
).c_str (),
1515 objectsMacro
.c_str (),
1516 libsMacro
.c_str () );
1520 static MingwKernelModuleHandler kernelmodule_handler
;
1522 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1523 : MingwModuleHandler ( Kernel
)
1528 MingwKernelModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1530 GeneratePreconditionDependencies ( module
);
1531 GenerateKernelModuleTarget ( module
, clean_files
);
1532 GenerateInvocations ( module
);
1536 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
, string_list
& clean_files
)
1538 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1539 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1540 string
target ( FixupTargetFilename (module
.GetPath ()) ); // i.e. "$(ROS_INT).\ntoskrnl\ntoskrnl.exe"
1541 string workingDirectory
= GetWorkingDirectory ();
1542 string objectsMacro
= GetObjectsMacro ( module
);
1543 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1544 string libsMacro
= GetLibsMacro ( module
);
1545 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1546 CLEAN_FILE ( base_tmp
);
1547 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1548 CLEAN_FILE ( junk_tmp
);
1549 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1550 CLEAN_FILE ( temp_exp
);
1551 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",
1552 module
.GetBasePath ().c_str (),
1553 module
.entrypoint
.c_str (),
1554 module
.baseaddress
.c_str () );
1556 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1558 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1560 fprintf ( fMakefile
, "%s: %s %s\n",
1562 objectsMacro
.c_str (),
1563 linkDepsMacro
.c_str () );
1564 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [LD] $@\n" );
1565 fprintf ( fMakefile
,
1566 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1567 GetLinkerMacro ( module
).c_str (),
1568 gccOptions
.c_str (),
1571 objectsMacro
.c_str (),
1572 linkDepsMacro
.c_str () );
1573 fprintf ( fMakefile
,
1575 junk_tmp
.c_str () );
1576 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1577 fprintf ( fMakefile
,
1578 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1579 targetName
.c_str (),
1583 fprintf ( fMakefile
,
1585 base_tmp
.c_str () );
1586 fprintf ( fMakefile
,
1587 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1588 GetLinkerMacro ( module
).c_str (),
1589 gccOptions
.c_str (),
1592 objectsMacro
.c_str (),
1593 linkDepsMacro
.c_str () );
1594 fprintf ( fMakefile
,
1596 temp_exp
.c_str () );
1597 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [RSYM] $@\n" );
1598 fprintf ( fMakefile
,
1599 "\t${rsym} %s %s\n\n",
1605 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1607 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1608 : MingwModuleHandler ( StaticLibrary
)
1613 MingwStaticLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1615 GeneratePreconditionDependencies ( module
);
1616 GenerateStaticLibraryModuleTarget ( module
, clean_files
);
1617 GenerateInvocations ( module
);
1621 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1623 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1627 static MingwObjectLibraryModuleHandler objectlibrary_handler
;
1629 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()
1630 : MingwModuleHandler ( ObjectLibrary
)
1635 MingwObjectLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1637 GeneratePreconditionDependencies ( module
);
1638 GenerateObjectLibraryModuleTarget ( module
, clean_files
);
1639 GenerateInvocations ( module
);
1643 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1645 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1649 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1651 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1652 : MingwModuleHandler ( KernelModeDLL
)
1657 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1659 GeneratePreconditionDependencies ( module
);
1660 GenerateKernelModeDLLModuleTarget ( module
, clean_files
);
1661 GenerateInvocations ( module
);
1665 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget (
1666 const Module
& module
,
1667 string_list
& clean_files
)
1669 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1670 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1671 string workingDirectory
= GetWorkingDirectory ( );
1672 string objectsMacro
= GetObjectsMacro ( module
);
1673 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1674 string libsMacro
= GetLibsMacro ( module
);
1676 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1678 if ( module
.non_if_data
.files
.size () > 0 )
1680 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1682 fprintf ( fMakefile
, "%s: %s %s\n",
1684 objectsMacro
.c_str (),
1685 linkDepsMacro
.c_str () );
1687 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1688 module
.entrypoint
.c_str (),
1689 module
.baseaddress
.c_str () );
1690 GenerateLinkerCommand ( module
,
1699 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1701 fprintf ( fMakefile
, "%s:\n",
1707 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1709 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1710 : MingwModuleHandler ( KernelModeDriver
)
1715 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1717 GeneratePreconditionDependencies ( module
);
1718 GenerateKernelModeDriverModuleTarget ( module
, clean_files
);
1719 GenerateInvocations ( module
);
1724 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget (
1725 const Module
& module
,
1726 string_list
& clean_files
)
1728 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1729 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1730 string workingDirectory
= GetWorkingDirectory ();
1731 string objectsMacro
= GetObjectsMacro ( module
);
1732 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1733 string libsMacro
= GetLibsMacro ( module
);
1735 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1737 if ( module
.non_if_data
.files
.size () > 0 )
1739 string
cflags ( "-D__NTDRIVER__" );
1740 GenerateMacrosAndTargetsTarget ( module
,
1745 fprintf ( fMakefile
, "%s: %s %s\n",
1747 objectsMacro
.c_str (),
1748 linkDepsMacro
.c_str () );
1750 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1751 module
.entrypoint
.c_str (),
1752 module
.baseaddress
.c_str () );
1753 GenerateLinkerCommand ( module
,
1762 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1764 fprintf ( fMakefile
, "%s:\n",
1770 static MingwNativeDLLModuleHandler nativedll_handler
;
1772 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1773 : MingwModuleHandler ( NativeDLL
)
1778 MingwNativeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1780 GeneratePreconditionDependencies ( module
);
1781 GenerateNativeDLLModuleTarget ( module
, clean_files
);
1782 GenerateInvocations ( module
);
1786 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1788 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1789 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1790 string workingDirectory
= GetWorkingDirectory ( );
1791 string objectsMacro
= GetObjectsMacro ( module
);
1792 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1793 string libsMacro
= GetLibsMacro ( module
);
1795 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1797 if ( module
.non_if_data
.files
.size () > 0 )
1799 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1801 fprintf ( fMakefile
, "%s: %s %s\n",
1803 objectsMacro
.c_str (),
1804 linkDepsMacro
.c_str () );
1806 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1807 module
.entrypoint
.c_str (),
1808 module
.baseaddress
.c_str () );
1809 GenerateLinkerCommand ( module
,
1818 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1820 fprintf ( fMakefile
, "%s:\n\n",
1826 static MingwNativeCUIModuleHandler nativecui_handler
;
1828 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ()
1829 : MingwModuleHandler ( NativeCUI
)
1834 MingwNativeCUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1836 GeneratePreconditionDependencies ( module
);
1837 GenerateNativeCUIModuleTarget ( module
, clean_files
);
1838 GenerateInvocations ( module
);
1842 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1844 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1845 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1846 string workingDirectory
= GetWorkingDirectory ( );
1847 string objectsMacro
= GetObjectsMacro ( module
);
1848 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1849 string libsMacro
= GetLibsMacro ( module
);
1851 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1853 if ( module
.non_if_data
.files
.size () > 0 )
1855 string
cflags ( "-D__NTAPP__" );
1856 GenerateMacrosAndTargetsTarget ( module
,
1861 fprintf ( fMakefile
, "%s: %s %s\n",
1863 objectsMacro
.c_str (),
1864 linkDepsMacro
.c_str () );
1866 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1867 module
.entrypoint
.c_str (),
1868 module
.baseaddress
.c_str () );
1869 GenerateLinkerCommand ( module
,
1878 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1880 fprintf ( fMakefile
, "%s:\n\n",
1886 static MingwWin32DLLModuleHandler win32dll_handler
;
1888 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1889 : MingwModuleHandler ( Win32DLL
)
1894 MingwWin32DLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1896 GenerateExtractWineDLLResourcesTarget ( module
, clean_files
);
1897 GeneratePreconditionDependencies ( module
);
1898 GenerateWin32DLLModuleTarget ( module
, clean_files
);
1899 GenerateInvocations ( module
);
1903 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
, string_list
& clean_files
)
1905 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1906 module
.name
.c_str () );
1907 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1908 module
.name
.c_str () );
1909 const vector
<File
*>& files
= module
.non_if_data
.files
;
1910 for ( size_t i
= 0; i
< files
.size (); i
++ )
1912 File
& file
= *files
[i
];
1913 string extension
= GetExtension ( file
.name
);
1914 if ( extension
== ".rc" || extension
== ".RC" )
1916 string resource
= FixupTargetFilename ( file
.name
);
1917 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [BIN2RES] $<\n" );
1918 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1919 resource
.c_str () );
1922 fprintf ( fMakefile
, "\n");
1926 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1928 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1929 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1930 string workingDirectory
= GetWorkingDirectory ( );
1931 string objectsMacro
= GetObjectsMacro ( module
);
1932 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1933 string libsMacro
= GetLibsMacro ( module
);
1935 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1937 if ( module
.non_if_data
.files
.size () > 0 )
1939 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
1941 fprintf ( fMakefile
, "%s: %s %s\n",
1943 objectsMacro
.c_str (),
1944 linkDepsMacro
.c_str () );
1947 if ( IsCPlusPlusModule ( module
) )
1952 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1953 module
.entrypoint
.c_str (),
1954 module
.baseaddress
.c_str () );
1955 GenerateLinkerCommand ( module
,
1964 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1966 fprintf ( fMakefile
, "%s:\n\n",
1972 static MingwWin32CUIModuleHandler win32cui_handler
;
1974 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ()
1975 : MingwModuleHandler ( Win32CUI
)
1980 MingwWin32CUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1982 GeneratePreconditionDependencies ( module
);
1983 GenerateWin32CUIModuleTarget ( module
, clean_files
);
1984 GenerateInvocations ( module
);
1988 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1990 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1991 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1992 string workingDirectory
= GetWorkingDirectory ( );
1993 string objectsMacro
= GetObjectsMacro ( module
);
1994 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1995 string libsMacro
= GetLibsMacro ( module
);
1997 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1999 if ( module
.non_if_data
.files
.size () > 0 )
2001 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
2003 fprintf ( fMakefile
, "%s: %s %s\n",
2005 objectsMacro
.c_str (),
2006 linkDepsMacro
.c_str () );
2009 if ( IsCPlusPlusModule ( module
) )
2014 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2015 module
.entrypoint
.c_str (),
2016 module
.baseaddress
.c_str () );
2017 GenerateLinkerCommand ( module
,
2026 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2028 fprintf ( fMakefile
, "%s:\n\n",
2034 static MingwWin32GUIModuleHandler win32gui_handler
;
2036 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
2037 : MingwModuleHandler ( Win32GUI
)
2042 MingwWin32GUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2044 GeneratePreconditionDependencies ( module
);
2045 GenerateWin32GUIModuleTarget ( module
, clean_files
);
2046 GenerateInvocations ( module
);
2050 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
2052 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2053 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2054 string workingDirectory
= GetWorkingDirectory ( );
2055 string objectsMacro
= GetObjectsMacro ( module
);
2056 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2057 string libsMacro
= GetLibsMacro ( module
);
2059 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
2061 if ( module
.non_if_data
.files
.size () > 0 )
2063 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
2065 fprintf ( fMakefile
, "%s: %s %s\n",
2067 objectsMacro
.c_str (),
2068 linkDepsMacro
.c_str () );
2071 if ( IsCPlusPlusModule ( module
) )
2076 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2077 module
.entrypoint
.c_str (),
2078 module
.baseaddress
.c_str () );
2079 GenerateLinkerCommand ( module
,
2088 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2090 fprintf ( fMakefile
, "%s:\n\n",
2096 static MingwBootLoaderModuleHandler bootloadermodule_handler
;
2098 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()
2099 : MingwModuleHandler ( BootLoader
)
2104 MingwBootLoaderModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2106 GeneratePreconditionDependencies ( module
);
2107 GenerateBootLoaderModuleTarget ( module
, clean_files
);
2108 GenerateInvocations ( module
);
2112 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget (
2113 const Module
& module
,
2114 string_list
& clean_files
)
2116 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2117 string
targetName ( module
.GetTargetName () );
2118 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2119 string workingDirectory
= GetWorkingDirectory ();
2120 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
2121 CLEAN_FILE ( junk_tmp
);
2122 string objectsMacro
= GetObjectsMacro ( module
);
2123 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2124 string libsMacro
= GetLibsMacro ( module
);
2126 GenerateMacrosAndTargetsTarget ( module
, clean_files
);
2128 fprintf ( fMakefile
, "%s: %s %s\n",
2130 objectsMacro
.c_str (),
2131 linkDepsMacro
.c_str () );
2133 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [LD] $@\n" );
2135 fprintf ( fMakefile
,
2136 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2137 GetLinkerMacro ( module
).c_str (),
2139 objectsMacro
.c_str (),
2140 linkDepsMacro
.c_str () );
2141 fprintf ( fMakefile
,
2142 "\t${objcopy} -O binary %s %s\n",
2145 fprintf ( fMakefile
,
2147 junk_tmp
.c_str () );
2151 static MingwBootSectorModuleHandler bootsectormodule_handler
;
2153 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ()
2154 : MingwModuleHandler ( BootSector
)
2159 MingwBootSectorModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2161 GeneratePreconditionDependencies ( module
);
2162 GenerateBootSectorModuleTarget ( module
, clean_files
);
2163 GenerateInvocations ( module
);
2167 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
, string_list
& clean_files
)
2169 string objectsMacro
= GetObjectsMacro ( module
);
2171 string
* nasmflags
= new string ( "-f bin" );
2172 GenerateMacrosAndTargetsTarget ( module
,
2177 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2178 module
.name
.c_str ());
2179 fprintf ( fMakefile
,
2181 module
.name
.c_str (),
2182 objectsMacro
.c_str () );
2186 static MingwIsoModuleHandler isomodule_handler
;
2188 MingwIsoModuleHandler::MingwIsoModuleHandler ()
2189 : MingwModuleHandler ( Iso
)
2194 MingwIsoModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2196 GeneratePreconditionDependencies ( module
);
2197 GenerateIsoModuleTarget ( module
, clean_files
);
2198 GenerateInvocations ( module
);
2202 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string bootcdDirectory
,
2203 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 targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
2211 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2212 fprintf ( fMakefile
,
2214 m
.GetPath ().c_str (),
2215 targetFilename
.c_str () );
2221 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string bootcdDirectory
,
2222 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 targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2228 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2229 fprintf ( fMakefile
,
2231 cdfile
.GetPath ().c_str (),
2232 targetFilename
.c_str () );
2237 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string bootcdDirectory
,
2238 const Module
& module
) const
2241 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2243 const Module
& m
= *module
.project
.modules
[i
];
2244 if ( m
.bootstrap
!= NULL
)
2246 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2247 if ( directories
.size () > 0 )
2249 directories
+= FixupTargetFilename ( targetDirecctory
);
2256 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string bootcdDirectory
,
2257 const Module
& module
) const
2260 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2262 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2263 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2264 if ( directories
.size () > 0 )
2266 directories
+= FixupTargetFilename ( targetDirecctory
);
2272 MingwIsoModuleHandler::GetCdDirectories ( const string bootcdDirectory
,
2273 const Module
& module
) const
2275 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2277 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2283 MingwIsoModuleHandler::GetBootstrapCdFiles ( const string bootcdDirectory
,
2284 const Module
& module
) const
2287 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2289 const Module
& m
= *module
.project
.modules
[i
];
2290 if ( m
.bootstrap
!= NULL
)
2292 if ( cdfiles
.size () > 0 )
2294 cdfiles
+= FixupTargetFilename ( m
.GetPath () );
2301 MingwIsoModuleHandler::GetNonModuleCdFiles ( const string bootcdDirectory
,
2302 const Module
& module
) const
2305 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2307 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2308 if ( cdfiles
.size () > 0 )
2310 cdfiles
+= NormalizeFilename ( cdfile
.GetPath () );
2316 MingwIsoModuleHandler::GetCdFiles ( const string bootcdDirectory
,
2317 const Module
& module
) const
2319 string cdfiles
= GetBootstrapCdFiles ( bootcdDirectory
,
2321 cdfiles
+= " " + GetNonModuleCdFiles ( bootcdDirectory
,
2327 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
, string_list
& clean_files
)
2329 string bootcdDirectory
= "cd";
2330 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2331 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2332 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2333 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2334 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2335 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2336 string cdDirectories
= bootcdReactos
+ " " + GetCdDirectories ( bootcdDirectory
,
2338 string cdFiles
= GetCdFiles ( bootcdDirectory
,
2341 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2342 module
.name
.c_str ());
2343 fprintf ( fMakefile
,
2344 "%s: all %s %s %s\n",
2345 module
.name
.c_str (),
2347 cdDirectories
.c_str (),
2349 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [CABMAN] $<\n" );
2350 fprintf ( fMakefile
,
2351 "\t${cabman} -C %s -L %s -I\n",
2352 reactosDff
.c_str (),
2353 bootcdReactos
.c_str () );
2354 fprintf ( fMakefile
,
2355 "\t${cabman} -C %s -RC %s -L %s -N\n",
2356 reactosDff
.c_str (),
2357 reactosInf
.c_str (),
2358 bootcdReactos
.c_str () );
2359 fprintf ( fMakefile
,
2361 reactosInf
.c_str () );
2362 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2364 OutputCdfileCopyCommands ( bootcdDirectory
,
2366 fprintf ( fMakefile
, "\t$(HALFVERBOSEECHO) [CDMAKE] $@\n" );
2367 fprintf ( fMakefile
,
2368 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2370 bootcdDirectory
.c_str () );
2371 fprintf ( fMakefile
,