]> git.tdb.fi Git - builder.git/blobdiff - source/sharedlibrary.cpp
Don't rely on component type in determining whether to use -fPIC
[builder.git] / source / sharedlibrary.cpp
index b1ad358fdbc675a3113333a6eaae5bcbcfd8f921..305061a02c5bd7c617ad8c4b8febb57d4ddd8197 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/strings/format.h>
 #include "builder.h"
 #include "component.h"
+#include "objectfile.h"
 #include "sharedlibrary.h"
 #include "sourcepackage.h"
 
@@ -9,7 +10,8 @@ using namespace std;
 using namespace Msp;
 
 SharedLibrary::SharedLibrary(Builder &b, const Msp::FS::Path &p):
-       Binary(b, p)
+       Binary(b, p),
+       import_lib(0)
 {
        libname = FS::basepart(FS::basename(path));
        if(!libname.compare(0, 3, "lib"))
@@ -18,29 +20,38 @@ SharedLibrary::SharedLibrary(Builder &b, const Msp::FS::Path &p):
 
 SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
        Binary(b, c, generate_filename(c), objs),
-       libname(c.get_name())
+       libname(c.get_name()),
+       import_lib(0)
 {
-       install_location = "lib";
+       if(builder.get_current_arch().get_system()=="windows")
+               install_location = "bin";
+       else
+               install_location = "lib";
        if(component->get_type()==Component::MODULE)
                install_location /= package->get_name();
 
-       const string &version = component->get_package().get_version();
+       const string &version = component->get_package().get_interface_version();
        if(!version.empty())
        {
-               string::size_type i = 0;
-               for(unsigned dots=0; i<version.size(); ++i)
-                       if(version[i]=='.' && ++dots>=2)
-                               break;
-
                const Architecture &arch = builder.get_current_arch();
                const Pattern &pattern = arch.get_shared_library_patterns().front();
                if(arch.get_system()=="windows")
-                       soname = pattern.apply(format("%s-%s", component->get_name(), version.substr(0, i)));
+                       soname = pattern.apply(format("%s-%s", component->get_name(), version));
+               else if(arch.get_system()=="darwin")
+               {
+                       string filename = pattern.apply(component->get_name());
+                       string base = FS::basepart(filename);
+                       string ext = FS::extpart(filename);
+                       soname = format("%s.%s%s", base, version, ext);
+               }
                else
-                       soname = format("%s.%s", pattern.apply(component->get_name()), version.substr(0, i));
+                       soname = format("%s.%s", pattern.apply(component->get_name()), version);
 
                install_filename = soname;
        }
+
+       for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+               (*i)->set_used_in_shared_library(true);
 }
 
 string SharedLibrary::generate_filename(const Component &comp)
@@ -53,3 +64,8 @@ string SharedLibrary::generate_filename(const Component &comp)
                return arch.get_shared_library_patterns().front().apply(comp.get_name());
        }
 }
+
+void SharedLibrary::set_import_library(ImportLibrary *imp)
+{
+       import_lib = imp;
+}