3 This file is part of builder
4 Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/io/print.h>
9 #include <msp/strings/utils.h>
10 #include "binarypackage.h"
16 BinaryPackage::BinaryPackage(Builder &b, const string &n):
23 void BinaryPackage::set_path(const Msp::FS::Path &p)
25 path=builder.get_cwd()/p;
28 void BinaryPackage::create_build_info()
30 for(StringList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
32 *i=(path/i->substr(1)).str();
34 for(StringList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
36 *i=(path/i->substr(1)).str();
39 BinaryPackage *BinaryPackage::from_pkgconfig(Builder &builder, const string &name)
42 argv.push_back("pkg-config");
43 argv.push_back("--silence-errors");
44 argv.push_back("--cflags");
45 argv.push_back("--libs");
47 if(builder.get_verbose()>=4)
48 IO::print("Running %s\n", join(argv.begin(), argv.end()));
49 string info=run_command(argv);
55 BinaryPackage *pkg=new BinaryPackage(builder, name);
56 pkg->use_pkgconfig=true;
57 BuildInfo &binfo=pkg->export_binfo;
59 vector<string> flags=split(info);
60 for(vector<string>::const_iterator i=flags.begin(); i!=flags.end(); ++i)
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));
76 BinaryPackage::Loader::Loader(BinaryPackage &p):
79 add("need_path", &BinaryPackage::need_path);
80 add("build_info", &Loader::build_info);
83 void BinaryPackage::Loader::build_info()
85 load_sub(static_cast<BinaryPackage &>(pkg).export_binfo);