Add --simple flag which generates a simple Makefile
This commit is contained in:
@@ -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
|
# and is licensed under MIT. Full source of the project can be found at
|
||||||
# https://github.com/Thraix/MakeGen
|
# https://github.com/Thraix/MakeGen
|
||||||
CC=@g++
|
CC=@g++
|
||||||
|
|||||||
+2
-1
@@ -13,7 +13,7 @@
|
|||||||
// Release , should be backwards compatible with any minor version
|
// Release , should be backwards compatible with any minor version
|
||||||
#define MAKEGEN_VERSION_RELEASE 1
|
#define MAKEGEN_VERSION_RELEASE 1
|
||||||
// Minor changes, should be compatible with any other minor version with same major and release.
|
// 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))
|
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
|
||||||
|
|
||||||
const static unsigned int FLAG_HELP = BIT(0);
|
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_REBUILD = BIT(7);
|
||||||
const static unsigned int FLAG_SINGLE_THREAD = BIT(8);
|
const static unsigned int FLAG_SINGLE_THREAD = BIT(8);
|
||||||
const static unsigned int FLAG_DEPENDENCY = BIT(9);
|
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
|
#define LOG_INFO(...) Log(__VA_ARGS__); std::cout << std::endl
|
||||||
|
|||||||
+8
-7
@@ -8,7 +8,8 @@
|
|||||||
#define FLAG_NONE 0
|
#define FLAG_NONE 0
|
||||||
#define FLAG_VECTOR 1
|
#define FLAG_VECTOR 1
|
||||||
#define FLAG_STRING 2
|
#define FLAG_STRING 2
|
||||||
#define FLAG_BOOL 3
|
#define FLAG_BOOL 3
|
||||||
|
|
||||||
ConfigFile::ConfigFile()
|
ConfigFile::ConfigFile()
|
||||||
: outputdir("bin"), outputname("out.a"), hFile(""),executable(true), shared(true), generateHFile(false)
|
: 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())
|
if(file.is_open())
|
||||||
{
|
{
|
||||||
// config name, { pointer to memory, isDirectory}
|
// 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}},
|
{"#srcdir", {&conf.srcdir, true}},
|
||||||
{"#outputdir", {&conf.outputdir, true}},
|
{"#outputdir", {&conf.outputdir, true}},
|
||||||
@@ -42,7 +43,7 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
|
|||||||
};
|
};
|
||||||
|
|
||||||
// config name, { pointer to memory, isDirectory}
|
// 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}},
|
{"#libs", {&conf.libs, false}},
|
||||||
{"#libdirs", {&conf.libdirs, true}},
|
{"#libdirs", {&conf.libdirs, true}},
|
||||||
@@ -52,7 +53,7 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
|
|||||||
{"#dependencies", {&conf.dependencies, true}},
|
{"#dependencies", {&conf.dependencies, true}},
|
||||||
};
|
};
|
||||||
|
|
||||||
std::map<std::string, bool*> booleans =
|
std::map<std::string, bool*> booleans =
|
||||||
{
|
{
|
||||||
{"#executable", &conf.executable},
|
{"#executable", &conf.executable},
|
||||||
{"#shared", &conf.shared},
|
{"#shared", &conf.shared},
|
||||||
@@ -83,7 +84,7 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
|
|||||||
isDirectory = itVec->second.second;
|
isDirectory = itVec->second.second;
|
||||||
loadFlag = FLAG_VECTOR;
|
loadFlag = FLAG_VECTOR;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto&& itBool{booleans.find(line)};
|
auto&& itBool{booleans.find(line)};
|
||||||
if(itBool != booleans.end())
|
if(itBool != booleans.end())
|
||||||
@@ -141,7 +142,7 @@ ConfigFile ConfigFile::Load(const std::string& filepath)
|
|||||||
void ConfigFile::InputBoolean(const std::string& inputText, bool& b)
|
void ConfigFile::InputBoolean(const std::string& inputText, bool& b)
|
||||||
{
|
{
|
||||||
std::string input;
|
std::string input;
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
LOG_INFO(inputText);
|
LOG_INFO(inputText);
|
||||||
std::getline(std::cin, input);
|
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)
|
void ConfigFile::InputMultiple(const std::string& inputText, std::vector<std::string>& vec, bool needEnding)
|
||||||
{
|
{
|
||||||
std::string input;
|
std::string input;
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
InputString(inputText, input, needEnding, true);
|
InputString(inputText, input, needEnding, true);
|
||||||
if(input == "")
|
if(input == "")
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ struct FileUtils
|
|||||||
// Remove the 'from' path
|
// Remove the 'from' path
|
||||||
return to.substr(from.size()+1);
|
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)
|
else if(strncmp(from.c_str(), to.c_str(), to.size()) == 0)
|
||||||
{
|
{
|
||||||
std::string sub = from.substr(to.size());
|
std::string sub = from.substr(to.size());
|
||||||
|
|||||||
+6
-4
@@ -8,13 +8,16 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fstream>
|
#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<HFile> hFiles; // hFile, directory
|
||||||
std::set<std::string> cppFiles;
|
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");
|
std::ofstream outputFile(conf.configPath + "Makefile");
|
||||||
outputFile << "# This Makefile was generated using MakeGen "<< MAKEGEN_VERSION<< " made by Tim Håkansson" << std::endl;
|
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 << std::endl;
|
||||||
outputFile << "\t$(info -[" << (int)(i / (float)cppFiles.size() * 100) << "%]- $<)" << std::endl;
|
outputFile << "\t$(info -[" << (int)(i / (float)cppFiles.size() * 100) << "%]- $<)" << std::endl;
|
||||||
outputFile << "\t$(CC) $(CFLAGS) -o $@ $<" << std::endl;
|
outputFile << "\t$(CC) $(CFLAGS) -o $@ $<" << std::endl;
|
||||||
//std::cout << *deps << std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -8,5 +8,5 @@
|
|||||||
class Makefile
|
class Makefile
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static void Save(const ConfigFile& conf);
|
static void Save(const ConfigFile& conf, unsigned int flags);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,6 +16,27 @@ std::string Utils::CommonPrefix(const std::string& s1, const std::string& s2)
|
|||||||
return s1.substr(0, n);
|
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)
|
void Utils::GetCppAndHFiles(const ConfigFile& conf, std::set<HFile>& hFiles, std::set<std::string>& cppFiles)
|
||||||
{
|
{
|
||||||
std::vector<std::string> files;
|
std::vector<std::string> files;
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ struct HFile
|
|||||||
struct Utils
|
struct Utils
|
||||||
{
|
{
|
||||||
static std::string CommonPrefix(const std::string& s1, const std::string& s2);
|
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 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);
|
static void GetHFiles(const std::string& dependencyDir, const ConfigFile& conf, std::set<HFile>& hFiles);
|
||||||
};
|
};
|
||||||
|
|||||||
+9
-3
@@ -45,6 +45,8 @@ void PrintHelp()
|
|||||||
LOG_INFO(" make all && make run");
|
LOG_INFO(" make all && make run");
|
||||||
LOG_INFO(" -s, single Runs additional makegen options as single thread");
|
LOG_INFO(" -s, single Runs additional makegen options as single thread");
|
||||||
LOG_INFO(" (no --jobs=X flag)");
|
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("");
|
||||||
LOG_INFO(" If no option is given it will run \"make all\"");
|
LOG_INFO(" If no option is given it will run \"make all\"");
|
||||||
LOG_INFO("");
|
LOG_INFO("");
|
||||||
@@ -64,11 +66,11 @@ std::optional<ConfigFile> GetConfigFile(const std::string& filepath)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void GenMakefile(const ConfigFile& conf)
|
void GenMakefile(const ConfigFile& conf, unsigned int flags)
|
||||||
{
|
{
|
||||||
if(conf.generateHFile)
|
if(conf.generateHFile)
|
||||||
HFileGen::Create(conf);
|
HFileGen::Create(conf);
|
||||||
Makefile::Save(conf);
|
Makefile::Save(conf, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ReadFlags(int argc, char** argv)
|
unsigned int ReadFlags(int argc, char** argv)
|
||||||
@@ -118,6 +120,10 @@ unsigned int ReadFlags(int argc, char** argv)
|
|||||||
{
|
{
|
||||||
flags |= FLAG_SINGLE_THREAD;
|
flags |= FLAG_SINGLE_THREAD;
|
||||||
}
|
}
|
||||||
|
else if(flag == "--simple")
|
||||||
|
{
|
||||||
|
flags |= FLAG_SIMPLE;
|
||||||
|
}
|
||||||
else if(flag != "")
|
else if(flag != "")
|
||||||
{
|
{
|
||||||
LOG_ERROR("Unknown argument ", 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("Building ", conf.projectname);
|
||||||
LOG_INFO("Generating Makefile...");
|
LOG_INFO("Generating Makefile...");
|
||||||
Timer timer;
|
Timer timer;
|
||||||
GenMakefile(conf);
|
GenMakefile(conf, flags);
|
||||||
LOG_INFO("Took ", round(timer.Elapsed()*1000.0)/1000.0,"s");
|
LOG_INFO("Took ", round(timer.Elapsed()*1000.0)/1000.0,"s");
|
||||||
LOG_INFO("Running Makefile...");
|
LOG_INFO("Running Makefile...");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user