diff --git a/Makefile b/Makefile index c0affb5..6ddaf47 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# This Makefile was generated using MakeGen v1.1.6 made by Tim HÃ¥kansson +# This Makefile was generated using MakeGen v1.1.7 made by Tim HÃ¥kansson # and is licensed under MIT. Full source of the project can be found at # https://github.com/Thraix/MakeGen CC=@g++ diff --git a/src/Common.h b/src/Common.h index a6d97ef..65fcabf 100755 --- a/src/Common.h +++ b/src/Common.h @@ -13,7 +13,7 @@ // Release , should be backwards compatible with any minor version #define MAKEGEN_VERSION_RELEASE 1 // Minor changes, should be compatible with any other minor version with same major and release. -#define MAKEGEN_VERSION_MINOR 6 +#define MAKEGEN_VERSION_MINOR 7 #define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR)) const static unsigned int FLAG_HELP = BIT(0); diff --git a/src/ConfigFile.cpp b/src/ConfigFile.cpp index 51d7877..c5b0967 100755 --- a/src/ConfigFile.cpp +++ b/src/ConfigFile.cpp @@ -15,10 +15,55 @@ ConfigFile::ConfigFile() { } +std::optional ConfigFile::GetConfigFile(const std::string& filepath) +{ + std::map loadedConfigs; + return GetConfigFile(filepath, loadedConfigs); +} + +std::optional ConfigFile::GetConfigFile(const std::string& filepath, std::map& loadedConfigs) +{ + std::string realPath = FileUtils::GetRealPath(filepath); + auto it = loadedConfigs.find(realPath); + if(it != loadedConfigs.end()) + { + return {}; + } + + std::ifstream f(filepath + CONFIG_FILENAME); + // Check if the file exists + if(f.good()) + { + f.close(); + ConfigFile conf = ConfigFile::Load(realPath); + loadedConfigs.emplace(realPath, conf); + + // Create dependency config files. + for(size_t i = 0; i < conf.dependencies.size();++i) + { + std::optional dep = GetConfigFile(conf.configPath + conf.dependencies[i], loadedConfigs); + if(dep) + { + conf.dependencyConfigs.push_back(*dep); + conf.dependencies[i] = dep->configPath; + } + else + { + // Remove the dependency since it is already accounted for + conf.dependencies.erase(conf.dependencies.begin() + i); + --i; + } + } + return conf; + } + return {}; +} + + ConfigFile ConfigFile::Load(const std::string& filepath) { ConfigFile conf; - conf.configPath = FileUtils::GetRealPath(filepath); + conf.configPath = filepath; unsigned int loadFlag = 0; std::vector* vec; @@ -129,13 +174,6 @@ ConfigFile ConfigFile::Load(const std::string& filepath) if(conf.hFile == "") conf.hFile = conf.projectname+".h"; - // Create dependency config files. - for(size_t i = 0; i < conf.dependencies.size();++i) - { - conf.dependencyConfigs.push_back(ConfigFile::Load(conf.configPath + conf.dependencies[i])); - conf.dependencies[i] = FileUtils::GetRealPath(conf.dependencies[i]); - } - return conf; } diff --git a/src/ConfigFile.h b/src/ConfigFile.h index e4194e8..e320d96 100755 --- a/src/ConfigFile.h +++ b/src/ConfigFile.h @@ -2,6 +2,8 @@ #include #include +#include +#include static const std::string CONFIG_FILENAME = "makegen.conf"; @@ -29,8 +31,10 @@ class ConfigFile ConfigFile(); void Save() const; static ConfigFile Gen(); - static ConfigFile Load(const std::string& filename); + static std::optional GetConfigFile(const std::string& filepath = "./"); private: + static std::optional GetConfigFile(const std::string& filepath, std::map& loadedConfigs); + static ConfigFile Load(const std::string& filename); static void InputBoolean(const std::string& inputText, bool& b); static void InputMultiple(const std::string& inputText, std::vector& vec, bool needEnding); static void InputString(const std::string& inputText, std::string& vec, bool needEnding, bool allowEmpty); diff --git a/src/main.cpp b/src/main.cpp index 7ec9a60..a54b164 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,18 +54,6 @@ void PrintHelp() LOG_INFO(" clean all install run, rebuild will be translated to \"clean make\""); } -std::optional GetConfigFile(const std::string& filepath) -{ - std::ifstream f(filepath + CONFIG_FILENAME); - if(f.good()) - { - ConfigFile conf = ConfigFile::Load(filepath); - return conf; - } - f.close(); - return {}; -} - void GenMakefile(const ConfigFile& conf, unsigned int flags) { if(conf.generateHFile) @@ -202,8 +190,8 @@ int main(int argc, char** argv) ConfigFile::Gen().Save(); return 0; } - - auto conf = GetConfigFile("./"); + std::map files{}; + auto conf = ConfigFile::GetConfigFile(); if(conf) { bool success = MakeGen("./", flags, *conf);