4 #include "../../rbuild.h"
6 #include "modulehandler.h"
11 #define CLEAN_FILE(f) clean_files.push_back ( f ); /*if ( module.name == "crt" ) printf ( "%s(%i): clean: %s\n", __FILE__, __LINE__, f.c_str() )*/
14 MingwModuleHandler::fMakefile
= NULL
;
16 MingwModuleHandler::use_pch
= false;
19 ReplaceExtension ( const string
& filename
,
20 const string
& newExtension
)
22 size_t index
= filename
.find_last_of ( '/' );
23 if ( index
== string::npos
)
25 size_t index2
= filename
.find_last_of ( '\\' );
26 if ( index2
!= string::npos
&& index2
> index
)
28 string tmp
= filename
.substr( index
/*, filename.size() - index*/ );
29 size_t ext_index
= tmp
.find_last_of( '.' );
30 if ( ext_index
!= string::npos
)
31 return filename
.substr ( 0, index
+ ext_index
) + newExtension
;
32 return filename
+ newExtension
;
37 const string
& filename
,
38 const string
& prefix
)
40 if ( !prefix
.length() )
43 const char* pfilename
= filename
.c_str();
44 const char* p1
= strrchr ( pfilename
, '/' );
45 const char* p2
= strrchr ( pfilename
, '\\' );
50 out
+= string(pfilename
,p1
-pfilename
) + CSEP
;
53 out
+= prefix
+ pfilename
;
57 string
v2s ( const vector
<string
>& v
, int wrap_at
)
63 for ( size_t i
= 0; i
< v
.size(); i
++ )
67 if ( wrap_at
> 0 && wrap_count
++ == wrap_at
)
76 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype
,
77 MingwBackend
* backend_
)
78 : backend ( backend_
)
82 MingwModuleHandler::~MingwModuleHandler()
87 MingwModuleHandler::PassThruCacheDirectory ( const string
&file
)
89 backend
->CreateDirectoryTargetIfNotYetCreated ( GetDirectory ( file
) );
94 MingwModuleHandler::GetDirectoryDependency ( const string
& file
)
96 return backend
->GetDirectoryDependency ( GetDirectory ( file
) );
100 MingwModuleHandler::SetMakefile ( FILE* f
)
106 MingwModuleHandler::SetUsePch ( bool b
)
112 MingwModuleHandler::InstanciateHandler ( const string
& location
,
113 ModuleType moduletype
,
114 MingwBackend
* backend
)
116 MingwModuleHandler
* handler
;
117 switch ( moduletype
)
120 handler
= new MingwBuildToolModuleHandler ( backend
);
123 handler
= new MingwStaticLibraryModuleHandler ( backend
);
126 handler
= new MingwObjectLibraryModuleHandler ( backend
);
129 handler
= new MingwKernelModuleHandler ( backend
);
132 handler
= new MingwNativeCUIModuleHandler ( backend
);
135 handler
= new MingwWin32CUIModuleHandler ( backend
);
138 handler
= new MingwWin32GUIModuleHandler ( backend
);
141 handler
= new MingwKernelModeDLLModuleHandler ( backend
);
144 handler
= new MingwNativeDLLModuleHandler ( backend
);
147 handler
= new MingwWin32DLLModuleHandler ( backend
);
149 case KernelModeDriver
:
150 handler
= new MingwKernelModeDriverModuleHandler ( backend
);
153 handler
= new MingwBootLoaderModuleHandler ( backend
);
156 handler
= new MingwBootSectorModuleHandler ( backend
);
159 handler
= new MingwIsoModuleHandler ( backend
);
166 MingwModuleHandler::GetWorkingDirectory () const
172 MingwModuleHandler::GetBasename ( const string
& filename
) const
174 size_t index
= filename
.find_last_of ( '.' );
175 if ( index
!= string::npos
)
176 return filename
.substr ( 0, index
);
181 MingwModuleHandler::GetActualSourceFilename ( const string
& filename
) const
183 string extension
= GetExtension ( filename
);
184 if ( extension
== ".spec" || extension
== "SPEC" )
186 string basename
= GetBasename ( filename
);
187 return basename
+ ".stubs.c";
194 MingwModuleHandler::GetModuleArchiveFilename ( const Module
& module
) const
196 return ReplaceExtension ( FixupTargetFilename ( module
.GetPath () ),
201 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
203 string extension
= GetExtension ( file
.name
);
204 if ( extension
== ".spec" || extension
== "SPEC" )
211 MingwModuleHandler::GetImportLibraryDependency ( const Module
& importedModule
)
213 if ( importedModule
.type
== ObjectLibrary
)
214 return GetObjectsMacro ( importedModule
);
216 return PassThruCacheDirectory ( FixupTargetFilename ( importedModule
.GetDependencyPath () ) );
220 MingwModuleHandler::GetModuleDependencies ( const Module
& module
)
222 if ( module
.dependencies
.size () == 0 )
225 string
dependencies ( "" );
226 for ( size_t i
= 0; i
< module
.dependencies
.size (); i
++ )
228 if ( dependencies
.size () > 0 )
230 const Dependency
* dependency
= module
.dependencies
[i
];
231 const Module
* dependencyModule
= dependency
->dependencyModule
;
232 dependencies
+= dependencyModule
->GetTargets ();
234 string definitionDependencies
= GetDefinitionDependencies ( module
);
235 if ( dependencies
.length () > 0 && definitionDependencies
.length () > 0 )
236 dependencies
+= " " + definitionDependencies
;
237 else if ( definitionDependencies
.length () > 0 )
238 dependencies
= definitionDependencies
;
243 MingwModuleHandler::GetSourceFilenames ( const Module
& module
,
244 bool includeGeneratedFiles
) const
248 string
sourceFilenames ( "" );
249 const vector
<File
*>& files
= module
.non_if_data
.files
;
250 for ( i
= 0; i
< files
.size (); i
++ )
252 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *files
[i
] ) )
253 sourceFilenames
+= " " + GetActualSourceFilename ( files
[i
]->name
);
255 // intentionally make a copy so that we can append more work in
256 // the middle of processing without having to go recursive
257 vector
<If
*> v
= module
.non_if_data
.ifs
;
258 for ( i
= 0; i
< v
.size (); i
++ )
262 // check for sub-ifs to add to list
263 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
264 for ( j
= 0; j
< ifs
.size (); j
++ )
265 v
.push_back ( ifs
[j
] );
266 const vector
<File
*>& files
= rIf
.data
.files
;
267 for ( j
= 0; j
< files
.size (); j
++ )
269 File
& file
= *files
[j
];
270 if ( includeGeneratedFiles
|| !IsGeneratedFile ( file
) )
271 sourceFilenames
+= " " + GetActualSourceFilename ( file
.name
);
274 return sourceFilenames
;
278 MingwModuleHandler::GetSourceFilenames ( const Module
& module
) const
280 return GetSourceFilenames ( module
,
285 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module
& module
) const
287 return GetSourceFilenames ( module
,
292 GetObjectFilename ( const Module
& module
, const string
& sourceFilename
)
295 string extension
= GetExtension ( sourceFilename
);
296 if ( extension
== ".rc" || extension
== ".RC" )
297 newExtension
= ".coff";
298 else if ( extension
== ".spec" || extension
== ".SPEC" )
299 newExtension
= ".stubs.o";
302 return FixupTargetFilename (
304 PrefixFilename(sourceFilename
,module
.prefix
),
309 MingwModuleHandler::GenerateCleanTarget (
310 const Module
& module
,
311 const string_list
& clean_files
) const
313 if ( 0 == clean_files
.size() )
315 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
316 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
317 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
320 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
321 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
323 fprintf ( fMakefile
, " 2>$(NUL)\n" );
324 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
328 MingwModuleHandler::GetObjectFilenames ( const Module
& module
)
330 const vector
<File
*>& files
= module
.non_if_data
.files
;
331 if ( files
.size () == 0 )
334 string
objectFilenames ( "" );
335 for ( size_t i
= 0; i
< files
.size (); i
++ )
337 if ( objectFilenames
.size () > 0 )
338 objectFilenames
+= " ";
339 objectFilenames
+= PassThruCacheDirectory (
340 GetObjectFilename ( module
, files
[i
]->name
) );
342 return objectFilenames
;
346 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector
<Define
*>& defines
) const
349 for ( size_t i
= 0; i
< defines
.size (); i
++ )
351 Define
& define
= *defines
[i
];
352 if (parameters
.length () > 0)
355 parameters
+= define
.name
;
356 if (define
.value
.length () > 0)
359 parameters
+= define
.value
;
366 MingwModuleHandler::GenerateGccDefineParameters ( const Module
& module
) const
368 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
369 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
370 if ( s
.length () > 0 )
379 MingwModuleHandler::ConcatenatePaths ( const string
& path1
,
380 const string
& path2
) const
382 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
384 if ( path1
[path1
.length ()] == CSEP
)
385 return path1
+ path2
;
387 return path1
+ CSEP
+ path2
;
391 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
394 for ( size_t i
= 0; i
< includes
.size (); i
++ )
396 Include
& include
= *includes
[i
];
397 if ( parameters
.length () > 0 )
399 parameters
+= "-I" + include
.directory
;
405 MingwModuleHandler::GenerateGccIncludeParameters ( const Module
& module
) const
407 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
408 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
409 if ( s
.length () > 0 )
419 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
422 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
424 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
425 if ( parameters
.length () > 0 )
427 parameters
+= compilerFlag
.flag
;
433 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
436 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
438 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
439 if ( parameters
.length () > 0 )
441 parameters
+= linkerFlag
.flag
;
447 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
448 const vector
<Library
*>& libraries
)
450 string
dependencies ( "" );
452 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
454 if ( wrap_count
++ == 5 )
455 dependencies
+= " \\\n\t\t", wrap_count
= 0;
456 else if ( dependencies
.size () > 0 )
458 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->imported_module
);
464 MingwModuleHandler::GenerateLinkerParameters ( const Module
& module
) const
466 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
470 MingwModuleHandler::GenerateMacro (
471 const char* assignmentOperation
,
473 const IfableData
& data
,
474 const vector
<CompilerFlag
*>* compilerFlags
)
482 assignmentOperation
);
484 if ( compilerFlags
!= NULL
)
486 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
487 if ( compilerParameters
.size () > 0 )
492 compilerParameters
.c_str () );
496 for ( i
= 0; i
< data
.includes
.size(); i
++ )
501 data
.includes
[i
]->directory
.c_str() );
503 for ( i
= 0; i
< data
.defines
.size(); i
++ )
505 Define
& d
= *data
.defines
[i
];
510 if ( d
.value
.size() )
516 fprintf ( fMakefile
, "\n" );
520 MingwModuleHandler::GenerateMacros (
521 const Module
& module
,
522 const char* assignmentOperation
,
523 const IfableData
& data
,
524 const vector
<CompilerFlag
*>* compilerFlags
,
525 const vector
<LinkerFlag
*>* linkerFlags
,
526 const string
& cflags_macro
,
527 const string
& nasmflags_macro
,
528 const string
& windresflags_macro
,
529 const string
& linkerflags_macro
,
530 const string
& objs_macro
,
531 const string
& libs_macro
,
532 const string
& linkdeps_macro
)
536 if ( data
.includes
.size () > 0 || data
.defines
.size () > 0 )
538 GenerateMacro ( assignmentOperation
,
542 GenerateMacro ( assignmentOperation
,
548 if ( linkerFlags
!= NULL
)
550 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
551 if ( linkerParameters
.size () > 0 )
556 linkerflags_macro
.c_str (),
558 linkerParameters
.c_str() );
562 if ( data
.libraries
.size () > 0 )
564 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
565 if ( deps
.size () > 0 )
576 const vector
<File
*>& files
= data
.files
;
577 if ( files
.size () > 0 )
579 for ( i
= 0; i
< files
.size (); i
++ )
581 File
& file
= *files
[i
];
587 PassThruCacheDirectory (
588 GetObjectFilename ( module
, file
.name
) ).c_str (),
589 objs_macro
.c_str() );
596 assignmentOperation
);
597 for ( i
= 0; i
< files
.size(); i
++ )
599 File
& file
= *files
[i
];
605 ( i
%10 == 9 ? "\\\n\t" : " " ),
606 PassThruCacheDirectory (
607 GetObjectFilename ( module
, file
.name
) ).c_str () );
610 fprintf ( fMakefile
, "\n" );
613 const vector
<If
*>& ifs
= data
.ifs
;
614 for ( i
= 0; i
< ifs
.size(); i
++ )
617 if ( rIf
.data
.defines
.size()
618 || rIf
.data
.includes
.size()
619 || rIf
.data
.libraries
.size()
620 || rIf
.data
.files
.size()
621 || rIf
.data
.ifs
.size() )
625 "ifeq (\"$(%s)\",\"%s\")\n",
626 rIf
.property
.c_str(),
649 MingwModuleHandler::GenerateMacros (
650 const Module
& module
,
651 const string
& cflags_macro
,
652 const string
& nasmflags_macro
,
653 const string
& windresflags_macro
,
654 const string
& linkerflags_macro
,
655 const string
& objs_macro
,
656 const string
& libs_macro
,
657 const string
& linkdeps_macro
)
663 &module
.compilerFlags
,
673 if ( module
.importLibrary
)
676 const vector
<File
*>& files
= module
.non_if_data
.files
;
677 for ( size_t i
= 0; i
< files
.size (); i
++ )
679 File
& file
= *files
[i
];
680 string extension
= GetExtension ( file
.name
);
681 if ( extension
== ".spec" || extension
== ".SPEC" )
683 if ( s
.length () > 0 )
685 s
+= GetSpecObjectDependencies ( file
.name
);
688 if ( s
.length () > 0 )
693 linkdeps_macro
.c_str(),
700 "%s += $(PROJECT_CFLAGS)\n",
701 cflags_macro
.c_str () );
705 "%s += $(PROJECT_RCFLAGS)\n",
706 windresflags_macro
.c_str () );
710 "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
711 module
.name
.c_str () );
716 linkdeps_macro
.c_str (),
717 libs_macro
.c_str () );
719 fprintf ( fMakefile
, "\n" );
723 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
724 const string
& sourceFilename
,
726 const string
& cflagsMacro
)
728 string deps
= sourceFilename
;
729 if ( module
.pch
&& use_pch
)
730 deps
+= " " + module
.pch
->header
+ ".gch";
731 string objectFilename
= PassThruCacheDirectory (
732 GetObjectFilename ( module
, sourceFilename
) );
735 objectFilename
.c_str (),
736 GetDirectoryDependency ( objectFilename
).c_str (),
738 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
740 "\t%s -c %s -o %s %s\n",
742 sourceFilename
.c_str (),
743 objectFilename
.c_str (),
744 cflagsMacro
.c_str () );
748 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
749 const string
& sourceFilename
,
751 const string
& cflagsMacro
)
753 string objectFilename
= PassThruCacheDirectory (
754 GetObjectFilename ( module
, sourceFilename
) );
757 objectFilename
.c_str (),
758 GetDirectoryDependency ( objectFilename
).c_str (),
759 sourceFilename
.c_str () );
760 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
762 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
764 sourceFilename
.c_str (),
765 objectFilename
.c_str (),
766 cflagsMacro
.c_str () );
770 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
771 const string
& sourceFilename
,
772 const string
& nasmflagsMacro
)
774 string objectFilename
= PassThruCacheDirectory (
775 GetObjectFilename ( module
, sourceFilename
) );
778 objectFilename
.c_str (),
779 GetDirectoryDependency ( objectFilename
).c_str (),
780 sourceFilename
.c_str () );
781 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
783 "\t%s -f win32 %s -o %s %s\n",
785 sourceFilename
.c_str (),
786 objectFilename
.c_str (),
787 nasmflagsMacro
.c_str () );
791 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
792 const string
& sourceFilename
,
793 const string
& windresflagsMacro
)
795 string objectFilename
= PassThruCacheDirectory (
796 GetObjectFilename ( module
, sourceFilename
) );
797 string rciFilename
= ReplaceExtension ( sourceFilename
,
799 string resFilename
= ReplaceExtension ( sourceFilename
,
802 "%s: %s %s $(WRC_TARGET)\n",
803 objectFilename
.c_str (),
804 GetDirectoryDependency ( objectFilename
).c_str (),
805 sourceFilename
.c_str () );
806 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
808 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
809 windresflagsMacro
.c_str (),
810 sourceFilename
.c_str (),
811 rciFilename
.c_str () );
813 "\t${wrc} ${%s} %s %s\n",
814 windresflagsMacro
.c_str (),
815 rciFilename
.c_str (),
816 resFilename
.c_str () );
819 rciFilename
.c_str () );
821 "\t${windres} %s -o %s\n",
822 resFilename
.c_str (),
823 objectFilename
.c_str () );
826 resFilename
.c_str () );
830 MingwModuleHandler::GenerateWinebuildCommands (
831 const Module
& module
,
832 const string
& sourceFilename
,
833 string_list
& clean_files
) const
835 string basename
= GetBasename ( sourceFilename
);
837 string def_file
= basename
+ ".spec.def";
838 CLEAN_FILE ( def_file
);
840 string stub_file
= basename
+ ".stubs.c";
841 CLEAN_FILE ( stub_file
);
846 sourceFilename
.c_str () );
847 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
849 "\t%s --def=%s -o %s\n",
851 sourceFilename
.c_str (),
857 sourceFilename
.c_str () );
858 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
860 "\t%s --pedll=%s -o %s\n",
862 sourceFilename
.c_str (),
863 stub_file
.c_str () );
867 MingwModuleHandler::GenerateCommands (
868 const Module
& module
,
869 const string
& sourceFilename
,
872 const string
& cflagsMacro
,
873 const string
& nasmflagsMacro
,
874 const string
& windresflagsMacro
,
875 string_list
& clean_files
)
877 CLEAN_FILE ( GetObjectFilename(module
,sourceFilename
) );
878 string extension
= GetExtension ( sourceFilename
);
879 if ( extension
== ".c" || extension
== ".C" )
881 GenerateGccCommand ( module
,
887 else if ( extension
== ".cc" || extension
== ".CC" ||
888 extension
== ".cpp" || extension
== ".CPP" ||
889 extension
== ".cxx" || extension
== ".CXX" )
891 GenerateGccCommand ( module
,
897 else if ( extension
== ".s" || extension
== ".S" )
899 GenerateGccAssemblerCommand ( module
,
905 else if ( extension
== ".asm" || extension
== ".ASM" )
907 GenerateNasmCommand ( module
,
912 else if ( extension
== ".rc" || extension
== ".RC" )
914 GenerateWindresCommand ( module
,
919 else if ( extension
== ".spec" || extension
== ".SPEC" )
921 GenerateWinebuildCommands ( module
,
924 GenerateGccCommand ( module
,
925 GetActualSourceFilename ( sourceFilename
),
931 throw InvalidOperationException ( __FILE__
,
933 "Unsupported filename extension '%s' in file '%s'",
935 sourceFilename
.c_str () );
939 MingwModuleHandler::GenerateLinkerCommand (
940 const Module
& module
,
941 const string
& target
,
942 const string
& dependencies
,
943 const string
& linker
,
944 const string
& linkerParameters
,
945 const string
& objectsMacro
,
946 const string
& libsMacro
,
947 string_list
& clean_files
) const
950 "%s: %s ${RSYM_TARGET}\n",
952 dependencies
.c_str () );
953 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
954 string
targetName ( module
.GetTargetName () );
955 if ( module
.importLibrary
!= NULL
)
957 static string
ros_junk ( "$(ROS_TEMPORARY)" );
958 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
959 CLEAN_FILE ( base_tmp
);
960 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
961 CLEAN_FILE ( junk_tmp
);
962 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
963 CLEAN_FILE ( temp_exp
);
964 string def_file
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
967 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
969 linkerParameters
.c_str (),
972 objectsMacro
.c_str (),
974 GetLinkerMacro ( module
).c_str () );
980 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
982 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
994 "\t%s %s %s -o %s %s %s %s\n",
996 linkerParameters
.c_str (),
999 objectsMacro
.c_str (),
1001 GetLinkerMacro ( module
).c_str () );
1003 fprintf ( fMakefile
,
1005 temp_exp
.c_str () );
1009 fprintf ( fMakefile
,
1010 "\t%s %s -o %s %s %s %s\n",
1012 linkerParameters
.c_str (),
1014 objectsMacro
.c_str (),
1016 GetLinkerMacro ( module
).c_str () );
1019 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1020 fprintf ( fMakefile
,
1021 "\t${rsym} %s %s\n\n",
1027 MingwModuleHandler::GenerateObjectFileTargets (
1028 const Module
& module
,
1029 const IfableData
& data
,
1032 const string
& cflagsMacro
,
1033 const string
& nasmflagsMacro
,
1034 const string
& windresflagsMacro
,
1035 string_list
& clean_files
)
1039 const vector
<File
*>& files
= data
.files
;
1040 for ( i
= 0; i
< files
.size (); i
++ )
1042 string sourceFilename
= files
[i
]->name
;
1043 GenerateCommands ( module
,
1051 fprintf ( fMakefile
,
1055 const vector
<If
*>& ifs
= data
.ifs
;
1056 for ( i
= 0; i
< ifs
.size(); i
++ )
1058 GenerateObjectFileTargets ( module
,
1070 MingwModuleHandler::GenerateObjectFileTargets (
1071 const Module
& module
,
1074 const string
& cflagsMacro
,
1075 const string
& nasmflagsMacro
,
1076 const string
& windresflagsMacro
,
1077 string_list
& clean_files
)
1081 const string
& pch_file
= module
.pch
->header
;
1082 string gch_file
= pch_file
+ ".gch";
1083 CLEAN_FILE(gch_file
);
1091 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1094 "\t%s -o %s %s -g %s\n\n",
1095 ( module
.cplusplus
? cppc
.c_str() : cc
.c_str() ),
1097 cflagsMacro
.c_str(),
1102 GenerateObjectFileTargets ( module
,
1110 fprintf ( fMakefile
, "\n" );
1114 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
1116 const string
& objs_macro
) const
1118 string archiveFilename
= GetModuleArchiveFilename ( module
);
1120 fprintf ( fMakefile
,
1122 archiveFilename
.c_str (),
1123 objs_macro
.c_str ());
1125 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1127 fprintf ( fMakefile
,
1128 "\t%s -rc %s %s\n\n",
1130 archiveFilename
.c_str (),
1131 objs_macro
.c_str ());
1133 return archiveFilename
;
1137 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
1139 return ssprintf ( "$(%s_CFLAGS)",
1140 module
.name
.c_str () );
1144 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
1146 return ssprintf ( "$(%s_OBJS)",
1147 module
.name
.c_str () );
1151 MingwModuleHandler::GetLinkingDependenciesMacro ( const Module
& module
) const
1153 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1157 MingwModuleHandler::GetLibsMacro ( const Module
& module
) const
1159 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1163 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
1165 return ssprintf ( "$(%s_LFLAGS)",
1166 module
.name
.c_str () );
1170 MingwModuleHandler::GenerateMacrosAndTargets (
1171 const Module
& module
,
1172 const string
* cflags
,
1173 const string
* nasmflags
,
1174 string_list
& clean_files
)
1176 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1177 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1178 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1180 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1181 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1182 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1183 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1184 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1185 string libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1186 string linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1188 GenerateMacros ( module
,
1197 if ( cflags
!= NULL
)
1199 fprintf ( fMakefile
,
1201 cflagsMacro
.c_str (),
1205 if ( nasmflags
!= NULL
)
1207 fprintf ( fMakefile
,
1209 nasmflagsMacro
.c_str (),
1210 nasmflags
->c_str () );
1213 // generate phony target for module name
1214 fprintf ( fMakefile
, ".PHONY: %s\n",
1215 module
.name
.c_str () );
1216 fprintf ( fMakefile
, "%s: %s\n\n",
1217 module
.name
.c_str (),
1218 FixupTargetFilename ( module
.GetPath () ).c_str () );
1220 // future references to the macros will be to get their values
1221 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1222 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1223 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1225 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1226 GenerateObjectFileTargets ( module
,
1234 CLEAN_FILE ( ar_target
);
1235 string tgt
= FixupTargetFilename(module
.GetPath());
1236 if ( tgt
!= ar_target
)
1243 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
)
1245 string dependencies
;
1246 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1248 Invoke
& invoke
= *module
.invocations
[i
];
1249 if (invoke
.invokeModule
== &module
)
1250 /* Protect against circular dependencies */
1252 if ( dependencies
.length () > 0 )
1253 dependencies
+= " ";
1254 dependencies
+= invoke
.GetTargets ();
1256 return dependencies
;
1260 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1262 if ( module
.invocations
.size () == 0 )
1265 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1267 const Invoke
& invoke
= *module
.invocations
[i
];
1269 if ( invoke
.invokeModule
->type
!= BuildTool
)
1271 throw InvalidBuildFileException ( module
.node
.location
,
1272 "Only modules of type buildtool can be invoked." );
1275 string invokeTarget
= module
.GetInvocationTarget ( i
);
1276 fprintf ( fMakefile
,
1278 invokeTarget
.c_str () );
1279 fprintf ( fMakefile
,
1281 invokeTarget
.c_str (),
1282 invoke
.GetTargets ().c_str () );
1283 fprintf ( fMakefile
,
1285 invoke
.GetTargets ().c_str (),
1286 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1287 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1288 fprintf ( fMakefile
,
1290 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1291 invoke
.GetParameters ().c_str () );
1296 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1298 return module
.name
+ "_precondition";
1302 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1304 /* Avoid circular dependency */
1305 if ( module
.type
== BuildTool
1306 || module
.name
== "zlib"
1307 || module
.name
== "hostzlib" )
1314 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
)
1316 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1317 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1318 string dependencies
= GetDefaultDependencies ( module
);
1319 string s
= GetModuleDependencies ( module
);
1320 if ( s
.length () > 0 )
1322 if ( dependencies
.length () > 0 )
1323 dependencies
+= " ";
1327 s
= GetInvocationDependencies ( module
);
1328 if ( s
.length () > 0 )
1330 if ( dependencies
.length () > 0 )
1331 dependencies
+= " ";
1335 fprintf ( fMakefile
,
1337 preconditionDependenciesName
.c_str (),
1338 dependencies
.c_str () );
1339 const char* p
= sourceFilenames
.c_str();
1340 const char* end
= p
+ strlen(p
);
1343 const char* p2
= &p
[512];
1346 while ( p2
> p
&& !isspace(*p2
) )
1350 p2
= strpbrk ( p
, " \t" );
1354 fprintf ( fMakefile
,
1358 preconditionDependenciesName
.c_str ());
1360 p
+= strspn ( p
, " \t" );
1362 fprintf ( fMakefile
, "\n" );
1366 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded (
1367 const Module
& module
,
1368 string_list
& clean_files
)
1370 if ( module
.importLibrary
!= NULL
)
1372 string library_target
= PassThruCacheDirectory ( FixupTargetFilename ( module
.GetDependencyPath () ) ).c_str ();
1373 CLEAN_FILE ( library_target
);
1375 string definitionDependencies
= GetDefinitionDependencies ( module
);
1376 fprintf ( fMakefile
, "%s: %s %s\n",
1377 library_target
.c_str (),
1378 GetDirectoryDependency ( library_target
).c_str (),
1379 definitionDependencies
.c_str () );
1381 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1383 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1384 fprintf ( fMakefile
,
1385 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1386 module
.GetTargetName ().c_str (),
1387 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1388 library_target
.c_str (),
1394 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1396 string basename
= GetBasename ( filename
);
1397 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1401 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
)
1403 string dependencies
;
1404 string dkNkmLibNoFixup
= "dk/nkm/lib";
1405 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1406 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1407 const vector
<File
*>& files
= module
.non_if_data
.files
;
1408 for ( size_t i
= 0; i
< files
.size (); i
++ )
1410 File
& file
= *files
[i
];
1411 string extension
= GetExtension ( file
.name
);
1412 if ( extension
== ".spec" || extension
== ".SPEC" )
1414 if ( dependencies
.length () > 0 )
1415 dependencies
+= " ";
1416 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1419 return dependencies
;
1423 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
)
1425 return module
.cplusplus
;
1429 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( MingwBackend
* backend
)
1430 : MingwModuleHandler ( BuildTool
,
1436 MingwBuildToolModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1438 GeneratePreconditionDependencies ( module
);
1439 GenerateBuildToolModuleTarget ( module
, clean_files
);
1440 GenerateInvocations ( module
);
1444 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
, string_list
& clean_files
)
1446 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1447 string objectsMacro
= GetObjectsMacro ( module
);
1448 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1449 string libsMacro
= GetLibsMacro ( module
);
1451 GenerateMacrosAndTargets (
1458 if ( IsCPlusPlusModule ( module
) )
1459 linker
= "${host_gpp}";
1461 linker
= "${host_gcc}";
1463 fprintf ( fMakefile
, "%s: %s %s\n",
1465 objectsMacro
.c_str (),
1466 linkDepsMacro
.c_str () );
1467 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1468 fprintf ( fMakefile
,
1469 "\t%s %s -o %s %s %s\n\n",
1471 GetLinkerMacro ( module
).c_str (),
1473 objectsMacro
.c_str (),
1474 libsMacro
.c_str () );
1478 MingwKernelModuleHandler::MingwKernelModuleHandler ( MingwBackend
* backend
)
1479 : MingwModuleHandler ( Kernel
,
1485 MingwKernelModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1487 GeneratePreconditionDependencies ( module
);
1488 GenerateKernelModuleTarget ( module
, clean_files
);
1489 GenerateInvocations ( module
);
1493 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
, string_list
& clean_files
)
1495 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1496 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1497 string
target ( FixupTargetFilename (module
.GetPath ()) ); // i.e. "$(ROS_INT).\ntoskrnl\ntoskrnl.exe"
1498 string workingDirectory
= GetWorkingDirectory ();
1499 string objectsMacro
= GetObjectsMacro ( module
);
1500 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1501 string libsMacro
= GetLibsMacro ( module
);
1502 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1503 CLEAN_FILE ( base_tmp
);
1504 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1505 CLEAN_FILE ( junk_tmp
);
1506 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1507 CLEAN_FILE ( temp_exp
);
1508 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",
1509 module
.GetBasePath ().c_str (),
1510 module
.entrypoint
.c_str (),
1511 module
.baseaddress
.c_str () );
1513 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1515 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1517 fprintf ( fMakefile
, "%s: %s %s ${RSYM_TARGET}\n",
1519 objectsMacro
.c_str (),
1520 linkDepsMacro
.c_str () );
1521 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1522 fprintf ( fMakefile
,
1523 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1524 GetLinkerMacro ( module
).c_str (),
1525 gccOptions
.c_str (),
1528 objectsMacro
.c_str (),
1529 linkDepsMacro
.c_str () );
1530 fprintf ( fMakefile
,
1532 junk_tmp
.c_str () );
1533 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1534 fprintf ( fMakefile
,
1535 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1536 targetName
.c_str (),
1540 fprintf ( fMakefile
,
1542 base_tmp
.c_str () );
1543 fprintf ( fMakefile
,
1544 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1545 GetLinkerMacro ( module
).c_str (),
1546 gccOptions
.c_str (),
1549 objectsMacro
.c_str (),
1550 linkDepsMacro
.c_str () );
1551 fprintf ( fMakefile
,
1553 temp_exp
.c_str () );
1554 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1555 fprintf ( fMakefile
,
1556 "\t${rsym} %s %s\n\n",
1562 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ( MingwBackend
* backend
)
1563 : MingwModuleHandler ( StaticLibrary
,
1569 MingwStaticLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1571 GeneratePreconditionDependencies ( module
);
1572 GenerateStaticLibraryModuleTarget ( module
, clean_files
);
1573 GenerateInvocations ( module
);
1577 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1579 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1583 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ( MingwBackend
* backend
)
1584 : MingwModuleHandler ( ObjectLibrary
,
1590 MingwObjectLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1592 GeneratePreconditionDependencies ( module
);
1593 GenerateObjectLibraryModuleTarget ( module
, clean_files
);
1594 GenerateInvocations ( module
);
1598 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1600 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1604 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ( MingwBackend
* backend
)
1605 : MingwModuleHandler ( KernelModeDLL
,
1611 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1613 GeneratePreconditionDependencies ( module
);
1614 GenerateKernelModeDLLModuleTarget ( module
, clean_files
);
1615 GenerateInvocations ( module
);
1619 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget (
1620 const Module
& module
,
1621 string_list
& clean_files
)
1623 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1624 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1625 string workingDirectory
= GetWorkingDirectory ( );
1626 string objectsMacro
= GetObjectsMacro ( module
);
1627 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1628 string libsMacro
= GetLibsMacro ( module
);
1630 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1632 if ( module
.non_if_data
.files
.size () > 0 )
1634 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1636 string dependencies
=
1637 objectsMacro
+ " " + linkDepsMacro
;
1639 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1640 module
.entrypoint
.c_str (),
1641 module
.baseaddress
.c_str () );
1642 GenerateLinkerCommand ( module
,
1653 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1655 fprintf ( fMakefile
, "%s:\n",
1661 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ( MingwBackend
* backend
)
1662 : MingwModuleHandler ( KernelModeDriver
,
1668 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1670 GeneratePreconditionDependencies ( module
);
1671 GenerateKernelModeDriverModuleTarget ( module
, clean_files
);
1672 GenerateInvocations ( module
);
1677 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget (
1678 const Module
& module
,
1679 string_list
& clean_files
)
1681 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1682 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1683 string workingDirectory
= GetWorkingDirectory ();
1684 string objectsMacro
= GetObjectsMacro ( module
);
1685 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1686 string libsMacro
= GetLibsMacro ( module
);
1688 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1690 if ( module
.non_if_data
.files
.size () > 0 )
1692 string
cflags ( "-D__NTDRIVER__" );
1693 GenerateMacrosAndTargets ( module
,
1698 string dependencies
=
1699 objectsMacro
+ " " + linkDepsMacro
;
1701 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1702 module
.entrypoint
.c_str (),
1703 module
.baseaddress
.c_str () );
1704 GenerateLinkerCommand ( module
,
1715 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1717 fprintf ( fMakefile
, "%s:\n",
1723 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ( MingwBackend
* backend
)
1724 : MingwModuleHandler ( NativeDLL
,
1730 MingwNativeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1732 GeneratePreconditionDependencies ( module
);
1733 GenerateNativeDLLModuleTarget ( module
, clean_files
);
1734 GenerateInvocations ( module
);
1738 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1740 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1741 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1742 string workingDirectory
= GetWorkingDirectory ( );
1743 string objectsMacro
= GetObjectsMacro ( module
);
1744 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1745 string libsMacro
= GetLibsMacro ( module
);
1747 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1749 if ( module
.non_if_data
.files
.size () > 0 )
1751 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1753 string dependencies
=
1754 objectsMacro
+ " " + linkDepsMacro
;
1756 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1757 module
.entrypoint
.c_str (),
1758 module
.baseaddress
.c_str () );
1759 GenerateLinkerCommand ( module
,
1770 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1772 fprintf ( fMakefile
, "%s:\n\n",
1778 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ( MingwBackend
* backend
)
1779 : MingwModuleHandler ( NativeCUI
,
1785 MingwNativeCUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1787 GeneratePreconditionDependencies ( module
);
1788 GenerateNativeCUIModuleTarget ( module
, clean_files
);
1789 GenerateInvocations ( module
);
1793 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1795 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1796 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1797 string workingDirectory
= GetWorkingDirectory ( );
1798 string objectsMacro
= GetObjectsMacro ( module
);
1799 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1800 string libsMacro
= GetLibsMacro ( module
);
1802 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1804 if ( module
.non_if_data
.files
.size () > 0 )
1806 string
cflags ( "-D__NTAPP__" );
1807 GenerateMacrosAndTargets ( module
,
1812 string dependencies
=
1813 objectsMacro
+ " " + linkDepsMacro
;
1815 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1816 module
.entrypoint
.c_str (),
1817 module
.baseaddress
.c_str () );
1818 GenerateLinkerCommand ( module
,
1829 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1831 fprintf ( fMakefile
, "%s:\n\n",
1837 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ( MingwBackend
* backend
)
1838 : MingwModuleHandler ( Win32DLL
,
1844 MingwWin32DLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1846 GenerateExtractWineDLLResourcesTarget ( module
, clean_files
);
1847 GeneratePreconditionDependencies ( module
);
1848 GenerateWin32DLLModuleTarget ( module
, clean_files
);
1849 GenerateInvocations ( module
);
1853 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
, string_list
& clean_files
)
1855 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1856 module
.name
.c_str () );
1857 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1858 module
.name
.c_str () );
1859 const vector
<File
*>& files
= module
.non_if_data
.files
;
1860 for ( size_t i
= 0; i
< files
.size (); i
++ )
1862 File
& file
= *files
[i
];
1863 string extension
= GetExtension ( file
.name
);
1864 if ( extension
== ".rc" || extension
== ".RC" )
1866 string resource
= FixupTargetFilename ( file
.name
);
1867 fprintf ( fMakefile
, "\t$(ECHO_BIN2RES)\n" );
1868 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1869 resource
.c_str () );
1872 fprintf ( fMakefile
, "\n");
1876 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1878 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1879 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1880 string workingDirectory
= GetWorkingDirectory ( );
1881 string objectsMacro
= GetObjectsMacro ( module
);
1882 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1883 string libsMacro
= GetLibsMacro ( module
);
1885 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1887 if ( module
.non_if_data
.files
.size () > 0 )
1889 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1891 string dependencies
=
1892 objectsMacro
+ " " + linkDepsMacro
;
1895 if ( module
.cplusplus
)
1900 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1901 module
.entrypoint
.c_str (),
1902 module
.baseaddress
.c_str () );
1903 GenerateLinkerCommand ( module
,
1914 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1916 fprintf ( fMakefile
, "%s:\n\n",
1922 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ( MingwBackend
* backend
)
1923 : MingwModuleHandler ( Win32CUI
,
1929 MingwWin32CUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1931 GeneratePreconditionDependencies ( module
);
1932 GenerateWin32CUIModuleTarget ( module
, clean_files
);
1933 GenerateInvocations ( module
);
1937 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1939 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1940 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1941 string workingDirectory
= GetWorkingDirectory ( );
1942 string objectsMacro
= GetObjectsMacro ( module
);
1943 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1944 string libsMacro
= GetLibsMacro ( module
);
1946 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1948 if ( module
.non_if_data
.files
.size () > 0 )
1950 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1952 string dependencies
=
1953 objectsMacro
+ " " + linkDepsMacro
;
1956 if ( module
.cplusplus
)
1961 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1962 module
.entrypoint
.c_str (),
1963 module
.baseaddress
.c_str () );
1964 GenerateLinkerCommand ( module
,
1975 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1977 fprintf ( fMakefile
, "%s:\n\n",
1983 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ( MingwBackend
* backend
)
1984 : MingwModuleHandler ( Win32GUI
,
1990 MingwWin32GUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1992 GeneratePreconditionDependencies ( module
);
1993 GenerateWin32GUIModuleTarget ( module
, clean_files
);
1994 GenerateInvocations ( module
);
1998 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
2000 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2001 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2002 string workingDirectory
= GetWorkingDirectory ( );
2003 string objectsMacro
= GetObjectsMacro ( module
);
2004 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2005 string libsMacro
= GetLibsMacro ( module
);
2007 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
2009 if ( module
.non_if_data
.files
.size () > 0 )
2011 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
2013 string dependencies
=
2014 objectsMacro
+ " " + linkDepsMacro
;
2017 if ( module
.cplusplus
)
2022 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2023 module
.entrypoint
.c_str (),
2024 module
.baseaddress
.c_str () );
2025 GenerateLinkerCommand ( module
,
2036 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2038 fprintf ( fMakefile
, "%s:\n\n",
2044 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ( MingwBackend
* backend
)
2045 : MingwModuleHandler ( BootLoader
,
2051 MingwBootLoaderModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2053 GeneratePreconditionDependencies ( module
);
2054 GenerateBootLoaderModuleTarget ( module
, clean_files
);
2055 GenerateInvocations ( module
);
2059 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget (
2060 const Module
& module
,
2061 string_list
& clean_files
)
2063 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2064 string
targetName ( module
.GetTargetName () );
2065 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2066 string workingDirectory
= GetWorkingDirectory ();
2067 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
2068 CLEAN_FILE ( junk_tmp
);
2069 string objectsMacro
= GetObjectsMacro ( module
);
2070 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2071 string libsMacro
= GetLibsMacro ( module
);
2073 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
2075 fprintf ( fMakefile
, "%s: %s %s\n",
2077 objectsMacro
.c_str (),
2078 linkDepsMacro
.c_str () );
2080 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2082 fprintf ( fMakefile
,
2083 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2084 GetLinkerMacro ( module
).c_str (),
2086 objectsMacro
.c_str (),
2087 linkDepsMacro
.c_str () );
2088 fprintf ( fMakefile
,
2089 "\t${objcopy} -O binary %s %s\n",
2092 fprintf ( fMakefile
,
2094 junk_tmp
.c_str () );
2098 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ( MingwBackend
* backend
)
2099 : MingwModuleHandler ( BootSector
,
2105 MingwBootSectorModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2107 GeneratePreconditionDependencies ( module
);
2108 GenerateBootSectorModuleTarget ( module
, clean_files
);
2109 GenerateInvocations ( module
);
2113 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
, string_list
& clean_files
)
2115 string objectsMacro
= GetObjectsMacro ( module
);
2117 string
* nasmflags
= new string ( "-f bin" );
2118 GenerateMacrosAndTargets ( module
,
2123 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2124 module
.name
.c_str ());
2125 fprintf ( fMakefile
,
2127 module
.name
.c_str (),
2128 objectsMacro
.c_str () );
2132 MingwIsoModuleHandler::MingwIsoModuleHandler ( MingwBackend
* backend
)
2133 : MingwModuleHandler ( Iso
,
2139 MingwIsoModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2141 GeneratePreconditionDependencies ( module
);
2142 GenerateIsoModuleTarget ( module
, clean_files
);
2143 GenerateInvocations ( module
);
2147 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string
& bootcdDirectory
,
2148 const Module
& module
)
2150 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2152 const Module
& m
= *module
.project
.modules
[i
];
2153 if ( m
.bootstrap
!= NULL
)
2155 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
2156 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2157 fprintf ( fMakefile
,
2159 m
.GetPath ().c_str (),
2160 targetFilename
.c_str () );
2166 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string
& bootcdDirectory
,
2167 const Module
& module
)
2169 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2171 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2172 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2173 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2174 fprintf ( fMakefile
,
2176 cdfile
.GetPath ().c_str (),
2177 targetFilename
.c_str () );
2182 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
,
2183 const Module
& module
)
2186 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2188 const Module
& m
= *module
.project
.modules
[i
];
2189 if ( m
.bootstrap
!= NULL
)
2191 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2192 if ( directories
.size () > 0 )
2194 directories
+= GetDirectoryDependency ( PassThruCacheDirectory ( FixupTargetFilename ( targetDirecctory
) ) );
2201 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
,
2202 const Module
& module
)
2205 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2207 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2208 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2209 if ( directories
.size () > 0 )
2211 directories
+= GetDirectoryDependency ( PassThruCacheDirectory ( FixupTargetFilename ( targetDirecctory
) ) );
2217 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
,
2218 const Module
& module
)
2220 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2222 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2228 MingwIsoModuleHandler::GetBootstrapCdFiles (
2229 vector
<string
>& out
,
2230 const Module
& module
) const
2232 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2234 const Module
& m
= *module
.project
.modules
[i
];
2235 if ( m
.bootstrap
!= NULL
)
2236 out
.push_back ( FixupTargetFilename ( m
.GetPath () ) );
2241 MingwIsoModuleHandler::GetNonModuleCdFiles (
2242 vector
<string
>& out
,
2243 const Module
& module
) const
2245 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2247 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2248 out
.push_back ( NormalizeFilename ( cdfile
.GetPath () ) );
2253 MingwIsoModuleHandler::GetCdFiles (
2254 vector
<string
>& out
,
2255 const Module
& module
) const
2257 GetBootstrapCdFiles ( out
, module
);
2258 GetNonModuleCdFiles ( out
, module
);
2262 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
, string_list
& clean_files
)
2264 string bootcdDirectory
= "cd";
2265 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2266 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2267 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2268 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2269 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2270 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2271 string cdDirectories
= GetCdDirectories ( bootcdDirectory
,
2273 vector
<string
> vCdFiles
;
2274 GetCdFiles ( vCdFiles
, module
);
2275 string cdFiles
= v2s ( vCdFiles
, 5 );
2277 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2278 module
.name
.c_str ());
2279 fprintf ( fMakefile
,
2280 "%s: all %s %s %s %s ${CABMAN_TARGET} ${CDMAKE_TARGET}\n",
2281 module
.name
.c_str (),
2283 GetDirectoryDependency ( PassThruCacheDirectory ( bootcdReactos
) ).c_str (),
2284 cdDirectories
.c_str (),
2286 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2287 fprintf ( fMakefile
,
2288 "\t${cabman} -C %s -L %s -I\n",
2289 reactosDff
.c_str (),
2290 bootcdReactos
.c_str () );
2291 fprintf ( fMakefile
,
2292 "\t${cabman} -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2293 reactosDff
.c_str (),
2294 reactosInf
.c_str (),
2295 bootcdReactos
.c_str ());
2296 fprintf ( fMakefile
,
2298 reactosInf
.c_str () );
2299 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2301 OutputCdfileCopyCommands ( bootcdDirectory
,
2303 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2304 fprintf ( fMakefile
,
2305 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2307 bootcdDirectory
.c_str () );
2308 fprintf ( fMakefile
,