]> git.tdb.fi Git - builder.git/blob - source/sharedlibrary.cpp
ae44f2cd5751701dff67a5e18dc29183960adb6b
[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         import_lib(0)
14 {
15         libname = FS::basepart(FS::basename(path));
16         if(!libname.compare(0, 3, "lib"))
17                 libname = libname.substr(3);
18 }
19
20 SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFile *> &objs):
21         Binary(b, c, generate_filename(c), objs),
22         libname(c.get_name()),
23         import_lib(0)
24 {
25         if(builder.get_current_arch().get_system()=="windows")
26                 install_location = "bin";
27         else
28                 install_location = "lib";
29         if(component->get_type()==Component::MODULE)
30                 install_location /= package->get_name();
31
32         const string &version = component->get_package().get_interface_version();
33         if(!version.empty())
34         {
35                 const Architecture &arch = builder.get_current_arch();
36                 const Pattern &pattern = arch.get_shared_library_patterns().front();
37                 if(arch.get_system()=="windows")
38                         soname = pattern.apply(format("%s-%s", component->get_name(), version));
39                 else if(arch.get_system()=="darwin")
40                 {
41                         string filename = pattern.apply(component->get_name());
42                         string base = FS::basepart(filename);
43                         string ext = FS::extpart(filename);
44                         soname = format("%s.%s%s", base, version, ext);
45                 }
46                 else
47                         soname = format("%s.%s", pattern.apply(component->get_name()), version);
48
49                 install_filename = soname;
50         }
51 }
52
53 string SharedLibrary::generate_filename(const Component &comp)
54 {
55         if(comp.get_type()==Component::MODULE)
56                 return comp.get_name()+".m";
57         else
58         {
59                 const Architecture &arch = comp.get_package().get_builder().get_current_arch();
60                 return arch.get_shared_library_patterns().front().apply(comp.get_name());
61         }
62 }
63
64 void SharedLibrary::set_import_library(ImportLibrary *imp)
65 {
66         import_lib = imp;
67 }