--- /dev/null
+#include "gameplugin.h"
+#include <msp/builder/toolchain.h>
+#include "gametools.h"
+
+void GamePlugin::add_tools(Toolchain &toolchain, const Architecture &) const
+{
+ toolchain.add_toolchain(new GameTools(builder));
+}
+
+
+#if defined(_WIN32)
+#define GAMETOOLS_API __declspec(dllexport)
+#elif defined(__GNUC__)
+#define GAMETOOLS_API __attribute__((visibility("default")))
+#else
+#define GAMETOOLS_API
+#endif
+
+extern "C"
+GAMETOOLS_API Plugin *create_plugin(Builder &builder)
+{
+ return new GamePlugin(builder);
+}
--- /dev/null
+#ifndef GAMESETUPDEFINITIONS_H_
+#define GAMESETUPDEFINITIONS_H_
+
+#include <msp/builder/sourcefile.h>
+
+class GameSetupDefinitions: public SourceFile
+{
+public:
+ GameSetupDefinitions(Builder &, const Component &, const Msp::FS::Path &);
+
+ const char *get_type() const override { return "GameSetupDefinitions"; }
+};
+
+#endif
--- /dev/null
+#include "gamesetupgenerator.h"
+#include <msp/builder/builder.h>
+#include <msp/fs/utils.h>
+#include "gamesetupdefinitions.h"
+
+using namespace std;
+using namespace Msp;
+
+GameSetupGenerator::GameSetupGenerator(Builder &b):
+ Tool(b, "MGSG")
+{
+ input_suffixes.push_back(".mgs");
+
+ set_command("mspgame-setupgen");
+ set_run_external(_run);
+}
+
+Target *GameSetupGenerator::create_source(const Component &comp, const FS::Path &path) const
+{
+ return new GameSetupDefinitions(builder, comp, path);
+}
+
+Target *GameSetupGenerator::create_target(const vector<Target *> &sources, const string &)
+{
+ if(sources.size()!=1)
+ throw invalid_argument("GameSetupGenerator::create_target");
+
+ GameSetupDefinitions &defs = dynamic_cast<GameSetupDefinitions &>(*sources.front());
+
+ const Component &comp = *defs.get_component();
+ const SourcePackage &spkg = comp.get_package();
+ FS::Path dir = spkg.get_temp_directory()/"generated";
+ dir /= FS::dirname(FS::relative(defs.get_path(), spkg.get_source_directory()));
+
+ Tool &compiler = builder.get_toolchain().get_tool("CC");
+ string base = FS::basepart(FS::basename(defs.get_path()));
+ Target *source = compiler.create_source(comp, dir/(base+".cpp"));
+ source->add_dependency(defs);
+ source->set_tool(*this);
+
+ Target *header = compiler.create_source(comp, dir/(base+".h"));
+ header->add_dependency(defs);
+ source->add_side_effect(*header);
+
+ return source;
+}
+
+ExternalTask::Arguments GameSetupGenerator::_run(const CSourceFile &out_src, FS::Path &work_dir)
+{
+ const Tool &tool = *out_src.get_tool();
+
+ ExternalTask::Arguments argv;
+ argv.push_back(tool.get_executable()->get_path().str());
+
+ for(const Target *d: out_src.get_dependencies())
+ if(const GameSetupDefinitions *defs = dynamic_cast<const GameSetupDefinitions *>(d))
+ argv.push_back(FS::relative(defs->get_path(), work_dir).str());
+
+ argv.push_back("-o");
+ argv.push_back(FS::relative(out_src.get_path(), work_dir).str());
+
+ return argv;
+}
--- /dev/null
+#ifndef GAMESETUPGENERATOR_H_
+#define GAMESETUPGENERATOR_H_
+
+#include <msp/builder/csourcefile.h>
+#include <msp/builder/tool.h>
+
+class GameSetupGenerator: public Tool
+{
+public:
+ GameSetupGenerator(Builder &);
+
+ Target *create_source(const Component &, const Msp::FS::Path &) const override;
+ Target *create_target(const std::vector<Target *> &, const std::string &) override;
+
+private:
+ static ExternalTask::Arguments _run(const CSourceFile &, Msp::FS::Path &);
+};
+
+#endif