]> git.tdb.fi Git - builder.git/blobdiff - source/sharedlibrary.cpp
More flexible way to manage filename patterns
[builder.git] / source / sharedlibrary.cpp
index 24e0e205682acec12951035b32d84bc26a9a0ece..5e479f3c9f652f64c03a9ab3eb472ae645c807ed 100644 (file)
@@ -1,7 +1,8 @@
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
+#include "binarycomponent.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,34 +20,51 @@ 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(component->get_type()==Component::MODULE)
-       {
-               install_location += '/';
-               install_location += package->get_name();
-       }
+       if(builder.get_current_arch().get_system()=="windows")
+               install_location = "bin";
+       else
+               install_location = "lib";
 
-       const string &version = component->get_package().get_version();
-       if(!version.empty())
+       const BinaryComponent &bcomp = dynamic_cast<const BinaryComponent &>(*component);
+       if(bcomp.get_type()==BinaryComponent::MODULE)
+               install_location /= package->get_name();
+       else
        {
-               string::size_type i = 0;
-               for(unsigned dots=0; i<version.size(); ++i)
-                       if(version[i]=='.' && ++dots>=2)
-                               break;
+               const string &version = component->get_package().get_interface_version();
+               if(!version.empty())
+               {
+                       const Architecture &arch = builder.get_current_arch();
+                       if(arch.get_system()=="windows")
+                               soname = arch.create_filename<SharedLibrary>(format("%s-%s", libname, version));
+                       else if(arch.get_system()=="darwin")
+                               soname = arch.create_filename<SharedLibrary>(format("%s.%s", libname, version));
+                       else
+                               soname = format("%s.%s", arch.create_filename<SharedLibrary>(libname), version);
 
-               soname = format("%s.%s", FS::basename(path), version.substr(0, i));
+                       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)
 {
-       if(comp.get_type()==Component::MODULE)
-               return comp.get_name()+".m";
+       const BinaryComponent &bcomp = dynamic_cast<const BinaryComponent &>(comp);
+       if(bcomp.get_type()==BinaryComponent::MODULE)
+               return comp.get_name()+".dlm";
        else
        {
                const Architecture &arch = comp.get_package().get_builder().get_current_arch();
-               return arch.get_shared_library_patterns().front().apply(comp.get_name());
+               return arch.create_filename<SharedLibrary>(comp.get_name());
        }
 }
+
+void SharedLibrary::set_import_library(ImportLibrary *imp)
+{
+       import_lib = imp;
+}