3 This file is part of builder
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
9 #include <msp/strings/utils.h>
10 #include "binarypackage.h"
16 BinaryPackage::BinaryPackage(Builder &b, const string &n):
24 Sets the path where the package files were installed. This is only useful if
25 the package doesn't use pkg-config.
27 void BinaryPackage::set_path(const Msp::FS::Path &p)
29 path=builder.get_cwd()/p;
32 void BinaryPackage::create_build_info()
34 for(StringList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
36 *i=(path/i->substr(1)).str();
38 for(StringList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
40 *i=(path/i->substr(1)).str();
43 BinaryPackage *BinaryPackage::from_pkgconfig(Builder &builder, const string &name)
46 argv.push_back("pkg-config");
47 argv.push_back("--silence-errors");
48 argv.push_back("--cflags");
49 argv.push_back("--libs");
51 if(builder.get_verbose()>=4)
52 cout<<"Running "<<join(argv.begin(), argv.end())<<'\n';
53 string info=run_command(argv);
59 BinaryPackage *pkg=new BinaryPackage(builder, name);
60 pkg->use_pkgconfig=true;
61 BuildInfo &binfo=pkg->export_binfo;
63 vector<string> flags=split(info);
64 for(vector<string>::const_iterator i=flags.begin(); i!=flags.end(); ++i)
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));
80 BinaryPackage::Loader::Loader(BinaryPackage &p):
83 add("need_path", &BinaryPackage::need_path);
84 add("build_info", &Loader::build_info);
87 void BinaryPackage::Loader::build_info()
89 load_sub(static_cast<BinaryPackage &>(pkg).export_binfo);