]> git.tdb.fi Git - builder.git/blob - source/sharedlibrary.cpp
Split Binary filename generation to Executable and SharedLibrary
[builder.git] / source / sharedlibrary.cpp
1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
3 #include "builder.h"
4 #include "component.h"
5 #include "sharedlibrary.h"
6 #include "sourcepackage.h"
7
8 using namespace std;
9 using namespace Msp;
10
11 SharedLibrary::SharedLibrary(Builder &b, const Msp::FS::Path &p):
12         Binary(b, p)
13 {
14         libname = FS::basepart(FS::basename(path));
15         if(!libname.compare(0, 3, "lib"))
16                 libname = libname.substr(3);
17 }
18
19 SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
20         Binary(b, c, generate_filename(c), objs),
21         libname(c.get_name()),
22         soname(create_soname(c))
23 {
24         install_location = "lib";
25         if(component->get_type()==Component::MODULE)
26         {
27                 install_location += '/';
28                 install_location += package->get_name();
29         }
30 }
31
32 string SharedLibrary::generate_filename(const Component &comp)
33 {
34         if(comp.get_type()==Component::MODULE)
35                 return comp.get_name()+".m";
36         else
37         {
38                 const Architecture &arch = comp.get_package().get_builder().get_current_arch();
39                 return arch.get_shared_library_patterns().front().apply(comp.get_name());
40         }
41 }
42
43 string SharedLibrary::create_soname(const Component &c)
44 {
45         const string &ver = c.get_package().get_version();
46         if(ver.empty())
47                 return string();
48
49         unsigned dots = 0;
50         unsigned i = 0;
51         for(; i<ver.size(); ++i)
52                 if(ver[i]=='.')
53                 {
54                         ++dots;
55                         if(dots>=2)
56                                 break;
57                 }
58
59         return format("%s.%s", FS::basename(path), ver.substr(0, i));
60 }