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