+ 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%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)
+ 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 to_be_built = 0;
+ for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j)
+ if(j->second->get_package()==*i)
+ {
+ ++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;
+}
+
+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;
+
+ 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));