+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)
+ return 0;
+
+ if(create_targets())
+ return 1;
+
+ if(verbose>=2)
+ {
+ IO::print("Building on %s, for %s%s\n", native_arch.get_name(),
+ current_arch->get_name(), (current_arch->is_native() ? " (native)" : ""));
+ IO::print("Prefix is %s\n", prefix);
+ }
+
+ if(verbose>=1)
+ {
+ unsigned n_packages = 0;
+ for(PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
+ if(i->second && i->second->is_configured())
+ ++n_packages;
+ IO::print("%d active packages, %d targets\n", n_packages, targets.size());
+ }
+
+ if(verbose>=2)
+ {
+ for(PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
+ {
+ if(!i->second->is_configured())
+ continue;
+
+ IO::print(" %s", i->second->get_name());
+ if(dynamic_cast<SourcePackage *>(i->second))
+ IO::print("*");
+ unsigned count = 0;
+ unsigned to_be_built = 0;
+ for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j)
+ if(j->second->get_package()==i->second)
+ {
+ ++count;
+ if(j->second->get_rebuild())
+ ++to_be_built;
+ }
+ if(count)
+ {
+ IO::print(" (%d targets", count);
+ if(to_be_built)
+ IO::print(", %d to be built", to_be_built);
+ 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);
+ if(!analyzer)
+ 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;
+}