]> git.tdb.fi Git - builder.git/blob - source/binarypackage.cpp
Adapt to changes in msppath
[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 <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 /**
24 Sets the path where the package files were installed.  This is only useful if
25 the package doesn't use pkg-config.
26 */
27 void BinaryPackage::set_path(const Msp::Path &p)
28 {
29         path=builder.get_cwd()/p;
30 }
31
32 void BinaryPackage::create_build_info()
33 {
34         for(StringList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
35                 if((*i)[0]=='@')
36                         *i=(path/i->substr(1)).str();
37
38         for(StringList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
39                 if((*i)[0]=='@')
40                         *i=(path/i->substr(1)).str();
41 }
42
43 BinaryPackage *BinaryPackage::from_pkgconfig(Builder &builder, const string &name)
44 {
45         list<string> argv;
46         argv.push_back("pkg-config");
47         argv.push_back("--silence-errors");
48         argv.push_back("--cflags");
49         argv.push_back("--libs");
50         argv.push_back(name);
51         if(builder.get_verbose()>=4)
52                 cout<<"Running "<<join(argv.begin(), argv.end())<<'\n';
53         string info=run_command(argv);
54
55         if(info.empty())
56                 return 0;
57
58
59         BinaryPackage *pkg=new BinaryPackage(builder, name);
60         pkg->use_pkgconfig=true;
61         BuildInfo &binfo=pkg->export_binfo;
62
63         vector<string> flags=split(info);
64         for(vector<string>::const_iterator i=flags.begin(); i!=flags.end(); ++i)
65         {
66                 if(!i->compare(0, 2, "-I"))
67                         binfo.incpath.push_back(i->substr(2));
68                 else if(!i->compare(0, 2, "-D"))
69                         binfo.defines.push_back(i->substr(2));
70                 else if(!i->compare(0, 2, "-L"))
71                         binfo.libpath.push_back(i->substr(2));
72                 else if(!i->compare(0, 2, "-l"))
73                         binfo.libs.push_back(i->substr(2));
74         }
75
76         return pkg;
77 }
78
79
80 BinaryPackage::Loader::Loader(BinaryPackage &p):
81         Package::Loader(p)
82 {
83         add("need_path", &BinaryPackage::need_path);
84         add("build_info", &Loader::build_info);
85 }
86
87 void BinaryPackage::Loader::build_info()
88 {
89         load_sub(static_cast<BinaryPackage &>(pkg).export_binfo);
90 }