diff --git a/Makefile b/Makefile index 66df2a4..c0affb5 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# This Makefile was generated using MakeGen v1.1.5 made by Tim Håkansson +# This Makefile was generated using MakeGen v1.1.6 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 b1c3bf7..a6d97ef 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 5 +#define MAKEGEN_VERSION_MINOR 6 #define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR)) const static unsigned int FLAG_HELP = BIT(0); @@ -26,6 +26,7 @@ const static unsigned int FLAG_INSTALL = BIT(6); const static unsigned int FLAG_REBUILD = BIT(7); const static unsigned int FLAG_SINGLE_THREAD = BIT(8); const static unsigned int FLAG_DEPENDENCY = BIT(9); +const static unsigned int FLAG_SIMPLE = BIT(10); #define LOG_INFO(...) Log(__VA_ARGS__); std::cout << std::endl diff --git a/src/ConfigFile.cpp b/src/ConfigFile.cpp index ac31102..51d7877 100755 --- a/src/ConfigFile.cpp +++ b/src/ConfigFile.cpp @@ -8,7 +8,8 @@ #define FLAG_NONE 0 #define FLAG_VECTOR 1 #define FLAG_STRING 2 -#define FLAG_BOOL 3 +#define FLAG_BOOL 3 + ConfigFile::ConfigFile() : outputdir("bin"), outputname("out.a"), hFile(""),executable(true), shared(true), generateHFile(false) { @@ -32,7 +33,7 @@ ConfigFile ConfigFile::Load(const std::string& filepath) if(file.is_open()) { // config name, { pointer to memory, isDirectory} - std::map> strings = + std::map> strings = { {"#srcdir", {&conf.srcdir, true}}, {"#outputdir", {&conf.outputdir, true}}, @@ -42,7 +43,7 @@ ConfigFile ConfigFile::Load(const std::string& filepath) }; // config name, { pointer to memory, isDirectory} - std::map*, bool>> vectors = + std::map*, bool>> vectors = { {"#libs", {&conf.libs, false}}, {"#libdirs", {&conf.libdirs, true}}, @@ -52,7 +53,7 @@ ConfigFile ConfigFile::Load(const std::string& filepath) {"#dependencies", {&conf.dependencies, true}}, }; - std::map booleans = + std::map booleans = { {"#executable", &conf.executable}, {"#shared", &conf.shared}, @@ -83,7 +84,7 @@ ConfigFile ConfigFile::Load(const std::string& filepath) isDirectory = itVec->second.second; loadFlag = FLAG_VECTOR; } - else + else { auto&& itBool{booleans.find(line)}; if(itBool != booleans.end()) @@ -141,7 +142,7 @@ ConfigFile ConfigFile::Load(const std::string& filepath) void ConfigFile::InputBoolean(const std::string& inputText, bool& b) { std::string input; - while(true) + while(true) { LOG_INFO(inputText); std::getline(std::cin, input); @@ -173,7 +174,7 @@ void ConfigFile::InputString(const std::string& inputText, std::string& str, boo void ConfigFile::InputMultiple(const std::string& inputText, std::vector& vec, bool needEnding) { std::string input; - while(true) + while(true) { InputString(inputText, input, needEnding, true); if(input == "") diff --git a/src/FileUtils.h b/src/FileUtils.h index b45b4a4..128c2e7 100644 --- a/src/FileUtils.h +++ b/src/FileUtils.h @@ -58,7 +58,7 @@ struct FileUtils // Remove the 'from' path return to.substr(from.size()+1); } - // Check if the directory is a child of from + // Check if the directory is a child of from else if(strncmp(from.c_str(), to.c_str(), to.size()) == 0) { std::string sub = from.substr(to.size()); diff --git a/src/Makefile.cpp b/src/Makefile.cpp index 8e983f9..64846f6 100755 --- a/src/Makefile.cpp +++ b/src/Makefile.cpp @@ -8,13 +8,16 @@ #include #include #include -#include +#include -void Makefile::Save(const ConfigFile& conf) +void Makefile::Save(const ConfigFile& conf, unsigned int flags) { std::set hFiles; // hFile, directory std::set cppFiles; - Utils::GetCppAndHFiles(conf, hFiles, cppFiles); + if(flags & FLAG_SIMPLE) + Utils::GetCppFiles(conf, cppFiles); + else + Utils::GetCppAndHFiles(conf, hFiles, cppFiles); std::ofstream outputFile(conf.configPath + "Makefile"); outputFile << "# This Makefile was generated using MakeGen "<< MAKEGEN_VERSION<< " made by Tim Håkansson" << std::endl; @@ -159,7 +162,6 @@ void Makefile::Save(const ConfigFile& conf) outputFile << std::endl; outputFile << "\t$(info -[" << (int)(i / (float)cppFiles.size() * 100) << "%]- $<)" << std::endl; outputFile << "\t$(CC) $(CFLAGS) -o $@ $<" << std::endl; - //std::cout << *deps << std::endl; } } } diff --git a/src/Makefile.h b/src/Makefile.h index bfe90bb..768f0b9 100755 --- a/src/Makefile.h +++ b/src/Makefile.h @@ -8,5 +8,5 @@ class Makefile { public: - static void Save(const ConfigFile& conf); + static void Save(const ConfigFile& conf, unsigned int flags); }; diff --git a/src/Utils.cpp b/src/Utils.cpp index 40cfef3..899559f 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -16,6 +16,27 @@ std::string Utils::CommonPrefix(const std::string& s1, const std::string& s2) return s1.substr(0, n); } +void Utils::GetCppFiles(const ConfigFile& conf, std::set& cppFiles) +{ + std::vector files; + std::string path = conf.configPath + conf.srcdir; + FileUtils::GetAllFiles(path, files); + + for(auto it = files.begin(); it!=files.end();++it) + { + size_t extensionPos = it->find_last_of("."); + if(extensionPos != std::string::npos) + { + std::string extension = it->substr(extensionPos+1); + std::string filename = it->substr(path.length()); + if(extension == "cpp" || extension == "c") + { + cppFiles.emplace(filename); + } + } + } +} + void Utils::GetCppAndHFiles(const ConfigFile& conf, std::set& hFiles, std::set& cppFiles) { std::vector files; diff --git a/src/Utils.h b/src/Utils.h index 781bb44..21c5def 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -28,6 +28,7 @@ struct HFile struct Utils { static std::string CommonPrefix(const std::string& s1, const std::string& s2); + static void GetCppFiles(const ConfigFile& conf, std::set& cppFiles); static void GetCppAndHFiles(const ConfigFile& conf, std::set& hFiles, std::set& cppFiles); static void GetHFiles(const std::string& dependencyDir, const ConfigFile& conf, std::set& hFiles); }; diff --git a/src/main.cpp b/src/main.cpp index 26e1294..9bbc68b 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -45,6 +45,8 @@ void PrintHelp() LOG_INFO(" make all && make run"); LOG_INFO(" -s, single Runs additional makegen options as single thread"); LOG_INFO(" (no --jobs=X flag)"); + LOG_INFO(" --simple Creates a simple Makefile without include dependencies"); + LOG_INFO(" (no --jobs=X flag)"); LOG_INFO(""); LOG_INFO(" If no option is given it will run \"make all\""); LOG_INFO(""); @@ -64,11 +66,11 @@ std::optional GetConfigFile(const std::string& filepath) return {}; } -void GenMakefile(const ConfigFile& conf) +void GenMakefile(const ConfigFile& conf, unsigned int flags) { if(conf.generateHFile) HFileGen::Create(conf); - Makefile::Save(conf); + Makefile::Save(conf, flags); } unsigned int ReadFlags(int argc, char** argv) @@ -118,6 +120,10 @@ unsigned int ReadFlags(int argc, char** argv) { flags |= FLAG_SINGLE_THREAD; } + else if(flag == "--simple") + { + flags |= FLAG_SIMPLE; + } else if(flag != "") { LOG_ERROR("Unknown argument ", flag); @@ -166,7 +172,7 @@ bool MakeGen(const std::string& filepath, unsigned int flags, const ConfigFile& LOG_INFO("Building ", conf.projectname); LOG_INFO("Generating Makefile..."); Timer timer; - GenMakefile(conf); + GenMakefile(conf, flags); LOG_INFO("Took ", round(timer.Elapsed()*1000.0)/1000.0,"s"); LOG_INFO("Running Makefile...");