+Msp::Path::Path Package::get_temp_dir() const
+{
+ return source/config.get_option("tempdir").value/config.get_option("profile").value;
+}
+
+Msp::Path::Path Package::get_out_dir() const
+{
+ return source/config.get_option("outdir").value;
+}
+
+/**
+Checks which kinds of things the components of this package install.
+
+@return A bitmask of installed things
+*/
+unsigned Package::get_install_flags()
+{
+ unsigned flags=0;
+ for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
+ {
+ if(i->get_install())
+ {
+ if(i->get_type()==Component::PROGRAM)
+ flags|=BIN;
+ else if(i->get_type()==Component::LIBRARY || i->get_type()==Component::MODULE)
+ flags|=LIB;
+ }
+ if(!i->get_install_headers().empty())
+ flags|=INCLUDE;
+ }
+
+ return flags;
+}
+
+LibMode Package::get_library_mode() const
+{
+ const string &mode=config.get_option("staticlibs").value;
+ if(mode=="all")
+ return ALL_STATIC;
+ else if(mode=="local")
+ return LOCAL_STATIC;
+ else if(mode=="none")
+ return DYNAMIC;
+ else
+ throw Exception("Unknown library mode");
+}
+
+/**
+Tries to resolve all references to dependency packages.
+*/
+void Package::resolve_refs()
+{
+ for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i)
+ {
+ Package *pkg=i->resolve();
+ if(pkg) all_reqs.push_back(pkg);
+ }
+
+ for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
+ {
+ i->resolve_refs();
+ const PkgRefList &creqs=i->get_requires();
+ for(PkgRefList::const_iterator j=creqs.begin(); j!=creqs.end(); ++j)
+ if(j->get_package())
+ all_reqs.push_back(j->get_package());
+ }
+
+ for(ConditionList::iterator i=conditions.begin(); i!=conditions.end(); ++i)
+ {
+ i->resolve_refs();
+ const PkgRefList &creqs=i->get_requires();
+ for(PkgRefList::const_iterator j=creqs.begin(); j!=creqs.end(); ++j)
+ if(j->get_package())
+ all_reqs.push_back(j->get_package());
+ }
+}
+
+/**
+Processes configuration options that were most likely obtained from the command
+line.
+*/
+void Package::configure(const StringMap &opts, unsigned flag)
+{
+ if(conf_done)
+ return;
+
+ if(builder.get_verbose()>=3)
+ cout<<"Configuring "<<name<<'\n';
+
+ if(buildable)
+ {
+ init_config();
+
+ StringMap::const_iterator prof=opts.find("profile");
+ if(prof!=opts.end() && flag)
+ config.select_profile(prof->second);
+ else
+ config.select_last_profile();
+
+ if(flag && config.update(opts))
+ {
+ if(builder.get_verbose()>=2)
+ cout<<"Configuration of "<<name<<" changed\n";
+ if(!builder.get_dry_run())
+ config.save();
+ }
+
+ config.finish();
+
+ for(ConditionList::iterator i=conditions.begin(); i!=conditions.end(); ++i)
+ if(i->eval())
+ {
+ const PkgRefList &reqs=i->get_requires();
+ requires.insert(requires.end(), reqs.begin(), reqs.end());
+ build_info.add(i->get_build_info());
+ }
+
+ for(PackageList::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
+ {
+ if((*i)->get_need_path())
+ (*i)->set_path(config.get_option((*i)->get_name()+"_path").value);
+ (*i)->configure(opts, flag&2);
+ }
+ }
+
+ create_build_info();
+
+ conf_done=true;
+}
+
+/**
+Creates a non-buildable package with the given name. Pkg-config is tried first
+to get build information. If it fails, a built-in list of known packages is
+consulted.
+*/
+Package *Package::create(Builder &b, const string &name)
+{
+ list<string> argv;
+ argv.push_back("pkg-config");
+ argv.push_back("--silence-errors");
+ argv.push_back("--cflags");
+ argv.push_back("--libs");
+ argv.push_back(name);
+ vector<string> info=split(run_command(argv));
+
+ bool need_path=false;
+ bool use_pkgconfig=true;
+ if(info.empty())
+ {
+ use_pkgconfig=false;
+
+ //XXX Put these in an external file
+ if(name=="opengl")
+ info.push_back("-lGL");
+ else if(name=="pthread")
+ info.push_back("-lpthread");
+ else if(name=="gmpxx")
+ info.push_back("-lgmpxx");
+ else if(name=="fmod4")
+ need_path=true;
+ else if(name=="devil")
+ info.push_back("-lIL");
+ else if(name=="Xlib")
+ info.push_back("-lX11");
+ else
+ return 0;
+ }
+
+ Package *pkg=new Package(b, name, info);
+ pkg->need_path=need_path;
+ pkg->use_pkgconfig=use_pkgconfig;
+ return pkg;
+}
+
+/*** private ***/
+
+Package::Package(Builder &b, const string &n, const vector<string> &info):