--- /dev/null
+#ifndef PACKAGEMANAGER_H_
+#define PACKAGEMANAGER_H_
+
+#include <list>
+#include <map>
+#include <string>
+#include <msp/fs/path.h>
+
+class Builder;
+class Package;
+
+/**
+Keeps track of packages. Also responsible for locating previously unknown
+packages by name.
+*/
+class PackageManager
+{
+public:
+ typedef std::map<std::string, Package *> PackageMap;
+
+private:
+ typedef std::list<Msp::FS::Path> SearchPath;
+
+ Builder &builder;
+ SearchPath pkg_path;
+ SearchPath pkg_dirs;
+ bool no_externals;
+ PackageMap packages;
+
+public:
+ PackageManager(Builder &);
+ ~PackageManager();
+
+ void set_no_externals(bool);
+
+ /** Adds a package to the manager. Called from Package constructor. */
+ void add_package(Package *);
+
+ /** Returns a package from the cache. */
+ Package *get_package(const std::string &);
+
+ const PackageMap &get_packages() const { return packages; }
+
+ /** Locates a package and creates it if necessary. */
+ Package *find_package(const std::string &);
+
+private:
+ std::string run_pkgconfig(const std::string &, const std::string &);
+
+ /** Determines the source directory of a package. Pkg-config is consulted
+ first, and if it fails, the package path is searched for matches. */
+ Msp::FS::Path get_package_location(const std::string &);
+};
+
+#endif