Move Config gen stuff to ConfigFile.cpp, Add version flag

This commit is contained in:
Thraix
2018-06-10 12:02:51 +02:00
parent 0af9887ea7
commit 464c483445
6 changed files with 133 additions and 78 deletions
+19 -65
View File
@@ -10,15 +10,15 @@
#include "Logging.h"
#define BIT(x) (1<<x)
#define STRINGIFY(x) #x
#define STR(x) STRINGIFY(x)
#define VERSION_MAJOR 1
#define VERSION_UPDATE 0
#define VERSION_MINOR 2
#define VERSION ("v" STR(VERSION_MAJOR) "." STR(VERSION_UPDATE) "." STR(VERSION_MINOR))
const static unsigned int FLAG_HELP = BIT(0);
const static unsigned int FLAG_GEN= BIT(1);
// Flags for loading conf file
const static unsigned int LOAD_FLAG_ERROR= BIT(0);
const static unsigned int LOAD_FLAG_VECTOR = BIT(1);
const static unsigned int LOAD_FLAG_STRING = BIT(2);
const static unsigned int FLAG_VERSION= BIT(2);
int flags = 0;
@@ -45,85 +45,39 @@ void ReadFlags(int argc, char** argv)
{
flags |= FLAG_GEN;
}
else if(flag == "--version")
{
flags |= FLAG_VERSION;
}
}
}
}
}
void InputMultiple(const std::string& inputText, std::vector<std::string>& 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<std::string> libs;
std::vector<std::string> libdirs;
std::vector<std::string> includedirs;
std::vector<std::string> 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...");