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 # 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
View File
@@ -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
+1
View File
@@ -9,6 +9,7 @@
#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)
{ {
+5 -3
View File
@@ -10,11 +10,14 @@
#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
View File
@@ -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);
}; };
+21
View File
@@ -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;
+1
View File
@@ -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
View File
@@ -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...");