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::SetMakefile ( FILE* f
)
100 MingwModuleHandler::SetUsePch ( bool b
)
106 MingwModuleHandler::InstanciateHandler ( const string
& location
,
107 ModuleType moduletype
,
108 MingwBackend
* backend
)
110 MingwModuleHandler
* handler
;
111 switch ( moduletype
)
114 handler
= new MingwBuildToolModuleHandler ( backend
);
117 handler
= new MingwStaticLibraryModuleHandler ( backend
);
120 handler
= new MingwObjectLibraryModuleHandler ( backend
);
123 handler
= new MingwKernelModuleHandler ( backend
);
126 handler
= new MingwNativeCUIModuleHandler ( backend
);
129 handler
= new MingwWin32CUIModuleHandler ( backend
);
132 handler
= new MingwWin32GUIModuleHandler ( backend
);
135 handler
= new MingwKernelModeDLLModuleHandler ( backend
);
138 handler
= new MingwNativeDLLModuleHandler ( backend
);
141 handler
= new MingwWin32DLLModuleHandler ( backend
);
143 case KernelModeDriver
:
144 handler
= new MingwKernelModeDriverModuleHandler ( backend
);
147 handler
= new MingwBootLoaderModuleHandler ( backend
);
150 handler
= new MingwBootSectorModuleHandler ( backend
);
153 handler
= new MingwIsoModuleHandler ( backend
);
160 MingwModuleHandler::GetWorkingDirectory () const
166 MingwModuleHandler::GetBasename ( const string
& filename
) const
168 size_t index
= filename
.find_last_of ( '.' );
169 if ( index
!= string::npos
)
170 return filename
.substr ( 0, index
);
175 MingwModuleHandler::GetActualSourceFilename ( const string
& filename
) const
177 string extension
= GetExtension ( filename
);
178 if ( extension
== ".spec" || extension
== "SPEC" )
180 string basename
= GetBasename ( filename
);
181 return basename
+ ".stubs.c";
188 MingwModuleHandler::GetModuleArchiveFilename ( const Module
& module
) const
190 return ReplaceExtension ( FixupTargetFilename ( module
.GetPath () ),
195 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
197 string extension
= GetExtension ( file
.name
);
198 if ( extension
== ".spec" || extension
== "SPEC" )
205 MingwModuleHandler::GetImportLibraryDependency ( const Module
& importedModule
)
207 if ( importedModule
.type
== ObjectLibrary
)
208 return GetObjectsMacro ( importedModule
);
210 return PassThruCacheDirectory ( FixupTargetFilename ( importedModule
.GetDependencyPath () ) );
214 MingwModuleHandler::GetModuleDependencies ( const Module
& module
)
216 if ( module
.dependencies
.size () == 0 )
219 string
dependencies ( "" );
220 for ( size_t i
= 0; i
< module
.dependencies
.size (); i
++ )
222 if ( dependencies
.size () > 0 )
224 const Dependency
* dependency
= module
.dependencies
[i
];
225 const Module
* dependencyModule
= dependency
->dependencyModule
;
226 dependencies
+= dependencyModule
->GetTargets ();
228 string definitionDependencies
= GetDefinitionDependencies ( module
);
229 if ( dependencies
.length () > 0 && definitionDependencies
.length () > 0 )
230 dependencies
+= " " + definitionDependencies
;
231 else if ( definitionDependencies
.length () > 0 )
232 dependencies
= definitionDependencies
;
237 MingwModuleHandler::GetSourceFilenames ( const Module
& module
,
238 bool includeGeneratedFiles
) const
242 string
sourceFilenames ( "" );
243 const vector
<File
*>& files
= module
.non_if_data
.files
;
244 for ( i
= 0; i
< files
.size (); i
++ )
246 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *files
[i
] ) )
247 sourceFilenames
+= " " + GetActualSourceFilename ( files
[i
]->name
);
249 // intentionally make a copy so that we can append more work in
250 // the middle of processing without having to go recursive
251 vector
<If
*> v
= module
.non_if_data
.ifs
;
252 for ( i
= 0; i
< v
.size (); i
++ )
256 // check for sub-ifs to add to list
257 const vector
<If
*>& ifs
= rIf
.data
.ifs
;
258 for ( j
= 0; j
< ifs
.size (); j
++ )
259 v
.push_back ( ifs
[j
] );
260 const vector
<File
*>& files
= rIf
.data
.files
;
261 for ( j
= 0; j
< files
.size (); j
++ )
263 File
& file
= *files
[j
];
264 if ( includeGeneratedFiles
|| !IsGeneratedFile ( file
) )
265 sourceFilenames
+= " " + GetActualSourceFilename ( file
.name
);
268 return sourceFilenames
;
272 MingwModuleHandler::GetSourceFilenames ( const Module
& module
) const
274 return GetSourceFilenames ( module
,
279 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module
& module
) const
281 return GetSourceFilenames ( module
,
286 GetObjectFilename ( const Module
& module
, const string
& sourceFilename
)
289 string extension
= GetExtension ( sourceFilename
);
290 if ( extension
== ".rc" || extension
== ".RC" )
291 newExtension
= ".coff";
292 else if ( extension
== ".spec" || extension
== ".SPEC" )
293 newExtension
= ".stubs.o";
296 return FixupTargetFilename (
298 PrefixFilename(sourceFilename
,module
.prefix
),
303 MingwModuleHandler::GenerateCleanTarget (
304 const Module
& module
,
305 const string_list
& clean_files
) const
307 if ( 0 == clean_files
.size() )
309 fprintf ( fMakefile
, ".PHONY: %s_clean\n", module
.name
.c_str() );
310 fprintf ( fMakefile
, "%s_clean:\n\t-@$(rm)", module
.name
.c_str() );
311 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
314 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
315 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
317 fprintf ( fMakefile
, " 2>$(NUL)\n" );
318 fprintf ( fMakefile
, "clean: %s_clean\n\n", module
.name
.c_str() );
322 MingwModuleHandler::GetObjectFilenames ( const Module
& module
)
324 const vector
<File
*>& files
= module
.non_if_data
.files
;
325 if ( files
.size () == 0 )
328 string
objectFilenames ( "" );
329 for ( size_t i
= 0; i
< files
.size (); i
++ )
331 if ( objectFilenames
.size () > 0 )
332 objectFilenames
+= " ";
333 objectFilenames
+= PassThruCacheDirectory (
334 GetObjectFilename ( module
, files
[i
]->name
) );
336 return objectFilenames
;
340 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector
<Define
*>& defines
) const
343 for ( size_t i
= 0; i
< defines
.size (); i
++ )
345 Define
& define
= *defines
[i
];
346 if (parameters
.length () > 0)
349 parameters
+= define
.name
;
350 if (define
.value
.length () > 0)
353 parameters
+= define
.value
;
360 MingwModuleHandler::GenerateGccDefineParameters ( const Module
& module
) const
362 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.non_if_data
.defines
);
363 string s
= GenerateGccDefineParametersFromVector ( module
.non_if_data
.defines
);
364 if ( s
.length () > 0 )
373 MingwModuleHandler::ConcatenatePaths ( const string
& path1
,
374 const string
& path2
) const
376 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
378 if ( path1
[path1
.length ()] == CSEP
)
379 return path1
+ path2
;
381 return path1
+ CSEP
+ path2
;
385 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
388 for ( size_t i
= 0; i
< includes
.size (); i
++ )
390 Include
& include
= *includes
[i
];
391 if ( parameters
.length () > 0 )
393 parameters
+= "-I" + include
.directory
;
399 MingwModuleHandler::GenerateGccIncludeParameters ( const Module
& module
) const
401 string parameters
= GenerateGccIncludeParametersFromVector ( module
.non_if_data
.includes
);
402 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.non_if_data
.includes
);
403 if ( s
.length () > 0 )
413 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
416 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
418 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
419 if ( parameters
.length () > 0 )
421 parameters
+= compilerFlag
.flag
;
427 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
430 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
432 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
433 if ( parameters
.length () > 0 )
435 parameters
+= linkerFlag
.flag
;
441 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
442 const vector
<Library
*>& libraries
)
444 string
dependencies ( "" );
446 for ( size_t i
= 0; i
< libraries
.size (); i
++ )
448 if ( wrap_count
++ == 5 )
449 dependencies
+= " \\\n\t\t", wrap_count
= 0;
450 else if ( dependencies
.size () > 0 )
452 dependencies
+= GetImportLibraryDependency ( *libraries
[i
]->imported_module
);
458 MingwModuleHandler::GenerateLinkerParameters ( const Module
& module
) const
460 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
464 MingwModuleHandler::GenerateMacro (
465 const char* assignmentOperation
,
467 const IfableData
& data
,
468 const vector
<CompilerFlag
*>* compilerFlags
)
476 assignmentOperation
);
478 if ( compilerFlags
!= NULL
)
480 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
481 if ( compilerParameters
.size () > 0 )
486 compilerParameters
.c_str () );
490 for ( i
= 0; i
< data
.includes
.size(); i
++ )
495 data
.includes
[i
]->directory
.c_str() );
497 for ( i
= 0; i
< data
.defines
.size(); i
++ )
499 Define
& d
= *data
.defines
[i
];
504 if ( d
.value
.size() )
510 fprintf ( fMakefile
, "\n" );
514 MingwModuleHandler::GenerateMacros (
515 const Module
& module
,
516 const char* assignmentOperation
,
517 const IfableData
& data
,
518 const vector
<CompilerFlag
*>* compilerFlags
,
519 const vector
<LinkerFlag
*>* linkerFlags
,
520 const string
& cflags_macro
,
521 const string
& nasmflags_macro
,
522 const string
& windresflags_macro
,
523 const string
& linkerflags_macro
,
524 const string
& objs_macro
,
525 const string
& libs_macro
,
526 const string
& linkdeps_macro
)
530 if ( data
.includes
.size () > 0 || data
.defines
.size () > 0 )
532 GenerateMacro ( assignmentOperation
,
536 GenerateMacro ( assignmentOperation
,
542 if ( linkerFlags
!= NULL
)
544 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
545 if ( linkerParameters
.size () > 0 )
550 linkerflags_macro
.c_str (),
552 linkerParameters
.c_str() );
556 if ( data
.libraries
.size () > 0 )
558 string deps
= GenerateImportLibraryDependenciesFromVector ( data
.libraries
);
559 if ( deps
.size () > 0 )
570 const vector
<File
*>& files
= data
.files
;
571 if ( files
.size () > 0 )
573 for ( i
= 0; i
< files
.size (); i
++ )
575 File
& file
= *files
[i
];
581 PassThruCacheDirectory (
582 GetObjectFilename ( module
, file
.name
) ).c_str (),
583 objs_macro
.c_str() );
590 assignmentOperation
);
591 for ( i
= 0; i
< files
.size(); i
++ )
593 File
& file
= *files
[i
];
599 ( i
%10 == 9 ? "\\\n\t" : " " ),
600 PassThruCacheDirectory (
601 GetObjectFilename ( module
, file
.name
) ).c_str () );
604 fprintf ( fMakefile
, "\n" );
607 const vector
<If
*>& ifs
= data
.ifs
;
608 for ( i
= 0; i
< ifs
.size(); i
++ )
611 if ( rIf
.data
.defines
.size()
612 || rIf
.data
.includes
.size()
613 || rIf
.data
.libraries
.size()
614 || rIf
.data
.files
.size()
615 || rIf
.data
.ifs
.size() )
619 "ifeq (\"$(%s)\",\"%s\")\n",
620 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
)
657 &module
.compilerFlags
,
667 if ( module
.importLibrary
)
670 const vector
<File
*>& files
= module
.non_if_data
.files
;
671 for ( size_t i
= 0; i
< files
.size (); i
++ )
673 File
& file
= *files
[i
];
674 string extension
= GetExtension ( file
.name
);
675 if ( extension
== ".spec" || extension
== ".SPEC" )
677 if ( s
.length () > 0 )
679 s
+= GetSpecObjectDependencies ( file
.name
);
682 if ( s
.length () > 0 )
687 linkdeps_macro
.c_str(),
694 "%s += $(PROJECT_CFLAGS)\n",
695 cflags_macro
.c_str () );
699 "%s += $(PROJECT_RCFLAGS)\n",
700 windresflags_macro
.c_str () );
704 "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
705 module
.name
.c_str () );
710 linkdeps_macro
.c_str (),
711 libs_macro
.c_str () );
713 fprintf ( fMakefile
, "\n" );
717 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
718 const string
& sourceFilename
,
720 const string
& cflagsMacro
)
722 string deps
= sourceFilename
;
723 if ( module
.pch
&& use_pch
)
724 deps
+= " " + module
.pch
->header
+ ".gch";
725 string objectFilename
= PassThruCacheDirectory (
726 GetObjectFilename ( module
, sourceFilename
) );
729 objectFilename
.c_str (),
731 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
733 "\t%s -c %s -o %s %s\n",
735 sourceFilename
.c_str (),
736 objectFilename
.c_str (),
737 cflagsMacro
.c_str () );
741 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
742 const string
& sourceFilename
,
744 const string
& cflagsMacro
)
746 string objectFilename
= PassThruCacheDirectory (
747 GetObjectFilename ( module
, sourceFilename
) );
750 objectFilename
.c_str (),
751 objectFilename
.c_str (),
752 sourceFilename
.c_str () );
753 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
755 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
757 sourceFilename
.c_str (),
758 objectFilename
.c_str (),
759 cflagsMacro
.c_str () );
763 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
764 const string
& sourceFilename
,
765 const string
& nasmflagsMacro
)
767 string objectFilename
= PassThruCacheDirectory (
768 GetObjectFilename ( module
, sourceFilename
) );
771 objectFilename
.c_str (),
772 objectFilename
.c_str (),
773 sourceFilename
.c_str () );
774 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
776 "\t%s -f win32 %s -o %s %s\n",
778 sourceFilename
.c_str (),
779 objectFilename
.c_str (),
780 nasmflagsMacro
.c_str () );
784 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
785 const string
& sourceFilename
,
786 const string
& windresflagsMacro
)
788 string objectFilename
= PassThruCacheDirectory (
789 GetObjectFilename ( module
, sourceFilename
) );
790 string rciFilename
= ReplaceExtension ( sourceFilename
,
792 string resFilename
= ReplaceExtension ( sourceFilename
,
795 "%s: %s %s $(WRC_TARGET)\n",
796 objectFilename
.c_str (),
797 objectFilename
.c_str (),
798 sourceFilename
.c_str () );
799 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
801 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
802 windresflagsMacro
.c_str (),
803 sourceFilename
.c_str (),
804 rciFilename
.c_str () );
806 "\t${wrc} ${%s} %s %s\n",
807 windresflagsMacro
.c_str (),
808 rciFilename
.c_str (),
809 resFilename
.c_str () );
812 rciFilename
.c_str () );
814 "\t${windres} %s -o %s\n",
815 resFilename
.c_str (),
816 objectFilename
.c_str () );
819 resFilename
.c_str () );
823 MingwModuleHandler::GenerateWinebuildCommands (
824 const Module
& module
,
825 const string
& sourceFilename
,
826 string_list
& clean_files
) const
828 string basename
= GetBasename ( sourceFilename
);
830 string def_file
= basename
+ ".spec.def";
831 CLEAN_FILE ( def_file
);
833 string stub_file
= basename
+ ".stubs.c";
834 CLEAN_FILE ( stub_file
);
837 "%s: %s $(WINEBUILD_TARGET)\n",
839 sourceFilename
.c_str () );
840 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
842 "\t%s --def=%s -o %s\n",
844 sourceFilename
.c_str (),
850 sourceFilename
.c_str () );
851 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
853 "\t%s --pedll=%s -o %s\n",
855 sourceFilename
.c_str (),
856 stub_file
.c_str () );
860 MingwModuleHandler::GenerateCommands (
861 const Module
& module
,
862 const string
& sourceFilename
,
865 const string
& cflagsMacro
,
866 const string
& nasmflagsMacro
,
867 const string
& windresflagsMacro
,
868 string_list
& clean_files
)
870 CLEAN_FILE ( GetObjectFilename(module
,sourceFilename
) );
871 string extension
= GetExtension ( sourceFilename
);
872 if ( extension
== ".c" || extension
== ".C" )
874 GenerateGccCommand ( module
,
880 else if ( extension
== ".cc" || extension
== ".CC" ||
881 extension
== ".cpp" || extension
== ".CPP" ||
882 extension
== ".cxx" || extension
== ".CXX" )
884 GenerateGccCommand ( module
,
890 else if ( extension
== ".s" || extension
== ".S" )
892 GenerateGccAssemblerCommand ( module
,
898 else if ( extension
== ".asm" || extension
== ".ASM" )
900 GenerateNasmCommand ( module
,
905 else if ( extension
== ".rc" || extension
== ".RC" )
907 GenerateWindresCommand ( module
,
912 else if ( extension
== ".spec" || extension
== ".SPEC" )
914 GenerateWinebuildCommands ( module
,
917 GenerateGccCommand ( module
,
918 GetActualSourceFilename ( sourceFilename
),
924 throw InvalidOperationException ( __FILE__
,
926 "Unsupported filename extension '%s' in file '%s'",
928 sourceFilename
.c_str () );
932 MingwModuleHandler::GenerateLinkerCommand (
933 const Module
& module
,
934 const string
& target
,
935 const string
& dependencies
,
936 const string
& linker
,
937 const string
& linkerParameters
,
938 const string
& objectsMacro
,
939 const string
& libsMacro
,
940 string_list
& clean_files
) const
943 "%s: %s ${RSYM_TARGET}\n",
945 dependencies
.c_str () );
946 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
947 string
targetName ( module
.GetTargetName () );
948 if ( module
.importLibrary
!= NULL
)
950 static string
ros_junk ( "$(ROS_TEMPORARY)" );
951 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
952 CLEAN_FILE ( base_tmp
);
953 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
954 CLEAN_FILE ( junk_tmp
);
955 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
956 CLEAN_FILE ( temp_exp
);
957 string def_file
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
960 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
962 linkerParameters
.c_str (),
965 objectsMacro
.c_str (),
967 GetLinkerMacro ( module
).c_str () );
973 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
975 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
987 "\t%s %s %s -o %s %s %s %s\n",
989 linkerParameters
.c_str (),
992 objectsMacro
.c_str (),
994 GetLinkerMacro ( module
).c_str () );
1002 fprintf ( fMakefile
,
1003 "\t%s %s -o %s %s %s %s\n",
1005 linkerParameters
.c_str (),
1007 objectsMacro
.c_str (),
1009 GetLinkerMacro ( module
).c_str () );
1012 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1013 fprintf ( fMakefile
,
1014 "\t${rsym} %s %s\n\n",
1020 MingwModuleHandler::GenerateObjectFileTargets (
1021 const Module
& module
,
1022 const IfableData
& data
,
1025 const string
& cflagsMacro
,
1026 const string
& nasmflagsMacro
,
1027 const string
& windresflagsMacro
,
1028 string_list
& clean_files
)
1032 const vector
<File
*>& files
= data
.files
;
1033 for ( i
= 0; i
< files
.size (); i
++ )
1035 string sourceFilename
= files
[i
]->name
;
1036 GenerateCommands ( module
,
1044 fprintf ( fMakefile
,
1048 const vector
<If
*>& ifs
= data
.ifs
;
1049 for ( i
= 0; i
< ifs
.size(); i
++ )
1051 GenerateObjectFileTargets ( module
,
1063 MingwModuleHandler::GenerateObjectFileTargets (
1064 const Module
& module
,
1067 const string
& cflagsMacro
,
1068 const string
& nasmflagsMacro
,
1069 const string
& windresflagsMacro
,
1070 string_list
& clean_files
)
1074 const string
& pch_file
= module
.pch
->header
;
1075 string gch_file
= pch_file
+ ".gch";
1076 CLEAN_FILE(gch_file
);
1084 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1087 "\t%s -o %s %s -g %s\n\n",
1088 ( module
.cplusplus
? cppc
.c_str() : cc
.c_str() ),
1090 cflagsMacro
.c_str(),
1095 GenerateObjectFileTargets ( module
,
1103 fprintf ( fMakefile
, "\n" );
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$(ECHO_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
,
1165 const string
* cflags
,
1166 const string
* nasmflags
,
1167 string_list
& clean_files
)
1169 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1170 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1171 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1173 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1174 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1175 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1176 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1177 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1178 string libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1179 string linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1181 GenerateMacros ( module
,
1190 if ( cflags
!= NULL
)
1192 fprintf ( fMakefile
,
1194 cflagsMacro
.c_str (),
1198 if ( nasmflags
!= NULL
)
1200 fprintf ( fMakefile
,
1202 nasmflagsMacro
.c_str (),
1203 nasmflags
->c_str () );
1206 // generate phony target for module name
1207 fprintf ( fMakefile
, ".PHONY: %s\n",
1208 module
.name
.c_str () );
1209 fprintf ( fMakefile
, "%s: %s\n\n",
1210 module
.name
.c_str (),
1211 FixupTargetFilename ( module
.GetPath () ).c_str () );
1213 // future references to the macros will be to get their values
1214 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1215 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1216 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1218 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1219 GenerateObjectFileTargets ( module
,
1227 CLEAN_FILE ( ar_target
);
1228 string tgt
= FixupTargetFilename(module
.GetPath());
1229 if ( tgt
!= ar_target
)
1236 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
)
1238 string dependencies
;
1239 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1241 Invoke
& invoke
= *module
.invocations
[i
];
1242 if (invoke
.invokeModule
== &module
)
1243 /* Protect against circular dependencies */
1245 if ( dependencies
.length () > 0 )
1246 dependencies
+= " ";
1247 dependencies
+= invoke
.GetTargets ();
1249 return dependencies
;
1253 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1255 if ( module
.invocations
.size () == 0 )
1258 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1260 const Invoke
& invoke
= *module
.invocations
[i
];
1262 if ( invoke
.invokeModule
->type
!= BuildTool
)
1264 throw InvalidBuildFileException ( module
.node
.location
,
1265 "Only modules of type buildtool can be invoked." );
1268 string invokeTarget
= module
.GetInvocationTarget ( i
);
1269 fprintf ( fMakefile
,
1271 invokeTarget
.c_str () );
1272 fprintf ( fMakefile
,
1274 invokeTarget
.c_str (),
1275 invoke
.GetTargets ().c_str () );
1276 fprintf ( fMakefile
,
1278 invoke
.GetTargets ().c_str (),
1279 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1280 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1281 fprintf ( fMakefile
,
1283 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1284 invoke
.GetParameters ().c_str () );
1289 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1291 return module
.name
+ "_precondition";
1295 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1297 /* Avoid circular dependency */
1298 if ( module
.type
== BuildTool
1299 || module
.name
== "zlib"
1300 || module
.name
== "hostzlib" )
1307 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
)
1309 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1310 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1311 string dependencies
= GetDefaultDependencies ( module
);
1312 string s
= GetModuleDependencies ( module
);
1313 if ( s
.length () > 0 )
1315 if ( dependencies
.length () > 0 )
1316 dependencies
+= " ";
1320 s
= GetInvocationDependencies ( module
);
1321 if ( s
.length () > 0 )
1323 if ( dependencies
.length () > 0 )
1324 dependencies
+= " ";
1328 fprintf ( fMakefile
,
1330 preconditionDependenciesName
.c_str (),
1331 dependencies
.c_str () );
1332 const char* p
= sourceFilenames
.c_str();
1333 const char* end
= p
+ strlen(p
);
1336 const char* p2
= &p
[512];
1339 while ( p2
> p
&& !isspace(*p2
) )
1343 p2
= strpbrk ( p
, " \t" );
1347 fprintf ( fMakefile
,
1351 preconditionDependenciesName
.c_str ());
1353 p
+= strspn ( p
, " \t" );
1355 fprintf ( fMakefile
, "\n" );
1359 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded (
1360 const Module
& module
,
1361 string_list
& clean_files
)
1363 if ( module
.importLibrary
!= NULL
)
1365 string library_target
= PassThruCacheDirectory ( FixupTargetFilename ( module
.GetDependencyPath () ) ).c_str ();
1366 CLEAN_FILE ( library_target
);
1368 string definitionDependencies
= GetDefinitionDependencies ( module
);
1369 fprintf ( fMakefile
, "%s: %s %s\n",
1370 library_target
.c_str (),
1371 library_target
.c_str (),
1372 definitionDependencies
.c_str () );
1374 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1376 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1377 fprintf ( fMakefile
,
1378 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1379 module
.GetTargetName ().c_str (),
1380 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1381 library_target
.c_str (),
1387 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1389 string basename
= GetBasename ( filename
);
1390 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1394 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
)
1396 string dependencies
;
1397 string dkNkmLibNoFixup
= "dk/nkm/lib";
1398 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1399 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1400 const vector
<File
*>& files
= module
.non_if_data
.files
;
1401 for ( size_t i
= 0; i
< files
.size (); i
++ )
1403 File
& file
= *files
[i
];
1404 string extension
= GetExtension ( file
.name
);
1405 if ( extension
== ".spec" || extension
== ".SPEC" )
1407 if ( dependencies
.length () > 0 )
1408 dependencies
+= " ";
1409 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1412 return dependencies
;
1416 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
)
1418 return module
.cplusplus
;
1422 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( MingwBackend
* backend
)
1423 : MingwModuleHandler ( BuildTool
,
1429 MingwBuildToolModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1431 GeneratePreconditionDependencies ( module
);
1432 GenerateBuildToolModuleTarget ( module
, clean_files
);
1433 GenerateInvocations ( module
);
1437 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
, string_list
& clean_files
)
1439 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1440 string objectsMacro
= GetObjectsMacro ( module
);
1441 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1442 string libsMacro
= GetLibsMacro ( module
);
1444 GenerateMacrosAndTargets (
1451 if ( IsCPlusPlusModule ( module
) )
1452 linker
= "${host_gpp}";
1454 linker
= "${host_gcc}";
1456 fprintf ( fMakefile
, "%s: %s %s\n",
1458 objectsMacro
.c_str (),
1459 linkDepsMacro
.c_str () );
1460 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1461 fprintf ( fMakefile
,
1462 "\t%s %s -o %s %s %s\n\n",
1464 GetLinkerMacro ( module
).c_str (),
1466 objectsMacro
.c_str (),
1467 libsMacro
.c_str () );
1471 MingwKernelModuleHandler::MingwKernelModuleHandler ( MingwBackend
* backend
)
1472 : MingwModuleHandler ( Kernel
,
1478 MingwKernelModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1480 GeneratePreconditionDependencies ( module
);
1481 GenerateKernelModuleTarget ( module
, clean_files
);
1482 GenerateInvocations ( module
);
1486 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
, string_list
& clean_files
)
1488 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1489 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1490 string
target ( FixupTargetFilename (module
.GetPath ()) ); // i.e. "$(ROS_INT).\ntoskrnl\ntoskrnl.exe"
1491 string workingDirectory
= GetWorkingDirectory ();
1492 string objectsMacro
= GetObjectsMacro ( module
);
1493 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1494 string libsMacro
= GetLibsMacro ( module
);
1495 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1496 CLEAN_FILE ( base_tmp
);
1497 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1498 CLEAN_FILE ( junk_tmp
);
1499 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1500 CLEAN_FILE ( temp_exp
);
1501 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",
1502 module
.GetBasePath ().c_str (),
1503 module
.entrypoint
.c_str (),
1504 module
.baseaddress
.c_str () );
1506 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1508 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1510 fprintf ( fMakefile
, "%s: %s %s ${RSYM_TARGET}\n",
1512 objectsMacro
.c_str (),
1513 linkDepsMacro
.c_str () );
1514 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1515 fprintf ( fMakefile
,
1516 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1517 GetLinkerMacro ( module
).c_str (),
1518 gccOptions
.c_str (),
1521 objectsMacro
.c_str (),
1522 linkDepsMacro
.c_str () );
1523 fprintf ( fMakefile
,
1525 junk_tmp
.c_str () );
1526 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1527 fprintf ( fMakefile
,
1528 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1529 targetName
.c_str (),
1533 fprintf ( fMakefile
,
1535 base_tmp
.c_str () );
1536 fprintf ( fMakefile
,
1537 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1538 GetLinkerMacro ( module
).c_str (),
1539 gccOptions
.c_str (),
1542 objectsMacro
.c_str (),
1543 linkDepsMacro
.c_str () );
1544 fprintf ( fMakefile
,
1546 temp_exp
.c_str () );
1547 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1548 fprintf ( fMakefile
,
1549 "\t${rsym} %s %s\n\n",
1555 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ( MingwBackend
* backend
)
1556 : MingwModuleHandler ( StaticLibrary
,
1562 MingwStaticLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1564 GeneratePreconditionDependencies ( module
);
1565 GenerateStaticLibraryModuleTarget ( module
, clean_files
);
1566 GenerateInvocations ( module
);
1570 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1572 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1576 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ( MingwBackend
* backend
)
1577 : MingwModuleHandler ( ObjectLibrary
,
1583 MingwObjectLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1585 GeneratePreconditionDependencies ( module
);
1586 GenerateObjectLibraryModuleTarget ( module
, clean_files
);
1587 GenerateInvocations ( module
);
1591 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1593 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1597 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ( MingwBackend
* backend
)
1598 : MingwModuleHandler ( KernelModeDLL
,
1604 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1606 GeneratePreconditionDependencies ( module
);
1607 GenerateKernelModeDLLModuleTarget ( module
, clean_files
);
1608 GenerateInvocations ( module
);
1612 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget (
1613 const Module
& module
,
1614 string_list
& clean_files
)
1616 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1617 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1618 string workingDirectory
= GetWorkingDirectory ( );
1619 string objectsMacro
= GetObjectsMacro ( module
);
1620 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1621 string libsMacro
= GetLibsMacro ( module
);
1623 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1625 if ( module
.non_if_data
.files
.size () > 0 )
1627 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1629 string dependencies
=
1630 objectsMacro
+ " " + linkDepsMacro
;
1632 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1633 module
.entrypoint
.c_str (),
1634 module
.baseaddress
.c_str () );
1635 GenerateLinkerCommand ( module
,
1646 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1648 fprintf ( fMakefile
, "%s:\n",
1654 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ( MingwBackend
* backend
)
1655 : MingwModuleHandler ( KernelModeDriver
,
1661 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1663 GeneratePreconditionDependencies ( module
);
1664 GenerateKernelModeDriverModuleTarget ( module
, clean_files
);
1665 GenerateInvocations ( module
);
1670 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget (
1671 const Module
& module
,
1672 string_list
& clean_files
)
1674 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1675 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1676 string workingDirectory
= GetWorkingDirectory ();
1677 string objectsMacro
= GetObjectsMacro ( module
);
1678 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1679 string libsMacro
= GetLibsMacro ( module
);
1681 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1683 if ( module
.non_if_data
.files
.size () > 0 )
1685 string
cflags ( "-D__NTDRIVER__" );
1686 GenerateMacrosAndTargets ( module
,
1691 string dependencies
=
1692 objectsMacro
+ " " + linkDepsMacro
;
1694 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1695 module
.entrypoint
.c_str (),
1696 module
.baseaddress
.c_str () );
1697 GenerateLinkerCommand ( module
,
1708 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1710 fprintf ( fMakefile
, "%s:\n",
1716 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ( MingwBackend
* backend
)
1717 : MingwModuleHandler ( NativeDLL
,
1723 MingwNativeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1725 GeneratePreconditionDependencies ( module
);
1726 GenerateNativeDLLModuleTarget ( module
, clean_files
);
1727 GenerateInvocations ( module
);
1731 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1733 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1734 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1735 string workingDirectory
= GetWorkingDirectory ( );
1736 string objectsMacro
= GetObjectsMacro ( module
);
1737 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1738 string libsMacro
= GetLibsMacro ( module
);
1740 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1742 if ( module
.non_if_data
.files
.size () > 0 )
1744 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1746 string dependencies
=
1747 objectsMacro
+ " " + linkDepsMacro
;
1749 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1750 module
.entrypoint
.c_str (),
1751 module
.baseaddress
.c_str () );
1752 GenerateLinkerCommand ( module
,
1763 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1765 fprintf ( fMakefile
, "%s:\n\n",
1771 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ( MingwBackend
* backend
)
1772 : MingwModuleHandler ( NativeCUI
,
1778 MingwNativeCUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1780 GeneratePreconditionDependencies ( module
);
1781 GenerateNativeCUIModuleTarget ( module
, clean_files
);
1782 GenerateInvocations ( module
);
1786 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( 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 string
cflags ( "-D__NTAPP__" );
1800 GenerateMacrosAndTargets ( module
,
1805 string dependencies
=
1806 objectsMacro
+ " " + linkDepsMacro
;
1808 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1809 module
.entrypoint
.c_str (),
1810 module
.baseaddress
.c_str () );
1811 GenerateLinkerCommand ( module
,
1822 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1824 fprintf ( fMakefile
, "%s:\n\n",
1830 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ( MingwBackend
* backend
)
1831 : MingwModuleHandler ( Win32DLL
,
1837 MingwWin32DLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1839 GenerateExtractWineDLLResourcesTarget ( module
, clean_files
);
1840 GeneratePreconditionDependencies ( module
);
1841 GenerateWin32DLLModuleTarget ( module
, clean_files
);
1842 GenerateInvocations ( module
);
1846 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
, string_list
& clean_files
)
1848 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1849 module
.name
.c_str () );
1850 fprintf ( fMakefile
, "%s_extractresources: $(BIN2RES_TARGET)\n",
1851 module
.name
.c_str () );
1852 const vector
<File
*>& files
= module
.non_if_data
.files
;
1853 for ( size_t i
= 0; i
< files
.size (); i
++ )
1855 File
& file
= *files
[i
];
1856 string extension
= GetExtension ( file
.name
);
1857 if ( extension
== ".rc" || extension
== ".RC" )
1859 string resource
= FixupTargetFilename ( file
.name
);
1860 fprintf ( fMakefile
, "\t$(ECHO_BIN2RES)\n" );
1861 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1862 resource
.c_str () );
1865 fprintf ( fMakefile
, "\n");
1869 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1871 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1872 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1873 string workingDirectory
= GetWorkingDirectory ( );
1874 string objectsMacro
= GetObjectsMacro ( module
);
1875 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1876 string libsMacro
= GetLibsMacro ( module
);
1878 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1880 if ( module
.non_if_data
.files
.size () > 0 )
1882 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1884 string dependencies
=
1885 objectsMacro
+ " " + linkDepsMacro
;
1888 if ( module
.cplusplus
)
1893 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1894 module
.entrypoint
.c_str (),
1895 module
.baseaddress
.c_str () );
1896 GenerateLinkerCommand ( module
,
1907 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1909 fprintf ( fMakefile
, "%s:\n\n",
1915 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ( MingwBackend
* backend
)
1916 : MingwModuleHandler ( Win32CUI
,
1922 MingwWin32CUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1924 GeneratePreconditionDependencies ( module
);
1925 GenerateWin32CUIModuleTarget ( module
, clean_files
);
1926 GenerateInvocations ( module
);
1930 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1932 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1933 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1934 string workingDirectory
= GetWorkingDirectory ( );
1935 string objectsMacro
= GetObjectsMacro ( module
);
1936 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1937 string libsMacro
= GetLibsMacro ( module
);
1939 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1941 if ( module
.non_if_data
.files
.size () > 0 )
1943 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1945 string dependencies
=
1946 objectsMacro
+ " " + linkDepsMacro
;
1949 if ( module
.cplusplus
)
1954 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1955 module
.entrypoint
.c_str (),
1956 module
.baseaddress
.c_str () );
1957 GenerateLinkerCommand ( module
,
1968 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1970 fprintf ( fMakefile
, "%s:\n\n",
1976 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ( MingwBackend
* backend
)
1977 : MingwModuleHandler ( Win32GUI
,
1983 MingwWin32GUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1985 GeneratePreconditionDependencies ( module
);
1986 GenerateWin32GUIModuleTarget ( module
, clean_files
);
1987 GenerateInvocations ( module
);
1991 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1993 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1994 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1995 string workingDirectory
= GetWorkingDirectory ( );
1996 string objectsMacro
= GetObjectsMacro ( module
);
1997 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1998 string libsMacro
= GetLibsMacro ( module
);
2000 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
2002 if ( module
.non_if_data
.files
.size () > 0 )
2004 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
2006 string dependencies
=
2007 objectsMacro
+ " " + linkDepsMacro
;
2010 if ( module
.cplusplus
)
2015 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2016 module
.entrypoint
.c_str (),
2017 module
.baseaddress
.c_str () );
2018 GenerateLinkerCommand ( module
,
2029 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2031 fprintf ( fMakefile
, "%s:\n\n",
2037 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ( MingwBackend
* backend
)
2038 : MingwModuleHandler ( BootLoader
,
2044 MingwBootLoaderModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2046 GeneratePreconditionDependencies ( module
);
2047 GenerateBootLoaderModuleTarget ( module
, clean_files
);
2048 GenerateInvocations ( module
);
2052 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget (
2053 const Module
& module
,
2054 string_list
& clean_files
)
2056 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2057 string
targetName ( module
.GetTargetName () );
2058 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2059 string workingDirectory
= GetWorkingDirectory ();
2060 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
2061 CLEAN_FILE ( junk_tmp
);
2062 string objectsMacro
= GetObjectsMacro ( module
);
2063 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2064 string libsMacro
= GetLibsMacro ( module
);
2066 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
2068 fprintf ( fMakefile
, "%s: %s %s\n",
2070 objectsMacro
.c_str (),
2071 linkDepsMacro
.c_str () );
2073 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2075 fprintf ( fMakefile
,
2076 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2077 GetLinkerMacro ( module
).c_str (),
2079 objectsMacro
.c_str (),
2080 linkDepsMacro
.c_str () );
2081 fprintf ( fMakefile
,
2082 "\t${objcopy} -O binary %s %s\n",
2085 fprintf ( fMakefile
,
2087 junk_tmp
.c_str () );
2091 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ( MingwBackend
* backend
)
2092 : MingwModuleHandler ( BootSector
,
2098 MingwBootSectorModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2100 GeneratePreconditionDependencies ( module
);
2101 GenerateBootSectorModuleTarget ( module
, clean_files
);
2102 GenerateInvocations ( module
);
2106 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
, string_list
& clean_files
)
2108 string objectsMacro
= GetObjectsMacro ( module
);
2110 string
* nasmflags
= new string ( "-f bin" );
2111 GenerateMacrosAndTargets ( module
,
2116 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2117 module
.name
.c_str ());
2118 fprintf ( fMakefile
,
2120 module
.name
.c_str (),
2121 objectsMacro
.c_str () );
2125 MingwIsoModuleHandler::MingwIsoModuleHandler ( MingwBackend
* backend
)
2126 : MingwModuleHandler ( Iso
,
2132 MingwIsoModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2134 GeneratePreconditionDependencies ( module
);
2135 GenerateIsoModuleTarget ( module
, clean_files
);
2136 GenerateInvocations ( module
);
2140 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string
& bootcdDirectory
,
2141 const Module
& module
)
2143 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2145 const Module
& m
= *module
.project
.modules
[i
];
2146 if ( m
.bootstrap
!= NULL
)
2148 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
2149 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2150 fprintf ( fMakefile
,
2152 m
.GetPath ().c_str (),
2153 targetFilename
.c_str () );
2159 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string
& bootcdDirectory
,
2160 const Module
& module
)
2162 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2164 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2165 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2166 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2167 fprintf ( fMakefile
,
2169 cdfile
.GetPath ().c_str (),
2170 targetFilename
.c_str () );
2175 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
,
2176 const Module
& module
)
2179 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2181 const Module
& m
= *module
.project
.modules
[i
];
2182 if ( m
.bootstrap
!= NULL
)
2184 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2185 if ( directories
.size () > 0 )
2187 directories
+= PassThruCacheDirectory ( FixupTargetFilename ( targetDirecctory
) );
2194 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
,
2195 const Module
& module
)
2198 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2200 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2201 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2202 if ( directories
.size () > 0 )
2204 directories
+= PassThruCacheDirectory ( FixupTargetFilename ( targetDirecctory
) );
2210 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
,
2211 const Module
& module
)
2213 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2215 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2221 MingwIsoModuleHandler::GetBootstrapCdFiles (
2222 vector
<string
>& out
,
2223 const Module
& module
) const
2225 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2227 const Module
& m
= *module
.project
.modules
[i
];
2228 if ( m
.bootstrap
!= NULL
)
2229 out
.push_back ( FixupTargetFilename ( m
.GetPath () ) );
2234 MingwIsoModuleHandler::GetNonModuleCdFiles (
2235 vector
<string
>& out
,
2236 const Module
& module
) const
2238 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2240 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2241 out
.push_back ( NormalizeFilename ( cdfile
.GetPath () ) );
2246 MingwIsoModuleHandler::GetCdFiles (
2247 vector
<string
>& out
,
2248 const Module
& module
) const
2250 GetBootstrapCdFiles ( out
, module
);
2251 GetNonModuleCdFiles ( out
, module
);
2255 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
, string_list
& clean_files
)
2257 string bootcdDirectory
= "cd";
2258 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2259 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2260 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2261 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2262 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2263 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2264 string cdDirectories
= GetCdDirectories ( bootcdDirectory
,
2266 vector
<string
> vCdFiles
;
2267 GetCdFiles ( vCdFiles
, module
);
2268 string cdFiles
= v2s ( vCdFiles
, 5 );
2270 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2271 module
.name
.c_str ());
2272 fprintf ( fMakefile
,
2273 "%s: all %s %s %s %s ${CABMAN_TARGET} ${CDMAKE_TARGET}\n",
2274 module
.name
.c_str (),
2276 PassThruCacheDirectory ( bootcdReactos
).c_str (),
2277 cdDirectories
.c_str (),
2279 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2280 fprintf ( fMakefile
,
2281 "\t${cabman} -C %s -L %s -I\n",
2282 reactosDff
.c_str (),
2283 bootcdReactos
.c_str () );
2284 fprintf ( fMakefile
,
2285 "\t${cabman} -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2286 reactosDff
.c_str (),
2287 reactosInf
.c_str (),
2288 bootcdReactos
.c_str ());
2289 fprintf ( fMakefile
,
2291 reactosInf
.c_str () );
2292 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2294 OutputCdfileCopyCommands ( bootcdDirectory
,
2296 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2297 fprintf ( fMakefile
,
2298 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2300 bootcdDirectory
.c_str () );
2301 fprintf ( fMakefile
,