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 (),
730 objectFilename
.c_str (),
732 fprintf ( fMakefile
, "\t$(ECHO_CC)\n" );
734 "\t%s -c %s -o %s %s\n",
736 sourceFilename
.c_str (),
737 objectFilename
.c_str (),
738 cflagsMacro
.c_str () );
742 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
743 const string
& sourceFilename
,
745 const string
& cflagsMacro
)
747 string objectFilename
= PassThruCacheDirectory (
748 GetObjectFilename ( module
, sourceFilename
) );
751 objectFilename
.c_str (),
752 objectFilename
.c_str (),
753 sourceFilename
.c_str () );
754 fprintf ( fMakefile
, "\t$(ECHO_GAS)\n" );
756 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
758 sourceFilename
.c_str (),
759 objectFilename
.c_str (),
760 cflagsMacro
.c_str () );
764 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
765 const string
& sourceFilename
,
766 const string
& nasmflagsMacro
)
768 string objectFilename
= PassThruCacheDirectory (
769 GetObjectFilename ( module
, sourceFilename
) );
772 objectFilename
.c_str (),
773 objectFilename
.c_str (),
774 sourceFilename
.c_str () );
775 fprintf ( fMakefile
, "\t$(ECHO_NASM)\n" );
777 "\t%s -f win32 %s -o %s %s\n",
779 sourceFilename
.c_str (),
780 objectFilename
.c_str (),
781 nasmflagsMacro
.c_str () );
785 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
786 const string
& sourceFilename
,
787 const string
& windresflagsMacro
)
789 string objectFilename
= PassThruCacheDirectory (
790 GetObjectFilename ( module
, sourceFilename
) );
791 string rciFilename
= ReplaceExtension ( sourceFilename
,
793 string resFilename
= ReplaceExtension ( sourceFilename
,
796 "%s: %s %s $(WRC_TARGET)\n",
797 objectFilename
.c_str (),
798 objectFilename
.c_str (),
799 sourceFilename
.c_str () );
800 fprintf ( fMakefile
, "\t$(ECHO_WRC)\n" );
802 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
803 windresflagsMacro
.c_str (),
804 sourceFilename
.c_str (),
805 rciFilename
.c_str () );
807 "\t${wrc} ${%s} %s %s\n",
808 windresflagsMacro
.c_str (),
809 rciFilename
.c_str (),
810 resFilename
.c_str () );
813 rciFilename
.c_str () );
815 "\t${windres} %s -o %s\n",
816 resFilename
.c_str (),
817 objectFilename
.c_str () );
820 resFilename
.c_str () );
824 MingwModuleHandler::GenerateWinebuildCommands (
825 const Module
& module
,
826 const string
& sourceFilename
,
827 string_list
& clean_files
) const
829 string basename
= GetBasename ( sourceFilename
);
831 string def_file
= basename
+ ".spec.def";
832 CLEAN_FILE ( def_file
);
834 string stub_file
= basename
+ ".stubs.c";
835 CLEAN_FILE ( stub_file
);
840 sourceFilename
.c_str () );
841 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
843 "\t%s --def=%s -o %s\n",
845 sourceFilename
.c_str (),
851 sourceFilename
.c_str () );
852 fprintf ( fMakefile
, "\t$(ECHO_WINEBLD)\n" );
854 "\t%s --pedll=%s -o %s\n",
856 sourceFilename
.c_str (),
857 stub_file
.c_str () );
861 MingwModuleHandler::GenerateCommands (
862 const Module
& module
,
863 const string
& sourceFilename
,
866 const string
& cflagsMacro
,
867 const string
& nasmflagsMacro
,
868 const string
& windresflagsMacro
,
869 string_list
& clean_files
)
871 CLEAN_FILE ( GetObjectFilename(module
,sourceFilename
) );
872 string extension
= GetExtension ( sourceFilename
);
873 if ( extension
== ".c" || extension
== ".C" )
875 GenerateGccCommand ( module
,
881 else if ( extension
== ".cc" || extension
== ".CC" ||
882 extension
== ".cpp" || extension
== ".CPP" ||
883 extension
== ".cxx" || extension
== ".CXX" )
885 GenerateGccCommand ( module
,
891 else if ( extension
== ".s" || extension
== ".S" )
893 GenerateGccAssemblerCommand ( module
,
899 else if ( extension
== ".asm" || extension
== ".ASM" )
901 GenerateNasmCommand ( module
,
906 else if ( extension
== ".rc" || extension
== ".RC" )
908 GenerateWindresCommand ( module
,
913 else if ( extension
== ".spec" || extension
== ".SPEC" )
915 GenerateWinebuildCommands ( module
,
918 GenerateGccCommand ( module
,
919 GetActualSourceFilename ( sourceFilename
),
925 throw InvalidOperationException ( __FILE__
,
927 "Unsupported filename extension '%s' in file '%s'",
929 sourceFilename
.c_str () );
933 MingwModuleHandler::GenerateLinkerCommand (
934 const Module
& module
,
935 const string
& target
,
936 const string
& dependencies
,
937 const string
& linker
,
938 const string
& linkerParameters
,
939 const string
& objectsMacro
,
940 const string
& libsMacro
,
941 string_list
& clean_files
) const
944 "%s: %s ${RSYM_TARGET}\n",
946 dependencies
.c_str () );
947 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
948 string
targetName ( module
.GetTargetName () );
949 if ( module
.importLibrary
!= NULL
)
951 static string
ros_junk ( "$(ROS_TEMPORARY)" );
952 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
953 CLEAN_FILE ( base_tmp
);
954 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
955 CLEAN_FILE ( junk_tmp
);
956 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
957 CLEAN_FILE ( temp_exp
);
958 string def_file
= module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
;
961 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
963 linkerParameters
.c_str (),
966 objectsMacro
.c_str (),
968 GetLinkerMacro ( module
).c_str () );
974 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
976 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
988 "\t%s %s %s -o %s %s %s %s\n",
990 linkerParameters
.c_str (),
993 objectsMacro
.c_str (),
995 GetLinkerMacro ( module
).c_str () );
1003 fprintf ( fMakefile
,
1004 "\t%s %s -o %s %s %s %s\n",
1006 linkerParameters
.c_str (),
1008 objectsMacro
.c_str (),
1010 GetLinkerMacro ( module
).c_str () );
1013 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1014 fprintf ( fMakefile
,
1015 "\t${rsym} %s %s\n\n",
1021 MingwModuleHandler::GenerateObjectFileTargets (
1022 const Module
& module
,
1023 const IfableData
& data
,
1026 const string
& cflagsMacro
,
1027 const string
& nasmflagsMacro
,
1028 const string
& windresflagsMacro
,
1029 string_list
& clean_files
)
1033 const vector
<File
*>& files
= data
.files
;
1034 for ( i
= 0; i
< files
.size (); i
++ )
1036 string sourceFilename
= files
[i
]->name
;
1037 GenerateCommands ( module
,
1045 fprintf ( fMakefile
,
1049 const vector
<If
*>& ifs
= data
.ifs
;
1050 for ( i
= 0; i
< ifs
.size(); i
++ )
1052 GenerateObjectFileTargets ( module
,
1064 MingwModuleHandler::GenerateObjectFileTargets (
1065 const Module
& module
,
1068 const string
& cflagsMacro
,
1069 const string
& nasmflagsMacro
,
1070 const string
& windresflagsMacro
,
1071 string_list
& clean_files
)
1075 const string
& pch_file
= module
.pch
->header
;
1076 string gch_file
= pch_file
+ ".gch";
1077 CLEAN_FILE(gch_file
);
1085 fprintf ( fMakefile
, "\t$(ECHO_PCH)\n" );
1088 "\t%s -o %s %s -g %s\n\n",
1089 ( module
.cplusplus
? cppc
.c_str() : cc
.c_str() ),
1091 cflagsMacro
.c_str(),
1096 GenerateObjectFileTargets ( module
,
1104 fprintf ( fMakefile
, "\n" );
1108 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
1110 const string
& objs_macro
) const
1112 string archiveFilename
= GetModuleArchiveFilename ( module
);
1114 fprintf ( fMakefile
,
1116 archiveFilename
.c_str (),
1117 objs_macro
.c_str ());
1119 fprintf ( fMakefile
, "\t$(ECHO_AR)\n" );
1121 fprintf ( fMakefile
,
1122 "\t%s -rc %s %s\n\n",
1124 archiveFilename
.c_str (),
1125 objs_macro
.c_str ());
1127 return archiveFilename
;
1131 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
1133 return ssprintf ( "$(%s_CFLAGS)",
1134 module
.name
.c_str () );
1138 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
1140 return ssprintf ( "$(%s_OBJS)",
1141 module
.name
.c_str () );
1145 MingwModuleHandler::GetLinkingDependenciesMacro ( const Module
& module
) const
1147 return ssprintf ( "$(%s_LINKDEPS)", module
.name
.c_str () );
1151 MingwModuleHandler::GetLibsMacro ( const Module
& module
) const
1153 return ssprintf ( "$(%s_LIBS)", module
.name
.c_str () );
1157 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
1159 return ssprintf ( "$(%s_LFLAGS)",
1160 module
.name
.c_str () );
1164 MingwModuleHandler::GenerateMacrosAndTargets (
1165 const Module
& module
,
1166 const string
* cflags
,
1167 const string
* nasmflags
,
1168 string_list
& clean_files
)
1170 string cc
= ( module
.host
== HostTrue
? "${host_gcc}" : "${gcc}" );
1171 string cppc
= ( module
.host
== HostTrue
? "${host_gpp}" : "${gpp}" );
1172 string ar
= ( module
.host
== HostTrue
? "${host_ar}" : "${ar}" );
1174 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
1175 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
1176 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
1177 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
1178 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
1179 string libsMacro
= ssprintf("%s_LIBS", module
.name
.c_str ());
1180 string linkDepsMacro
= ssprintf ("%s_LINKDEPS", module
.name
.c_str ());
1182 GenerateMacros ( module
,
1191 if ( cflags
!= NULL
)
1193 fprintf ( fMakefile
,
1195 cflagsMacro
.c_str (),
1199 if ( nasmflags
!= NULL
)
1201 fprintf ( fMakefile
,
1203 nasmflagsMacro
.c_str (),
1204 nasmflags
->c_str () );
1207 // generate phony target for module name
1208 fprintf ( fMakefile
, ".PHONY: %s\n",
1209 module
.name
.c_str () );
1210 fprintf ( fMakefile
, "%s: %s\n\n",
1211 module
.name
.c_str (),
1212 FixupTargetFilename ( module
.GetPath () ).c_str () );
1214 // future references to the macros will be to get their values
1215 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
1216 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
1217 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
1219 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
1220 GenerateObjectFileTargets ( module
,
1228 CLEAN_FILE ( ar_target
);
1229 string tgt
= FixupTargetFilename(module
.GetPath());
1230 if ( tgt
!= ar_target
)
1237 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
)
1239 string dependencies
;
1240 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1242 Invoke
& invoke
= *module
.invocations
[i
];
1243 if (invoke
.invokeModule
== &module
)
1244 /* Protect against circular dependencies */
1246 if ( dependencies
.length () > 0 )
1247 dependencies
+= " ";
1248 dependencies
+= invoke
.GetTargets ();
1250 return dependencies
;
1254 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1256 if ( module
.invocations
.size () == 0 )
1259 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1261 const Invoke
& invoke
= *module
.invocations
[i
];
1263 if ( invoke
.invokeModule
->type
!= BuildTool
)
1265 throw InvalidBuildFileException ( module
.node
.location
,
1266 "Only modules of type buildtool can be invoked." );
1269 string invokeTarget
= module
.GetInvocationTarget ( i
);
1270 fprintf ( fMakefile
,
1272 invokeTarget
.c_str () );
1273 fprintf ( fMakefile
,
1275 invokeTarget
.c_str (),
1276 invoke
.GetTargets ().c_str () );
1277 fprintf ( fMakefile
,
1279 invoke
.GetTargets ().c_str (),
1280 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1281 fprintf ( fMakefile
, "\t$(ECHO_INVOKE)\n" );
1282 fprintf ( fMakefile
,
1284 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1285 invoke
.GetParameters ().c_str () );
1290 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1292 return module
.name
+ "_precondition";
1296 MingwModuleHandler::GetDefaultDependencies ( const Module
& module
) const
1298 /* Avoid circular dependency */
1299 if ( module
.type
== BuildTool
1300 || module
.name
== "zlib"
1301 || module
.name
== "hostzlib" )
1308 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
)
1310 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1311 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1312 string dependencies
= GetDefaultDependencies ( module
);
1313 string s
= GetModuleDependencies ( module
);
1314 if ( s
.length () > 0 )
1316 if ( dependencies
.length () > 0 )
1317 dependencies
+= " ";
1321 s
= GetInvocationDependencies ( module
);
1322 if ( s
.length () > 0 )
1324 if ( dependencies
.length () > 0 )
1325 dependencies
+= " ";
1329 fprintf ( fMakefile
,
1331 preconditionDependenciesName
.c_str (),
1332 dependencies
.c_str () );
1333 const char* p
= sourceFilenames
.c_str();
1334 const char* end
= p
+ strlen(p
);
1337 const char* p2
= &p
[512];
1340 while ( p2
> p
&& !isspace(*p2
) )
1344 p2
= strpbrk ( p
, " \t" );
1348 fprintf ( fMakefile
,
1352 preconditionDependenciesName
.c_str ());
1354 p
+= strspn ( p
, " \t" );
1356 fprintf ( fMakefile
, "\n" );
1360 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded (
1361 const Module
& module
,
1362 string_list
& clean_files
)
1364 if ( module
.importLibrary
!= NULL
)
1366 string library_target
= PassThruCacheDirectory ( FixupTargetFilename ( module
.GetDependencyPath () ) ).c_str ();
1367 CLEAN_FILE ( library_target
);
1369 string definitionDependencies
= GetDefinitionDependencies ( module
);
1370 fprintf ( fMakefile
, "%s: %s %s\n",
1371 library_target
.c_str (),
1372 library_target
.c_str (),
1373 definitionDependencies
.c_str () );
1375 fprintf ( fMakefile
, "\t$(ECHO_DLLTOOL)\n" );
1377 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1378 fprintf ( fMakefile
,
1379 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1380 module
.GetTargetName ().c_str (),
1381 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1382 library_target
.c_str (),
1388 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1390 string basename
= GetBasename ( filename
);
1391 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1395 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
)
1397 string dependencies
;
1398 string dkNkmLibNoFixup
= "dk/nkm/lib";
1399 dependencies
+= FixupTargetFilename ( dkNkmLibNoFixup
);
1400 PassThruCacheDirectory ( dkNkmLibNoFixup
+ SSEP
);
1401 const vector
<File
*>& files
= module
.non_if_data
.files
;
1402 for ( size_t i
= 0; i
< files
.size (); i
++ )
1404 File
& file
= *files
[i
];
1405 string extension
= GetExtension ( file
.name
);
1406 if ( extension
== ".spec" || extension
== ".SPEC" )
1408 if ( dependencies
.length () > 0 )
1409 dependencies
+= " ";
1410 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1413 return dependencies
;
1417 MingwModuleHandler::IsCPlusPlusModule ( const Module
& module
)
1419 return module
.cplusplus
;
1423 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( MingwBackend
* backend
)
1424 : MingwModuleHandler ( BuildTool
,
1430 MingwBuildToolModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1432 GeneratePreconditionDependencies ( module
);
1433 GenerateBuildToolModuleTarget ( module
, clean_files
);
1434 GenerateInvocations ( module
);
1438 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
, string_list
& clean_files
)
1440 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1441 string objectsMacro
= GetObjectsMacro ( module
);
1442 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1443 string libsMacro
= GetLibsMacro ( module
);
1445 GenerateMacrosAndTargets (
1452 if ( IsCPlusPlusModule ( module
) )
1453 linker
= "${host_gpp}";
1455 linker
= "${host_gcc}";
1457 fprintf ( fMakefile
, "%s: %s %s\n",
1459 objectsMacro
.c_str (),
1460 linkDepsMacro
.c_str () );
1461 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1462 fprintf ( fMakefile
,
1463 "\t%s %s -o %s %s %s\n\n",
1465 GetLinkerMacro ( module
).c_str (),
1467 objectsMacro
.c_str (),
1468 libsMacro
.c_str () );
1472 MingwKernelModuleHandler::MingwKernelModuleHandler ( MingwBackend
* backend
)
1473 : MingwModuleHandler ( Kernel
,
1479 MingwKernelModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1481 GeneratePreconditionDependencies ( module
);
1482 GenerateKernelModuleTarget ( module
, clean_files
);
1483 GenerateInvocations ( module
);
1487 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
, string_list
& clean_files
)
1489 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1490 string
targetName ( module
.GetTargetName () ); // i.e. "ntoskrnl.exe"
1491 string
target ( FixupTargetFilename (module
.GetPath ()) ); // i.e. "$(ROS_INT).\ntoskrnl\ntoskrnl.exe"
1492 string workingDirectory
= GetWorkingDirectory ();
1493 string objectsMacro
= GetObjectsMacro ( module
);
1494 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1495 string libsMacro
= GetLibsMacro ( module
);
1496 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1497 CLEAN_FILE ( base_tmp
);
1498 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1499 CLEAN_FILE ( junk_tmp
);
1500 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1501 CLEAN_FILE ( temp_exp
);
1502 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",
1503 module
.GetBasePath ().c_str (),
1504 module
.entrypoint
.c_str (),
1505 module
.baseaddress
.c_str () );
1507 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1509 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1511 fprintf ( fMakefile
, "%s: %s %s ${RSYM_TARGET}\n",
1513 objectsMacro
.c_str (),
1514 linkDepsMacro
.c_str () );
1515 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
1516 fprintf ( fMakefile
,
1517 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1518 GetLinkerMacro ( module
).c_str (),
1519 gccOptions
.c_str (),
1522 objectsMacro
.c_str (),
1523 linkDepsMacro
.c_str () );
1524 fprintf ( fMakefile
,
1526 junk_tmp
.c_str () );
1527 string killAt
= module
.mangledSymbols
? "" : "--kill-at";
1528 fprintf ( fMakefile
,
1529 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1530 targetName
.c_str (),
1534 fprintf ( fMakefile
,
1536 base_tmp
.c_str () );
1537 fprintf ( fMakefile
,
1538 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1539 GetLinkerMacro ( module
).c_str (),
1540 gccOptions
.c_str (),
1543 objectsMacro
.c_str (),
1544 linkDepsMacro
.c_str () );
1545 fprintf ( fMakefile
,
1547 temp_exp
.c_str () );
1548 fprintf ( fMakefile
, "\t$(ECHO_RSYM)\n" );
1549 fprintf ( fMakefile
,
1550 "\t${rsym} %s %s\n\n",
1556 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ( MingwBackend
* backend
)
1557 : MingwModuleHandler ( StaticLibrary
,
1563 MingwStaticLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1565 GeneratePreconditionDependencies ( module
);
1566 GenerateStaticLibraryModuleTarget ( module
, clean_files
);
1567 GenerateInvocations ( module
);
1571 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1573 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1577 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ( MingwBackend
* backend
)
1578 : MingwModuleHandler ( ObjectLibrary
,
1584 MingwObjectLibraryModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1586 GeneratePreconditionDependencies ( module
);
1587 GenerateObjectLibraryModuleTarget ( module
, clean_files
);
1588 GenerateInvocations ( module
);
1592 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
, string_list
& clean_files
)
1594 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1598 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ( MingwBackend
* backend
)
1599 : MingwModuleHandler ( KernelModeDLL
,
1605 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1607 GeneratePreconditionDependencies ( module
);
1608 GenerateKernelModeDLLModuleTarget ( module
, clean_files
);
1609 GenerateInvocations ( module
);
1613 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget (
1614 const Module
& module
,
1615 string_list
& clean_files
)
1617 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1618 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1619 string workingDirectory
= GetWorkingDirectory ( );
1620 string objectsMacro
= GetObjectsMacro ( module
);
1621 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1622 string libsMacro
= GetLibsMacro ( module
);
1624 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1626 if ( module
.non_if_data
.files
.size () > 0 )
1628 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1630 string dependencies
=
1631 objectsMacro
+ " " + linkDepsMacro
;
1633 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1634 module
.entrypoint
.c_str (),
1635 module
.baseaddress
.c_str () );
1636 GenerateLinkerCommand ( module
,
1647 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1649 fprintf ( fMakefile
, "%s:\n",
1655 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ( MingwBackend
* backend
)
1656 : MingwModuleHandler ( KernelModeDriver
,
1662 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1664 GeneratePreconditionDependencies ( module
);
1665 GenerateKernelModeDriverModuleTarget ( module
, clean_files
);
1666 GenerateInvocations ( module
);
1671 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget (
1672 const Module
& module
,
1673 string_list
& clean_files
)
1675 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1676 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1677 string workingDirectory
= GetWorkingDirectory ();
1678 string objectsMacro
= GetObjectsMacro ( module
);
1679 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1680 string libsMacro
= GetLibsMacro ( module
);
1682 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1684 if ( module
.non_if_data
.files
.size () > 0 )
1686 string
cflags ( "-D__NTDRIVER__" );
1687 GenerateMacrosAndTargets ( module
,
1692 string dependencies
=
1693 objectsMacro
+ " " + linkDepsMacro
;
1695 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1696 module
.entrypoint
.c_str (),
1697 module
.baseaddress
.c_str () );
1698 GenerateLinkerCommand ( module
,
1709 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1711 fprintf ( fMakefile
, "%s:\n",
1717 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ( MingwBackend
* backend
)
1718 : MingwModuleHandler ( NativeDLL
,
1724 MingwNativeDLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1726 GeneratePreconditionDependencies ( module
);
1727 GenerateNativeDLLModuleTarget ( module
, clean_files
);
1728 GenerateInvocations ( module
);
1732 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1734 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1735 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1736 string workingDirectory
= GetWorkingDirectory ( );
1737 string objectsMacro
= GetObjectsMacro ( module
);
1738 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1739 string libsMacro
= GetLibsMacro ( module
);
1741 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1743 if ( module
.non_if_data
.files
.size () > 0 )
1745 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1747 string dependencies
=
1748 objectsMacro
+ " " + linkDepsMacro
;
1750 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1751 module
.entrypoint
.c_str (),
1752 module
.baseaddress
.c_str () );
1753 GenerateLinkerCommand ( module
,
1764 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1766 fprintf ( fMakefile
, "%s:\n\n",
1772 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ( MingwBackend
* backend
)
1773 : MingwModuleHandler ( NativeCUI
,
1779 MingwNativeCUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1781 GeneratePreconditionDependencies ( module
);
1782 GenerateNativeCUIModuleTarget ( module
, clean_files
);
1783 GenerateInvocations ( module
);
1787 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1789 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1790 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1791 string workingDirectory
= GetWorkingDirectory ( );
1792 string objectsMacro
= GetObjectsMacro ( module
);
1793 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1794 string libsMacro
= GetLibsMacro ( module
);
1796 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1798 if ( module
.non_if_data
.files
.size () > 0 )
1800 string
cflags ( "-D__NTAPP__" );
1801 GenerateMacrosAndTargets ( module
,
1806 string dependencies
=
1807 objectsMacro
+ " " + linkDepsMacro
;
1809 string linkerParameters
= ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1810 module
.entrypoint
.c_str (),
1811 module
.baseaddress
.c_str () );
1812 GenerateLinkerCommand ( module
,
1823 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1825 fprintf ( fMakefile
, "%s:\n\n",
1831 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ( MingwBackend
* backend
)
1832 : MingwModuleHandler ( Win32DLL
,
1838 MingwWin32DLLModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1840 GenerateExtractWineDLLResourcesTarget ( module
, clean_files
);
1841 GeneratePreconditionDependencies ( module
);
1842 GenerateWin32DLLModuleTarget ( module
, clean_files
);
1843 GenerateInvocations ( module
);
1847 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
, string_list
& clean_files
)
1849 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1850 module
.name
.c_str () );
1851 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1852 module
.name
.c_str () );
1853 const vector
<File
*>& files
= module
.non_if_data
.files
;
1854 for ( size_t i
= 0; i
< files
.size (); i
++ )
1856 File
& file
= *files
[i
];
1857 string extension
= GetExtension ( file
.name
);
1858 if ( extension
== ".rc" || extension
== ".RC" )
1860 string resource
= FixupTargetFilename ( file
.name
);
1861 fprintf ( fMakefile
, "\t$(ECHO_BIN2RES)\n" );
1862 fprintf ( fMakefile
, "\t@:echo ${bin2res} -f -x %s\n",
1863 resource
.c_str () );
1866 fprintf ( fMakefile
, "\n");
1870 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
, string_list
& clean_files
)
1872 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1873 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1874 string workingDirectory
= GetWorkingDirectory ( );
1875 string objectsMacro
= GetObjectsMacro ( module
);
1876 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1877 string libsMacro
= GetLibsMacro ( module
);
1879 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1881 if ( module
.non_if_data
.files
.size () > 0 )
1883 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1885 string dependencies
=
1886 objectsMacro
+ " " + linkDepsMacro
;
1889 if ( module
.cplusplus
)
1894 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1895 module
.entrypoint
.c_str (),
1896 module
.baseaddress
.c_str () );
1897 GenerateLinkerCommand ( module
,
1908 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1910 fprintf ( fMakefile
, "%s:\n\n",
1916 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ( MingwBackend
* backend
)
1917 : MingwModuleHandler ( Win32CUI
,
1923 MingwWin32CUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1925 GeneratePreconditionDependencies ( module
);
1926 GenerateWin32CUIModuleTarget ( module
, clean_files
);
1927 GenerateInvocations ( module
);
1931 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1933 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1934 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1935 string workingDirectory
= GetWorkingDirectory ( );
1936 string objectsMacro
= GetObjectsMacro ( module
);
1937 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1938 string libsMacro
= GetLibsMacro ( module
);
1940 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
1942 if ( module
.non_if_data
.files
.size () > 0 )
1944 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
1946 string dependencies
=
1947 objectsMacro
+ " " + linkDepsMacro
;
1950 if ( module
.cplusplus
)
1955 string linkerParameters
= ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1956 module
.entrypoint
.c_str (),
1957 module
.baseaddress
.c_str () );
1958 GenerateLinkerCommand ( module
,
1969 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1971 fprintf ( fMakefile
, "%s:\n\n",
1977 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ( MingwBackend
* backend
)
1978 : MingwModuleHandler ( Win32GUI
,
1984 MingwWin32GUIModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
1986 GeneratePreconditionDependencies ( module
);
1987 GenerateWin32GUIModuleTarget ( module
, clean_files
);
1988 GenerateInvocations ( module
);
1992 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
, string_list
& clean_files
)
1994 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1995 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1996 string workingDirectory
= GetWorkingDirectory ( );
1997 string objectsMacro
= GetObjectsMacro ( module
);
1998 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
1999 string libsMacro
= GetLibsMacro ( module
);
2001 GenerateImportLibraryTargetIfNeeded ( module
, clean_files
);
2003 if ( module
.non_if_data
.files
.size () > 0 )
2005 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
2007 string dependencies
=
2008 objectsMacro
+ " " + linkDepsMacro
;
2011 if ( module
.cplusplus
)
2016 string linkerParameters
= ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2017 module
.entrypoint
.c_str (),
2018 module
.baseaddress
.c_str () );
2019 GenerateLinkerCommand ( module
,
2030 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2032 fprintf ( fMakefile
, "%s:\n\n",
2038 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ( MingwBackend
* backend
)
2039 : MingwModuleHandler ( BootLoader
,
2045 MingwBootLoaderModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2047 GeneratePreconditionDependencies ( module
);
2048 GenerateBootLoaderModuleTarget ( module
, clean_files
);
2049 GenerateInvocations ( module
);
2053 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget (
2054 const Module
& module
,
2055 string_list
& clean_files
)
2057 static string
ros_junk ( "$(ROS_TEMPORARY)" );
2058 string
targetName ( module
.GetTargetName () );
2059 string
target ( FixupTargetFilename ( module
.GetPath () ) );
2060 string workingDirectory
= GetWorkingDirectory ();
2061 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
2062 CLEAN_FILE ( junk_tmp
);
2063 string objectsMacro
= GetObjectsMacro ( module
);
2064 string linkDepsMacro
= GetLinkingDependenciesMacro ( module
);
2065 string libsMacro
= GetLibsMacro ( module
);
2067 GenerateMacrosAndTargets ( module
, NULL
, NULL
, clean_files
);
2069 fprintf ( fMakefile
, "%s: %s %s\n",
2071 objectsMacro
.c_str (),
2072 linkDepsMacro
.c_str () );
2074 fprintf ( fMakefile
, "\t$(ECHO_LD)\n" );
2076 fprintf ( fMakefile
,
2077 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2078 GetLinkerMacro ( module
).c_str (),
2080 objectsMacro
.c_str (),
2081 linkDepsMacro
.c_str () );
2082 fprintf ( fMakefile
,
2083 "\t${objcopy} -O binary %s %s\n",
2086 fprintf ( fMakefile
,
2088 junk_tmp
.c_str () );
2092 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ( MingwBackend
* backend
)
2093 : MingwModuleHandler ( BootSector
,
2099 MingwBootSectorModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2101 GeneratePreconditionDependencies ( module
);
2102 GenerateBootSectorModuleTarget ( module
, clean_files
);
2103 GenerateInvocations ( module
);
2107 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module
& module
, string_list
& clean_files
)
2109 string objectsMacro
= GetObjectsMacro ( module
);
2111 string
* nasmflags
= new string ( "-f bin" );
2112 GenerateMacrosAndTargets ( module
,
2117 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2118 module
.name
.c_str ());
2119 fprintf ( fMakefile
,
2121 module
.name
.c_str (),
2122 objectsMacro
.c_str () );
2126 MingwIsoModuleHandler::MingwIsoModuleHandler ( MingwBackend
* backend
)
2127 : MingwModuleHandler ( Iso
,
2133 MingwIsoModuleHandler::Process ( const Module
& module
, string_list
& clean_files
)
2135 GeneratePreconditionDependencies ( module
);
2136 GenerateIsoModuleTarget ( module
, clean_files
);
2137 GenerateInvocations ( module
);
2141 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string
& bootcdDirectory
,
2142 const Module
& module
)
2144 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2146 const Module
& m
= *module
.project
.modules
[i
];
2147 if ( m
.bootstrap
!= NULL
)
2149 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
+ SSEP
+ m
.bootstrap
->nameoncd
;
2150 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2151 fprintf ( fMakefile
,
2153 m
.GetPath ().c_str (),
2154 targetFilename
.c_str () );
2160 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string
& bootcdDirectory
,
2161 const Module
& module
)
2163 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2165 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2166 string targetFilenameNoFixup
= bootcdDirectory
+ SSEP
+ cdfile
.base
+ SSEP
+ cdfile
.nameoncd
;
2167 string targetFilename
= PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup
) );
2168 fprintf ( fMakefile
,
2170 cdfile
.GetPath ().c_str (),
2171 targetFilename
.c_str () );
2176 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string
& bootcdDirectory
,
2177 const Module
& module
)
2180 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2182 const Module
& m
= *module
.project
.modules
[i
];
2183 if ( m
.bootstrap
!= NULL
)
2185 string targetDirecctory
= bootcdDirectory
+ SSEP
+ m
.bootstrap
->base
;
2186 if ( directories
.size () > 0 )
2188 directories
+= PassThruCacheDirectory ( FixupTargetFilename ( targetDirecctory
) );
2195 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string
& bootcdDirectory
,
2196 const Module
& module
)
2199 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2201 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2202 string targetDirecctory
= bootcdDirectory
+ SSEP
+ cdfile
.base
;
2203 if ( directories
.size () > 0 )
2205 directories
+= PassThruCacheDirectory ( FixupTargetFilename ( targetDirecctory
) );
2211 MingwIsoModuleHandler::GetCdDirectories ( const string
& bootcdDirectory
,
2212 const Module
& module
)
2214 string directories
= GetBootstrapCdDirectories ( bootcdDirectory
,
2216 directories
+= " " + GetNonModuleCdDirectories ( bootcdDirectory
,
2222 MingwIsoModuleHandler::GetBootstrapCdFiles (
2223 vector
<string
>& out
,
2224 const Module
& module
) const
2226 for ( size_t i
= 0; i
< module
.project
.modules
.size (); i
++ )
2228 const Module
& m
= *module
.project
.modules
[i
];
2229 if ( m
.bootstrap
!= NULL
)
2230 out
.push_back ( FixupTargetFilename ( m
.GetPath () ) );
2235 MingwIsoModuleHandler::GetNonModuleCdFiles (
2236 vector
<string
>& out
,
2237 const Module
& module
) const
2239 for ( size_t i
= 0; i
< module
.project
.cdfiles
.size (); i
++ )
2241 const CDFile
& cdfile
= *module
.project
.cdfiles
[i
];
2242 out
.push_back ( NormalizeFilename ( cdfile
.GetPath () ) );
2247 MingwIsoModuleHandler::GetCdFiles (
2248 vector
<string
>& out
,
2249 const Module
& module
) const
2251 GetBootstrapCdFiles ( out
, module
);
2252 GetNonModuleCdFiles ( out
, module
);
2256 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module
& module
, string_list
& clean_files
)
2258 string bootcdDirectory
= "cd";
2259 string isoboot
= FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2260 string bootcdReactosNoFixup
= bootcdDirectory
+ "/reactos";
2261 string bootcdReactos
= FixupTargetFilename ( bootcdReactosNoFixup
);
2262 PassThruCacheDirectory ( bootcdReactos
+ SSEP
);
2263 string reactosInf
= FixupTargetFilename ( bootcdReactosNoFixup
+ "/reactos.inf" );
2264 string reactosDff
= NormalizeFilename ( "bootdata/packages/reactos.dff" );
2265 string cdDirectories
= GetCdDirectories ( bootcdDirectory
,
2267 vector
<string
> vCdFiles
;
2268 GetCdFiles ( vCdFiles
, module
);
2269 string cdFiles
= v2s ( vCdFiles
, 5 );
2271 fprintf ( fMakefile
, ".PHONY: %s\n\n",
2272 module
.name
.c_str ());
2273 fprintf ( fMakefile
,
2274 "%s: all %s %s %s %s ${CABMAN_TARGET} ${CDMAKE_TARGET}\n",
2275 module
.name
.c_str (),
2277 PassThruCacheDirectory ( bootcdReactos
).c_str (),
2278 cdDirectories
.c_str (),
2280 fprintf ( fMakefile
, "\t$(ECHO_CABMAN)\n" );
2281 fprintf ( fMakefile
,
2282 "\t${cabman} -C %s -L %s -I\n",
2283 reactosDff
.c_str (),
2284 bootcdReactos
.c_str () );
2285 fprintf ( fMakefile
,
2286 "\t${cabman} -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2287 reactosDff
.c_str (),
2288 reactosInf
.c_str (),
2289 bootcdReactos
.c_str ());
2290 fprintf ( fMakefile
,
2292 reactosInf
.c_str () );
2293 OutputBootstrapfileCopyCommands ( bootcdDirectory
,
2295 OutputCdfileCopyCommands ( bootcdDirectory
,
2297 fprintf ( fMakefile
, "\t$(ECHO_CDMAKE)\n" );
2298 fprintf ( fMakefile
,
2299 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2301 bootcdDirectory
.c_str () );
2302 fprintf ( fMakefile
,