4 #include "../../rbuild.h"
6 #include "modulehandler.h"
13 map
<ModuleType
,MingwModuleHandler
*>*
14 MingwModuleHandler::handler_map
= NULL
;
16 MingwModuleHandler::directory_set
;
18 MingwModuleHandler::ref
= 0;
21 MingwModuleHandler::fMakefile
= NULL
;
23 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype
)
26 handler_map
= new map
<ModuleType
,MingwModuleHandler
*>;
27 (*handler_map
)[moduletype
] = this;
30 MingwModuleHandler::~MingwModuleHandler()
40 MingwModuleHandler::PassThruCacheDirectory( const string
&file
) const
42 directory_set
.insert( ReplaceExtension( GetDirectory( file
), "" ) );
47 MingwModuleHandler::SetMakefile ( FILE* f
)
53 MingwModuleHandler::LookupHandler ( const string
& location
,
54 ModuleType moduletype
)
57 throw Exception ( "internal tool error: no registered module handlers" );
58 MingwModuleHandler
* h
= (*handler_map
)[moduletype
];
61 throw UnknownModuleTypeException ( location
, moduletype
);
68 MingwModuleHandler::GetWorkingDirectory () const
74 MingwModuleHandler::GetDirectory ( const string
& filename
) const
76 size_t index
= filename
.find_last_of ( '/' );
77 if (index
== string::npos
) return ".";
78 else return filename
.substr ( 0, index
);
82 MingwModuleHandler::GetExtension ( const string
& filename
) const
84 size_t index
= filename
.find_last_of ( '/' );
85 if (index
== string::npos
) index
= 0;
86 string tmp
= filename
.substr( index
, filename
.size() - index
);
87 size_t ext_index
= tmp
.find_last_of( '.' );
88 if (ext_index
!= string::npos
)
89 return filename
.substr ( index
+ ext_index
, filename
.size() );
94 MingwModuleHandler::GetBasename ( const string
& filename
) const
96 size_t index
= filename
.find_last_of ( '.' );
97 if (index
!= string::npos
)
98 return filename
.substr ( 0, index
);
103 MingwModuleHandler::ReplaceExtension ( const string
& filename
,
104 const string
& newExtension
) const
106 size_t index
= filename
.find_last_of ( '/' );
107 if (index
== string::npos
) index
= 0;
108 string tmp
= filename
.substr( index
, filename
.size() - index
);
109 size_t ext_index
= tmp
.find_last_of( '.' );
110 if (ext_index
!= string::npos
)
111 return filename
.substr ( 0, index
+ ext_index
) + newExtension
;
112 return filename
+ newExtension
;
116 MingwModuleHandler::GetActualSourceFilename ( const string
& filename
) const
118 string extension
= GetExtension ( filename
);
119 if ( extension
== ".spec" || extension
== "SPEC" )
121 string basename
= GetBasename( filename
);
122 return basename
+ ".stubs.c";
129 MingwModuleHandler::GetModuleArchiveFilename ( const Module
& module
) const
131 return ReplaceExtension ( FixupTargetFilename ( module
.GetPath () ),
136 MingwModuleHandler::GetImportLibraryDependencies ( const Module
& module
) const
138 if ( module
.libraries
.size () == 0 )
141 string
dependencies ( "" );
142 for ( size_t i
= 0; i
< module
.libraries
.size (); i
++ )
144 if ( dependencies
.size () > 0 )
146 const Module
* importedModule
= module
.project
.LocateModule ( module
.libraries
[i
]->name
);
147 assert ( importedModule
!= NULL
);
148 dependencies
+= PassThruCacheDirectory ( FixupTargetFilename ( importedModule
->GetDependencyPath () ) ).c_str ();
154 MingwModuleHandler::GetModuleDependencies ( const Module
& module
) const
156 if ( module
.dependencies
.size () == 0 )
159 string
dependencies ( "" );
160 for ( size_t i
= 0; i
< module
.dependencies
.size (); i
++ )
162 if ( dependencies
.size () > 0 )
164 const Dependency
* dependency
= module
.dependencies
[i
];
165 const Module
* dependencyModule
= dependency
->dependencyModule
;
166 dependencies
+= dependencyModule
->GetTargets ();
168 string definitionDependencies
= GetDefinitionDependencies ( module
);
169 if ( dependencies
.length () > 0 && definitionDependencies
.length () > 0 )
170 dependencies
+= " " + definitionDependencies
;
171 else if ( definitionDependencies
.length () > 0 )
172 dependencies
= definitionDependencies
;
177 MingwModuleHandler::GetAllDependencies ( const Module
& module
) const
179 string dependencies
= GetImportLibraryDependencies ( module
);
180 string s
= GetModuleDependencies ( module
);
190 MingwModuleHandler::GetSourceFilenames ( const Module
& module
) const
194 string
sourceFilenames ( "" );
195 for ( i
= 0; i
< module
.files
.size (); i
++ )
196 sourceFilenames
+= " " + GetActualSourceFilename ( module
.files
[i
]->name
);
197 vector
<If
*> ifs
= module
.ifs
;
198 for ( i
= 0; i
< ifs
.size(); i
++ )
202 for ( j
= 0; j
< rIf
.ifs
.size(); j
++ )
203 ifs
.push_back ( rIf
.ifs
[j
] );
204 for ( j
= 0; j
< rIf
.files
.size(); j
++ )
205 sourceFilenames
+= " " + GetActualSourceFilename ( rIf
.files
[j
]->name
);
207 return sourceFilenames
;
211 MingwModuleHandler::GetObjectFilename ( const string
& sourceFilename
) const
214 string extension
= GetExtension ( sourceFilename
);
215 if ( extension
== ".rc" || extension
== ".RC" )
216 newExtension
= ".coff";
217 else if ( extension
== ".spec" || extension
== ".SPEC" )
218 newExtension
= ".stubs.o";
221 return PassThruCacheDirectory
222 ( FixupTargetFilename ( ReplaceExtension ( sourceFilename
,
227 MingwModuleHandler::GetObjectFilenames ( const Module
& module
) const
229 if ( module
.files
.size () == 0 )
232 string
objectFilenames ( "" );
233 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
235 if ( objectFilenames
.size () > 0 )
236 objectFilenames
+= " ";
237 objectFilenames
+= GetObjectFilename ( module
.files
[i
]->name
);
239 return objectFilenames
;
243 MingwModuleHandler::GenerateDirectoryTargets() const
245 fprintf( fMakefile
, "ifneq ($(ROS_INTERMEDIATE),)\ndirectories::" );
247 for( set
<string
>::iterator i
= directory_set
.begin();
248 i
!= directory_set
.end();
250 fprintf( fMakefile
, " %s", i
->c_str() );
252 fprintf( fMakefile
, "\n\n" );
254 for( set
<string
>::iterator i
= directory_set
.begin();
255 i
!= directory_set
.end();
257 fprintf( fMakefile
, "%s ", i
->c_str() );
260 "::\n\t${mkdir} $@\n\n"
265 directory_set
.clear();
269 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector
<Define
*>& defines
) const
272 for (size_t i
= 0; i
< defines
.size (); i
++)
274 Define
& define
= *defines
[i
];
275 if (parameters
.length () > 0)
278 parameters
+= define
.name
;
279 if (define
.value
.length () > 0)
282 parameters
+= define
.value
;
289 MingwModuleHandler::GenerateGccDefineParameters ( const Module
& module
) const
291 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.defines
);
292 string s
= GenerateGccDefineParametersFromVector ( module
.defines
);
302 MingwModuleHandler::ConcatenatePaths ( const string
& path1
,
303 const string
& path2
) const
305 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
307 if ( path1
[path1
.length ()] == CSEP
)
308 return path1
+ path2
;
310 return path1
+ CSEP
+ path2
;
314 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
317 for ( size_t i
= 0; i
< includes
.size (); i
++ )
319 Include
& include
= *includes
[i
];
320 if (parameters
.length () > 0)
322 parameters
+= "-I" + include
.directory
;
328 MingwModuleHandler::GenerateGccIncludeParameters ( const Module
& module
) const
330 string parameters
= GenerateGccIncludeParametersFromVector ( module
.includes
);
331 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.includes
);
332 if ( s
.length () > 0 )
342 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
345 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
347 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
348 if ( parameters
.length () > 0 )
350 parameters
+= linkerFlag
.flag
;
356 MingwModuleHandler::GenerateLinkerParameters ( const Module
& module
) const
358 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
362 MingwModuleHandler::GenerateMacro ( const char* assignmentOperation
,
364 const vector
<Include
*>& includes
,
365 const vector
<Define
*>& defines
) const
373 assignmentOperation
);
374 for ( i
= 0; i
< includes
.size(); i
++ )
379 includes
[i
]->directory
.c_str() );
381 for ( i
= 0; i
< defines
.size(); i
++ )
383 Define
& d
= *defines
[i
];
388 if ( d
.value
.size() )
394 fprintf ( fMakefile
, "\n" );
398 MingwModuleHandler::GenerateMacros (
399 const char* assignmentOperation
,
400 const vector
<File
*>& files
,
401 const vector
<Include
*>& includes
,
402 const vector
<Define
*>& defines
,
403 const vector
<LinkerFlag
*>* linkerFlags
,
404 const vector
<If
*>& ifs
,
405 const string
& cflags_macro
,
406 const string
& nasmflags_macro
,
407 const string
& windresflags_macro
,
408 const string
& linkerflags_macro
,
409 const string
& objs_macro
) const
413 if ( includes
.size() || defines
.size() )
415 GenerateMacro ( assignmentOperation
,
419 GenerateMacro ( assignmentOperation
,
425 if ( linkerFlags
!= NULL
)
427 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
428 if ( linkerParameters
.size () > 0 )
433 linkerflags_macro
.c_str (),
435 linkerParameters
.c_str() );
445 assignmentOperation
);
446 for ( i
= 0; i
< files
.size(); i
++ )
448 string extension
= GetExtension ( files
[i
]->name
);
449 if ( extension
!= ".spec" && extension
!= ".SPEC" )
454 ( i
%10 == 9 ? "\\\n\t" : " " ),
455 GetObjectFilename(files
[i
]->name
).c_str() );
458 fprintf ( fMakefile
, "\n" );
461 for ( i
= 0; i
< ifs
.size(); i
++ )
464 if ( rIf
.defines
.size() || rIf
.includes
.size() || rIf
.files
.size() || rIf
.ifs
.size() )
468 "ifeq (\"$(%s)\",\"%s\")\n",
469 rIf
.property
.c_str(),
491 MingwModuleHandler::GenerateMacros (
492 const Module
& module
,
493 const string
& cflags_macro
,
494 const string
& nasmflags_macro
,
495 const string
& windresflags_macro
,
496 const string
& linkerflags_macro
,
497 const string
& objs_macro
) const
511 fprintf ( fMakefile
, "\n" );
515 "%s += $(PROJECT_CFLAGS)\n\n",
516 cflags_macro
.c_str () );
520 "%s += $(PROJECT_RCFLAGS)\n\n",
521 windresflags_macro
.c_str () );
525 "%s_LFLAGS += $(PROJECT_LFLAGS)\n\n",
526 module
.name
.c_str () );
530 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
531 const string
& sourceFilename
,
533 const string
& cflagsMacro
) const
535 string objectFilename
= GetObjectFilename ( sourceFilename
);
538 objectFilename
.c_str (),
539 sourceFilename
.c_str () );
541 "\t%s -c %s -o %s %s\n",
543 sourceFilename
.c_str (),
544 objectFilename
.c_str (),
545 cflagsMacro
.c_str () );
549 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
550 const string
& sourceFilename
,
552 const string
& cflagsMacro
) const
554 string objectFilename
= GetObjectFilename ( sourceFilename
);
557 objectFilename
.c_str (),
558 sourceFilename
.c_str () );
560 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
562 sourceFilename
.c_str (),
563 objectFilename
.c_str (),
564 cflagsMacro
.c_str () );
568 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
569 const string
& sourceFilename
,
570 const string
& nasmflagsMacro
) const
572 string objectFilename
= GetObjectFilename ( sourceFilename
);
575 objectFilename
.c_str (),
576 sourceFilename
.c_str () );
578 "\t%s -f win32 %s -o %s %s\n",
580 sourceFilename
.c_str (),
581 objectFilename
.c_str (),
582 nasmflagsMacro
.c_str () );
586 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
587 const string
& sourceFilename
,
588 const string
& windresflagsMacro
) const
590 string objectFilename
= GetObjectFilename ( sourceFilename
);
593 objectFilename
.c_str (),
594 sourceFilename
.c_str () );
596 "\t%s %s -o %s ${%s}\n",
598 sourceFilename
.c_str (),
599 objectFilename
.c_str (),
600 windresflagsMacro
.c_str () );
604 MingwModuleHandler::GenerateWinebuildCommands ( const Module
& module
,
605 const string
& sourceFilename
) const
607 string basename
= GetBasename ( sourceFilename
);
611 sourceFilename
.c_str () );
613 "\t%s --def=%s -o %s.def\n",
615 sourceFilename
.c_str (),
621 sourceFilename
.c_str () );
623 "\t%s --pedll=%s -o %s.stubs.c\n",
625 sourceFilename
.c_str (),
630 MingwModuleHandler::GenerateCommands ( const Module
& module
,
631 const string
& sourceFilename
,
633 const string
& cflagsMacro
,
634 const string
& nasmflagsMacro
,
635 const string
& windresflagsMacro
) const
637 string extension
= GetExtension ( sourceFilename
);
638 if ( extension
== ".c" || extension
== ".C" )
640 GenerateGccCommand ( module
,
646 else if ( extension
== ".s" || extension
== ".S" )
648 GenerateGccAssemblerCommand ( module
,
654 else if ( extension
== ".asm" || extension
== ".ASM" )
656 GenerateNasmCommand ( module
,
661 else if ( extension
== ".rc" || extension
== ".RC" )
663 GenerateWindresCommand ( module
,
668 else if ( extension
== ".spec" || extension
== ".SPEC" )
670 GenerateWinebuildCommands ( module
,
672 GenerateGccCommand ( module
,
673 GetActualSourceFilename ( sourceFilename
),
679 throw InvalidOperationException ( __FILE__
,
681 "Unsupported filename extension '%s' in file '%s'",
683 sourceFilename
.c_str () );
687 MingwModuleHandler::GenerateLinkerCommand ( const Module
& module
,
688 const string
& linker
,
689 const string
& linkerParameters
,
690 const string
& objectFilenames
) const
692 string
targetName ( module
.GetTargetName () );
693 string
target ( FixupTargetFilename ( module
.GetPath () ) );
694 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
695 if ( module
.importLibrary
!= NULL
)
697 static string
ros_junk ( "$(ROS_TEMPORARY)" );
698 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
699 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
700 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
703 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
705 linkerParameters
.c_str (),
708 objectFilenames
.c_str (),
709 importLibraryDependencies
.c_str (),
710 GetLinkerMacro ( module
).c_str () );
717 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s --kill-at\n",
720 (module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
728 "\t%s %s %s -o %s %s %s %s\n\n",
730 linkerParameters
.c_str (),
733 objectFilenames
.c_str (),
734 importLibraryDependencies
.c_str (),
735 GetLinkerMacro ( module
).c_str () );
744 "\t%s %s -o %s %s %s %s\n\n",
746 linkerParameters
.c_str (),
748 objectFilenames
.c_str (),
749 importLibraryDependencies
.c_str (),
750 GetLinkerMacro ( module
).c_str () );
755 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
756 const vector
<File
*>& files
,
757 const vector
<If
*>& ifs
,
759 const string
& cflagsMacro
,
760 const string
& nasmflagsMacro
,
761 const string
& windresflagsMacro
) const
765 for ( i
= 0; i
< files
.size (); i
++ )
767 string sourceFilename
= files
[i
]->name
;
768 GenerateCommands ( module
,
778 for ( i
= 0; i
< ifs
.size(); i
++ )
779 GenerateObjectFileTargets ( module
,
789 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
791 const string
& cflagsMacro
,
792 const string
& nasmflagsMacro
,
793 const string
& windresflagsMacro
) const
795 GenerateObjectFileTargets ( module
,
802 fprintf ( fMakefile
, "\n" );
806 MingwModuleHandler::GetCleanTargets ( vector
<string
>& out
,
807 const vector
<File
*>& files
,
808 const vector
<If
*>& ifs
) const
812 for ( i
= 0; i
< files
.size(); i
++ )
813 out
.push_back ( GetObjectFilename(files
[i
]->name
) );
815 for ( i
= 0; i
< ifs
.size(); i
++ )
816 GetCleanTargets ( out
, ifs
[i
]->files
, ifs
[i
]->ifs
);
820 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
822 const string
& objs_macro
) const
824 string archiveFilename
= GetModuleArchiveFilename ( module
);
828 archiveFilename
.c_str (),
829 objs_macro
.c_str ());
832 "\t%s -rc %s %s\n\n",
834 archiveFilename
.c_str (),
835 objs_macro
.c_str ());
837 return archiveFilename
;
841 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
843 return ssprintf ( "$(%s_CFLAGS)",
844 module
.name
.c_str () );
848 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
850 return ssprintf ( "$(%s_OBJS)",
851 module
.name
.c_str () );
855 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
857 return ssprintf ( "$(%s_LFLAGS)",
858 module
.name
.c_str () );
862 MingwModuleHandler::GenerateMacrosAndTargets (
863 const Module
& module
,
866 const string
* cflags
) const
868 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
869 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
870 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
871 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
872 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
874 GenerateMacros ( module
,
881 if ( cflags
!= NULL
)
885 cflagsMacro
.c_str (),
889 // generate phony target for module name
890 fprintf ( fMakefile
, ".PHONY: %s\n",
891 module
.name
.c_str () );
892 fprintf ( fMakefile
, "%s: %s\n\n",
893 module
.name
.c_str (),
894 module
.GetPath ().c_str () );
896 // future references to the macros will be to get their values
897 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
898 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
899 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
901 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
902 GenerateObjectFileTargets ( module
,
908 vector
<string
> clean_files
;
909 clean_files
.push_back ( FixupTargetFilename(module
.GetPath()) );
910 clean_files
.push_back ( ar_target
);
911 GetCleanTargets ( clean_files
, module
.files
, module
.ifs
);
913 fprintf ( fMakefile
, "clean::\n\t-@$(rm)" );
914 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
917 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
918 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
920 fprintf ( fMakefile
, " 2>$(NUL)\n\n" );
924 MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module
& module
) const
926 GenerateMacrosAndTargets ( module
, "${host_gcc}", "${host_ar}", NULL
);
930 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
) const
932 GenerateMacrosAndTargetsTarget ( module
,
937 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
,
938 const string
* clags
) const
940 GenerateMacrosAndTargets ( module
, "${gcc}", "${ar}", clags
);
944 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
947 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
949 Invoke
& invoke
= *module
.invocations
[i
];
950 if (invoke
.invokeModule
== &module
)
951 /* Protect against circular dependencies */
953 if ( dependencies
.length () > 0 )
955 dependencies
+= invoke
.GetTargets ();
961 MingwModuleHandler::GetInvocationParameters ( const Invoke
& invoke
) const
963 string
parameters ( "" );
965 for (i
= 0; i
< invoke
.output
.size (); i
++)
967 if (parameters
.length () > 0)
969 InvokeFile
& invokeFile
= *invoke
.output
[i
];
970 if (invokeFile
.switches
.length () > 0)
972 parameters
+= invokeFile
.switches
;
975 parameters
+= invokeFile
.name
;
978 for (i
= 0; i
< invoke
.input
.size (); i
++)
980 if (parameters
.length () > 0)
982 InvokeFile
& invokeFile
= *invoke
.input
[i
];
983 if (invokeFile
.switches
.length () > 0)
985 parameters
+= invokeFile
.switches
;
988 parameters
+= invokeFile
.name
;
995 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
997 if ( module
.invocations
.size () == 0 )
1000 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1002 const Invoke
& invoke
= *module
.invocations
[i
];
1004 if ( invoke
.invokeModule
->type
!= BuildTool
)
1005 throw InvalidBuildFileException ( module
.node
.location
,
1006 "Only modules of type buildtool can be invoked." );
1008 string invokeTarget
= module
.GetInvocationTarget ( i
);
1009 fprintf ( fMakefile
,
1011 invoke
.GetTargets ().c_str (),
1012 invokeTarget
.c_str () );
1013 fprintf ( fMakefile
,
1015 invokeTarget
.c_str (),
1016 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1017 fprintf ( fMakefile
,
1019 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1020 GetInvocationParameters ( invoke
).c_str () );
1021 fprintf ( fMakefile
,
1023 invokeTarget
.c_str () );
1028 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1030 return ssprintf ( "%s_precondition",
1031 module
.name
.c_str () );
1035 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
1037 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1038 string sourceFilenames
= GetSourceFilenames ( module
);
1039 string dependencies
= GetModuleDependencies ( module
);
1040 string s
= GetInvocationDependencies ( module
);
1041 if ( s
.length () > 0 )
1043 if ( dependencies
.length () > 0 )
1044 dependencies
+= " ";
1048 fprintf ( fMakefile
,
1050 preconditionDependenciesName
.c_str () );
1051 fprintf ( fMakefile
,
1053 preconditionDependenciesName
.c_str (),
1054 dependencies
.c_str () );
1055 const char* p
= sourceFilenames
.c_str();
1056 const char* end
= p
+ strlen(p
);
1059 const char* p2
= &p
[512];
1062 while ( p2
> p
&& !isspace(*p2
) )
1066 p2
= strpbrk ( p
, " \t" );
1070 fprintf ( fMakefile
,
1074 preconditionDependenciesName
.c_str ());
1076 p
+= strspn ( p
, " \t" );
1078 fprintf ( fMakefile
, "\n" );
1082 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module
& module
) const
1084 if ( module
.importLibrary
!= NULL
)
1086 string definitionDependencies
= GetDefinitionDependencies ( module
);
1087 fprintf ( fMakefile
, "%s: %s\n",
1088 FixupTargetFilename( module
.GetDependencyPath () ).c_str (),
1089 definitionDependencies
.c_str () );
1091 fprintf ( fMakefile
,
1092 "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
1093 module
.GetTargetName ().c_str (),
1094 (module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1095 FixupTargetFilename ( module
.GetDependencyPath () ).c_str () );
1100 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1102 string basename
= GetBasename ( filename
);
1103 return basename
+ ".def" + " " + basename
+ ".stubs.c";
1107 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
) const
1109 string dependencies
;
1110 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
1112 File
& file
= *module
.files
[i
];
1113 string extension
= GetExtension ( file
.name
);
1114 if ( extension
== ".spec" || extension
== ".SPEC" )
1116 if ( dependencies
.length () > 0 )
1117 dependencies
+= " ";
1118 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1121 return dependencies
;
1125 MingwModuleHandler::GetLinkingDependencies ( const Module
& module
) const
1127 string dependencies
= GetImportLibraryDependencies ( module
);
1128 string s
= GetDefinitionDependencies ( module
);
1129 if ( s
.length () > 0 )
1131 dependencies
+= " ";
1134 return dependencies
;
1138 static MingwBuildToolModuleHandler buildtool_handler
;
1140 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1141 : MingwModuleHandler ( BuildTool
)
1146 MingwBuildToolModuleHandler::Process ( const Module
& module
)
1148 GeneratePreconditionDependencies ( module
);
1149 GenerateBuildToolModuleTarget ( module
);
1150 GenerateInvocations ( module
);
1154 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
)
1156 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1157 string archiveFilename
= GetModuleArchiveFilename ( module
);
1159 GenerateMacrosAndTargetsHost ( module
);
1161 fprintf ( fMakefile
, "%s: %s\n",
1163 archiveFilename
.c_str () );
1164 fprintf ( fMakefile
,
1165 "\t${host_gcc} %s -o %s %s\n\n",
1166 GetLinkerMacro ( module
).c_str (),
1168 archiveFilename
.c_str () );
1171 static MingwKernelModuleHandler kernelmodule_handler
;
1173 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1174 : MingwModuleHandler ( Kernel
)
1179 MingwKernelModuleHandler::Process ( const Module
& module
)
1181 GeneratePreconditionDependencies ( module
);
1182 GenerateKernelModuleTarget ( module
);
1183 GenerateInvocations ( module
);
1187 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
)
1189 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1190 string
targetName ( module
.GetTargetName () );
1191 string
target ( FixupTargetFilename (module
.GetPath ()) );
1192 string workingDirectory
= GetWorkingDirectory ();
1193 string objectsMacro
= GetObjectsMacro ( module
);
1194 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1195 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1196 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1197 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1198 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",
1199 module
.GetBasePath ().c_str () );
1201 GenerateMacrosAndTargetsTarget ( module
);
1203 GenerateImportLibraryTargetIfNeeded ( module
);
1205 fprintf ( fMakefile
, "%s: %s %s\n",
1207 objectsMacro
.c_str (),
1208 importLibraryDependencies
.c_str () );
1209 fprintf ( fMakefile
,
1210 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1211 GetLinkerMacro ( module
).c_str (),
1212 gccOptions
.c_str (),
1215 objectsMacro
.c_str (),
1216 importLibraryDependencies
.c_str () );
1217 fprintf ( fMakefile
,
1219 junk_tmp
.c_str () );
1220 fprintf ( fMakefile
,
1221 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s --kill-at\n",
1222 targetName
.c_str (),
1224 temp_exp
.c_str () );
1225 fprintf ( fMakefile
,
1227 base_tmp
.c_str () );
1228 fprintf ( fMakefile
,
1229 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1230 GetLinkerMacro ( module
).c_str (),
1231 gccOptions
.c_str (),
1234 objectsMacro
.c_str (),
1235 importLibraryDependencies
.c_str () );
1236 fprintf ( fMakefile
,
1238 temp_exp
.c_str () );
1242 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1244 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1245 : MingwModuleHandler ( StaticLibrary
)
1250 MingwStaticLibraryModuleHandler::Process ( const Module
& module
)
1252 GeneratePreconditionDependencies ( module
);
1253 GenerateStaticLibraryModuleTarget ( module
);
1254 GenerateInvocations ( module
);
1258 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
)
1260 GenerateMacrosAndTargetsTarget ( module
);
1264 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1266 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1267 : MingwModuleHandler ( KernelModeDLL
)
1272 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
)
1274 GeneratePreconditionDependencies ( module
);
1275 GenerateKernelModeDLLModuleTarget ( module
);
1276 GenerateInvocations ( module
);
1280 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Module
& module
)
1282 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1283 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1284 string workingDirectory
= GetWorkingDirectory ( );
1285 string archiveFilename
= GetModuleArchiveFilename ( module
);
1286 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1288 GenerateImportLibraryTargetIfNeeded ( module
);
1290 if ( module
.files
.size () > 0 )
1292 GenerateMacrosAndTargetsTarget ( module
);
1294 fprintf ( fMakefile
, "%s: %s %s\n",
1296 archiveFilename
.c_str (),
1297 importLibraryDependencies
.c_str () );
1299 string
linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );
1300 GenerateLinkerCommand ( module
,
1307 fprintf ( fMakefile
, "%s:\n",
1309 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1315 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1317 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1318 : MingwModuleHandler ( KernelModeDriver
)
1323 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
)
1325 GeneratePreconditionDependencies ( module
);
1326 GenerateKernelModeDriverModuleTarget ( module
);
1327 GenerateInvocations ( module
);
1332 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module
& module
)
1334 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1335 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1336 string workingDirectory
= GetWorkingDirectory ( );
1337 string archiveFilename
= GetModuleArchiveFilename ( module
);
1338 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1340 GenerateImportLibraryTargetIfNeeded ( module
);
1342 if ( module
.files
.size () > 0 )
1344 string
* cflags
= new string ( "-D__NTDRIVER__" );
1345 GenerateMacrosAndTargetsTarget ( module
,
1349 fprintf ( fMakefile
, "%s: %s %s\n",
1351 archiveFilename
.c_str (),
1352 importLibraryDependencies
.c_str () );
1354 string
linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );
1355 GenerateLinkerCommand ( module
,
1362 fprintf ( fMakefile
, "%s:\n",
1364 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1370 static MingwNativeDLLModuleHandler nativedll_handler
;
1372 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1373 : MingwModuleHandler ( NativeDLL
)
1378 MingwNativeDLLModuleHandler::Process ( const Module
& module
)
1380 GeneratePreconditionDependencies ( module
);
1381 GenerateNativeDLLModuleTarget ( module
);
1382 GenerateInvocations ( module
);
1386 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
)
1388 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1389 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1390 string workingDirectory
= GetWorkingDirectory ( );
1391 string objectFilenames
= GetObjectFilenames ( module
);
1392 string archiveFilename
= GetModuleArchiveFilename ( module
);
1393 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1395 GenerateImportLibraryTargetIfNeeded ( module
);
1397 if ( module
.files
.size () > 0 )
1400 fprintf ( fMakefile
,
1401 "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
1402 module
.GetTargetName ().c_str (),
1403 (module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1404 FixupTargetFilename ( module
.GetDependencyPath () ).c_str () );
1407 if (module
.files
.size () > 0)
1409 GenerateMacrosAndTargetsTarget ( module
);
1411 fprintf ( fMakefile
, "%s: %s %s\n",
1413 archiveFilename
.c_str (),
1414 importLibraryDependencies
.c_str () );
1416 string
linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DllMainCRTStartup@12 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll" );
1417 GenerateLinkerCommand ( module
,
1424 fprintf ( fMakefile
, "%s:\n\n",
1426 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1432 static MingwWin32DLLModuleHandler win32dll_handler
;
1434 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1435 : MingwModuleHandler ( Win32DLL
)
1440 MingwWin32DLLModuleHandler::Process ( const Module
& module
)
1442 GeneratePreconditionDependencies ( module
);
1443 GenerateWin32DLLModuleTarget ( module
);
1444 GenerateInvocations ( module
);
1448 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
)
1450 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1451 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1452 string workingDirectory
= GetWorkingDirectory ( );
1453 string objectFilenames
= GetObjectFilenames ( module
);
1454 string linkingDependencies
= GetLinkingDependencies ( module
);
1456 GenerateImportLibraryTargetIfNeeded ( module
);
1457 if ( module
.files
.size () > 0 )
1459 GenerateMacrosAndTargetsTarget ( module
);
1461 fprintf ( fMakefile
, "%s: %s %s\n",
1463 objectFilenames
.c_str (),
1464 linkingDependencies
.c_str () );
1466 string
linkerParameters ( "-Wl,--subsystem,console -Wl,--entry,_DllMain@12 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll" );
1467 GenerateLinkerCommand ( module
,
1474 fprintf ( fMakefile
, "%s:\n\n",
1476 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1482 static MingwWin32GUIModuleHandler win32gui_handler
;
1484 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
1485 : MingwModuleHandler ( Win32GUI
)
1490 MingwWin32GUIModuleHandler::Process ( const Module
& module
)
1492 GeneratePreconditionDependencies ( module
);
1493 GenerateWin32GUIModuleTarget ( module
);
1494 GenerateInvocations ( module
);
1498 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
)
1500 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1501 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1502 string workingDirectory
= GetWorkingDirectory ( );
1503 string objectFilenames
= GetObjectFilenames ( module
);
1504 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1506 GenerateImportLibraryTargetIfNeeded ( module
);
1508 if ( module
.files
.size () > 0 )
1510 GenerateMacrosAndTargetsTarget ( module
);
1512 fprintf ( fMakefile
, "%s: %s %s\n",
1514 objectFilenames
.c_str (),
1515 importLibraryDependencies
.c_str () );
1517 string
linkerParameters ( "-Wl,--subsystem,windows -Wl,--entry,_WinMainCRTStartup -Wl,--image-base,0x00400000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000" );
1518 GenerateLinkerCommand ( module
,
1525 fprintf ( fMakefile
, "%s:\n\n",
1527 fprintf ( fMakefile
, ".PHONY: %s\n\n",