]> git.tdb.fi Git - builder.git/blobdiff - source/sharedlibrary.cpp
It's okay to throw exceptions from Loader functions
[builder.git] / source / sharedlibrary.cpp
index 868e822159847deebf24a76ff23867442485c142..9b2fdbb1bd99b02bc3a99f877ec67779b4790c31 100644 (file)
@@ -1,11 +1,6 @@
-/* $Id$
-
-This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
+#include <msp/fs/utils.h>
 #include <msp/strings/format.h>
+#include "builder.h"
 #include "component.h"
 #include "sharedlibrary.h"
 #include "sourcepackage.h"
@@ -13,28 +8,41 @@ Distributed under the LGPL
 using namespace std;
 using namespace Msp;
 
-SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
-       FileTarget(b, &c.get_package(), generate_target_path(c)),
-       Binary(b, c, objs),
-       Library(b, &c.get_package(), path, c.get_name()),
-       soname(create_soname(c))
-{ }
+SharedLibrary::SharedLibrary(Builder &b, const Msp::FS::Path &p):
+       Binary(b, p)
+{
+       libname = FS::basepart(FS::basename(path));
+       if(!libname.compare(0, 3, "lib"))
+               libname = libname.substr(3);
+}
 
-string SharedLibrary::create_soname(const Component &c)
+SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
+       Binary(b, c, generate_filename(c), objs),
+       libname(c.get_name())
 {
-       const string &ver = c.get_package().get_version();
-       if(ver.empty())
-               return string();
+       install_location = "lib";
+       if(component->get_type()==Component::MODULE)
+               install_location /= package->get_name();
 
-       unsigned dots = 0;
-       unsigned i = 0;
-       for(; i<ver.size(); ++i)
-               if(ver[i]=='.')
-               {
-                       ++dots;
-                       if(dots>=2)
+       const string &version = component->get_package().get_version();
+       if(!version.empty())
+       {
+               string::size_type i = 0;
+               for(unsigned dots=0; i<version.size(); ++i)
+                       if(version[i]=='.' && ++dots>=2)
                                break;
-               }
 
-       return format("%s.%s", name, ver.substr(0, i));
+               soname = format("%s.%s", FS::basename(path), version.substr(0, i));
+       }
+}
+
+string SharedLibrary::generate_filename(const Component &comp)
+{
+       if(comp.get_type()==Component::MODULE)
+               return comp.get_name()+".m";
+       else
+       {
+               const Architecture &arch = comp.get_package().get_builder().get_current_arch();
+               return arch.get_shared_library_patterns().front().apply(comp.get_name());
+       }
 }