4 #include "../../rbuild.h"
6 #include "modulehandler.h"
13 typedef set
<string
> set_string
;
15 map
<ModuleType
,MingwModuleHandler
*>*
16 MingwModuleHandler::handler_map
= NULL
;
18 MingwModuleHandler::directory_set
;
20 MingwModuleHandler::ref
= 0;
23 MingwModuleHandler::fMakefile
= NULL
;
25 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype
)
28 handler_map
= new map
<ModuleType
,MingwModuleHandler
*>;
29 (*handler_map
)[moduletype
] = this;
32 MingwModuleHandler::~MingwModuleHandler()
42 MingwModuleHandler::PassThruCacheDirectory( const string
&file
) const
44 directory_set
.insert( ReplaceExtension( GetDirectory( file
), "" ) );
49 MingwModuleHandler::SetMakefile ( FILE* f
)
55 MingwModuleHandler::LookupHandler ( const string
& location
,
56 ModuleType moduletype
)
59 throw Exception ( "internal tool error: no registered module handlers" );
60 MingwModuleHandler
* h
= (*handler_map
)[moduletype
];
63 throw UnknownModuleTypeException ( location
, moduletype
);
70 MingwModuleHandler::GetWorkingDirectory () const
76 MingwModuleHandler::GetDirectory ( const string
& filename
) const
78 size_t index
= filename
.find_last_of ( '/' );
79 if (index
== string::npos
)
82 return filename
.substr ( 0, index
);
86 MingwModuleHandler::GetExtension ( const string
& filename
) const
88 size_t index
= filename
.find_last_of ( '/' );
89 if (index
== string::npos
) index
= 0;
90 string tmp
= filename
.substr( index
, filename
.size() - index
);
91 size_t ext_index
= tmp
.find_last_of( '.' );
92 if (ext_index
!= string::npos
)
93 return filename
.substr ( index
+ ext_index
, filename
.size() );
98 MingwModuleHandler::GetBasename ( const string
& filename
) const
100 size_t index
= filename
.find_last_of ( '.' );
101 if (index
!= string::npos
)
102 return filename
.substr ( 0, index
);
107 MingwModuleHandler::ReplaceExtension ( const string
& filename
,
108 const string
& newExtension
) const
110 size_t index
= filename
.find_last_of ( '/' );
111 if (index
== string::npos
) index
= 0;
112 string tmp
= filename
.substr( index
, filename
.size() - index
);
113 size_t ext_index
= tmp
.find_last_of( '.' );
114 if (ext_index
!= string::npos
)
115 return filename
.substr ( 0, index
+ ext_index
) + newExtension
;
116 return filename
+ newExtension
;
120 MingwModuleHandler::GetActualSourceFilename ( const string
& filename
) const
122 string extension
= GetExtension ( filename
);
123 if ( extension
== ".spec" || extension
== "SPEC" )
125 string basename
= GetBasename( filename
);
126 return basename
+ ".stubs.c";
133 MingwModuleHandler::GetModuleArchiveFilename ( const Module
& module
) const
135 return ReplaceExtension ( FixupTargetFilename ( module
.GetPath () ),
140 MingwModuleHandler::IsGeneratedFile ( const File
& file
) const
142 string extension
= GetExtension ( file
.name
);
143 if ( extension
== ".spec" || extension
== "SPEC" )
150 MingwModuleHandler::GetImportLibraryDependency ( const Module
& importedModule
) const
152 if ( importedModule
.type
== ObjectLibrary
)
153 return GetObjectsMacro ( importedModule
);
155 return PassThruCacheDirectory ( FixupTargetFilename ( importedModule
.GetDependencyPath () ) );
159 MingwModuleHandler::GetImportLibraryDependencies ( const Module
& module
) const
161 string
dependencies ( "" );
162 for ( size_t i
= 0; i
< module
.libraries
.size (); i
++ )
164 if ( dependencies
.size () > 0 )
166 const Module
* importedModule
= module
.project
.LocateModule ( module
.libraries
[i
]->name
);
167 assert ( importedModule
!= NULL
);
168 dependencies
+= GetImportLibraryDependency ( *importedModule
);
174 MingwModuleHandler::GetModuleDependencies ( const Module
& module
) const
176 if ( module
.dependencies
.size () == 0 )
179 string
dependencies ( "" );
180 for ( size_t i
= 0; i
< module
.dependencies
.size (); i
++ )
182 if ( dependencies
.size () > 0 )
184 const Dependency
* dependency
= module
.dependencies
[i
];
185 const Module
* dependencyModule
= dependency
->dependencyModule
;
186 dependencies
+= dependencyModule
->GetTargets ();
188 string definitionDependencies
= GetDefinitionDependencies ( module
);
189 if ( dependencies
.length () > 0 && definitionDependencies
.length () > 0 )
190 dependencies
+= " " + definitionDependencies
;
191 else if ( definitionDependencies
.length () > 0 )
192 dependencies
= definitionDependencies
;
197 MingwModuleHandler::GetAllDependencies ( const Module
& module
) const
199 string dependencies
= GetImportLibraryDependencies ( module
);
200 string s
= GetModuleDependencies ( module
);
210 MingwModuleHandler::GetSourceFilenames ( const Module
& module
,
211 bool includeGeneratedFiles
) const
215 string
sourceFilenames ( "" );
216 for ( i
= 0; i
< module
.files
.size (); i
++ )
218 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *module
.files
[i
] ) )
219 sourceFilenames
+= " " + GetActualSourceFilename ( module
.files
[i
]->name
);
221 vector
<If
*> ifs
= module
.ifs
;
222 for ( i
= 0; i
< ifs
.size(); i
++ )
226 for ( j
= 0; j
< rIf
.ifs
.size(); j
++ )
227 ifs
.push_back ( rIf
.ifs
[j
] );
228 for ( j
= 0; j
< rIf
.files
.size(); j
++ )
230 if ( includeGeneratedFiles
|| !IsGeneratedFile ( *rIf
.files
[j
] ) )
231 sourceFilenames
+= " " + GetActualSourceFilename ( rIf
.files
[j
]->name
);
234 return sourceFilenames
;
238 MingwModuleHandler::GetSourceFilenames ( const Module
& module
) const
240 return GetSourceFilenames ( module
,
245 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module
& module
) const
247 return GetSourceFilenames ( module
,
252 MingwModuleHandler::GetObjectFilename ( const string
& sourceFilename
) const
255 string extension
= GetExtension ( sourceFilename
);
256 if ( extension
== ".rc" || extension
== ".RC" )
257 newExtension
= ".coff";
258 else if ( extension
== ".spec" || extension
== ".SPEC" )
259 newExtension
= ".stubs.o";
262 return PassThruCacheDirectory (
263 FixupTargetFilename (
264 ReplaceExtension ( sourceFilename
, newExtension
) ) );
268 MingwModuleHandler::GetObjectFilenames ( const Module
& module
) const
270 if ( module
.files
.size () == 0 )
273 string
objectFilenames ( "" );
274 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
276 if ( objectFilenames
.size () > 0 )
277 objectFilenames
+= " ";
278 objectFilenames
+= GetObjectFilename ( module
.files
[i
]->name
);
280 return objectFilenames
;
284 MingwModuleHandler::GenerateDirectoryTargets() const
286 set_string::iterator i
;
287 fprintf( fMakefile
, "ifneq ($(ROS_INTERMEDIATE),)\ndirectories::" );
289 for ( i
= directory_set
.begin();
290 i
!= directory_set
.end();
293 fprintf ( fMakefile
, " %s", i
->c_str() );
296 fprintf( fMakefile
, "\n\n" );
298 for ( i
= directory_set
.begin();
299 i
!= directory_set
.end();
302 fprintf ( fMakefile
, "%s ", i
->c_str() );
306 "::\n\t${mkdir} $@\n\n"
311 directory_set
.clear();
315 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector
<Define
*>& defines
) const
318 for ( size_t i
= 0; i
< defines
.size (); i
++ )
320 Define
& define
= *defines
[i
];
321 if (parameters
.length () > 0)
324 parameters
+= define
.name
;
325 if (define
.value
.length () > 0)
328 parameters
+= define
.value
;
335 MingwModuleHandler::GenerateGccDefineParameters ( const Module
& module
) const
337 string parameters
= GenerateGccDefineParametersFromVector ( module
.project
.defines
);
338 string s
= GenerateGccDefineParametersFromVector ( module
.defines
);
339 if ( s
.length () > 0 )
348 MingwModuleHandler::ConcatenatePaths ( const string
& path1
,
349 const string
& path2
) const
351 if ( ( path1
.length () == 0 ) || ( path1
== "." ) || ( path1
== "./" ) )
353 if ( path1
[path1
.length ()] == CSEP
)
354 return path1
+ path2
;
356 return path1
+ CSEP
+ path2
;
360 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector
<Include
*>& includes
) const
363 for ( size_t i
= 0; i
< includes
.size (); i
++ )
365 Include
& include
= *includes
[i
];
366 if (parameters
.length () > 0)
368 parameters
+= "-I" + include
.directory
;
374 MingwModuleHandler::GenerateGccIncludeParameters ( const Module
& module
) const
376 string parameters
= GenerateGccIncludeParametersFromVector ( module
.includes
);
377 string s
= GenerateGccIncludeParametersFromVector ( module
.project
.includes
);
378 if ( s
.length () > 0 )
388 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector
<CompilerFlag
*>& compilerFlags
) const
391 for ( size_t i
= 0; i
< compilerFlags
.size (); i
++ )
393 CompilerFlag
& compilerFlag
= *compilerFlags
[i
];
394 if ( parameters
.length () > 0 )
396 parameters
+= compilerFlag
.flag
;
402 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector
<LinkerFlag
*>& linkerFlags
) const
405 for ( size_t i
= 0; i
< linkerFlags
.size (); i
++ )
407 LinkerFlag
& linkerFlag
= *linkerFlags
[i
];
408 if ( parameters
.length () > 0 )
410 parameters
+= linkerFlag
.flag
;
416 MingwModuleHandler::GenerateLinkerParameters ( const Module
& module
) const
418 return GenerateLinkerParametersFromVector ( module
.linkerFlags
);
422 MingwModuleHandler::GenerateMacro ( const char* assignmentOperation
,
424 const vector
<Include
*>& includes
,
425 const vector
<Define
*>& defines
,
426 const vector
<CompilerFlag
*>* compilerFlags
) const
434 assignmentOperation
);
436 if ( compilerFlags
!= NULL
)
438 string compilerParameters
= GenerateCompilerParametersFromVector ( *compilerFlags
);
439 if ( compilerParameters
.size () > 0 )
444 compilerParameters
.c_str () );
448 for ( i
= 0; i
< includes
.size(); i
++ )
453 includes
[i
]->directory
.c_str() );
455 for ( i
= 0; i
< defines
.size(); i
++ )
457 Define
& d
= *defines
[i
];
462 if ( d
.value
.size() )
468 fprintf ( fMakefile
, "\n" );
472 MingwModuleHandler::GenerateMacros (
473 const char* assignmentOperation
,
474 const vector
<File
*>& files
,
475 const vector
<Include
*>& includes
,
476 const vector
<Define
*>& defines
,
477 const vector
<CompilerFlag
*>* compilerFlags
,
478 const vector
<LinkerFlag
*>* linkerFlags
,
479 const vector
<If
*>& ifs
,
480 const string
& cflags_macro
,
481 const string
& nasmflags_macro
,
482 const string
& windresflags_macro
,
483 const string
& linkerflags_macro
,
484 const string
& objs_macro
) const
488 if ( includes
.size() || defines
.size() )
490 GenerateMacro ( assignmentOperation
,
495 GenerateMacro ( assignmentOperation
,
502 if ( linkerFlags
!= NULL
)
504 string linkerParameters
= GenerateLinkerParametersFromVector ( *linkerFlags
);
505 if ( linkerParameters
.size () > 0 )
510 linkerflags_macro
.c_str (),
512 linkerParameters
.c_str() );
518 for ( i
= 0; i
< files
.size(); i
++ )
520 if ( files
[i
]->first
)
525 GetObjectFilename(files
[i
]->name
).c_str(),
526 objs_macro
.c_str() );
533 assignmentOperation
);
534 for ( i
= 0; i
< files
.size(); i
++ )
536 string extension
= GetExtension ( files
[i
]->name
);
537 if ( extension
!= ".spec"
538 && extension
!= ".SPEC"
539 && !files
[i
]->first
)
544 ( i
%10 == 9 ? "\\\n\t" : " " ),
545 GetObjectFilename(files
[i
]->name
).c_str() );
548 fprintf ( fMakefile
, "\n" );
551 for ( i
= 0; i
< ifs
.size(); i
++ )
554 if ( rIf
.defines
.size() || rIf
.includes
.size() || rIf
.files
.size() || rIf
.ifs
.size() )
558 "ifeq (\"$(%s)\",\"%s\")\n",
559 rIf
.property
.c_str(),
582 MingwModuleHandler::GenerateMacros (
583 const Module
& module
,
584 const string
& cflags_macro
,
585 const string
& nasmflags_macro
,
586 const string
& windresflags_macro
,
587 const string
& linkerflags_macro
,
588 const string
& objs_macro
) const
595 &module
.compilerFlags
,
603 fprintf ( fMakefile
, "\n" );
607 "%s += $(PROJECT_CFLAGS)\n\n",
608 cflags_macro
.c_str () );
612 "%s += $(PROJECT_RCFLAGS)\n\n",
613 windresflags_macro
.c_str () );
617 "%s_LFLAGS += $(PROJECT_LFLAGS)\n\n",
618 module
.name
.c_str () );
622 MingwModuleHandler::GenerateGccCommand ( const Module
& module
,
623 const string
& sourceFilename
,
625 const string
& cflagsMacro
) const
627 string objectFilename
= GetObjectFilename ( sourceFilename
);
630 objectFilename
.c_str (),
631 sourceFilename
.c_str () );
633 "\t%s -c %s -o %s %s\n",
635 sourceFilename
.c_str (),
636 objectFilename
.c_str (),
637 cflagsMacro
.c_str () );
641 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module
& module
,
642 const string
& sourceFilename
,
644 const string
& cflagsMacro
) const
646 string objectFilename
= GetObjectFilename ( sourceFilename
);
649 objectFilename
.c_str (),
650 sourceFilename
.c_str () );
652 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
654 sourceFilename
.c_str (),
655 objectFilename
.c_str (),
656 cflagsMacro
.c_str () );
660 MingwModuleHandler::GenerateNasmCommand ( const Module
& module
,
661 const string
& sourceFilename
,
662 const string
& nasmflagsMacro
) const
664 string objectFilename
= GetObjectFilename ( sourceFilename
);
667 objectFilename
.c_str (),
668 sourceFilename
.c_str () );
670 "\t%s -f win32 %s -o %s %s\n",
672 sourceFilename
.c_str (),
673 objectFilename
.c_str (),
674 nasmflagsMacro
.c_str () );
678 MingwModuleHandler::GenerateWindresCommand ( const Module
& module
,
679 const string
& sourceFilename
,
680 const string
& windresflagsMacro
) const
682 string objectFilename
= GetObjectFilename ( sourceFilename
);
685 objectFilename
.c_str (),
686 sourceFilename
.c_str () );
688 "\t%s %s -o %s ${%s}\n",
690 sourceFilename
.c_str (),
691 objectFilename
.c_str (),
692 windresflagsMacro
.c_str () );
696 MingwModuleHandler::GenerateWinebuildCommands ( const Module
& module
,
697 const string
& sourceFilename
) const
699 string basename
= GetBasename ( sourceFilename
);
703 sourceFilename
.c_str () );
705 "\t%s --def=%s -o %s.spec.def\n",
707 sourceFilename
.c_str (),
713 sourceFilename
.c_str () );
715 "\t%s --pedll=%s -o %s.stubs.c\n",
717 sourceFilename
.c_str (),
722 MingwModuleHandler::GenerateCommands ( const Module
& module
,
723 const string
& sourceFilename
,
725 const string
& cflagsMacro
,
726 const string
& nasmflagsMacro
,
727 const string
& windresflagsMacro
) const
729 string extension
= GetExtension ( sourceFilename
);
730 if ( extension
== ".c" || extension
== ".C" )
732 GenerateGccCommand ( module
,
738 else if ( extension
== ".s" || extension
== ".S" )
740 GenerateGccAssemblerCommand ( module
,
746 else if ( extension
== ".asm" || extension
== ".ASM" )
748 GenerateNasmCommand ( module
,
753 else if ( extension
== ".rc" || extension
== ".RC" )
755 GenerateWindresCommand ( module
,
760 else if ( extension
== ".spec" || extension
== ".SPEC" )
762 GenerateWinebuildCommands ( module
,
764 GenerateGccCommand ( module
,
765 GetActualSourceFilename ( sourceFilename
),
771 throw InvalidOperationException ( __FILE__
,
773 "Unsupported filename extension '%s' in file '%s'",
775 sourceFilename
.c_str () );
779 MingwModuleHandler::GenerateLinkerCommand ( const Module
& module
,
780 const string
& linker
,
781 const string
& linkerParameters
,
782 const string
& objectFilenames
) const
784 string
targetName ( module
.GetTargetName () );
785 string
target ( FixupTargetFilename ( module
.GetPath () ) );
786 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
787 if ( module
.importLibrary
!= NULL
)
789 static string
ros_junk ( "$(ROS_TEMPORARY)" );
790 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
791 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
792 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
795 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
797 linkerParameters
.c_str (),
800 objectFilenames
.c_str (),
801 importLibraryDependencies
.c_str (),
802 GetLinkerMacro ( module
).c_str () );
809 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s --kill-at\n",
812 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
820 "\t%s %s %s -o %s %s %s %s\n\n",
822 linkerParameters
.c_str (),
825 objectFilenames
.c_str (),
826 importLibraryDependencies
.c_str (),
827 GetLinkerMacro ( module
).c_str () );
836 "\t%s %s -o %s %s %s %s\n\n",
838 linkerParameters
.c_str (),
840 objectFilenames
.c_str (),
841 importLibraryDependencies
.c_str (),
842 GetLinkerMacro ( module
).c_str () );
847 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
848 const vector
<File
*>& files
,
849 const vector
<If
*>& ifs
,
851 const string
& cflagsMacro
,
852 const string
& nasmflagsMacro
,
853 const string
& windresflagsMacro
) const
857 for ( i
= 0; i
< files
.size (); i
++ )
859 string sourceFilename
= files
[i
]->name
;
860 GenerateCommands ( module
,
870 for ( i
= 0; i
< ifs
.size(); i
++ )
872 GenerateObjectFileTargets ( module
,
883 MingwModuleHandler::GenerateObjectFileTargets ( const Module
& module
,
885 const string
& cflagsMacro
,
886 const string
& nasmflagsMacro
,
887 const string
& windresflagsMacro
) const
889 GenerateObjectFileTargets ( module
,
896 fprintf ( fMakefile
, "\n" );
900 MingwModuleHandler::GetCleanTargets ( vector
<string
>& out
,
901 const vector
<File
*>& files
,
902 const vector
<If
*>& ifs
) const
906 for ( i
= 0; i
< files
.size(); i
++ )
907 out
.push_back ( GetObjectFilename(files
[i
]->name
) );
909 for ( i
= 0; i
< ifs
.size(); i
++ )
910 GetCleanTargets ( out
, ifs
[i
]->files
, ifs
[i
]->ifs
);
914 MingwModuleHandler::GenerateArchiveTarget ( const Module
& module
,
916 const string
& objs_macro
) const
918 string archiveFilename
= GetModuleArchiveFilename ( module
);
922 archiveFilename
.c_str (),
923 objs_macro
.c_str ());
926 "\t%s -rc %s %s\n\n",
928 archiveFilename
.c_str (),
929 objs_macro
.c_str ());
931 return archiveFilename
;
935 MingwModuleHandler::GetCFlagsMacro ( const Module
& module
) const
937 return ssprintf ( "$(%s_CFLAGS)",
938 module
.name
.c_str () );
942 MingwModuleHandler::GetObjectsMacro ( const Module
& module
) const
944 return ssprintf ( "$(%s_OBJS)",
945 module
.name
.c_str () );
949 MingwModuleHandler::GetLinkerMacro ( const Module
& module
) const
951 return ssprintf ( "$(%s_LFLAGS)",
952 module
.name
.c_str () );
956 MingwModuleHandler::GenerateMacrosAndTargets (
957 const Module
& module
,
960 const string
* cflags
) const
962 string cflagsMacro
= ssprintf ("%s_CFLAGS", module
.name
.c_str ());
963 string nasmflagsMacro
= ssprintf ("%s_NASMFLAGS", module
.name
.c_str ());
964 string windresflagsMacro
= ssprintf ("%s_RCFLAGS", module
.name
.c_str ());
965 string linkerFlagsMacro
= ssprintf ("%s_LFLAGS", module
.name
.c_str ());
966 string objectsMacro
= ssprintf ("%s_OBJS", module
.name
.c_str ());
968 GenerateMacros ( module
,
975 if ( cflags
!= NULL
)
979 cflagsMacro
.c_str (),
983 // generate phony target for module name
984 fprintf ( fMakefile
, ".PHONY: %s\n",
985 module
.name
.c_str () );
986 fprintf ( fMakefile
, "%s: %s\n\n",
987 module
.name
.c_str (),
988 FixupTargetFilename ( module
.GetPath () ).c_str () );
990 // future references to the macros will be to get their values
991 cflagsMacro
= ssprintf ("$(%s)", cflagsMacro
.c_str ());
992 nasmflagsMacro
= ssprintf ("$(%s)", nasmflagsMacro
.c_str ());
993 objectsMacro
= ssprintf ("$(%s)", objectsMacro
.c_str ());
995 string ar_target
= GenerateArchiveTarget ( module
, ar
, objectsMacro
);
996 GenerateObjectFileTargets ( module
,
1000 windresflagsMacro
);
1002 vector
<string
> clean_files
;
1003 clean_files
.push_back ( FixupTargetFilename(module
.GetPath()) );
1004 clean_files
.push_back ( ar_target
);
1005 GetCleanTargets ( clean_files
, module
.files
, module
.ifs
);
1007 fprintf ( fMakefile
, "clean::\n\t-@$(rm)" );
1008 for ( size_t i
= 0; i
< clean_files
.size(); i
++ )
1011 fprintf ( fMakefile
, " 2>$(NUL)\n\t-@$(rm)" );
1012 fprintf ( fMakefile
, " %s", clean_files
[i
].c_str() );
1014 fprintf ( fMakefile
, " 2>$(NUL)\n\n" );
1018 MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module
& module
) const
1020 GenerateMacrosAndTargets ( module
, "${host_gcc}", "${host_ar}", NULL
);
1024 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
) const
1026 GenerateMacrosAndTargetsTarget ( module
,
1031 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module
& module
,
1032 const string
* clags
) const
1034 GenerateMacrosAndTargets ( module
, "${gcc}", "${ar}", clags
);
1038 MingwModuleHandler::GetInvocationDependencies ( const Module
& module
) const
1040 string dependencies
;
1041 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1043 Invoke
& invoke
= *module
.invocations
[i
];
1044 if (invoke
.invokeModule
== &module
)
1045 /* Protect against circular dependencies */
1047 if ( dependencies
.length () > 0 )
1048 dependencies
+= " ";
1049 dependencies
+= invoke
.GetTargets ();
1051 return dependencies
;
1055 MingwModuleHandler::GetInvocationParameters ( const Invoke
& invoke
) const
1057 string
parameters ( "" );
1059 for (i
= 0; i
< invoke
.output
.size (); i
++)
1061 if (parameters
.length () > 0)
1063 InvokeFile
& invokeFile
= *invoke
.output
[i
];
1064 if (invokeFile
.switches
.length () > 0)
1066 parameters
+= invokeFile
.switches
;
1069 parameters
+= invokeFile
.name
;
1072 for (i
= 0; i
< invoke
.input
.size (); i
++)
1074 if (parameters
.length () > 0)
1076 InvokeFile
& invokeFile
= *invoke
.input
[i
];
1077 if (invokeFile
.switches
.length () > 0)
1079 parameters
+= invokeFile
.switches
;
1082 parameters
+= invokeFile
.name
;
1089 MingwModuleHandler::GenerateInvocations ( const Module
& module
) const
1091 if ( module
.invocations
.size () == 0 )
1094 for ( size_t i
= 0; i
< module
.invocations
.size (); i
++ )
1096 const Invoke
& invoke
= *module
.invocations
[i
];
1098 if ( invoke
.invokeModule
->type
!= BuildTool
)
1100 throw InvalidBuildFileException ( module
.node
.location
,
1101 "Only modules of type buildtool can be invoked." );
1104 string invokeTarget
= module
.GetInvocationTarget ( i
);
1105 fprintf ( fMakefile
,
1107 invokeTarget
.c_str () );
1108 fprintf ( fMakefile
,
1110 invokeTarget
.c_str (),
1111 invoke
.GetTargets ().c_str () );
1112 fprintf ( fMakefile
,
1114 invoke
.GetTargets ().c_str (),
1115 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str () );
1116 fprintf ( fMakefile
,
1118 FixupTargetFilename ( invoke
.invokeModule
->GetPath () ).c_str (),
1119 GetInvocationParameters ( invoke
).c_str () );
1124 MingwModuleHandler::GetPreconditionDependenciesName ( const Module
& module
) const
1126 return ssprintf ( "%s_precondition",
1127 module
.name
.c_str () );
1131 MingwModuleHandler::GeneratePreconditionDependencies ( const Module
& module
) const
1133 string preconditionDependenciesName
= GetPreconditionDependenciesName ( module
);
1134 string sourceFilenames
= GetSourceFilenamesWithoutGeneratedFiles ( module
);
1135 string dependencies
= GetModuleDependencies ( module
);
1136 string s
= GetInvocationDependencies ( module
);
1137 if ( s
.length () > 0 )
1139 if ( dependencies
.length () > 0 )
1140 dependencies
+= " ";
1144 fprintf ( fMakefile
,
1146 preconditionDependenciesName
.c_str () );
1147 fprintf ( fMakefile
,
1149 preconditionDependenciesName
.c_str (),
1150 dependencies
.c_str () );
1151 const char* p
= sourceFilenames
.c_str();
1152 const char* end
= p
+ strlen(p
);
1155 const char* p2
= &p
[512];
1158 while ( p2
> p
&& !isspace(*p2
) )
1162 p2
= strpbrk ( p
, " \t" );
1166 fprintf ( fMakefile
,
1170 preconditionDependenciesName
.c_str ());
1172 p
+= strspn ( p
, " \t" );
1174 fprintf ( fMakefile
, "\n" );
1178 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module
& module
) const
1180 if ( module
.importLibrary
!= NULL
)
1182 string definitionDependencies
= GetDefinitionDependencies ( module
);
1183 fprintf ( fMakefile
, "%s: %s\n",
1184 FixupTargetFilename( module
.GetDependencyPath () ).c_str (),
1185 definitionDependencies
.c_str () );
1187 fprintf ( fMakefile
,
1188 "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
1189 module
.GetTargetName ().c_str (),
1190 ( module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1191 FixupTargetFilename ( module
.GetDependencyPath () ).c_str () );
1196 MingwModuleHandler::GetSpecObjectDependencies ( const string
& filename
) const
1198 string basename
= GetBasename ( filename
);
1199 return basename
+ ".spec.def" + " " + basename
+ ".stubs.c";
1203 MingwModuleHandler::GetDefinitionDependencies ( const Module
& module
) const
1205 string dependencies
;
1206 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
1208 File
& file
= *module
.files
[i
];
1209 string extension
= GetExtension ( file
.name
);
1210 if ( extension
== ".spec" || extension
== ".SPEC" )
1212 if ( dependencies
.length () > 0 )
1213 dependencies
+= " ";
1214 dependencies
+= GetSpecObjectDependencies ( file
.name
);
1217 return dependencies
;
1221 MingwModuleHandler::GetLinkingDependencies ( const Module
& module
) const
1223 string dependencies
= GetImportLibraryDependencies ( module
);
1224 string s
= GetDefinitionDependencies ( module
);
1225 if ( s
.length () > 0 )
1227 dependencies
+= " ";
1230 return dependencies
;
1234 static MingwBuildToolModuleHandler buildtool_handler
;
1236 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1237 : MingwModuleHandler ( BuildTool
)
1242 MingwBuildToolModuleHandler::Process ( const Module
& module
)
1244 GeneratePreconditionDependencies ( module
);
1245 GenerateBuildToolModuleTarget ( module
);
1246 GenerateInvocations ( module
);
1250 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module
& module
)
1252 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1253 string archiveFilename
= GetModuleArchiveFilename ( module
);
1255 GenerateMacrosAndTargetsHost ( module
);
1257 fprintf ( fMakefile
, "%s: %s\n",
1259 archiveFilename
.c_str () );
1260 fprintf ( fMakefile
,
1261 "\t${host_gcc} %s -o %s %s\n\n",
1262 GetLinkerMacro ( module
).c_str (),
1264 archiveFilename
.c_str () );
1268 static MingwKernelModuleHandler kernelmodule_handler
;
1270 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1271 : MingwModuleHandler ( Kernel
)
1276 MingwKernelModuleHandler::Process ( const Module
& module
)
1278 GeneratePreconditionDependencies ( module
);
1279 GenerateKernelModuleTarget ( module
);
1280 GenerateInvocations ( module
);
1284 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module
& module
)
1286 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1287 string
targetName ( module
.GetTargetName () );
1288 string
target ( FixupTargetFilename (module
.GetPath ()) );
1289 string workingDirectory
= GetWorkingDirectory ();
1290 string objectsMacro
= GetObjectsMacro ( module
);
1291 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1292 string base_tmp
= ros_junk
+ module
.name
+ ".base.tmp";
1293 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1294 string temp_exp
= ros_junk
+ module
.name
+ ".temp.exp";
1295 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",
1296 module
.GetBasePath ().c_str () );
1298 GenerateMacrosAndTargetsTarget ( module
);
1300 GenerateImportLibraryTargetIfNeeded ( module
);
1302 fprintf ( fMakefile
, "%s: %s %s\n",
1304 objectsMacro
.c_str (),
1305 importLibraryDependencies
.c_str () );
1306 fprintf ( fMakefile
,
1307 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1308 GetLinkerMacro ( module
).c_str (),
1309 gccOptions
.c_str (),
1312 objectsMacro
.c_str (),
1313 importLibraryDependencies
.c_str () );
1314 fprintf ( fMakefile
,
1316 junk_tmp
.c_str () );
1317 fprintf ( fMakefile
,
1318 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s --kill-at\n",
1319 targetName
.c_str (),
1321 temp_exp
.c_str () );
1322 fprintf ( fMakefile
,
1324 base_tmp
.c_str () );
1325 fprintf ( fMakefile
,
1326 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1327 GetLinkerMacro ( module
).c_str (),
1328 gccOptions
.c_str (),
1331 objectsMacro
.c_str (),
1332 importLibraryDependencies
.c_str () );
1333 fprintf ( fMakefile
,
1335 temp_exp
.c_str () );
1339 static MingwStaticLibraryModuleHandler staticlibrary_handler
;
1341 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1342 : MingwModuleHandler ( StaticLibrary
)
1347 MingwStaticLibraryModuleHandler::Process ( const Module
& module
)
1349 GeneratePreconditionDependencies ( module
);
1350 GenerateStaticLibraryModuleTarget ( module
);
1351 GenerateInvocations ( module
);
1355 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module
& module
)
1357 GenerateMacrosAndTargetsTarget ( module
);
1361 static MingwObjectLibraryModuleHandler objectlibrary_handler
;
1363 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ()
1364 : MingwModuleHandler ( ObjectLibrary
)
1369 MingwObjectLibraryModuleHandler::Process ( const Module
& module
)
1371 GeneratePreconditionDependencies ( module
);
1372 GenerateObjectLibraryModuleTarget ( module
);
1373 GenerateInvocations ( module
);
1377 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module
& module
)
1379 GenerateMacrosAndTargetsTarget ( module
);
1383 static MingwKernelModeDLLModuleHandler kernelmodedll_handler
;
1385 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1386 : MingwModuleHandler ( KernelModeDLL
)
1391 MingwKernelModeDLLModuleHandler::Process ( const Module
& module
)
1393 GeneratePreconditionDependencies ( module
);
1394 GenerateKernelModeDLLModuleTarget ( module
);
1395 GenerateInvocations ( module
);
1399 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Module
& module
)
1401 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1402 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1403 string workingDirectory
= GetWorkingDirectory ( );
1404 string archiveFilename
= GetModuleArchiveFilename ( module
);
1405 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1407 GenerateImportLibraryTargetIfNeeded ( module
);
1409 if ( module
.files
.size () > 0 )
1411 GenerateMacrosAndTargetsTarget ( module
);
1413 fprintf ( fMakefile
, "%s: %s %s\n",
1415 archiveFilename
.c_str (),
1416 importLibraryDependencies
.c_str () );
1418 string
linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );
1419 GenerateLinkerCommand ( module
,
1426 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1428 fprintf ( fMakefile
, "%s:\n",
1434 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler
;
1436 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1437 : MingwModuleHandler ( KernelModeDriver
)
1442 MingwKernelModeDriverModuleHandler::Process ( const Module
& module
)
1444 GeneratePreconditionDependencies ( module
);
1445 GenerateKernelModeDriverModuleTarget ( module
);
1446 GenerateInvocations ( module
);
1451 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module
& module
)
1453 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1454 string
target ( PassThruCacheDirectory( FixupTargetFilename ( module
.GetPath () ) ) );
1455 string workingDirectory
= GetWorkingDirectory ( );
1456 string archiveFilename
= GetModuleArchiveFilename ( module
);
1457 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1459 GenerateImportLibraryTargetIfNeeded ( module
);
1461 if ( module
.files
.size () > 0 )
1463 string
* cflags
= new string ( "-D__NTDRIVER__" );
1464 GenerateMacrosAndTargetsTarget ( module
,
1468 fprintf ( fMakefile
, "%s: %s %s\n",
1470 archiveFilename
.c_str (),
1471 importLibraryDependencies
.c_str () );
1473 string
linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );
1474 GenerateLinkerCommand ( module
,
1481 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1483 fprintf ( fMakefile
, "%s:\n",
1489 static MingwNativeDLLModuleHandler nativedll_handler
;
1491 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1492 : MingwModuleHandler ( NativeDLL
)
1497 MingwNativeDLLModuleHandler::Process ( const Module
& module
)
1499 GeneratePreconditionDependencies ( module
);
1500 GenerateNativeDLLModuleTarget ( module
);
1501 GenerateInvocations ( module
);
1505 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module
& module
)
1507 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1508 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1509 string workingDirectory
= GetWorkingDirectory ( );
1510 string objectFilenames
= GetObjectFilenames ( module
);
1511 string archiveFilename
= GetModuleArchiveFilename ( module
);
1512 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1514 GenerateImportLibraryTargetIfNeeded ( module
);
1516 if ( module
.files
.size () > 0 )
1519 fprintf ( fMakefile
,
1520 "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
1521 module
.GetTargetName ().c_str (),
1522 (module
.GetBasePath () + SSEP
+ module
.importLibrary
->definition
).c_str (),
1523 FixupTargetFilename ( module
.GetDependencyPath () ).c_str () );
1526 if (module
.files
.size () > 0)
1528 GenerateMacrosAndTargetsTarget ( module
);
1530 fprintf ( fMakefile
, "%s: %s %s\n",
1532 archiveFilename
.c_str (),
1533 importLibraryDependencies
.c_str () );
1535 string
linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DllMainCRTStartup@12 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll" );
1536 GenerateLinkerCommand ( module
,
1543 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1545 fprintf ( fMakefile
, "%s:\n\n",
1551 static MingwWin32DLLModuleHandler win32dll_handler
;
1553 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1554 : MingwModuleHandler ( Win32DLL
)
1559 MingwWin32DLLModuleHandler::Process ( const Module
& module
)
1561 GenerateExtractWineDLLResourcesTarget ( module
);
1562 GeneratePreconditionDependencies ( module
);
1563 GenerateWin32DLLModuleTarget ( module
);
1564 GenerateInvocations ( module
);
1568 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module
& module
)
1570 fprintf ( fMakefile
, ".PHONY: %s_extractresources\n\n",
1571 module
.name
.c_str () );
1572 fprintf ( fMakefile
, "%s_extractresources: bin2res\n",
1573 module
.name
.c_str () );
1574 for ( size_t i
= 0; i
< module
.files
.size (); i
++ )
1576 File
& file
= *module
.files
[i
];
1577 string extension
= GetExtension ( file
.name
);
1578 if ( extension
== ".rc" || extension
== ".RC" )
1580 string resource
= FixupTargetFilename ( file
.name
);
1581 fprintf ( fMakefile
, "\t@echo ${bin2res} -f -x %s\n",
1582 resource
.c_str () );
1585 fprintf ( fMakefile
, "\n");
1589 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module
& module
)
1591 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1592 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1593 string workingDirectory
= GetWorkingDirectory ( );
1594 string objectFilenames
= GetObjectFilenames ( module
);
1595 string linkingDependencies
= GetLinkingDependencies ( module
);
1597 GenerateImportLibraryTargetIfNeeded ( module
);
1598 if ( module
.files
.size () > 0 )
1600 GenerateMacrosAndTargetsTarget ( module
);
1602 fprintf ( fMakefile
, "%s: %s %s\n",
1604 objectFilenames
.c_str (),
1605 linkingDependencies
.c_str () );
1607 string
linkerParameters ( "-Wl,--subsystem,console -Wl,--entry,_DllMain@12 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll" );
1608 GenerateLinkerCommand ( module
,
1615 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1617 fprintf ( fMakefile
, "%s:\n\n",
1623 static MingwWin32GUIModuleHandler win32gui_handler
;
1625 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
1626 : MingwModuleHandler ( Win32GUI
)
1631 MingwWin32GUIModuleHandler::Process ( const Module
& module
)
1633 GeneratePreconditionDependencies ( module
);
1634 GenerateWin32GUIModuleTarget ( module
);
1635 GenerateInvocations ( module
);
1639 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module
& module
)
1641 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1642 string
target ( FixupTargetFilename ( module
.GetPath () ) );
1643 string workingDirectory
= GetWorkingDirectory ( );
1644 string objectFilenames
= GetObjectFilenames ( module
);
1645 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1647 GenerateImportLibraryTargetIfNeeded ( module
);
1649 if ( module
.files
.size () > 0 )
1651 GenerateMacrosAndTargetsTarget ( module
);
1653 fprintf ( fMakefile
, "%s: %s %s\n",
1655 objectFilenames
.c_str (),
1656 importLibraryDependencies
.c_str () );
1658 string
linkerParameters ( "-Wl,--subsystem,windows -Wl,--entry,_WinMainCRTStartup -Wl,--image-base,0x00400000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000" );
1659 GenerateLinkerCommand ( module
,
1666 fprintf ( fMakefile
, ".PHONY: %s\n\n",
1668 fprintf ( fMakefile
, "%s:\n\n",
1674 static MingwBootLoaderModuleHandler bootloadermodule_handler
;
1676 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ()
1677 : MingwModuleHandler ( BootLoader
)
1682 MingwBootLoaderModuleHandler::Process ( const Module
& module
)
1684 GeneratePreconditionDependencies ( module
);
1685 GenerateBootLoaderModuleTarget ( module
);
1686 GenerateInvocations ( module
);
1690 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ( const Module
& module
)
1692 static string
ros_junk ( "$(ROS_TEMPORARY)" );
1693 string
targetName ( module
.GetTargetName () );
1694 string
target ( FixupTargetFilename (module
.GetPath ()) );
1695 string workingDirectory
= GetWorkingDirectory ();
1696 string junk_tmp
= ros_junk
+ module
.name
+ ".junk.tmp";
1697 string objectsMacro
= GetObjectsMacro ( module
);
1698 string importLibraryDependencies
= GetImportLibraryDependencies ( module
);
1700 GenerateMacrosAndTargetsTarget ( module
);
1702 fprintf ( fMakefile
, "%s: %s %s\n",
1704 objectsMacro
.c_str (),
1705 importLibraryDependencies
.c_str () );
1707 fprintf ( fMakefile
,
1708 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
1709 GetLinkerMacro ( module
).c_str (),
1711 objectsMacro
.c_str (),
1712 importLibraryDependencies
.c_str () );
1713 fprintf ( fMakefile
,
1714 "\t${objcopy} -O binary %s %s\n",
1717 fprintf ( fMakefile
,
1719 junk_tmp
.c_str () );