diff --git a/README.md b/README.md index fc2715a..a4a77ed 100644 --- a/README.md +++ b/README.md @@ -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. @@ -59,4 +65,4 @@ If multiple options are given to MakeGen it will execute them in the following o clean all install run Since MakeGen generates include dependencies in your Makefile it can cause the Makefile to get very cluttered. -In order to make it less cluttered you can run `makegen --simple` which will generate (and run) a Makefile without header file dependencies. \ No newline at end of file +In order to make it less cluttered you can run `makegen --simple` which will generate (and run) a Makefile without header file dependencies. diff --git a/src/Common.h b/src/Common.h index 6b5af40..6dea76f 100755 --- a/src/Common.h +++ b/src/Common.h @@ -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); diff --git a/src/ConfigCLI.cpp b/src/ConfigCLI.cpp index d8d8796..7e70407 100644 --- a/src/ConfigCLI.cpp +++ b/src/ConfigCLI.cpp @@ -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); diff --git a/src/ConfigFile.cpp b/src/ConfigFile.cpp index 46c7887..5347bee 100755 --- a/src/ConfigFile.cpp +++ b/src/ConfigFile.cpp @@ -2,6 +2,7 @@ #include "FileUtils.h" +#include #include #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::GetConfigFile(const std::string& filepath) diff --git a/src/FileUtils.h b/src/FileUtils.h index 128c2e7..89fb867 100644 --- a/src/FileUtils.h +++ b/src/FileUtils.h @@ -3,6 +3,7 @@ #include "Common.h" #include "Utils.h" #include +#include #include #include #include @@ -10,6 +11,7 @@ #include #include #include +#include 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__)