Move Config gen stuff to ConfigFile.cpp, Add version flag
This commit is contained in:
@@ -11,10 +11,7 @@ CFLAGS=$(INCLUDES) -std=c++17 -c -w -g3 -D_DEBUG
|
|||||||
LIBS=
|
LIBS=
|
||||||
OUTPUT=$(BIN)makegen
|
OUTPUT=$(BIN)makegen
|
||||||
all: $(OUTPUT)
|
all: $(OUTPUT)
|
||||||
$(info ------------------------)
|
rebuild: clean all
|
||||||
$(info ---- Done Compiling ----)
|
|
||||||
$(info ------------------------)
|
|
||||||
rebuid: clean all
|
|
||||||
clean:
|
clean:
|
||||||
$(info Removing intermediates)
|
$(info Removing intermediates)
|
||||||
rm -rf $(OBJPATH)/*.o
|
rm -rf $(OBJPATH)/*.o
|
||||||
|
|||||||
+11
-4
@@ -1,8 +1,15 @@
|
|||||||
|
#libs
|
||||||
|
#libdirs
|
||||||
|
#includedirs
|
||||||
#srcdirs
|
#srcdirs
|
||||||
src/
|
src/
|
||||||
#outputdir
|
|
||||||
bin/
|
|
||||||
#outputname
|
|
||||||
makegen
|
|
||||||
#defines
|
#defines
|
||||||
_DEBUG
|
_DEBUG
|
||||||
|
#outputdir
|
||||||
|
bin/
|
||||||
|
#projectname
|
||||||
|
MakeGen
|
||||||
|
#outputname
|
||||||
|
makegen
|
||||||
|
#executable
|
||||||
|
true
|
||||||
|
|||||||
@@ -65,6 +65,11 @@ ConfigFile ConfigFile::Load()
|
|||||||
s = &conf.outputname;
|
s = &conf.outputname;
|
||||||
loadFlag = FLAG_STRING;
|
loadFlag = FLAG_STRING;
|
||||||
}
|
}
|
||||||
|
else if(line == "#projectname")
|
||||||
|
{
|
||||||
|
s = &conf.projectname;
|
||||||
|
loadFlag = FLAG_STRING;
|
||||||
|
}
|
||||||
else if(line == "#executable")
|
else if(line == "#executable")
|
||||||
{
|
{
|
||||||
b = &conf.executable;
|
b = &conf.executable;
|
||||||
@@ -96,3 +101,92 @@ ConfigFile ConfigFile::Load()
|
|||||||
}
|
}
|
||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigFile::InputMultiple(const std::string& inputText, std::vector<std::string>& 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();
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,10 +13,13 @@ class ConfigFile
|
|||||||
std::vector<std::string> defines;
|
std::vector<std::string> defines;
|
||||||
std::string outputdir;
|
std::string outputdir;
|
||||||
std::string outputname;
|
std::string outputname;
|
||||||
|
std::string projectname;
|
||||||
bool executable;
|
bool executable;
|
||||||
public:
|
public:
|
||||||
ConfigFile();
|
ConfigFile();
|
||||||
void Save() const;
|
void Save() const;
|
||||||
static ConfigFile Gen();
|
static ConfigFile Gen();
|
||||||
static ConfigFile Load();
|
static ConfigFile Load();
|
||||||
|
private:
|
||||||
|
static void InputMultiple(const std::string& inputText, std::vector<std::string>& vec, bool needEnding);
|
||||||
};
|
};
|
||||||
|
|||||||
+5
-5
@@ -79,10 +79,10 @@ void Makefile::Save(const ConfigFile& conf)
|
|||||||
outputFile << std::endl;
|
outputFile << std::endl;
|
||||||
outputFile << "OUTPUT=$(BIN)" << conf.outputname << std::endl;
|
outputFile << "OUTPUT=$(BIN)" << conf.outputname << std::endl;
|
||||||
outputFile << "all: $(OUTPUT)" << std::endl;
|
outputFile << "all: $(OUTPUT)" << std::endl;
|
||||||
outputFile << "\t$(info ------------------------)" << std::endl;
|
//outputFile << "\t$(info ------------------------)" << std::endl;
|
||||||
outputFile << "\t$(info ---- Done Compiling ----)" << std::endl;
|
//outputFile << "\t$(info ---- Done Compiling ----)" << std::endl;
|
||||||
outputFile << "\t$(info ------------------------)" << std::endl;
|
//outputFile << "\t$(info ------------------------)" << std::endl;
|
||||||
outputFile << "rebuid: clean all" << std::endl;
|
outputFile << "rebuild: clean all" << std::endl;
|
||||||
outputFile << "clean:" << std::endl;
|
outputFile << "clean:" << std::endl;
|
||||||
outputFile << "\t$(info Removing intermediates)" << std::endl;
|
outputFile << "\t$(info Removing intermediates)" << std::endl;
|
||||||
outputFile << "\trm -rf $(OBJPATH)/*.o" << 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$(info Generating output file)" << std::endl;
|
||||||
outputFile << "\t$(CO) $(OUTPUT) $(OBJECTS) $(LIBS)" << std::endl;
|
outputFile << "\t$(CO) $(OUTPUT) $(OBJECTS) $(LIBS)" << std::endl;
|
||||||
outputFile << "install: all" << 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;
|
outputFile << "\t@cp $(OUTPUT) /usr/bin/" << conf.outputname << std::endl;
|
||||||
std::map<std::string, IncludeDeps*> dependencies;
|
std::map<std::string, IncludeDeps*> dependencies;
|
||||||
for(auto it = cppFiles.begin(); it!=cppFiles.end();++it)
|
for(auto it = cppFiles.begin(); it!=cppFiles.end();++it)
|
||||||
|
|||||||
+19
-65
@@ -10,15 +10,15 @@
|
|||||||
#include "Logging.h"
|
#include "Logging.h"
|
||||||
|
|
||||||
#define BIT(x) (1<<x)
|
#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_HELP = BIT(0);
|
||||||
const static unsigned int FLAG_GEN= BIT(1);
|
const static unsigned int FLAG_GEN= BIT(1);
|
||||||
|
const static unsigned int FLAG_VERSION= BIT(2);
|
||||||
// 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);
|
|
||||||
|
|
||||||
|
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
@@ -45,85 +45,39 @@ void ReadFlags(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
flags |= FLAG_GEN;
|
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)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
ReadFlags(argc,argv);
|
ReadFlags(argc,argv);
|
||||||
if((flags & FLAG_HELP))
|
if(flags & FLAG_HELP)
|
||||||
{
|
{
|
||||||
LOG_INFO("Usage: makegen [options]");
|
LOG_INFO("Usage: makegen [options]");
|
||||||
LOG_INFO(" Options:");
|
LOG_INFO(" Options:");
|
||||||
LOG_INFO(" --help\tDisplays this information");
|
LOG_INFO(" --help\tDisplays this information");
|
||||||
LOG_INFO(" --conf\tGenerate a config file for the project");
|
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(" install\tGenerates a Makefile and runs make install");
|
||||||
LOG_INFO(" clean\tGenerates a Makefile and runs make clean");
|
LOG_INFO(" clean\tGenerates a Makefile and runs make clean");
|
||||||
LOG_INFO(" rebuild\tGenerates a Makefile and runs make rebuild");
|
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");
|
LOG_INFO(" If no option is given it will generate a Makefile and run default make");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if(flags & FLAG_VERSION)
|
||||||
|
{
|
||||||
|
LOG_INFO("MakeGen ",VERSION);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
if(flags & FLAG_GEN)
|
if(flags & FLAG_GEN)
|
||||||
{
|
{
|
||||||
GenConfFile();
|
ConfigFile::Gen().Save();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
LOG_INFO("Generating Makefile...");
|
LOG_INFO("Generating Makefile...");
|
||||||
|
|||||||
Reference in New Issue
Block a user