--- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.cpp 2005-03-09 08:04:40 UTC (rev 13898)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.cpp 2005-03-09 08:12:30 UTC (rev 13899)
@@ -12,6 +12,8 @@
typedef set<string> set_string;
+#define CLEAN_FILE(f) clean_files.push_back ( f ); /*if ( module.name == "crt" ) printf ( "%s(%i): clean: %s\n", __FILE__, __LINE__, f.c_str() )*/
+
map<ModuleType,MingwModuleHandler*>*
MingwModuleHandler::handler_map = NULL;
set_string
@@ -135,21 +137,6 @@
}
string
-MingwModuleHandler::GetImportLibraryDependencies ( const Module& module ) const
-{
- string dependencies ( "" );
- for ( size_t i = 0; i < module.libraries.size (); i++ )
- {
- if ( dependencies.size () > 0 )
- dependencies += " ";
- const Module* importedModule = module.project.LocateModule ( module.libraries[i]->name );
- assert ( importedModule != NULL );
- dependencies += GetImportLibraryDependency ( *importedModule );
- }
- return dependencies;
-}
-
-string
MingwModuleHandler::GetModuleDependencies ( const Module& module ) const
{
if ( module.dependencies.size () == 0 )
@@ -172,10 +159,10 @@
return dependencies;
}
-string
+/*string
MingwModuleHandler::GetAllDependencies ( const Module& module ) const
{
- string dependencies = GetImportLibraryDependencies ( module );
+ string dependencies = GetImportMacro ( module );
string s = GetModuleDependencies ( module );
if ( s.length () > 0 )
{
@@ -183,7 +170,7 @@
dependencies += s;
}
return dependencies;
-}
+}*/
string
MingwModuleHandler::GetSourceFilenames ( const Module& module,
@@ -241,6 +228,25 @@
return FixupTargetFilename ( ReplaceExtension ( sourceFilename, newExtension ) );
}
+void
+MingwModuleHandler::GenerateCleanTarget (
+ const Module& module,
+ const string_list& clean_files ) const
+{
+ if ( 0 == clean_files.size() )
+ return;
+ fprintf ( fMakefile, ".PHONY: %s_clean\n", module.name.c_str() );
+ fprintf ( fMakefile, "%s_clean:\n\t-@$(rm)", module.name.c_str() );
+ for ( size_t i = 0; i < clean_files.size(); i++ )
+ {
+ if ( 9==((i+1)%10) )
+ fprintf ( fMakefile, " 2>$(NUL)\n\t-@$(rm)" );
+ fprintf ( fMakefile, " %s", clean_files[i].c_str() );
+ }
+ fprintf ( fMakefile, " 2>$(NUL)\n" );
+ fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );
+}
+
string
MingwModuleHandler::GetObjectFilenames ( const Module& module ) const
{
@@ -272,32 +278,38 @@
if ( directory_set.size () == 0 )
return;
- set_string::iterator i;
+ set_string::iterator it;
+ size_t wrap_count = 0;
fprintf ( fMakefile, "directories::" );
- for ( i = directory_set.begin ();
- i != directory_set.end ();
- i++ )
+ for ( it = directory_set.begin ();
+ it != directory_set.end ();
+ it++ )
{
- if ( IncludeDirectoryTarget ( *i ) )
+ if ( IncludeDirectoryTarget ( *it ) )
{
+ if ( wrap_count++ == 5 )
+ fprintf ( fMakefile, " \\\n\t\t" ), wrap_count = 0;
fprintf ( fMakefile,
" %s",
- i->c_str () );
+ it->c_str () );
}
}
fprintf ( fMakefile, "\n\n" );
+ wrap_count = 0;
- for ( i = directory_set.begin ();
- i != directory_set.end ();
- i++ )
+ for ( it = directory_set.begin ();
+ it != directory_set.end ();
+ it++ )
{
- if ( IncludeDirectoryTarget ( *i ) )
+ if ( IncludeDirectoryTarget ( *it ) )
{
+ if ( wrap_count++ == 5 )
+ fprintf ( fMakefile, " \\\n\t\t" ), wrap_count = 0;
fprintf ( fMakefile,
"%s ",
- i->c_str () );
+ it->c_str () );
}
}
@@ -409,6 +421,23 @@
}
string
+MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
+ const vector<Library*>& libraries ) const
+{
+ string dependencies ( "" );
+ int wrap_count = 0;
+ for ( size_t i = 0; i < libraries.size (); i++ )
+ {
+ if ( wrap_count++ == 5 )
+ dependencies += " \\\n\t\t", wrap_count = 0;
+ else if ( dependencies.size () > 0 )
+ dependencies += " ";
+ dependencies += GetImportLibraryDependency ( *libraries[i]->imported_module );
+ }
+ return dependencies;
+}
+
+string
MingwModuleHandler::GenerateLinkerParameters ( const Module& module ) const
{
return GenerateLinkerParametersFromVector ( module.linkerFlags );
@@ -470,6 +499,7 @@
const vector<File*>& files,
const vector<Include*>& includes,
const vector<Define*>& defines,
+ const vector<Library*>& libraries,
const vector<CompilerFlag*>* compilerFlags,
const vector<LinkerFlag*>* linkerFlags,
const vector<If*>& ifs,
@@ -477,7 +507,9 @@
const string& nasmflags_macro,
const string& windresflags_macro,
const string& linkerflags_macro,
- const string& objs_macro) const
+ const string& objs_macro,
+ const string& libs_macro,
+ const string& linkdeps_macro ) const
{
size_t i;
@@ -508,7 +540,21 @@
linkerParameters.c_str() );
}
}
-
+
+ if ( libraries.size () > 0 )
+ {
+ string deps = GenerateImportLibraryDependenciesFromVector ( libraries );
+ if ( deps.size () > 0 )
+ {
+ fprintf (
+ fMakefile,
+ "%s %s %s\n",
+ libs_macro.c_str(),
+ assignmentOperation,
+ deps.c_str() );
+ }
+ }
+
if ( files.size () > 0 )
{
for ( i = 0; i < files.size (); i++ )
@@ -544,7 +590,11 @@
for ( i = 0; i < ifs.size(); i++ )
{
If& rIf = *ifs[i];
- if ( rIf.defines.size() || rIf.includes.size() || rIf.files.size() || rIf.ifs.size() )
+ if ( rIf.defines.size()
+ || rIf.includes.size()
+ || rIf.libraries.size()
+ || rIf.files.size()
+ || rIf.ifs.size() )
{
fprintf (
fMakefile,
@@ -556,6 +606,7 @@
rIf.files,
rIf.includes,
rIf.defines,
+ rIf.libraries,
NULL,
NULL,
rIf.ifs,
@@ -563,7 +614,9 @@
nasmflags_macro,
windresflags_macro,
linkerflags_macro,
- objs_macro );
+ objs_macro,
+ libs_macro,
+ linkdeps_macro );
fprintf (
fMakefile,
"endif\n\n" );
@@ -578,13 +631,16 @@
const string& nasmflags_macro,
const string& windresflags_macro,
const string& linkerflags_macro,
- const string& objs_macro) const
+ const string& objs_macro,
+ const string& libs_macro,
+ const string& linkdeps_macro ) const
{
GenerateMacros (
"=",
module.files,
module.includes,
module.defines,
+ module.libraries,
&module.compilerFlags,
&module.linkerFlags,
module.ifs,
@@ -592,23 +648,56 @@
nasmflags_macro,
windresflags_macro,
linkerflags_macro,
- objs_macro );
- fprintf ( fMakefile, "\n" );
+ objs_macro,
+ libs_macro,
+ linkdeps_macro );
+ if ( module.importLibrary )
+ {
+ string s;
+ for ( size_t i = 0; i < module.files.size (); i++ )
+ {
+ File& file = *module.files[i];
+ string extension = GetExtension ( file.name );
+ if ( extension == ".spec" || extension == ".SPEC" )
+ {
+ if ( s.length () > 0 )
+ s += " ";
+ s += GetSpecObjectDependencies ( file.name );
+ }
+ }
+ if ( s.length () > 0 )
+ {
+ fprintf (
+ fMakefile,
+ "%s += %s\n",
+ linkdeps_macro.c_str(),
+ s.c_str() );
+ }
+ }
+
fprintf (
fMakefile,
- "%s += $(PROJECT_CFLAGS)\n\n",
+ "%s += $(PROJECT_CFLAGS)\n",
cflags_macro.c_str () );
fprintf (
fMakefile,
- "%s += $(PROJECT_RCFLAGS)\n\n",
+ "%s += $(PROJECT_RCFLAGS)\n",
windresflags_macro.c_str () );
fprintf (
fMakefile,
- "%s_LFLAGS += $(PROJECT_LFLAGS)\n\n",
+ "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
module.name.c_str () );
+
+ fprintf (
+ fMakefile,
+ "%s += $(%s)",
+ linkdeps_macro.c_str (),
+ libs_macro.c_str () );
+
+ fprintf ( fMakefile, "\n" );
}
void
@@ -622,6 +711,7 @@
"%s: %s\n",
objectFilename.c_str (),
sourceFilename.c_str () );
+ fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [CC] $<\n" );
fprintf ( fMakefile,
"\t%s -c %s -o %s %s\n",
cc.c_str (),
@@ -641,6 +731,7 @@
"%s: %s\n",
objectFilename.c_str (),
sourceFilename.c_str () );
+ fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [GAS] $<\n" );
fprintf ( fMakefile,
"\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
cc.c_str (),
@@ -659,9 +750,10 @@
"%s: %s\n",
objectFilename.c_str (),
sourceFilename.c_str () );
+ fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [NASM] $<\n" );
fprintf ( fMakefile,
"\t%s -f win32 %s -o %s %s\n",
- "nasm",
+ "$(Q)nasm",
sourceFilename.c_str (),
objectFilename.c_str (),
nasmflagsMacro.c_str () );
@@ -673,14 +765,15 @@
const string& windresflagsMacro ) const
{
string objectFilename = PassThruCacheDirectory ( MingwModuleHandler::GetObjectFilename ( sourceFilename ) );
- string rciFilename = ReplaceExtension ( sourceFilename,
- ".rci" );
- string resFilename = ReplaceExtension ( sourceFilename,
- ".res" );
+ string rciFilename = ReplaceExtension ( sourceFilename,
+ ".rci" );
+ string resFilename = ReplaceExtension ( sourceFilename,
+ ".res" );
fprintf ( fMakefile,
"%s: %s\n",
objectFilename.c_str (),
sourceFilename.c_str () );
+ fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [WRC] $@\n" );
fprintf ( fMakefile,
"\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
windresflagsMacro.c_str (),
@@ -692,52 +785,66 @@
rciFilename.c_str (),
resFilename.c_str () );
fprintf ( fMakefile,
- "\t${rm} %s\n",
+ "\t-@${rm} %s\n",
rciFilename.c_str () );
fprintf ( fMakefile,
"\t${windres} %s -o %s\n",
resFilename.c_str (),
objectFilename.c_str () );
fprintf ( fMakefile,
- "\t${rm} %s\n",
+ "\t-@${rm} %s\n",
resFilename.c_str () );
}
void
-MingwModuleHandler::GenerateWinebuildCommands ( const Module& module,
- const string& sourceFilename ) const
+MingwModuleHandler::GenerateWinebuildCommands (
+ const Module& module,
+ const string& sourceFilename,
+ string_list& clean_files ) const
{
string basename = GetBasename ( sourceFilename );
+
+ string def_file = basename + ".spec.def";
+ CLEAN_FILE ( def_file );
+
+ string stub_file = basename + ".stubs.c";
+ CLEAN_FILE ( stub_file );
+
fprintf ( fMakefile,
- "%s.spec.def: %s\n",
- basename.c_str (),
+ "%s: %s\n",
+ def_file.c_str (),
sourceFilename.c_str () );
+ fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [WINEBLD] $@\n" );
fprintf ( fMakefile,
- "\t%s --def=%s -o %s.spec.def\n",
+ "\t%s --def=%s -o %s\n",
"${winebuild}",
sourceFilename.c_str (),
- basename.c_str () );
+ def_file.c_str () );
fprintf ( fMakefile,
- "%s.stubs.c: %s\n",
- basename.c_str (),
+ "%s: %s\n",
+ stub_file.c_str (),
sourceFilename.c_str () );
+ fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [WINEBLD] $@\n" );
fprintf ( fMakefile,
- "\t%s --pedll=%s -o %s.stubs.c\n",
+ "\t%s --pedll=%s -o %s\n",
"${winebuild}",
sourceFilename.c_str (),
- basename.c_str () );
+ stub_file.c_str () );
}
void
-MingwModuleHandler::GenerateCommands ( const Module& module,
- const string& sourceFilename,
- const string& cc,
- const string& cppc,
- const string& cflagsMacro,
- const string& nasmflagsMacro,
- const string& windresflagsMacro ) const
+MingwModuleHandler::GenerateCommands (
+ const Module& module,
+ const string& sourceFilename,
+ const string& cc,
+ const string& cppc,
+ const string& cflagsMacro,
+ const string& nasmflagsMacro,
+ const string& windresflagsMacro,
+ string_list& clean_files ) const
{
+ CLEAN_FILE ( GetObjectFilename(sourceFilename) );
string extension = GetExtension ( sourceFilename );
if ( extension == ".c" || extension == ".C" )
{
@@ -782,7 +889,8 @@
else if ( extension == ".spec" || extension == ".SPEC" )
{
GenerateWinebuildCommands ( module,
- sourceFilename );
+ sourceFilename,
+ clean_files );
GenerateGccCommand ( module,
GetActualSourceFilename ( sourceFilename ),
cc,
@@ -798,20 +906,27 @@
}
void
-MingwModuleHandler::GenerateLinkerCommand ( const Module& module,
- const string& linker,
- const string& linkerParameters,
- const string& objectFilenames ) const
+MingwModuleHandler::GenerateLinkerCommand (
+ const Module& module,
+ const string& linker,
+ const string& linkerParameters,
+ const string& objectsMacro,
+ const string& libsMacro,
+ string_list& clean_files ) const
{
+ fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [LD] $@\n" );
string targetName ( module.GetTargetName () );
string target ( FixupTargetFilename ( module.GetPath () ) );
- string importLibraryDependencies = GetImportLibraryDependencies ( module );
if ( module.importLibrary != NULL )
{
static string ros_junk ( "$(ROS_TEMPORARY)" );
string base_tmp = ros_junk + module.name + ".base.tmp";
+ CLEAN_FILE ( base_tmp );
string junk_tmp = ros_junk + module.name + ".junk.tmp";
+ CLEAN_FILE ( junk_tmp );
string temp_exp = ros_junk + module.name + ".temp.exp";
+ CLEAN_FILE ( temp_exp );
+ string def_file = module.GetBasePath () + SSEP + module.importLibrary->definition;
fprintf ( fMakefile,
"\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
@@ -819,12 +934,12 @@
linkerParameters.c_str (),
base_tmp.c_str (),
junk_tmp.c_str (),
- objectFilenames.c_str (),
- importLibraryDependencies.c_str (),
+ objectsMacro.c_str (),
+ libsMacro.c_str (),
GetLinkerMacro ( module ).c_str () );
fprintf ( fMakefile,
- "\t${rm} %s\n",
+ "\t-@${rm} %s\n",
junk_tmp.c_str () );
string killAt = module.mangledSymbols ? "" : "--kill-at";
@@ -832,26 +947,26 @@
"\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
targetName.c_str (),
base_tmp.c_str (),
- ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
+ def_file.c_str (),
temp_exp.c_str (),
killAt.c_str () );
fprintf ( fMakefile,
- "\t${rm} %s\n",
+ "\t-@${rm} %s\n",
base_tmp.c_str () );
fprintf ( fMakefile,
- "\t%s %s %s -o %s %s %s %s\n\n",
+ "\t%s %s %s -o %s %s %s %s\n",
linker.c_str (),
linkerParameters.c_str (),
temp_exp.c_str (),
target.c_str (),
- objectFilenames.c_str (),
- importLibraryDependencies.c_str (),
+ objectsMacro.c_str (),
+ libsMacro.c_str (),
GetLinkerMacro ( module ).c_str () );
fprintf ( fMakefile,
- "\t${rm} %s\n\n",
+ "\t-@${rm} %s\n",
temp_exp.c_str () );
}
else
@@ -861,26 +976,29 @@
linker.c_str (),
linkerParameters.c_str (),
target.c_str (),
- objectFilenames.c_str (),
- importLibraryDependencies.c_str (),
+ objectsMacro.c_str (),
+ libsMacro.c_str (),
GetLinkerMacro ( module ).c_str () );
}
+ fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [RSYM] $@\n" );
fprintf ( fMakefile,
- "\t${rsym} %s %s\n\n",
- target.c_str (),
- target.c_str () );
+ "\t${rsym} %s %s\n\n",
+ target.c_str (),
+ target.c_str () );
}
void
-MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,
- const vector<File*>& files,
- const vector<If*>& ifs,
- const string& cc,
- const string& cppc,
- const string& cflagsMacro,
- const string& nasmflagsMacro,
- const string& windresflagsMacro ) const
+MingwModuleHandler::GenerateObjectFileTargets (
+ const Module& module,
+ const vector<File*>& files,
+ const vector<If*>& ifs,
+ const string& cc,
+ const string& cppc,
+ const string& cflagsMacro,
+ const string& nasmflagsMacro,
+ const string& windresflagsMacro,
+ string_list& clean_files ) const
{
size_t i;
@@ -893,7 +1011,8 @@
cppc,
cflagsMacro,
nasmflagsMacro,
- windresflagsMacro );
+ windresflagsMacro,
+ clean_files );
fprintf ( fMakefile,
"\n" );
}
@@ -907,17 +1026,20 @@
cppc,
cflagsMacro,
nasmflagsMacro,
- windresflagsMacro );
+ windresflagsMacro,
+ clean_files );
}
}
void
-MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,
- const string& cc,
- const string& cppc,
- const string& cflagsMacro,
- const string& nasmflagsMacro,
- const string& windresflagsMacro ) const
+MingwModuleHandler::GenerateObjectFileTargets (
+ const Module& module,
+ const string& cc,
+ const string& cppc,
+ const string& cflagsMacro,
+ const string& nasmflagsMacro,
+ const string& windresflagsMacro,
+ string_list& clean_files ) const
{
GenerateObjectFileTargets ( module,
module.files,
@@ -926,12 +1048,13 @@
cppc,
cflagsMacro,
nasmflagsMacro,
- windresflagsMacro );
+ windresflagsMacro,
+ clean_files );
fprintf ( fMakefile, "\n" );
}
void
-MingwModuleHandler::GetCleanTargets ( vector<string>& out,
+MingwModuleHandler::GetCleanTargets ( string_list& out,
const vector<File*>& files,
const vector<If*>& ifs ) const
{
@@ -956,6 +1079,8 @@
archiveFilename.c_str (),
objs_macro.c_str ());
+ fprintf ( fMakefile, "\t$(HALFVERBOSEECHO) [AR] $@\n" );
+
fprintf ( fMakefile,
"\t%s -rc %s %s\n\n",
ar.c_str (),
@@ -980,12 +1105,24 @@
}
string
+MingwModuleHandler::GetLinkingDependenciesMacro ( const Module& module ) const
+{
+ return ssprintf ( "$(%s_LINKDEPS)", module.name.c_str () );
+}
+
+string
+MingwModuleHandler::GetLibsMacro ( const Module& module ) const
+{
+ return ssprintf ( "$(%s_LIBS)", module.name.c_str () );
+}
+
+string
MingwModuleHandler::GetLinkerMacro ( const Module& module ) const
{
return ssprintf ( "$(%s_LFLAGS)",
module.name.c_str () );
}
-
+
void
MingwModuleHandler::GenerateMacrosAndTargets (
const Module& module,
@@ -993,20 +1130,25 @@
const string& cppc,
const string& ar,
const string* cflags,
- const string* nasmflags ) const
+ const string* nasmflags,
+ string_list& clean_files ) const
{
string cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
string nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
string windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());
string linkerFlagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());
string objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());
+ string libsMacro = ssprintf("%s_LIBS", module.name.c_str ());
+ string linkDepsMacro = ssprintf ("%s_LINKDEPS", module.name.c_str ());
GenerateMacros ( module,
cflagsMacro,
nasmflagsMacro,
windresflagsMacro,
linkerFlagsMacro,
- objectsMacro );
+ objectsMacro,
+ libsMacro,
+ linkDepsMacro );
if ( cflags != NULL )
{
@@ -1042,55 +1184,59 @@
cppc,
cflagsMacro,
nasmflagsMacro,
- windresflagsMacro );
+ windresflagsMacro,
+ clean_files );
- vector<string> clean_files;
- clean_files.push_back ( FixupTargetFilename(module.GetPath()) );
- clean_files.push_back ( ar_target );
- GetCleanTargets ( clean_files, module.files, module.ifs );
-
- fprintf ( fMakefile, ".PHONY: %s_clean\n", module.name.c_str() );
- fprintf ( fMakefile, "%s_clean:\n\t-@$(rm)", module.name.c_str() );
- for ( size_t i = 0; i < clean_files.size(); i++ )
+ CLEAN_FILE ( ar_target );
+ string tgt = FixupTargetFilename(module.GetPath());
+ if ( tgt != ar_target )
{
- if ( 9==(i%10) )
- fprintf ( fMakefile, " 2>$(NUL)\n\t-@$(rm)" );
- fprintf ( fMakefile, " %s", clean_files[i].c_str() );
+ CLEAN_FILE ( tgt );
}
- fprintf ( fMakefile, " 2>$(NUL)\n" );
- fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );
}
void
-MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module& module ) const
+MingwModuleHandler::GenerateMacrosAndTargetsHost (
+ const Module& module,
+ string_list& clean_files ) const
{
- GenerateMacrosAndTargets ( module,
- "${host_gcc}",
- "${host_gpp}",
- "${host_ar}",
- NULL,
- NULL );
+ GenerateMacrosAndTargets (
+ module,
+ "${host_gcc}",
+ "${host_gpp}",
+ "${host_ar}",
+ NULL,
+ NULL,
+ clean_files );
}
void
-MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module ) const
+MingwModuleHandler::GenerateMacrosAndTargetsTarget (
+ const Module& module,
+ string_list& clean_files ) const
{
- GenerateMacrosAndTargetsTarget ( module,
- NULL,
- NULL );
+ GenerateMacrosAndTargetsTarget (
+ module,
+ NULL,
+ NULL,
+ clean_files );
}
void
-MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module,
- const string* cflags,
- const string* nasmflags ) const
+MingwModuleHandler::GenerateMacrosAndTargetsTarget (
+ const Module& module,
+ const string* cflags,
+ const string* nasmflags,
+ string_list& clean_files ) const
[truncated at 1000 lines; 1274 more skipped]