5 #include "../../rbuild.h"
7 #include "modulehandler.h"
13 map
<ModuleType
,MingwModuleHandler
*>*
14 MingwModuleHandler::handler_map
= NULL
;
16 MingwModuleHandler::ref
= 0;
19 MingwModuleHandler::fMakefile
= NULL
;
21 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype
)
24 handler_map
= new map
<ModuleType
,MingwModuleHandler
*>;
25 (*handler_map
)[moduletype
] = this;
28 MingwModuleHandler::~MingwModuleHandler()
38 MingwModuleHandler::SetMakefile ( FILE* f
)
44 MingwModuleHandler::LookupHandler ( const string
& location
,
45 ModuleType moduletype
)
48 throw Exception ( "internal tool error: no registered module handlers" );
49 MingwModuleHandler
* h
= (*handler_map
)[moduletype
];
52 throw UnknownModuleTypeException ( location
, moduletype
);
59 MingwModuleHandler::GetWorkingDirectory () const
65 MingwModuleHandler::GetExtension ( const string
& filename
) const
67 size_t index
= filename
.find_last_of ( '.' );
68 if (index
!= string::npos
)
69 return filename
.substr ( index
);
74 MingwModuleHandler::ReplaceExtension ( const string
& filename
,
75 const string
& newExtension
) const
77 size_t index
= filename
.find_last_of ( '.' );
78 if (index
!= string::npos
)
79 return filename
.substr ( 0, index
) + newExtension
;
84 MingwModuleHandler::GetModuleArchiveFilename ( const Module
& module
) const
86 return ReplaceExtension ( FixupTargetFilename ( module
.GetPath () ),
91 MingwModuleHandler::GetImportLibraryDependencies ( const Module
& module
) const
93 if ( module
.libraries
.size () == 0 )
96 string
dependencies ( "" );
97 for ( size_t i
= 0; i
< module
.libraries
.size (); i
++ )
99 if ( dependencies
.size () > 0 )
101 const Module
* importedModule
= module
.project
.LocateModule ( module
.libraries
[i
]->name
);
102 assert ( importedModule
!= NULL
);
103 dependencies
+= FixupTargetFilename ( importedModule
->GetDependencyPath () ).c_str ();
109 MingwModuleHandler::GetModuleDependencies ( const Module
& module
) const
111 if ( module
.dependencies
.size () == 0 )
114 string
dependencies ( "" );
115 for ( size_t i
= 0; i
< module
.dependencies
.size (); i
++ )
117 if ( dependencies
.size () > 0 )
119 const Dependency
* dependency
= module
.dependencies
[i
];
120 const Module
* dependencyModule
= dependency
->dependencyModule
;
121 dependencies
+= dependencyModule
->GetTargets ();
127 MingwModuleHandler::GetAllDependencies ( const Module
& module
) const
129 string dependencies
= GetImportLibraryDependencies ( module
);
130 string s
= GetModuleDependencies ( module
);
140 MingwModuleHandler::GetSourceFilenames ( const Module
& module
) const
144 string
sourceFilenames ( "" );
145 for ( i
= 0; i
< module
.files
.size (); i
++ )
146 sourceFilenames
+= " " + module
.files
[i
]->name
;
147 vector
<If
*> ifs
= module
.ifs
;
148 for ( i
= 0; i
< ifs
.size(); i
++ )
152 for ( j
= 0; j
< rIf
.ifs
.size(); j
++ )
153 ifs
.push_back ( rIf
.ifs
[j
] );
154 for ( j
= 0; j
< rIf
.files
.size(); j
++ )
155 sourceFilenames
+= " " + rIf
.files
[j
]->name
;
157 return sourceFilenames
;
161 MingwModuleHandler::GetObjectFilename ( const string
& sourceFilename
) const
164 string extension
= GetExtension ( sourceFilename
);
165 if ( extension
== ".rc" || extension
== ".RC" )
166 newExtension
= ".coff";
169 return FixupTargetFilename ( ReplaceExtension ( sourceFilename
,
174 MingwModuleHandler::GetObjectFilenames ( const Module
& module
) const
176 if ( module
.files
.size () == 0 )
179 string
objectFilenames ( "" );
180 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
182 if ( objectFilenames
.size () > 0 )
183 objectFilenames
+= " ";
184 objectFilenames
+= GetObjectFilename ( module
.files
[i
]->name
);
186 return objectFilenames
;
190 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector
<Define
*>& defines
) const
193 for (size_t i
= 0; i
< defines
.size (); i
++)
195 Define
& define
= *defines
[i
];
196 if (parameters
.length () > 0)
199 parameters
+= define
.name
;
200 if (define
.value
.length () > 0)
203 parameters
+= define
.value
;
210 MingwModuleHandler::GenerateGccDefineParameters ( const Module
& module
) const
212 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.defines
);
213 string s
= GenerateGccDefineParametersFromVector ( module
.defines
);
223 MingwModuleHandler::ConcatenatePaths ( const string
& path1
,
224 const string
& path2
) const
226 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
228 if ( path1
[path1
.length ()] == CSEP
)
229 return path1
+ path2
;
231 return path1
+ CSEP
+ path2
;
235 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
238 for ( size_t i
= 0; i
< includes
.size (); i
++ )
240 Include
& include
= *includes
[i
];
241 if (parameters
.length () > 0)
243 parameters
+= "-I" + include
.directory
;
249 MingwModuleHandler::GenerateGccIncludeParameters ( const Module
& module
) const
251 string parameters
= GenerateGccIncludeParametersFromVector ( module
.includes
);
252 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.includes
);
253 if ( s
.length () > 0 )
263 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
266 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
268 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
269 if ( parameters
.length () > 0 )
271 parameters
+= linkerFlag
.flag
;
277 MingwModuleHandler::GenerateLinkerParameters ( const Module
& module
) const
279 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
283 MingwModuleHandler::GenerateMacro ( const char* assignmentOperation
,
285 const vector
<Include
*>& includes
,
286 const vector
<Define
*>& defines
) const
294 assignmentOperation
);
295 for ( i
= 0; i
< includes
.size(); i
++ )
300 includes
[i
]->directory
.c_str() );
302 for ( i
= 0; i
< defines
.size(); i
++ )
304 Define
& d
= *defines
[i
];
309 if ( d
.value
.size() )
315 fprintf ( fMakefile
, "\n" );
319 MingwModuleHandler::GenerateMacros (
320 const char* assignmentOperation
,
321 const vector
<File
*>& files
,
322 const vector
<Include
*>& includes
,
323 const vector
<Define
*>& defines
,
324 const vector
<LinkerFlag
*>* linkerFlags
,
325 const vector
<If
*>& ifs
,
326 const string
& cflags_macro
,
327 const string
& nasmflags_macro
,
328 const string
& windresflags_macro
,
329 const string
& linkerflags_macro
,
330 const string
& objs_macro
) const
334 if ( includes
.size() || defines
.size() )
336 GenerateMacro ( assignmentOperation
,
340 GenerateMacro ( assignmentOperation
,
346 if ( linkerFlags
!= NULL
)
348 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
349 if ( linkerParameters
.size () > 0 )
354 linkerflags_macro
.c_str (),
356 linkerParameters
.c_str() );
366 assignmentOperation
);
367 for ( i
= 0; i
< files
.size(); i
++ )
372 ( i
%10 == 9 ? "\\\n\t" : " " ),
373 GetObjectFilename(files
[i
]->name
).c_str() );
375 fprintf ( fMakefile
, "\n" );
378 for ( i
= 0; i
< ifs
.size(); i
++ )
381 if ( rIf
.defines
.size() || rIf
.includes
.size() || rIf
.files
.size() || rIf
.ifs
.size() )
385 "ifeq (\"$(%s)\",\"%s\")\n",
386 rIf
.property
.c_str(),
408 MingwModuleHandler::GenerateMacros (
409 const Module
& module
,
410 const string
& cflags_macro
,
411 const string
& nasmflags_macro
,
412 const string
& windresflags_macro
,
413 const string
& linkerflags_macro
,
414 const string
& objs_macro
) const
428 fprintf ( fMakefile
, "\n" );
432 "%s += $(PROJECT_CFLAGS)\n\n",
433 cflags_macro
.c_str () );
437 "%s += $(PROJECT_RCFLAGS)\n\n",
438 windresflags_macro
.c_str () );
442 "%s_LFLAGS += $(PROJECT_LFLAGS)\n\n",
443 module
.name
.c_str () );
447 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
448 const string
& sourceFilename
,
450 const string
& cflagsMacro
) const
452 string objectFilename
= GetObjectFilename ( sourceFilename
);
453 return ssprintf ( "%s -c %s -o %s %s\n",
455 sourceFilename
.c_str (),
456 objectFilename
.c_str (),
457 cflagsMacro
.c_str () );
461 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
462 const string
& sourceFilename
,
464 const string
& cflagsMacro
) const
466 string objectFilename
= GetObjectFilename ( sourceFilename
);
467 return ssprintf ( "%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
469 sourceFilename
.c_str (),
470 objectFilename
.c_str (),
471 cflagsMacro
.c_str () );
475 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
476 const string
& sourceFilename
,
477 const string
& nasmflagsMacro
) const
479 string objectFilename
= GetObjectFilename ( sourceFilename
);
480 return ssprintf ( "%s -f win32 %s -o %s %s\n",
482 sourceFilename
.c_str (),
483 objectFilename
.c_str (),
484 nasmflagsMacro
.c_str () );
488 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
489 const string
& sourceFilename
,
490 const string
& windresflagsMacro
) const
492 string objectFilename
= GetObjectFilename ( sourceFilename
);
493 return ssprintf ( "%s %s -o %s ${%s}\n",
495 sourceFilename
.c_str (),
496 objectFilename
.c_str (),
497 windresflagsMacro
.c_str () );
501 MingwModuleHandler::GenerateCommand ( const Module
& module
,
502 const string
& sourceFilename
,
504 const string
& cflagsMacro
,
505 const string
& nasmflagsMacro
,
506 const string
& windresflagsMacro
) const
508 string extension
= GetExtension ( sourceFilename
);
509 if ( extension
== ".c" || extension
== ".C" )
510 return GenerateGccCommand ( module
,
514 else if ( extension
== ".s" || extension
== ".S" )
515 return GenerateGccAssemblerCommand ( module
,
519 else if ( extension
== ".asm" || extension
== ".ASM" )
520 return GenerateNasmCommand ( module
,
523 else if ( extension
== ".rc" || extension
== ".RC" )
524 return GenerateWindresCommand ( module
,
528 throw InvalidOperationException ( __FILE__
,
530 "Unsupported filename extension '%s' in file '%s'",
532 sourceFilename
.c_str () );
536 MingwModuleHandler::GenerateLinkerCommand ( const Module
& module
,
537 const string
& linker
,
538 const string
& linkerParameters
,
539 const string
& objectFilenames
) const
541 string
targetName ( module
.GetTargetName () );
542 string
target ( FixupTargetFilename ( module
.GetPath () ) );
543 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
544 if ( module
.importLibrary
!= NULL
)
546 static string
ros_junk ( "$(ROS_TEMPORARY)" );
547 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
548 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
549 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
552 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
554 linkerParameters
.c_str (),
557 objectFilenames
.c_str (),
558 importLibraryDependencies
.c_str (),
559 GetLinkerMacro ( module
).c_str () );
566 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s --kill-at\n",
569 FixupTargetFilename ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
577 "\t%s %s %s -o %s %s %s %s\n\n",
579 linkerParameters
.c_str (),
582 objectFilenames
.c_str (),
583 importLibraryDependencies
.c_str (),
584 GetLinkerMacro ( module
).c_str () );
593 "\t%s %s -o %s %s %s %s\n\n",
595 linkerParameters
.c_str (),
597 objectFilenames
.c_str (),
598 importLibraryDependencies
.c_str (),
599 GetLinkerMacro ( module
).c_str () );
604 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
605 const vector
<File
*>& files
,
606 const vector
<If
*>& ifs
,
608 const string
& cflagsMacro
,
609 const string
& nasmflagsMacro
,
610 const string
& windresflagsMacro
) const
614 for ( i
= 0; i
< files
.size (); i
++ )
616 string sourceFilename
= files
[i
]->name
;
617 string objectFilename
= GetObjectFilename ( sourceFilename
);
620 objectFilename
.c_str (),
621 sourceFilename
.c_str () );
624 GenerateCommand ( module
,
629 windresflagsMacro
).c_str () );
632 for ( i
= 0; i
< ifs
.size(); i
++ )
633 GenerateObjectFileTargets ( module
,
643 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
645 const string
& cflagsMacro
,
646 const string
& nasmflagsMacro
,
647 const string
& windresflagsMacro
) const
649 GenerateObjectFileTargets ( module
,
656 fprintf ( fMakefile
, "\n" );
660 MingwModuleHandler::GetCleanTargets ( vector
<string
>& out
,
661 const vector
<File
*>& files
,
662 const vector
<If
*>& ifs
) const
666 for ( i
= 0; i
< files
.size(); i
++ )
667 out
.push_back ( GetObjectFilename(files
[i
]->name
) );
669 for ( i
= 0; i
< ifs
.size(); i
++ )
670 GetCleanTargets ( out
, ifs
[i
]->files
, ifs
[i
]->ifs
);
674 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
676 const string
& objs_macro
) const
678 string archiveFilename
= GetModuleArchiveFilename ( module
);
682 archiveFilename
.c_str (),
683 objs_macro
.c_str ());
686 "\t%s -rc %s %s\n\n",
688 archiveFilename
.c_str (),
689 objs_macro
.c_str ());
691 return archiveFilename
;
695 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
697 return ssprintf ( "$(%s_CFLAGS)",
698 module
.name
.c_str () );
702 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
704 return ssprintf ( "$(%s_OBJS)",
705 module
.name
.c_str () );
709 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
711 return ssprintf ( "$(%s_LFLAGS)",
712 module
.name
.c_str () );
716 MingwModuleHandler::GenerateMacrosAndTargets (
717 const Module
& module
,
720 const string
* cflags
) const
722 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
723 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
724 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
725 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
726 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
728 GenerateMacros ( module
,
735 if ( cflags
!= NULL
)
739 cflagsMacro
.c_str (),
743 // generate phony target for module name
744 fprintf ( fMakefile
, ".PHONY: %s\n",
745 module
.name
.c_str () );
746 fprintf ( fMakefile
, "%s: %s\n\n",
747 module
.name
.c_str (),
748 module
.GetPath ().c_str () );
750 // future references to the macros will be to get their values
751 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
752 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
753 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
755 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
756 GenerateObjectFileTargets ( module
,
762 vector
<string
> clean_files
;
763 clean_files
.push_back ( FixupTargetFilename(module
.GetPath()) );
764 clean_files
.push_back ( ar_target
);
765 GetCleanTargets ( clean_files
, module
.files
, module
.ifs
);
767 fprintf ( fMakefile
, "clean::\n\t-@$(rm)" );
768 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
771 fprintf ( fMakefile
, " 2>NUL\n\t-@$(rm)" );
772 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
774 fprintf ( fMakefile
, " 2>NUL\n\n" );
778 MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module
& module
) const
780 GenerateMacrosAndTargets ( module
, "${host_gcc}", "${host_ar}", NULL
);
784 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
) const
786 GenerateMacrosAndTargetsTarget ( module
,
791 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
,
792 const string
* clags
) const
794 GenerateMacrosAndTargets ( module
, "${gcc}", "${ar}", clags
);
798 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
801 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
803 Invoke
& invoke
= *module
.invocations
[i
];
804 if (invoke
.invokeModule
== &module
)
805 /* Protect against circular dependencies */
807 if ( dependencies
.length () > 0 )
809 dependencies
+= invoke
.GetTargets ();
815 MingwModuleHandler::GetInvocationParameters ( const Invoke
& invoke
) const
817 string
parameters ( "" );
819 for (i
= 0; i
< invoke
.output
.size (); i
++)
821 if (parameters
.length () > 0)
823 InvokeFile
& invokeFile
= *invoke
.output
[i
];
824 if (invokeFile
.switches
.length () > 0)
826 parameters
+= invokeFile
.switches
;
829 parameters
+= invokeFile
.name
;
832 for (i
= 0; i
< invoke
.input
.size (); i
++)
834 if (parameters
.length () > 0)
836 InvokeFile
& invokeFile
= *invoke
.input
[i
];
837 if (invokeFile
.switches
.length () > 0)
839 parameters
+= invokeFile
.switches
;
842 parameters
+= invokeFile
.name
;
849 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
851 if ( module
.invocations
.size () == 0 )
854 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
856 const Invoke
& invoke
= *module
.invocations
[i
];
858 if ( invoke
.invokeModule
->type
!= BuildTool
)
859 throw InvalidBuildFileException ( module
.node
.location
,
860 "Only modules of type buildtool can be invoked." );
862 string invokeTarget
= module
.GetInvocationTarget ( i
);
865 invoke
.GetTargets ().c_str (),
866 invokeTarget
.c_str () );
869 invokeTarget
.c_str (),
870 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
873 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
874 GetInvocationParameters ( invoke
).c_str () );
877 invokeTarget
.c_str () );
882 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
884 return ssprintf ( "%s_precondition",
885 module
.name
.c_str () );
889 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
891 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
892 string sourceFilenames
= GetSourceFilenames ( module
);
893 string dependencies
= GetModuleDependencies ( module
);
894 string s
= GetInvocationDependencies ( module
);
895 if ( s
.length () > 0 )
897 if ( dependencies
.length () > 0 )
904 preconditionDependenciesName
.c_str () );
907 preconditionDependenciesName
.c_str (),
908 dependencies
.c_str () );
909 const char* p
= sourceFilenames
.c_str();
910 const char* end
= p
+ strlen(p
);
913 const char* p2
= &p
[512];
916 while ( p2
> p
&& !isspace(*p2
) )
920 p2
= strpbrk ( p
, " \t" );
928 preconditionDependenciesName
.c_str ());
930 p
+= strspn ( p
, " \t" );
932 fprintf ( fMakefile
, "\n" );
936 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module
& module
) const
938 if ( module
.importLibrary
!= NULL
)
940 fprintf ( fMakefile
, "%s:\n",
941 module
.GetDependencyPath ().c_str () );
944 "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
945 module
.GetTargetName ().c_str (),
946 FixupTargetFilename ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
947 FixupTargetFilename ( module
.GetDependencyPath () ).c_str () );
952 static MingwBuildToolModuleHandler buildtool_handler
;
954 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
955 : MingwModuleHandler ( BuildTool
)
960 MingwBuildToolModuleHandler::Process ( const Module
& module
)
962 GeneratePreconditionDependencies ( module
);
963 GenerateBuildToolModuleTarget ( module
);
964 GenerateInvocations ( module
);
968 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
)
970 string
target ( FixupTargetFilename ( module
.GetPath () ) );
971 string archiveFilename
= GetModuleArchiveFilename ( module
);
973 GenerateMacrosAndTargetsHost ( module
);
975 fprintf ( fMakefile
, "%s: %s\n",
977 archiveFilename
.c_str () );
979 "\t${host_gcc} %s -o %s %s\n\n",
980 GetLinkerMacro ( module
).c_str (),
982 archiveFilename
.c_str () );
985 static MingwKernelModuleHandler kernelmodule_handler
;
987 MingwKernelModuleHandler::MingwKernelModuleHandler ()
988 : MingwModuleHandler ( Kernel
)
993 MingwKernelModuleHandler::Process ( const Module
& module
)
995 GeneratePreconditionDependencies ( module
);
996 GenerateKernelModuleTarget ( module
);
997 GenerateInvocations ( module
);
1001 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
)
1003 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1004 string
targetName ( module
.GetTargetName () );
1005 string
target ( FixupTargetFilename (module
.GetPath ()) );
1006 string workingDirectory
= GetWorkingDirectory ();
1007 string objectsMacro
= GetObjectsMacro ( module
);
1008 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1009 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1010 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1011 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1012 string gccOptions
= ssprintf ("-Wl,-T,%s" SSEP
"ntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,_NtProcessStartup -Wl,--image-base,0xC0000000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1013 module
.GetBasePath ().c_str () );
1015 GenerateMacrosAndTargetsTarget ( module
);
1017 GenerateImportLibraryTargetIfNeeded ( module
);
1019 fprintf ( fMakefile
, "%s: %s %s\n",
1021 objectsMacro
.c_str (),
1022 importLibraryDependencies
.c_str () );
1023 fprintf ( fMakefile
,
1024 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1025 GetLinkerMacro ( module
).c_str (),
1026 gccOptions
.c_str (),
1029 objectsMacro
.c_str (),
1030 importLibraryDependencies
.c_str () );
1031 fprintf ( fMakefile
,
1033 junk_tmp
.c_str () );
1034 fprintf ( fMakefile
,
1035 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s --kill-at\n",
1036 targetName
.c_str (),
1038 temp_exp
.c_str () );
1039 fprintf ( fMakefile
,
1041 base_tmp
.c_str () );
1042 fprintf ( fMakefile
,
1043 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1044 GetLinkerMacro ( module
).c_str (),
1045 gccOptions
.c_str (),
1048 objectsMacro
.c_str (),
1049 importLibraryDependencies
.c_str () );
1050 fprintf ( fMakefile
,
1052 temp_exp
.c_str () );
1056 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1058 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1059 : MingwModuleHandler ( StaticLibrary
)
1064 MingwStaticLibraryModuleHandler::Process ( const Module
& module
)
1066 GeneratePreconditionDependencies ( module
);
1067 GenerateStaticLibraryModuleTarget ( module
);
1068 GenerateInvocations ( module
);
1072 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
)
1074 GenerateMacrosAndTargetsTarget ( module
);
1078 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1080 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1081 : MingwModuleHandler ( KernelModeDLL
)
1086 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
)
1088 GeneratePreconditionDependencies ( module
);
1089 GenerateKernelModeDLLModuleTarget ( module
);
1090 GenerateInvocations ( module
);
1094 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Module
& module
)
1096 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1097 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1098 string workingDirectory
= GetWorkingDirectory ( );
1099 string archiveFilename
= GetModuleArchiveFilename ( module
);
1100 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1102 GenerateImportLibraryTargetIfNeeded ( module
);
1104 if ( module
.files
.size () > 0 )
1106 GenerateMacrosAndTargetsTarget ( module
);
1108 fprintf ( fMakefile
, "%s: %s %s\n",
1110 archiveFilename
.c_str (),
1111 importLibraryDependencies
.c_str () );
1113 string
linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );
1114 GenerateLinkerCommand ( module
,
1121 fprintf ( fMakefile
, "%s:\n",
1123 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1129 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1131 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1132 : MingwModuleHandler ( KernelModeDriver
)
1137 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
)
1139 GeneratePreconditionDependencies ( module
);
1140 GenerateKernelModeDriverModuleTarget ( module
);
1141 GenerateInvocations ( module
);
1145 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module
& module
)
1147 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1148 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1149 string workingDirectory
= GetWorkingDirectory ( );
1150 string archiveFilename
= GetModuleArchiveFilename ( module
);
1151 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1153 GenerateImportLibraryTargetIfNeeded ( module
);
1155 if ( module
.files
.size () > 0 )
1157 string
* cflags
= new string ( "-D__NTDRIVER__" );
1158 GenerateMacrosAndTargetsTarget ( module
,
1162 fprintf ( fMakefile
, "%s: %s %s\n",
1164 archiveFilename
.c_str (),
1165 importLibraryDependencies
.c_str () );
1167 string
linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );
1168 GenerateLinkerCommand ( module
,
1175 fprintf ( fMakefile
, "%s:\n",
1177 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1183 static MingwNativeDLLModuleHandler nativedll_handler
;
1185 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1186 : MingwModuleHandler ( NativeDLL
)
1191 MingwNativeDLLModuleHandler::Process ( const Module
& module
)
1193 GeneratePreconditionDependencies ( module
);
1194 GenerateNativeDLLModuleTarget ( module
);
1195 GenerateInvocations ( module
);
1199 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
)
1201 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1202 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1203 string workingDirectory
= GetWorkingDirectory ( );
1204 string objectFilenames
= GetObjectFilenames ( module
);
1205 string archiveFilename
= GetModuleArchiveFilename ( module
);
1206 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1208 GenerateImportLibraryTargetIfNeeded ( module
);
1210 if ( module
.files
.size () > 0 )
1212 GenerateMacrosAndTargetsTarget ( module
);
1214 fprintf ( fMakefile
, "%s: %s %s\n",
1216 archiveFilename
.c_str (),
1217 importLibraryDependencies
.c_str () );
1219 string
linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DllMainCRTStartup@12 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll" );
1220 GenerateLinkerCommand ( module
,
1227 fprintf ( fMakefile
, "%s:\n\n",
1229 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1235 static MingwWin32DLLModuleHandler win32dll_handler
;
1237 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1238 : MingwModuleHandler ( Win32DLL
)
1243 MingwWin32DLLModuleHandler::Process ( const Module
& module
)
1245 GeneratePreconditionDependencies ( module
);
1246 GenerateWin32DLLModuleTarget ( module
);
1247 GenerateInvocations ( module
);
1251 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
)
1253 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1254 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1255 string workingDirectory
= GetWorkingDirectory ( );
1256 string archiveFilename
= GetModuleArchiveFilename ( module
);
1257 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1259 GenerateImportLibraryTargetIfNeeded ( module
);
1261 if ( module
.files
.size () > 0 )
1263 GenerateMacrosAndTargetsTarget ( module
);
1265 fprintf ( fMakefile
, "%s: %s %s\n",
1267 archiveFilename
.c_str (),
1268 importLibraryDependencies
.c_str () );
1270 string
linkerParameters ( "-Wl,--subsystem,console -Wl,--entry,_DllMain@12 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll" );
1271 GenerateLinkerCommand ( module
,
1278 fprintf ( fMakefile
, "%s:\n\n",
1280 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1286 static MingwWin32GUIModuleHandler win32gui_handler
;
1288 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
1289 : MingwModuleHandler ( Win32GUI
)
1294 MingwWin32GUIModuleHandler::Process ( const Module
& module
)
1296 GeneratePreconditionDependencies ( module
);
1297 GenerateWin32GUIModuleTarget ( module
);
1298 GenerateInvocations ( module
);
1302 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
)
1304 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1305 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1306 string workingDirectory
= GetWorkingDirectory ( );
1307 string objectFilenames
= GetObjectFilenames ( module
);
1308 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1310 GenerateImportLibraryTargetIfNeeded ( module
);
1312 if ( module
.files
.size () > 0 )
1314 GenerateMacrosAndTargetsTarget ( module
);
1316 fprintf ( fMakefile
, "%s: %s %s\n",
1318 objectFilenames
.c_str (),
1319 importLibraryDependencies
.c_str () );
1321 string
linkerParameters ( "-Wl,--subsystem,windows -Wl,--entry,_WinMainCRTStartup -Wl,--image-base,0x00400000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000" );
1322 GenerateLinkerCommand ( module
,
1329 fprintf ( fMakefile
, "%s:\n\n",
1331 fprintf ( fMakefile
, ".PHONY: %s\n\n",