diff options
Diffstat (limited to 'devtools/create_project/create_project.cpp')
-rw-r--r-- | devtools/create_project/create_project.cpp | 165 |
1 files changed, 112 insertions, 53 deletions
diff --git a/devtools/create_project/create_project.cpp b/devtools/create_project/create_project.cpp index e013377241..ad3160d778 100644 --- a/devtools/create_project/create_project.cpp +++ b/devtools/create_project/create_project.cpp @@ -81,22 +81,6 @@ std::string unifyPath(const std::string &path); * @param exe Name of the executable. */ void displayHelp(const char *exe); - -/** - * Structure for describing an FSNode. This is a very minimalistic - * description, which includes everything we need. - * It only contains the name of the node and whether it is a directory - * or not. - */ -struct FSNode { - FSNode() : name(), isDirectory(false) {} - FSNode(const std::string &n, bool iD) : name(n), isDirectory(iD) {} - - std::string name; ///< Name of the file system node - bool isDirectory; ///< Whether it is a directory or not -}; - -typedef std::list<FSNode> FileList; } // End of anonymous namespace enum ProjectType { @@ -128,7 +112,7 @@ int main(int argc, char *argv[]) { setup.filePrefix = setup.srcDir; setup.outputDir = '.'; - setup.engines = parseConfigure(setup.srcDir); + setup.engines = parseEngines(setup.srcDir); if (setup.engines.empty()) { std::cout << "WARNING: No engines found in configure file or configure file missing in \"" << setup.srcDir << "\"\n"; @@ -672,47 +656,51 @@ void displayHelp(const char *exe) { } /** - * Try to parse a given line and create an engine definition - * out of the result. - * - * This may take *any* input line, when the line is not used - * to define an engine the result of the function will be "false". + * Parse the configure.engine file of a given engine directory and return a + * list of all defined engines. * - * Note that the contents of "engine" are undefined, when this - * function returns "false". + * @param engineDir The directory of the engine. + * @return The list of all defined engines. + */ +EngineDescList parseEngineConfigure(const std::string &engineDir); + +/** + * Compares two FSNode entries in a strict-weak fashion based on the name. * - * @param line Text input line. - * @param engine Reference to an object, where the engine information - * is to be stored in. - * @return "true", when parsing succeeded, "false" otherwise. + * @param left The first operand. + * @param right The second operand. + * @return "true" when the name of the left operand is strictly smaller than + * the name of the second operand. "false" otherwise. */ -bool parseEngine(const std::string &line, EngineDesc &engine); +bool compareFSNode(const CreateProjectTool::FSNode &left, const CreateProjectTool::FSNode &right); } // End of anonymous namespace -EngineDescList parseConfigure(const std::string &srcDir) { - std::string configureFile = srcDir + "/engines/configure.engines"; +EngineDescList parseEngines(const std::string &srcDir) { + using CreateProjectTool::FileList; + using CreateProjectTool::listDirectory; - std::ifstream configure(configureFile.c_str()); - if (!configure) - return EngineDescList(); + EngineDescList engineList; - std::string line; - EngineDescList engines; + FileList engineFiles = listDirectory(srcDir + "/engines/"); - for (;;) { - std::getline(configure, line); - if (configure.eof()) - break; + // Sort file list alphabetically this allows for a nicer order in + // --list-engines output, for example. + engineFiles.sort(&compareFSNode); - if (configure.fail()) - error("Failed while reading from " + configureFile); + for (FileList::const_iterator i = engineFiles.begin(), end = engineFiles.end(); i != end; ++i) { + // Each engine requires its own sub directory thus we will skip all + // non directory file nodes here. + if (!i->isDirectory) { + continue; + } - EngineDesc desc; - if (parseEngine(line, desc)) - engines.push_back(desc); + // Retrieve all engines defined in this sub directory and add them to + // the list of all engines. + EngineDescList list = parseEngineConfigure(srcDir + "/engines/" + i->name); + engineList.splice(engineList.end(), list); } - return engines; + return engineList; } bool isSubEngine(const std::string &name, const EngineDescList &engines) { @@ -777,6 +765,21 @@ StringList getEngineDefines(const EngineDescList &engines) { } namespace { +/** + * Try to parse a given line and create an engine definition + * out of the result. + * + * This may take *any* input line, when the line is not used + * to define an engine the result of the function will be "false". + * + * Note that the contents of "engine" are undefined, when this + * function returns "false". + * + * @param line Text input line. + * @param engine Reference to an object, where the engine information + * is to be stored in. + * @return "true", when parsing succeeded, "false" otherwise. + */ bool parseEngine(const std::string &line, EngineDesc &engine) { // Format: // add_engine engine_name "Readable Description" enable_default ["SubEngineList"] @@ -799,6 +802,36 @@ bool parseEngine(const std::string &line, EngineDesc &engine) { return true; } + +EngineDescList parseEngineConfigure(const std::string &engineDir) { + std::string configureFile = engineDir + "/configure.engine"; + + std::ifstream configure(configureFile.c_str()); + if (!configure) + return EngineDescList(); + + std::string line; + EngineDescList engines; + + for (;;) { + std::getline(configure, line); + if (configure.eof()) + break; + + if (configure.fail()) + error("Failed while reading from " + configureFile); + + EngineDesc desc; + if (parseEngine(line, desc)) + engines.push_back(desc); + } + + return engines; +} + +bool compareFSNode(const CreateProjectTool::FSNode &left, const CreateProjectTool::FSNode &right) { + return left.name < right.name; +} } // End of anonymous namespace TokenList tokenize(const std::string &input, char separator) { @@ -1048,13 +1081,6 @@ bool compareNodes(const FileNode *l, const FileNode *r) { } } -/** - * Returns a list of all files and directories in the specified - * path. - * - * @param dir Directory which should be listed. - * @return List of all children. - */ FileList listDirectory(const std::string &dir) { FileList result; #ifdef USE_WIN32_API @@ -1242,6 +1268,12 @@ void ProjectProvider::createProject(BuildSetup &setup) { // Create other misc. build files createOtherBuildFiles(setup); + + // In case we create the main ScummVM project files we will need to + // generate engines/plugins_table.h too. + if (!setup.tests && !setup.devTools) { + createEnginePluginsTable(setup); + } } ProjectProvider::UUIDMap ProjectProvider::createUUIDMap(const BuildSetup &setup) const { @@ -1569,6 +1601,33 @@ void ProjectProvider::createModuleList(const std::string &moduleDir, const Strin error("Malformed file " + moduleMkFile); } +void ProjectProvider::createEnginePluginsTable(const BuildSetup &setup) { + const std::string enginePluginsTableFile = setup.outputDir + "/engines/plugins_table.h"; + std::ofstream enginePluginsTable(enginePluginsTableFile.c_str()); + if (!enginePluginsTable) { + error("Could not open \"" + enginePluginsTableFile + "\" for writing"); + } + + enginePluginsTable << "/* This file is automatically generated by create_project */\n" + << "/* DO NOT EDIT MANUALLY */\n" + << "// This file is being included by \"base/plugins.cpp\"\n"; + + for (EngineDescList::const_iterator i = setup.engines.begin(), end = setup.engines.end(); i != end; ++i) { + // We ignore all sub engines here because they require no special + // handling. + if (isSubEngine(i->name, setup.engines)) { + continue; + } + + // Make the engine name all uppercase. + std::string engineName; + std::transform(i->name.begin(), i->name.end(), std::back_inserter(engineName), toupper); + + enginePluginsTable << "#if PLUGIN_ENABLED_STATIC(" << engineName << ")\n" + << "LINK_PLUGIN(" << engineName << ")\n" + << "#endif\n"; + } +} } // End of anonymous namespace void error(const std::string &message) { |