modified tools/rbuild/backend/mingw/modulehandler.cpp

Use a Rule object for formatting PCH rules. Results in an almost identical makefile.auto, the differences (improvements) being:
    - the new rule uses $@ and $< instead of the full filenames
    - the new rule doesn't add the -g option (the module's CFLAGS/CXXFLAGS already contain it)
    - .gch files now depend on the module's .rbuild as well (a standard Rule feature)
   No rebuild needed, but rbuild will force one for most of you anyways

modified   tools/rbuild/backend/mingw/rule.cpp
modified   tools/rbuild/backend/mingw/rule.h
   Rule::Execute now supports an arbitrary set of replaceable variables, too (required for the PCH rule)

svn path=/trunk/; revision=39048
This commit is contained in:
KJK::Hyperion 2009-01-23 14:27:12 +00:00
parent aba3c0d759
commit f51410ed14
3 changed files with 79 additions and 31 deletions

View file

@ -1158,14 +1158,14 @@ Rule widlProxyRule ( "$(source): ${$(module_name)_precondition}\n"
"\t$(ECHO_WIDL)\n"
"\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) -h -H $(intermediate_path_noext)_p.h -p -P $(intermediate_path_noext)_p.c $(source)\n"
"$(intermediate_path_noext)_p.o: $(intermediate_path_noext)_p.c $(intermediate_path_noext)_p.h$(dependencies) | $(intermediate_dir)\n"
"\t$(ECHO_CC)\n"
"\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -fno-unit-at-a-time -c $<\n",
"\t$(ECHO_CC)\n"
"\t${gcc} -o $@ $($(module_name)_CFLAGS)$(compiler_flags) -fno-unit-at-a-time -c $<\n",
"$(intermediate_path_noext)_p.h",
"$(intermediate_path_noext)_p.c",
"$(intermediate_path_noext)_p.o",
"$(intermediate_dir)$(SEP)", NULL );
Rule widlDlldataRule ( "$(source): $(dependencies) ${$(module_name)_precondition} $(WIDL_TARGET) | $(intermediate_dir)\n"
"\t$(ECHO_WIDL)\n"
"\t$(ECHO_WIDL)\n"
"\t$(Q)$(WIDL_TARGET) $($(module_name)_WIDLFLAGS) --dlldata-only --dlldata=$(source) $(bare_dependencies)\n"
"$(intermediate_path_noext).o: $(source) $(dependencies) | $(intermediate_dir)\n"
"\t$(ECHO_CC)\n"
@ -1196,6 +1196,10 @@ Rule gppHostRule ( "$(source): ${$(module_name)_precondition}\n"
"\t$(ECHO_HOSTCC)\n"
"\t${host_gpp} -o $@ $($(module_name)_CXXFLAGS)$(compiler_flags) -c $<\n",
"$(intermediate_path_unique).o", NULL );
Rule pchRule ( "$(intermediate_dir)$(SEP).gch_$(module_name)$(SEP)$(source_name).gch: $(source)$(dependencies) | $(intermediate_dir)$(SEP).gch_$(module_name)\n"
"\t$(ECHO_PCH)\n"
"\t$(pch_cc) -o $@ $(pch_ccflags)$(compiler_flags) -x $(pch_language) -c $<\n",
"$(intermediate_dir)$(SEP).gch_$(module_name)$(SEP)$(source_name).gch", NULL );
Rule emptyRule ( "", NULL );
void
@ -1689,38 +1693,45 @@ MingwModuleHandler::GenerateObjectFileTargets ( const IfableData& data )
void
MingwModuleHandler::GenerateObjectFileTargets ()
{
const FileLocation *pchFilename = GetPrecompiledHeaderFilename ();
fprintf ( fMakefile, "# OBJECT FILE TARGETS\n" );
if ( pchFilename )
if ( module.pch && use_pch )
{
string cc = ( ModuleHandlerInformations[module.type].DefaultHost == HostTrue ? "${host_gcc}" : "${gcc}" );
string cppc = ( ModuleHandlerInformations[module.type].DefaultHost == HostTrue ? "${host_gpp}" : "${gpp}" );
const FileLocation& baseHeaderFile = *module.pch->file;
CLEAN_FILE ( *pchFilename );
string dependencies = backend->GetFullName ( baseHeaderFile );
std::map<string, string> vars;
if ( ModuleHandlerInformations[module.type].DefaultHost == HostTrue )
vars["pch_cc"] = "${host_gcc}";
else
vars["pch_cc"] = "${gcc}";
if ( module.cplusplus )
{
vars["pch_language"] = "c++-header";
vars["pch_ccflags"] = cxxflagsMacro.c_str();
}
else
{
vars["pch_language"] = "c-header";
vars["pch_ccflags"] = cflagsMacro.c_str();
}
/* WIDL generated headers may be used */
string dependencies;
vector<FileLocation> rpcDependencies;
GetRpcHeaderDependencies ( rpcDependencies );
if ( rpcDependencies.size () > 0 )
dependencies += " " + v2s ( backend, rpcDependencies, 5 );
fprintf ( fMakefile,
"%s: %s | %s\n",
backend->GetFullName ( *pchFilename ).c_str(),
dependencies.c_str(),
backend->GetFullPath ( *pchFilename ).c_str() );
fprintf ( fMakefile, "\t$(ECHO_PCH)\n" );
fprintf ( fMakefile,
"\t%s -o %s %s %s -gstabs+ -x %s %s\n\n",
cc.c_str(),
backend->GetFullName ( *pchFilename ).c_str(),
module.cplusplus ? cxxflagsMacro.c_str() : cflagsMacro.c_str(),
GenerateCompilerParametersFromVector ( module.non_if_data.compilerFlags, module.cplusplus ? CompilerTypeCPP : CompilerTypeCC ).c_str(),
module.cplusplus ? "c++-header" : "c-header",
backend->GetFullName ( baseHeaderFile ).c_str() );
delete pchFilename;
dependencies = v2s ( backend, rpcDependencies, 5 );
pchRule.Execute ( fMakefile,
backend,
module,
module.pch->file,
clean_files,
dependencies,
GenerateCompilerParametersFromVector ( module.non_if_data.compilerFlags, module.cplusplus ? CompilerTypeCPP : CompilerTypeCC ).c_str(),
vars );
fprintf ( fMakefile, "\n" );
}
GenerateObjectFileTargets ( module.non_if_data );

View file

@ -37,9 +37,16 @@ ReplaceVariable( string& str,
static std::string
FixString ( const string& str, Backend *backend, const Module& module, const FileLocation *source,
const std::string& additional_dependencies, const std::string& compiler_flags )
const std::string& additional_dependencies, const std::string& compiler_flags,
const std::map<std::string, std::string>& custom_variables )
{
string ret = str;
for ( std::map<std::string, std::string>::const_iterator p = custom_variables.begin(); p != custom_variables.end(); ++ p )
{
ReplaceVariable ( ret, "$(" + p->first + ")", p->second );
}
string dep = additional_dependencies;
dep += " " + module.xmlbuildFile;
@ -91,15 +98,16 @@ void Rule::Execute ( FILE *outputFile,
const FileLocation *source,
string_list& clean_files,
const std::string& additional_dependencies,
const std::string& compiler_flags ) const
const std::string& compiler_flags,
const std::map<std::string, std::string>& custom_variables ) const
{
string cmd = FixString ( command, backend, module, source, additional_dependencies, compiler_flags );
string cmd = FixString ( command, backend, module, source, additional_dependencies, compiler_flags, custom_variables );
fprintf ( outputFile, "%s", cmd.c_str () );
for ( size_t i = 0; i < generatedFiles.size (); i++ )
{
string file = FixString ( generatedFiles[i], backend, module, source, "", "" );
string file = FixString ( generatedFiles[i], backend, module, source, "", "", custom_variables );
if ( file[file.length () - 1] != cSep )
{
clean_files.push_back ( file );
@ -128,3 +136,22 @@ void Rule::Execute ( FILE *outputFile,
dir.c_str () );
}
}
void Rule::Execute ( FILE *outputFile,
MingwBackend *backend,
const Module& module,
const FileLocation *source,
string_list& clean_files,
const std::string& additional_dependencies,
const std::string& compiler_flags ) const
{
this->Execute ( outputFile,
backend,
module,
source,
clean_files,
additional_dependencies,
compiler_flags,
std::map<std::string, std::string>() );
}

View file

@ -21,6 +21,8 @@
#include "mingw.h"
#include <map>
class Rule
{
public:
@ -32,6 +34,14 @@ public:
string_list& clean_files,
const std::string& additional_dependencies = "",
const std::string& compiler_flags = "" ) const;
void Execute ( FILE *outputFile,
MingwBackend *backend,
const Module& module,
const FileLocation *source,
string_list& clean_files,
const std::string& additional_dependencies,
const std::string& compiler_flags,
const std::map<std::string, std::string>& custom_variables ) const;
private:
const std::string command;
string_list generatedFiles;