]> git.tdb.fi Git - builder.git/commitdiff
Generate export definitions with dlltool
authorMikko Rasa <tdb@tdb.fi>
Fri, 28 Sep 2012 12:36:43 +0000 (15:36 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 28 Sep 2012 12:36:43 +0000 (15:36 +0300)
Having it as a side effect was causing trouble with rebuild check, and
it's cleaner to build each file separately anyway.

source/exportdefinitions.cpp
source/exportdefinitions.h
source/gnulinker.cpp
source/importlibrary.cpp
source/importlibrary.h
source/mingwdlltool.cpp

index cc50e16cd8217af58ff0a34db05ca7a5ec5cc60d..8fbf76e9f037c21ffaf3b2b541ac2a6e780039da 100644 (file)
@@ -1,14 +1,17 @@
 #include "component.h"
 #include "exportdefinitions.h"
+#include "objectfile.h"
 #include "sourcepackage.h"
 
+using namespace std;
 using namespace Msp;
 
-ExportDefinitions::ExportDefinitions(Builder &b, const Component &c, SharedLibrary &l):
-       FileTarget(b, c.get_package(), generate_target_path(c)),
-       lib(l)
+ExportDefinitions::ExportDefinitions(Builder &b, const Component &c, const list<ObjectFile *> &objs):
+       FileTarget(b, c.get_package(), generate_target_path(c))
 {
        component = &c;
+       for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
+               add_dependency(**i);
 }
 
 FS::Path ExportDefinitions::generate_target_path(const Component &comp)
index 73d6f0fb46a8ab73200abc0a74812b6f88ae4e72..22ba94bfbcc7fba2685b8759a9bb3978a51c7007 100644 (file)
@@ -3,25 +3,20 @@
 
 #include "filetarget.h"
 
-class SharedLibrary;
+class ObjectFile;
 
 /**
 An export definition file for a shared library.  Only used on Windows.
 */
 class ExportDefinitions: public FileTarget
 {
-private:
-       SharedLibrary &lib;
-
 public:
-       ExportDefinitions(Builder &, const Component &, SharedLibrary &);
+       ExportDefinitions(Builder &, const Component &, const std::list<ObjectFile *> &);
 private:
        static Msp::FS::Path generate_target_path(const Component &);
 
 public:
        virtual const char *get_type() const { return "ExportDefinitions"; }
-
-       SharedLibrary &get_library() const { return lib; }
 };
 
 #endif
index cd40a853cac56ffe8d06295c4bb9c96650e9c7cf..ede0119aeb44dec627cd37d39e14e15ad108420f 100644 (file)
@@ -74,11 +74,8 @@ Target *GnuLinker::create_target(const list<Target *> &sources, const string &ar
                SharedLibrary *shlib = new SharedLibrary(builder, comp, objs);
                if(architecture->get_system()=="windows")
                {
-                       ExportDefinitions *exp = new ExportDefinitions(builder, comp, *shlib);
-                       shlib->add_side_effect(*exp);
                        const Tool &dlltool = builder.get_toolchain().get_tool("DLL");
-                       ImportLibrary *imp = dynamic_cast<ImportLibrary *>(dlltool.create_target(*exp));
-                       shlib->set_import_library(imp);
+                       dlltool.create_target(*shlib);
                }
                bin = shlib;
        }
@@ -176,12 +173,6 @@ Task *GnuLinker::Linker::run(const Target &target) const
        {
                argv.push_back("-shared");
                argv.push_back("-fPIC");
-               const Target::Dependencies &side_eff = target.get_side_effects();
-               for(Target::Dependencies::const_iterator i=side_eff.begin(); i!=side_eff.end(); ++i)
-               {
-                       if(ExportDefinitions *exp = dynamic_cast<ExportDefinitions *>(*i))
-                               argv.push_back("-Wl,--output-def,"+relative(exp->get_path(), work_dir).str());
-               }
                if(architecture->get_system()!="windows" && !shlib->get_soname().empty())
                        argv.push_back("-Wl,-soname,"+shlib->get_soname());
        }
index 9ac441f419ea6d683eb86c07890f622232711084..0fb5f72ff88d3628f46723fa5cb09dd3f4dc49a0 100644 (file)
@@ -2,6 +2,7 @@
 #include "component.h"
 #include "exportdefinitions.h"
 #include "importlibrary.h"
+#include "sharedlibrary.h"
 #include "sourcepackage.h"
 
 using namespace std;
@@ -12,16 +13,17 @@ ImportLibrary::ImportLibrary(Builder &b, const FS::Path &p):
        shared_lib(0)
 { }
 
-ImportLibrary::ImportLibrary(Builder &b, const Component &c, ExportDefinitions &exp):
-       FileTarget(b, c.get_package(), c.get_package().get_out_dir()/format("lib%s.dll.a", c.get_name())),
-       shared_lib(&exp.get_library())
+ImportLibrary::ImportLibrary(Builder &b, const Component &c, SharedLibrary &sl, ExportDefinitions &exp):
+       FileTarget(b, c.get_package(), c.get_package().get_out_dir()/format("lib%s.dll.a", sl.get_libname())),
+       shared_lib(&sl)
 {
        component = &c;
        add_dependency(exp);
+       shared_lib->set_import_library(this);
 
        install_location = "lib";
 
        const string &version = component->get_package().get_interface_version();
        if(!version.empty())
-               install_filename = format("lib%s-%s.dll.a", c.get_name(), version);
+               install_filename = format("lib%s-%s.dll.a", sl.get_libname(), version);
 }
index 99db24d26fac2a0a1134f94d6cc37f0a598fed95..aac11f94f18ae04c78f907a33f2918f59c9a72b6 100644 (file)
@@ -17,7 +17,7 @@ private:
 
 public:
        ImportLibrary(Builder &, const Msp::FS::Path &);
-       ImportLibrary(Builder &, const Component &, ExportDefinitions &);
+       ImportLibrary(Builder &, const Component &, SharedLibrary &, ExportDefinitions &);
 
        virtual const char *get_type() const { return "ImportLibrary"; }
 
index f76fb1cc883d2a3c2b44b910623f5d7b10bcd155..5f62a02c954dadbcbc808b15b37d55938d90d812 100644 (file)
@@ -9,6 +9,7 @@
 #include "importlibrary.h"
 #include "installedfile.h"
 #include "mingwdlltool.h"
+#include "objectfile.h"
 #include "sharedlibrary.h"
 #include "sourcepackage.h"
 
@@ -28,9 +29,20 @@ Target *MingwDllTool::create_target(const list<Target *> &sources, const string
 {
        if(sources.size()!=1)
                throw invalid_argument("MingwDllTool::create_target");
-       ExportDefinitions &def = dynamic_cast<ExportDefinitions &>(*sources.front());
-       ImportLibrary *imp = new ImportLibrary(builder, *def.get_component(), def);
+       SharedLibrary &shlib = dynamic_cast<SharedLibrary &>(*sources.front());
+
+       list<ObjectFile *> objs;
+       const Target::Dependencies &depends = shlib.get_dependencies();
+       for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+                       objs.push_back(obj);
+
+       ExportDefinitions *exp = new ExportDefinitions(builder, *shlib.get_component(), objs);
+       exp->set_tool(*this);
+
+       ImportLibrary *imp = new ImportLibrary(builder, *shlib.get_component(), shlib, *exp);
        imp->set_tool(*this);
+
        return imp;
 }
 
@@ -51,9 +63,14 @@ Target *MingwDllTool::create_install(Target &target) const
 
 Task *MingwDllTool::run(const Target &target) const
 {
-       const ImportLibrary &imp = dynamic_cast<const ImportLibrary &>(target);
-       const ExportDefinitions &exp = dynamic_cast<const ExportDefinitions &>(*imp.get_dependencies().front());
-       const SharedLibrary &shlib = exp.get_library();
+       const ImportLibrary *imp = dynamic_cast<const ImportLibrary *>(&target);
+       const ExportDefinitions *exp = 0;
+       if(imp)
+               exp = &dynamic_cast<const ExportDefinitions &>(*imp->get_dependencies().front());
+       else
+               exp = dynamic_cast<const ExportDefinitions *>(&target);
+       if(!imp && !exp)
+               throw invalid_argument("MingwDllTool::run");
 
        vector<string> argv;
        argv.push_back(executable->get_path().str());
@@ -66,20 +83,40 @@ Task *MingwDllTool::run(const Target &target) const
                random[i] = 'a'+(rand()%26);
        argv.push_back(string("/tmp/")+string(random, 8));
 
-       const Component &comp = *imp.get_component();
+       const Component &comp = *target.get_component();
        FS::Path work_dir = comp.get_package().get_source_directory();
 
-       argv.push_back("-d");
-       argv.push_back(relative(exp.get_path(), work_dir).str());
+       if(imp)
+       {
+               const SharedLibrary &shlib = *imp->get_shared_library();
+
+               argv.push_back("-d");
+               argv.push_back(relative(exp->get_path(), work_dir).str());
+
+               argv.push_back("-D");
+               if(shlib.get_install_filename().empty())
+                       argv.push_back(FS::basename(shlib.get_path()));
+               else
+                       argv.push_back(shlib.get_install_filename());
 
-       argv.push_back("-D");
-       if(shlib.get_install_filename().empty())
-               argv.push_back(FS::basename(shlib.get_path()));
+               argv.push_back("-l");
+               argv.push_back(relative(imp->get_path(), work_dir).str());
+       }
        else
-               argv.push_back(shlib.get_install_filename());
+       {
+               const Target::Dependencies &depends = exp->get_dependencies();
+               for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+               {
+                       if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+                               argv.push_back(relative(obj->get_path(), work_dir).str());
+               }
+
+               // XXX Should use dllexport, but that has some other problems to solve
+               argv.push_back("--export-all-symbols");
 
-       argv.push_back("-l");
-       argv.push_back(relative(imp.get_path(), work_dir).str());
+               argv.push_back("-z");
+               argv.push_back(relative(exp->get_path(), work_dir).str());
+       }
 
        return new ExternalTask(argv, work_dir);
 }