]> git.tdb.fi Git - builder.git/blob - source/sharedlibrary.cpp
Get rid of the Library and SystemLibrary classes as unnecessary abstractions
[builder.git] / source / sharedlibrary.cpp
1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
3 #include "component.h"
4 #include "sharedlibrary.h"
5 #include "sourcepackage.h"
6
7 using namespace std;
8 using namespace Msp;
9
10 SharedLibrary::SharedLibrary(Builder &b, const Msp::FS::Path &p):
11         Binary(b, p)
12 {
13         libname = FS::basepart(FS::basename(path));
14         if(!libname.compare(0, 3, "lib"))
15                 libname = libname.substr(3);
16 }
17
18 SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
19         Binary(b, c, objs),
20         libname(c.get_name()),
21         soname(create_soname(c))
22 {
23         install_location = "lib";
24         if(component->get_type()==Component::MODULE)
25         {
26                 install_location += '/';
27                 install_location += package->get_name();
28         }
29 }
30
31 string SharedLibrary::create_soname(const Component &c)
32 {
33         const string &ver = c.get_package().get_version();
34         if(ver.empty())
35                 return string();
36
37         unsigned dots = 0;
38         unsigned i = 0;
39         for(; i<ver.size(); ++i)
40                 if(ver[i]=='.')
41                 {
42                         ++dots;
43                         if(dots>=2)
44                                 break;
45                 }
46
47         return format("%s.%s", FS::basename(path), ver.substr(0, i));
48 }