#include "gamesetupdefinitions.h"
+#include <msp/builder/builder.h>
+#include <msp/builder/component.h>
+#include <msp/datafile/parser.h>
+#include <msp/fs/utils.h>
+#include <msp/io/file.h>
+using namespace std;
using namespace Msp;
GameSetupDefinitions::GameSetupDefinitions(Builder &b, const Component &c, const FS::Path &p):
SourceFile(b, c, p)
-{ }
+{
+ install_location = "include";
+}
+
+void GameSetupDefinitions::find_dependencies()
+{
+ if(!mtime)
+ return;
+
+ vector<string> imports;
+
+ Cache &cache = package->get_cache();
+ if(mtime<cache.get_mtime() && cache.has_key(this, "imports"))
+ imports = cache.get_values(this, "imports");
+ else
+ {
+ builder.get_logger().log("files", "Reading imports from %s", path.str());
+
+ imports = parse_imports(path);
+ cache.set_values(this, "imports", imports);
+ }
+
+ Tool *generator = builder.get_toolchain().get_tool_for_suffix(FS::extpart(FS::basename(path)));
+
+ BuildInfo binfo = component->get_build_info_for_path(path);
+ for(const string &i: imports)
+ if(Target *imp = builder.get_vfs().find_header(i+".mgs", generator, binfo.incpath))
+ add_dependency(*imp);
+}
+
+vector<string> GameSetupDefinitions::parse_imports(const FS::Path &fn)
+{
+ vector<string> imports;
+
+ IO::BufferedFile in_file(fn.str());
+ DataFile::Parser parser(in_file, fn.str());
+ while(parser)
+ {
+ DataFile::Statement st = parser.parse();
+ if(st.keyword=="import" && st.args.size()==1)
+ imports.push_back(st.args.front().get<string>());
+ }
+
+ return imports;
+}