]> git.tdb.fi Git - builder.git/blob - source/lib/sharedlibrary.cpp
Remove a lib prefix from the libname of built SharedLibraries
[builder.git] / source / lib / sharedlibrary.cpp
1 #include <msp/fs/utils.h>
2 #include <msp/strings/format.h>
3 #include "binarycomponent.h"
4 #include "builder.h"
5 #include "objectfile.h"
6 #include "sharedlibrary.h"
7 #include "sourcepackage.h"
8
9 using namespace std;
10 using namespace Msp;
11
12 SharedLibrary::SharedLibrary(Builder &b, const Msp::FS::Path &p):
13         Binary(b, p)
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 vector<ObjectFile *> &objs):
21         Binary(b, c, generate_filename(c), objs),
22         libname(c.get_name()),
23         import_lib(0)
24 {
25         if(!libname.compare(0, 3, "lib"))
26                 libname = libname.substr(3);
27
28         if(builder.get_current_arch().get_system()=="windows")
29                 install_location = "bin";
30         else
31                 install_location = "lib";
32
33         const BinaryComponent &bcomp = dynamic_cast<const BinaryComponent &>(*component);
34         if(bcomp.get_type()==BinaryComponent::MODULE)
35                 install_location /= package->get_name();
36         else
37         {
38                 const string &version = component->get_package().get_interface_version();
39                 if(!version.empty())
40                 {
41                         const Architecture &arch = builder.get_current_arch();
42                         if(arch.get_system()=="windows")
43                                 soname = arch.create_filename<SharedLibrary>(format("%s-%s", libname, version));
44                         else if(arch.get_system()=="darwin")
45                                 soname = arch.create_filename<SharedLibrary>(format("%s.%s", libname, version));
46                         else
47                                 soname = format("%s.%s", arch.create_filename<SharedLibrary>(libname), version);
48
49                         install_filename = soname;
50                 }
51         }
52
53         for(ObjectFile *o: objects)
54                 o->set_used_in_shared_library(true);
55 }
56
57 string SharedLibrary::generate_filename(const Component &comp)
58 {
59         const BinaryComponent &bcomp = dynamic_cast<const BinaryComponent &>(comp);
60         if(bcomp.get_type()==BinaryComponent::MODULE)
61                 return comp.get_name()+".dlm";
62         else
63         {
64                 const Architecture &arch = comp.get_package().get_builder().get_current_arch();
65                 return arch.create_filename<SharedLibrary>(comp.get_name());
66         }
67 }
68
69 void SharedLibrary::set_import_library(ImportLibrary *imp)
70 {
71         import_lib = imp;
72 }