From f51410ed14673af176d9d5b110d3423d0c439318 Mon Sep 17 00:00:00 2001 From: "KJK::Hyperion" Date: Fri, 23 Jan 2009 14:27:12 +0000 Subject: [PATCH] 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 --- .../rbuild/backend/mingw/modulehandler.cpp | 65 +++++++++++-------- reactos/tools/rbuild/backend/mingw/rule.cpp | 35 ++++++++-- reactos/tools/rbuild/backend/mingw/rule.h | 10 +++ 3 files changed, 79 insertions(+), 31 deletions(-) diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp index d5315393730..7bfd5ca07d1 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp @@ -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 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 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 ); diff --git a/reactos/tools/rbuild/backend/mingw/rule.cpp b/reactos/tools/rbuild/backend/mingw/rule.cpp index d5dd8e44c8f..d2eff5ffddc 100644 --- a/reactos/tools/rbuild/backend/mingw/rule.cpp +++ b/reactos/tools/rbuild/backend/mingw/rule.cpp @@ -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& custom_variables ) { string ret = str; + + for ( std::map::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& 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() ); +} diff --git a/reactos/tools/rbuild/backend/mingw/rule.h b/reactos/tools/rbuild/backend/mingw/rule.h index e32b923ebf2..a23ee54b05d 100644 --- a/reactos/tools/rbuild/backend/mingw/rule.h +++ b/reactos/tools/rbuild/backend/mingw/rule.h @@ -21,6 +21,8 @@ #include "mingw.h" +#include + 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& custom_variables ) const; private: const std::string command; string_list generatedFiles;