+int Builder::main()
+{
+ if(prefix.str()!="/usr")
+ {
+ FS::Path pcdir=prefix/"lib"/"pkgconfig";
+ if(const char *pcp=getenv("PKG_CONFIG_PATH"))
+ {
+ vector<string> path=split(pcp, ':');
+ bool found=false;
+ for(vector<string>::const_iterator i=path.begin(); (!found && i!=path.end()); ++i)
+ found=(*i==pcdir.str());
+ if(!found)
+ {
+ path.push_back(pcdir.str());
+ setenv("PKG_CONFIG_PATH", join(path.begin(), path.end(), ":").c_str(), true);
+ }
+ }
+ else
+ setenv("PKG_CONFIG_PATH", pcdir.str().c_str(), true);
+ }
+
+ if(load_build_file(cwd/build_file))
+ {
+ if(help)
+ {
+ usage(0, "builder", false);
+ return 0;
+ }
+ else
+ {
+ IO::print(IO::cerr, "No build info here.\n");
+ return 1;
+ }
+ }
+
+ main_pkg->configure(cmdline_options, conf_all?2:1);
+
+ if(help)
+ {
+ usage(0, "builder", false);
+ IO::print("\n");
+ package_help();
+ return 0;
+ }
+
+ if(!conf_only && create_targets())
+ return 1;
+
+ PackageList all_reqs=main_pkg->collect_requires();
+
+ if(conf_only)
+ return 0;
+
+ if(verbose>=2)
+ IO::print("Building on %s, for %s\n", native_arch->get_name(), current_arch->get_name());
+ if(verbose>=1)
+ IO::print("%d active packages, %d targets\n", all_reqs.size(), targets.size());
+ if(verbose>=2)
+ {
+ for(PackageList::const_iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
+ {
+ IO::print(" %s", (*i)->get_name());
+ if(dynamic_cast<SourcePackage *>(*i))
+ IO::print("*");
+ unsigned count=0;
+ unsigned ood_count=0;
+ for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j)
+ if(j->second->get_package()==*i)
+ {
+ ++count;
+ if(j->second->get_rebuild())
+ ++ood_count;
+ }
+ if(count)
+ {
+ IO::print(" (%d targets", count);
+ if(ood_count)
+ IO::print(", %d out-of-date", ood_count);
+ IO::print(")");
+ }
+ IO::print("\n");
+ }
+ }
+
+ if(analyzer)
+ analyzer->analyze();
+
+ if(!problems.empty())
+ {
+ IO::print(IO::cerr, "The following problems were detected:\n");
+ for(ProblemList::iterator i=problems.begin(); i!=problems.end(); ++i)
+ IO::print(IO::cerr, " %s: %s\n", i->package, i->descr);
+ IO::print(IO::cerr, "Please fix them and try again.\n");
+ return 1;
+ }
+
+ if(clean)
+ exit_code=do_clean();
+ else if(build)
+ exit_code=do_build();
+
+ return exit_code;
+}
+
+string Builder::run_pkgconfig(const string &pkg, const string &what)
+{
+ list<string> 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()));
+
+ int status;
+ string res=run_command(argv, &status);
+ if(status)
+ throw Exception(format("pkg-config for package %s failed", pkg));
+
+ return res;
+}