Author: tkreuzer
Date: Mon Jul 27 00:36:55 2009
New Revision: 42242

URL: http://svn.reactos.org/svn/reactos?rev=42242&view=rev
Log:
[rbuild] Implement delay import support for gcc in rbuild.
As soon as you declare a library import with 
<library delayimport="true"> you will link to the autogenerated delayimportlib. 
This will currenlty not work without a patched version of dlltool.

Modified:
    trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp
    trunk/reactos/tools/rbuild/backend/mingw/modulehandler.h
    trunk/reactos/tools/rbuild/module.cpp
    trunk/reactos/tools/rbuild/rbuild.h

Modified: trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp?rev=42242&r1=42241&r2=42242&view=diff
==============================================================================
--- trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp [iso-8859-1] 
(original)
+++ trunk/reactos/tools/rbuild/backend/mingw/modulehandler.cpp [iso-8859-1] Mon 
Jul 27 00:36:55 2009
@@ -145,9 +145,23 @@
 const FileLocation*
 MingwModuleHandler::GetImportLibraryFilename (
        const Module& module,
-       string_list* pclean_files )
-{
-       FileLocation *target = new FileLocation ( *module.dependency );
+       string_list* pclean_files,
+       bool delayimp )
+{
+       FileLocation *target;
+
+       if (module.HasImportLibrary())
+       {
+               if (delayimp)
+               {
+                       target = new FileLocation ( 
*module.delayImportLibrary->target );
+               }
+               else
+                       target = new FileLocation ( 
*module.importLibrary->target );
+       }
+       else
+               target = new FileLocation ( *module.dependency );
+
        if ( pclean_files )
        {
                string_list& clean_files = *pclean_files;
@@ -324,7 +338,8 @@
 
 string
 MingwModuleHandler::GetImportLibraryDependency (
-       const Module& importedModule )
+       const Module& importedModule,
+       bool delayimp )
 {
        string dep;
        if ( ReferenceObjects ( importedModule ) )
@@ -346,7 +361,7 @@
        }
        else
        {
-               const FileLocation *library_target = GetImportLibraryFilename ( 
importedModule, NULL );
+               const FileLocation *library_target = GetImportLibraryFilename ( 
importedModule, NULL, delayimp );
                dep = backend->GetFullName ( *library_target );
                delete library_target;
        }
@@ -358,7 +373,7 @@
                for ( size_t i = 0; i < libraries.size (); ++ i )
                {
                        dep += " ";
-                       dep += GetImportLibraryDependency ( 
*libraries[i]->importedModule );
+                       dep += GetImportLibraryDependency ( 
*libraries[i]->importedModule, libraries[i]->delayimp );
                }
        }
 
@@ -378,7 +393,7 @@
                }
        }
        else
-               targets.push_back ( GetImportLibraryDependency ( 
dependencyModule ) );
+               targets.push_back ( GetImportLibraryDependency ( 
dependencyModule, false ) );
 }
 
 void
@@ -746,7 +761,7 @@
                        dependencies += " \\\n\t\t", wrap_count = 0;
                else if ( dependencies.size () > 0 )
                        dependencies += " ";
-               dependencies += GetImportLibraryDependency ( 
*libraries[i]->importedModule );
+               dependencies += GetImportLibraryDependency ( 
*libraries[i]->importedModule, libraries[i]->delayimp );
        }
        return dependencies;
 }
@@ -2135,42 +2150,57 @@
 }
 
 void
+MingwModuleHandler::GenerateImportLibraryTarget (
+       const FileLocation *defFilename,
+       const FileLocation *library_target,
+       bool delayimp)
+{
+       string empty = "tools" + sSep + "rbuild" + sSep + "empty.def";
+
+       fprintf ( fMakefile, "# IMPORT LIBRARY RULE\n" );
+
+       fprintf ( fMakefile, "%s:",
+                 backend->GetFullName ( *library_target ).c_str () );
+
+       if ( defFilename )
+       {
+               fprintf ( fMakefile, " %s",
+                         backend->GetFullName ( *defFilename ).c_str () );
+       }
+
+       fprintf ( fMakefile, " | %s\n",
+                 backend->GetFullPath ( *library_target ).c_str () );
+
+       fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );
+
+       fprintf ( fMakefile,
+                 "\t${dlltool} --dllname %s --def %s %s %s%s%s\n\n",
+                 module.GetDllName ().c_str (),
+                 defFilename ? backend->GetFullName ( *defFilename ).c_str ()
+                             : empty.c_str (),
+                 delayimp ? "--output-delaylib" : "--output-lib",
+                 backend->GetFullName ( *library_target ).c_str (),
+                 module.mangledSymbols ? "" : " --kill-at",
+                 module.underscoreSymbols ? " --add-underscore" : "" );
+}
+
+void
 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
 {
        if ( module.importLibrary != NULL )
        {
-               const FileLocation *library_target = GetImportLibraryFilename ( 
module, &clean_files );
+               const FileLocation *library_target = GetImportLibraryFilename ( 
module, &clean_files, false );
+               const FileLocation *delayimp_target = GetImportLibraryFilename 
( module, &clean_files, true );
                const FileLocation *defFilename = GetDefinitionFilename ();
-               string empty = "tools" + sSep + "rbuild" + sSep + "empty.def";
-
-               fprintf ( fMakefile, "# IMPORT LIBRARY RULE\n" );
-
-               fprintf ( fMakefile, "%s:",
-                         backend->GetFullName ( *library_target ).c_str () );
-
-               if ( defFilename )
-               {
-                       fprintf ( fMakefile, " %s",
-                                 backend->GetFullName ( *defFilename ).c_str 
() );
-               }
-
-               fprintf ( fMakefile, " | %s\n",
-                         backend->GetFullPath ( *library_target ).c_str () );
-
-               fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );
-
-               fprintf ( fMakefile,
-                         "\t${dlltool} --dllname %s --def %s --output-lib 
%s%s%s\n\n",
-                         module.GetDllName ().c_str (),
-                         defFilename ? backend->GetFullName ( *defFilename 
).c_str ()
-                                     : empty.c_str (),
-                         backend->GetFullName ( *library_target ).c_str (),
-                         module.mangledSymbols ? "" : " --kill-at",
-                         module.underscoreSymbols ? " --add-underscore" : "" );
+
+               GenerateImportLibraryTarget(defFilename, library_target, false);
+               GenerateImportLibraryTarget(defFilename, delayimp_target, true);
 
                if ( defFilename )
                        delete defFilename;
                delete library_target;
+               delete delayimp_target;
+
        }
 }
 

Modified: trunk/reactos/tools/rbuild/backend/mingw/modulehandler.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/backend/mingw/modulehandler.h?rev=42242&r1=42241&r2=42242&view=diff
==============================================================================
--- trunk/reactos/tools/rbuild/backend/mingw/modulehandler.h [iso-8859-1] 
(original)
+++ trunk/reactos/tools/rbuild/backend/mingw/modulehandler.h [iso-8859-1] Mon 
Jul 27 00:36:55 2009
@@ -57,7 +57,8 @@
 
        static const FileLocation* GetImportLibraryFilename (
                const Module& module,
-               string_list* pclean_files );
+               string_list* pclean_files,
+               bool delayimp );
 
        static std::string GenerateGccDefineParametersFromVector ( const 
std::vector<Define*>& defines, std::set<std::string> &used_defs );
        static std::string GenerateDefineParametersFromVector ( const 
std::vector<Define*>& defines, CompilerType compiler );
@@ -95,7 +96,7 @@
        std::string GetBasename ( const std::string& filename ) const;
        std::string GetCompilationUnitDependencies ( const CompilationUnit& 
compilationUnit ) const;
        const FileLocation* GetModuleArchiveFilename () const;
-       std::string GetImportLibraryDependency ( const Module& importedModule );
+       std::string GetImportLibraryDependency ( const Module& importedModule, 
bool delayimp );
        void GetTargets ( const Module& dependencyModule,
                          string_list& targets );
        void GetModuleDependencies ( string_list& dependencies );
@@ -118,6 +119,7 @@
        void GeneratePhonyTarget() const;
        void GenerateBuildMapCode ( const FileLocation *mapTarget = NULL );
        void GenerateRules ();
+       void GenerateImportLibraryTarget (const FileLocation *defFilename, 
const FileLocation *library_target, bool delayimp);
        void GenerateImportLibraryTargetIfNeeded ();
        void GetDefinitionDependencies ( std::vector<FileLocation>& 
dependencies ) const;
        std::string GetLinkingDependencies () const;

Modified: trunk/reactos/tools/rbuild/module.cpp
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/module.cpp?rev=42242&r1=42241&r2=42242&view=diff
==============================================================================
--- trunk/reactos/tools/rbuild/module.cpp [iso-8859-1] (original)
+++ trunk/reactos/tools/rbuild/module.cpp [iso-8859-1] Mon Jul 27 00:36:55 2009
@@ -260,6 +260,7 @@
        : project (project),
          node (moduleNode),
          importLibrary (NULL),
+         delayImportLibrary (NULL),
          metadata (NULL),
          bootSector (NULL),
          bootstrap (NULL),
@@ -715,7 +716,10 @@
        }
        else if ( e.name == "library" && e.value.size () )
        {
+               const XMLAttribute* att = e.GetAttribute ( "delayimport", false 
);
                Library* pLibrary = new Library ( e, *this, e.value );
+               if ( att && !stricmp ( att->value.c_str(), "true" ) )
+                       pLibrary->delayimp = true;
                non_if_data.libraries.push_back ( pLibrary );
                subs_invalid = true;
        }
@@ -780,7 +784,8 @@
                                e.location,
                                "Only one <importlibrary> is valid per module" 
);
                }
-               SetImportLibrary ( new ImportLibrary ( project, e, this ) );
+               SetImportLibrary ( new ImportLibrary ( project, e, this, false 
) );
+               SetDelayImportLibrary ( new ImportLibrary ( project, e, this, 
true ) );
                subs_invalid = true;
        }
        else if ( e.name == "if" || e.name == "ifnot" )
@@ -1420,6 +1425,12 @@
                                        HasImportLibrary () ? "lib" + name + 
".a" : output->name );
 }
 
+void
+Module::SetDelayImportLibrary ( ImportLibrary* importLibrary )
+{
+       this->delayImportLibrary = importLibrary;
+}
+
 std::string
 Module::GetDllName () const
 {
@@ -1482,7 +1493,8 @@
        : node(&_node),
          module(_module),
          name(_name),
-         importedModule(_module.project.LocateModule(_name))
+         importedModule(_module.project.LocateModule(_name)),
+         delayimp(false)
 {
        if ( module.name == name )
        {
@@ -1506,7 +1518,8 @@
        : node(NULL),
          module(_module),
          name(_name),
-         importedModule(_module.project.LocateModule(_name))
+         importedModule(_module.project.LocateModule(_name)),
+         delayimp(false)
 {
        if ( !importedModule )
        {
@@ -1817,12 +1830,14 @@
 ImportLibrary::~ImportLibrary ()
 {
        delete source;
+       delete target;
 }
 
 
 ImportLibrary::ImportLibrary ( const Project& project,
                                const XMLElement& node,
-                               const Module* module )
+                               const Module* module,
+                               bool delayimp )
        : XmlNode ( project, node ),
          module (module)
 {
@@ -1889,6 +1904,11 @@
                                            name,
                                            &node );
        }
+
+       target = new FileLocation ( IntermediateDirectory,
+                                   base->output->relative_path,
+                                   "lib" + module->name + (delayimp ? 
".delayimp.a" :  ".a" ));
+
 }
 
 

Modified: trunk/reactos/tools/rbuild/rbuild.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/rbuild/rbuild.h?rev=42242&r1=42241&r2=42242&view=diff
==============================================================================
--- trunk/reactos/tools/rbuild/rbuild.h [iso-8859-1] (original)
+++ trunk/reactos/tools/rbuild/rbuild.h [iso-8859-1] Mon Jul 27 00:36:55 2009
@@ -377,6 +377,7 @@
        std::string buildtype;
        ModuleType type;
        ImportLibrary* importLibrary;
+       ImportLibrary* delayImportLibrary;
        Metadata* metadata;
        Bootsector* bootSector;
        bool mangledSymbols;
@@ -429,6 +430,7 @@
        std::string GetDllName() const;
 private:
        void SetImportLibrary ( ImportLibrary* importLibrary );
+       void SetDelayImportLibrary ( ImportLibrary* importLibrary );
        DirectoryLocation GetTargetDirectoryTree () const;
        std::string GetDefaultModuleExtension () const;
        std::string GetDefaultModuleEntrypoint () const;
@@ -555,6 +557,7 @@
        const Module& module;
        std::string name;
        const Module* importedModule;
+       bool delayimp;
 
        Library ( const XMLElement& _node,
                  const Module& _module,
@@ -655,10 +658,12 @@
        const Module* module;
        std::string dllname;
        FileLocation *source;
+       FileLocation *target;
 
        ImportLibrary ( const Project& project,
                        const XMLElement& node,
-                       const Module* module );
+                       const Module* module,
+                       bool delayimp );
        ~ImportLibrary ();
 };
 


Reply via email to