]> git.tdb.fi Git - builder.git/blob - source/sharedlibrary.cpp
Fix an incorrect assumption of target name being the basename of its path
[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 Component &c, const list<ObjectFile *> &objs):
11         FileTarget(b, &c.get_package(), generate_target_path(c)),
12         Binary(b, c, objs),
13         Library(b, &c.get_package(), path, c.get_name()),
14         soname(create_soname(c))
15 { }
16
17 string SharedLibrary::create_soname(const Component &c)
18 {
19         const string &ver = c.get_package().get_version();
20         if(ver.empty())
21                 return string();
22
23         unsigned dots = 0;
24         unsigned i = 0;
25         for(; i<ver.size(); ++i)
26                 if(ver[i]=='.')
27                 {
28                         ++dots;
29                         if(dots>=2)
30                                 break;
31                 }
32
33         return format("%s.%s", FS::basename(path), ver.substr(0, i));
34 }