]> git.tdb.fi Git - builder.git/blob - source/binarypackage.cpp
Pass the full path to the Build file to SourcePackage and create a target for it
[builder.git] / source / binarypackage.cpp
1 #include <msp/io/print.h>
2 #include <msp/strings/utils.h>
3 #include "binarypackage.h"
4 #include "builder.h"
5
6 using namespace std;
7 using namespace Msp;
8
9 BinaryPackage::BinaryPackage(Builder &b, const string &n):
10         Package(b, n)
11 {
12         use_pkgconfig = false;
13 }
14
15 void BinaryPackage::create_build_info()
16 {
17         for(BuildInfo::PathList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
18                 if((*i)[0]=="@")
19                         *i = builder.get_prefix()/i->subpath(1);
20
21         for(BuildInfo::PathList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
22                 if((*i)[0]=="@")
23                         *i = builder.get_prefix()/i->subpath(1);
24 }
25
26 BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, const vector<string> &flags)
27 {
28         BinaryPackage *pkg = new BinaryPackage(builder, name);
29         pkg->use_pkgconfig = true;
30         BuildInfo &binfo = pkg->export_binfo;
31
32         for(vector<string>::const_iterator i=flags.begin(); i!=flags.end(); ++i)
33         {
34                 if(!i->compare(0, 2, "-I"))
35                         binfo.incpath.push_back(i->substr(2));
36                 else if(!i->compare(0, 2, "-D"))
37                 {
38                         string::size_type equals = i->find('=');
39                         if(equals!=string::npos)
40                                 binfo.defines[i->substr(2, equals-2)] = i->substr(equals+1);
41                         else
42                                 binfo.defines[i->substr(2)] = string();
43                 }
44                 else if(!i->compare(0, 2, "-L"))
45                         binfo.libpath.push_back(i->substr(2));
46                 else if(!i->compare(0, 2, "-l"))
47                         binfo.libs.push_back(i->substr(2));
48                 else if(*i=="-pthread")
49                         binfo.threads = true;
50         }
51
52         return pkg;
53 }
54
55
56 BinaryPackage::Loader::Loader(BinaryPackage &p):
57         DataFile::DerivedObjectLoader<BinaryPackage, Package>(p)
58 {
59         add("build_info", &Loader::build_info);
60 }
61
62 void BinaryPackage::Loader::build_info()
63 {
64         load_sub(obj.export_binfo);
65 }