diff --git a/Makefile b/Makefile index 384dfbb..74e89c2 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,7 @@ CFLAGS=$(INCLUDES) -std=c++17 -c -w -g3 -D_DEBUG LIBS= OUTPUT=$(BIN)makegen all: $(OUTPUT) - $(info ------------------------) - $(info ---- Done Compiling ----) - $(info ------------------------) -rebuid: clean all +rebuild: clean all clean: $(info Removing intermediates) rm -rf $(OBJPATH)/*.o diff --git a/makegen.conf b/makegen.conf index f1ca93a..a305e5f 100644 --- a/makegen.conf +++ b/makegen.conf @@ -1,8 +1,15 @@ +#libs +#libdirs +#includedirs #srcdirs src/ -#outputdir -bin/ -#outputname -makegen #defines _DEBUG +#outputdir +bin/ +#projectname +MakeGen +#outputname +makegen +#executable +true diff --git a/src/ConfigFile.cpp b/src/ConfigFile.cpp index 413d63b..7f9fe5b 100644 --- a/src/ConfigFile.cpp +++ b/src/ConfigFile.cpp @@ -65,6 +65,11 @@ ConfigFile ConfigFile::Load() s = &conf.outputname; loadFlag = FLAG_STRING; } + else if(line == "#projectname") + { + s = &conf.projectname; + loadFlag = FLAG_STRING; + } else if(line == "#executable") { b = &conf.executable; @@ -96,3 +101,92 @@ ConfigFile ConfigFile::Load() } return conf; } + +void ConfigFile::InputMultiple(const std::string& inputText, std::vector& vec, bool needEnding) +{ + std::string input; + while(true) + { + LOG_INFO(inputText); + std::getline(std::cin, input); + if(input == "") + break; + if(needEnding && input[input.length()-1] != '/') + input+='/'; + vec.push_back(input); + } +} + +ConfigFile ConfigFile::Gen() +{ + ConfigFile conf; + InputMultiple("Enter library:", conf.libs,true); + InputMultiple("Enter library directory:", conf.libdirs,true); + InputMultiple("Enter include directory:", conf.includedirs,true); + InputMultiple("Enter source directories:", conf.srcdirs,true); + InputMultiple("Enter preprocessor definitions:", conf.defines,false); + LOG_INFO("Enter output directory (default: bin):"); + std::getline(std::cin, conf.outputdir); + if(conf.outputdir == "") + conf.outputdir = "bin/"; + conf.outputname = ""; + while(conf.projectname == "") + { + LOG_INFO("Enter a name for the project:"); + std::getline(std::cin, conf.projectname); + } + while(conf.outputname == "") + { + LOG_INFO("Enter a name for the output file:"); + std::getline(std::cin, conf.outputname); + } + std::string input = ""; + while(input == "") + { + LOG_INFO("Should it be compiled as an executable (y/n):"); + std::getline(std::cin, input); + if(input[0] != 'y' && input[0] != 'n') + input = ""; + } + conf.executable = input[0] == 'y'; + return conf; +} + +void ConfigFile::Save() const +{ + std::ofstream file("makegen.conf"); + file << "#libs" << std::endl; + for(auto it = libs.begin();it!=libs.end();++it) + { + file << *it << std::endl; + } + file << "#libdirs" << std::endl; + for(auto it = libdirs.begin();it!=libdirs.end();++it) + { + file << *it << std::endl; + } + file << "#includedirs" << std::endl; + for(auto it = includedirs.begin();it!=includedirs.end();++it) + { + file << *it << std::endl; + } + file << "#srcdirs" << std::endl; + for(auto it = srcdirs.begin();it!=srcdirs.end();++it) + { + file << *it << std::endl; + } + file << "#defines" << std::endl; + for(auto it = defines.begin();it!=defines.end();++it) + { + file << *it << std::endl; + } + file << "#outputdir" << std::endl; + file << outputdir << std::endl; + file << "#projectname" << std::endl; + file << projectname << std::endl; + file << "#outputname" << std::endl; + file << outputname << std::endl; + file << "#executable" << std::endl; + file << (executable ? "true" : "false") << std::endl; + file.close(); +} diff --git a/src/ConfigFile.h b/src/ConfigFile.h index 2adbdea..7cf4b76 100644 --- a/src/ConfigFile.h +++ b/src/ConfigFile.h @@ -13,10 +13,13 @@ class ConfigFile std::vector defines; std::string outputdir; std::string outputname; + std::string projectname; bool executable; public: ConfigFile(); void Save() const; static ConfigFile Gen(); static ConfigFile Load(); + private: + static void InputMultiple(const std::string& inputText, std::vector& vec, bool needEnding); }; diff --git a/src/Makefile.cpp b/src/Makefile.cpp index a948d5e..27493a8 100644 --- a/src/Makefile.cpp +++ b/src/Makefile.cpp @@ -79,10 +79,10 @@ void Makefile::Save(const ConfigFile& conf) outputFile << std::endl; outputFile << "OUTPUT=$(BIN)" << conf.outputname << std::endl; outputFile << "all: $(OUTPUT)" << std::endl; - outputFile << "\t$(info ------------------------)" << std::endl; - outputFile << "\t$(info ---- Done Compiling ----)" << std::endl; - outputFile << "\t$(info ------------------------)" << std::endl; - outputFile << "rebuid: clean all" << std::endl; + //outputFile << "\t$(info ------------------------)" << std::endl; + //outputFile << "\t$(info ---- Done Compiling ----)" << std::endl; + //outputFile << "\t$(info ------------------------)" << std::endl; + outputFile << "rebuild: clean all" << std::endl; outputFile << "clean:" << std::endl; outputFile << "\t$(info Removing intermediates)" << std::endl; outputFile << "\trm -rf $(OBJPATH)/*.o" << std::endl; @@ -90,7 +90,7 @@ void Makefile::Save(const ConfigFile& conf) outputFile << "\t$(info Generating output file)" << std::endl; outputFile << "\t$(CO) $(OUTPUT) $(OBJECTS) $(LIBS)" << std::endl; outputFile << "install: all" << std::endl; - outputFile << "\t$(info Installing MakeGen to /usr/bin/)" << std::endl; + outputFile << "\t$(info Installing " << conf.projectname <<" to /usr/bin/)" << std::endl; outputFile << "\t@cp $(OUTPUT) /usr/bin/" << conf.outputname << std::endl; std::map dependencies; for(auto it = cppFiles.begin(); it!=cppFiles.end();++it) diff --git a/src/main.cpp b/src/main.cpp index 186040b..a61303b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,15 +10,15 @@ #include "Logging.h" #define BIT(x) (1<& ret) -{ - std::string input; - while(true) - { - LOG_INFO(inputText); - std::getline(std::cin, input); - if(input == "") - break; - ret.push_back(input); - } - -} - -void GenConfFile() -{ - std::vector libs; - std::vector libdirs; - std::vector includedirs; - std::vector srcdirs; - std::string outputDir; - InputMultiple("Enter library:", libs); - InputMultiple("Enter library directory:", libdirs); - InputMultiple("Enter include directory:", includedirs); - InputMultiple("Enter source directories:", srcdirs); - LOG_INFO("Enter output directory (default: bin):"); - std::getline(std::cin, outputDir); - if(outputDir == "") - outputDir = "bin"; - - std::ofstream file("makegen.conf"); - file << "#libs" << std::endl; - for(auto it = libs.begin();it!=libs.end();++it) - { - file << *it << std::endl; - } - file << "#libdirs" << std::endl; - for(auto it = libdirs.begin();it!=libdirs.end();++it) - { - file << *it << std::endl; - } - file << "#includedirs" << std::endl; - for(auto it = includedirs.begin();it!=includedirs.end();++it) - { - file << *it << std::endl; - } - file << "#srcdirs" << std::endl; - for(auto it = srcdirs.begin();it!=srcdirs.end();++it) - { - file << *it << std::endl; - } - file << "#outputdir" << std::endl; - file << outputDir << std::endl; - file.close(); -} - int main(int argc, char** argv) { ReadFlags(argc,argv); - if((flags & FLAG_HELP)) + if(flags & FLAG_HELP) { LOG_INFO("Usage: makegen [options]"); LOG_INFO(" Options:"); LOG_INFO(" --help\tDisplays this information"); LOG_INFO(" --conf\tGenerate a config file for the project"); + LOG_INFO(" --version\tDisplays the version of this program"); LOG_INFO(" install\tGenerates a Makefile and runs make install"); LOG_INFO(" clean\tGenerates a Makefile and runs make clean"); LOG_INFO(" rebuild\tGenerates a Makefile and runs make rebuild"); LOG_INFO(" If no option is given it will generate a Makefile and run default make"); return 0; } + if(flags & FLAG_VERSION) + { + LOG_INFO("MakeGen ",VERSION); + return 0; + } if(flags & FLAG_GEN) { - GenConfFile(); + ConfigFile::Gen().Save(); return 0; } LOG_INFO("Generating Makefile...");