-string Builder::run_pkgconfig(const string &pkg, const string &what)
-{
- ExternalTask::Arguments argv;
- argv.push_back("pkg-config");
- if(what=="cflags" || what=="libs")
- argv.push_back("--"+what);
- else if(what=="flags")
- {
- argv.push_back("--cflags");
- argv.push_back("--libs");
- }
- else
- argv.push_back("--variable="+what);
- argv.push_back(pkg);
-
- if(verbose>=4)
- IO::print("Running %s\n", join(argv.begin(), argv.end()));
-
- ExternalTask task(argv, FS::Path());
- task.set_stdout(ExternalTask::CAPTURE);
- task.set_stderr(ExternalTask::IGNORE);
- task.start();
- Task::Status status;
- while((status=task.check())==Task::RUNNING)
- Time::sleep(10*Time::msec);
- if(status==Task::ERROR)
- throw runtime_error(format("pkg-config for package %s failed", pkg));
-
- return task.get_output();
-}
-
-Package *Builder::get_package(const string &name)
-{
- PackageMap::iterator i = packages.find(format("%s/%s", name, current_arch->get_system()));
- if(i==packages.end())
- i = packages.find(name);
- if(i!=packages.end())
- return i->second;
-
- if(!no_externals)
- {
- FS::Path path = get_package_location(name);
- if(!path.empty() && !load_build_file(path/"Build"))
- {
- i = packages.find(name);
- if(i!=packages.end())
- return i->second;
- }
- }
-
- Package *pkg = 0;
- try
- {
- // Package source not found - create a binary package
- pkg = BinaryPackage::from_pkgconfig(*this, name);
- }
- catch(...)
- {
- problem(name, "not found");
- }
-
- packages.insert(PackageMap::value_type(name, pkg));
-
- return pkg;
-}
-