]> git.tdb.fi Git - builder.git/blob - source/binarypackage.cpp
Miscellaneous minor code cleanups
[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 <msp/io/print.h>
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 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         string info=builder.run_pkgconfig(name, "flags");
42
43         BinaryPackage *pkg=new BinaryPackage(builder, name);
44         pkg->use_pkgconfig=true;
45         BuildInfo &binfo=pkg->export_binfo;
46
47         vector<string> flags=split(info);
48         for(vector<string>::const_iterator i=flags.begin(); i!=flags.end(); ++i)
49         {
50                 if(!i->compare(0, 2, "-I"))
51                         binfo.incpath.push_back(i->substr(2));
52                 else if(!i->compare(0, 2, "-D"))
53                         binfo.defines.push_back(i->substr(2));
54                 else if(!i->compare(0, 2, "-L"))
55                         binfo.libpath.push_back(i->substr(2));
56                 else if(!i->compare(0, 2, "-l"))
57                         binfo.libs.push_back(i->substr(2));
58         }
59
60         return pkg;
61 }
62
63
64 BinaryPackage::Loader::Loader(BinaryPackage &p):
65         Package::Loader(p)
66 {
67         add("need_path", &BinaryPackage::need_path);
68         add("build_info", &Loader::build_info);
69 }
70
71 void BinaryPackage::Loader::build_info()
72 {
73         load_sub(static_cast<BinaryPackage &>(pkg).export_binfo);
74 }