Add default config generation

This commit is contained in:
Thraix
2019-10-10 23:26:10 +02:00
parent 647ce0e3d8
commit 67de469181
5 changed files with 60 additions and 5 deletions
+6
View File
@@ -35,6 +35,12 @@ In order to create a MakeGen configuration file use the following command:
makegen conf gen prompt
This will prompt you with all the needed configurations in order to create a Makefile which will compile your code.
If you want to create a quick and simple config file you can also run:
makegen conf gen default
Which will default the source directory to `src/`, output directory to `bin/` and project name to the current directory name.
When this is done it will create a file called `makegen.conf` which contains all relevant data for MakeGen to create a Makefile.
If you want to change your config you can modify the makegen.conf file or use makegens config command line interface.
+3 -3
View File
@@ -9,10 +9,10 @@
// Major changes, probably not be backwards compatible
#define MAKEGEN_VERSION_MAJOR 1
// Release , should be backwards compatible with any minor version
#define MAKEGEN_VERSION_RELEASE 1
// Release, should be backwards compatible with any minor version
#define MAKEGEN_VERSION_RELEASE 2
// Minor changes, should be compatible with any other minor version with same major and release.
#define MAKEGEN_VERSION_MINOR 8
#define MAKEGEN_VERSION_MINOR 0
#define MAKEGEN_VERSION ("v" STR(MAKEGEN_VERSION_MAJOR) "." STR(MAKEGEN_VERSION_RELEASE) "." STR(MAKEGEN_VERSION_MINOR))
const static unsigned int FLAG_HELP = BIT(0);
+8
View File
@@ -34,6 +34,9 @@ void ConfigCLI::DisplayGenHelp()
LOG_INFO("");
LOG_INFO("options:");
LOG_INFO(" prompt Prompt the user for all needed settings");
LOG_INFO(" default Generate a default config file. Source directory is set to");
LOG_INFO(" src/, outputdir is set to bin/ and project name is set to");
LOG_INFO(" the current directory name.");
}
void ConfigCLI::DisplayAddHelp()
@@ -158,6 +161,11 @@ int ConfigCLI::Gen(int argc, char** argv)
ConfigFile::Gen().Save();
return 0;
}
if(option == "default")
{
ConfigFile{}.Save();
return 0;
}
else
{
LOG_ERROR("Invalid option: ", option);
+26 -1
View File
@@ -2,6 +2,7 @@
#include "FileUtils.h"
#include <algorithm>
#include <fstream>
#define FLAG_NONE 0
@@ -10,8 +11,32 @@
#define FLAG_BOOL 3
ConfigFile::ConfigFile()
: outputdir("bin"), outputname("out.a"), hFile(""),executable(true), shared(true), generateHFile(false)
: outputdir("bin/"), srcdir("src/"), outputname(""), projectname(FileUtils::GetCurrentDirectory()), hFile(""), executable(true), shared(true), generateHFile(false)
{
// Converts project name (current directory) to lowercase
// and replace whitespace with underscore
std::transform(
projectname.begin(),
projectname.end(),
std::back_inserter(outputname),
[](unsigned char c)
{
if(c == ' ')
return '_';
return (char)std::tolower(c);
});
// Removes all other characters
std::remove_if(
outputdir.begin(),
outputdir.end(),
[](unsigned char c)
{
return (c < 'a' || c > 'z') && c != '_';
});
// Add suffix
outputname += ".out";
}
std::optional<ConfigFile> ConfigFile::GetConfigFile(const std::string& filepath)
+16
View File
@@ -3,6 +3,7 @@
#include "Common.h"
#include "Utils.h"
#include <algorithm>
#include <assert.h>
#include <cstring>
#include <dirent.h>
#include <fstream>
@@ -10,6 +11,7 @@
#include <stdlib.h>
#include <string>
#include <vector>
#include <unistd.h>
struct FileUtils
{
@@ -28,6 +30,20 @@ struct FileUtils
return mkdir(path.c_str(), 0777);
}
static std::string GetCurrentDirectory()
{
static char path[256]; // Usual maximum filename
getcwd(path, sizeof(path));
std::string dir = path;
size_t pos = dir.find_last_of("/");
if(pos == std::string::npos)
{
LOG_ERROR("Couldn't find / (slash) in directory. This shouldn't occur.");
assert(false);
}
return dir.substr(pos+1);
}
static std::string GetRealPath(const std::string& filename)
{
#if defined(__linux__)