]> git.tdb.fi Git - builder.git/blob - source/sharedlibrary.cpp
Further changes for library compatibility
[builder.git] / source / sharedlibrary.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <msp/strings/format.h>
9 #include "component.h"
10 #include "sharedlibrary.h"
11 #include "sourcepackage.h"
12
13 using namespace std;
14 using namespace Msp;
15
16 SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
17         FileTarget(b, &c.get_package(), generate_target_path(c)),
18         Binary(b, c, objs),
19         Library(b, &c.get_package(), path, c.get_name()),
20         soname(create_soname(c))
21 { }
22
23 string SharedLibrary::create_soname(const Component &c)
24 {
25         const string &ver = c.get_package().get_version();
26         if(ver.empty())
27                 return string();
28
29         unsigned dots = 0;
30         unsigned i = 0;
31         for(; i<ver.size(); ++i)
32                 if(ver[i]=='.')
33                 {
34                         ++dots;
35                         if(dots>=2)
36                                 break;
37                 }
38
39         return format("%s.%s", name, ver.substr(0, i));
40 }