Add --simple flag which generates a simple Makefile

This commit is contained in:
Thraix
2019-10-05 16:51:43 +02:00
parent 6b2b83d25c
commit ec98ddbfd4
9 changed files with 50 additions and 18 deletions
+1 -1
View File
@@ -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++
+2 -1
View File
@@ -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
+8 -7
View File
@@ -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<std::string, std::pair<std::string*, bool>> strings =
std::map<std::string, std::pair<std::string*, bool>> 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<std::string, std::pair<std::vector<std::string>*, bool>> vectors =
std::map<std::string, std::pair<std::vector<std::string>*, 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<std::string, bool*> booleans =
std::map<std::string, bool*> 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<std::string>& vec, bool needEnding)
{
std::string input;
while(true)
while(true)
{
InputString(inputText, input, needEnding, true);
if(input == "")
+1 -1
View File
@@ -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());
+6 -4
View File
@@ -8,13 +8,16 @@
#include <cstring>
#include <dirent.h>
#include <fstream>
#include <map>
#include <map>
void Makefile::Save(const ConfigFile& conf)
void Makefile::Save(const ConfigFile& conf, unsigned int flags)
{
std::set<HFile> hFiles; // hFile, directory
std::set<std::string> 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;
}
}
}
+1 -1
View File
@@ -8,5 +8,5 @@
class Makefile
{
public:
static void Save(const ConfigFile& conf);
static void Save(const ConfigFile& conf, unsigned int flags);
};
+21
View File
@@ -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<std::string>& cppFiles)
{
std::vector<std::string> 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<HFile>& hFiles, std::set<std::string>& cppFiles)
{
std::vector<std::string> files;
+1
View File
@@ -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<std::string>& cppFiles);
static void GetCppAndHFiles(const ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles);
static void GetHFiles(const std::string& dependencyDir, const ConfigFile& conf, std::set<HFile>& hFiles);
};
+9 -3
View File
@@ -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<ConfigFile> 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...");