]> git.tdb.fi Git - builder.git/blob - source/binarypackage.cpp
Reorder class members
[builder.git] / source / binarypackage.cpp
1 /* $Id$
2
3 This file is part of builder
4 Copyright © 2007-2009  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <iostream>
9 #include <msp/strings/utils.h>
10 #include "binarypackage.h"
11 #include "builder.h"
12
13 using namespace std;
14 using namespace Msp;
15
16 BinaryPackage::BinaryPackage(Builder &b, const string &n):
17         Package(b, n),
18         need_path(false)
19 {
20         use_pkgconfig=false;
21 }
22
23 void BinaryPackage::set_path(const Msp::FS::Path &p)
24 {
25         path=builder.get_cwd()/p;
26 }
27
28 void BinaryPackage::create_build_info()
29 {
30         for(StringList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
31                 if((*i)[0]=='@')
32                         *i=(path/i->substr(1)).str();
33
34         for(StringList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
35                 if((*i)[0]=='@')
36                         *i=(path/i->substr(1)).str();
37 }
38
39 BinaryPackage *BinaryPackage::from_pkgconfig(Builder &builder, const string &name)
40 {
41         list<string> argv;
42         argv.push_back("pkg-config");
43         argv.push_back("--silence-errors");
44         argv.push_back("--cflags");
45         argv.push_back("--libs");
46         argv.push_back(name);
47         if(builder.get_verbose()>=4)
48                 cout<<"Running "<<join(argv.begin(), argv.end())<<'\n';
49         string info=run_command(argv);
50
51         if(info.empty())
52                 return 0;
53
54
55         BinaryPackage *pkg=new BinaryPackage(builder, name);
56         pkg->use_pkgconfig=true;
57         BuildInfo &binfo=pkg->export_binfo;
58
59         vector<string> flags=split(info);
60         for(vector<string>::const_iterator i=flags.begin(); i!=flags.end(); ++i)
61         {
62                 if(!i->compare(0, 2, "-I"))
63                         binfo.incpath.push_back(i->substr(2));
64                 else if(!i->compare(0, 2, "-D"))
65                         binfo.defines.push_back(i->substr(2));
66                 else if(!i->compare(0, 2, "-L"))
67                         binfo.libpath.push_back(i->substr(2));
68                 else if(!i->compare(0, 2, "-l"))
69                         binfo.libs.push_back(i->substr(2));
70         }
71
72         return pkg;
73 }
74
75
76 BinaryPackage::Loader::Loader(BinaryPackage &p):
77         Package::Loader(p)
78 {
79         add("need_path", &BinaryPackage::need_path);
80         add("build_info", &Loader::build_info);
81 }
82
83 void BinaryPackage::Loader::build_info()
84 {
85         load_sub(static_cast<BinaryPackage &>(pkg).export_binfo);
86 }