From 21809e3724f3d830aec25197f5939f4f7d84352b Mon Sep 17 00:00:00 2001 From: Thraix Date: Sun, 18 Nov 2018 00:32:31 +0100 Subject: [PATCH] Add shared settings to makegen --- .gitignore | 0 .ycm_extra_conf.py | 0 LICENSE | 0 Makefile | 0 makegen.conf | 0 src/Common.h | 2 +- src/ConfigFile.cpp | 21 ++++++++++++++++++++- src/ConfigFile.h | 1 + src/IncludeDeps.cpp | 0 src/IncludeDeps.h | 0 src/Makefile.cpp | 18 +++++++++++++++--- src/Makefile.h | 0 src/Timer.h | 0 src/main.cpp | 0 14 files changed, 37 insertions(+), 5 deletions(-) mode change 100644 => 100755 .gitignore mode change 100644 => 100755 .ycm_extra_conf.py mode change 100644 => 100755 LICENSE mode change 100644 => 100755 Makefile mode change 100644 => 100755 makegen.conf mode change 100644 => 100755 src/Common.h mode change 100644 => 100755 src/ConfigFile.cpp mode change 100644 => 100755 src/ConfigFile.h mode change 100644 => 100755 src/IncludeDeps.cpp mode change 100644 => 100755 src/IncludeDeps.h mode change 100644 => 100755 src/Makefile.cpp mode change 100644 => 100755 src/Makefile.h mode change 100644 => 100755 src/Timer.h mode change 100644 => 100755 src/main.cpp diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/.ycm_extra_conf.py b/.ycm_extra_conf.py old mode 100644 new mode 100755 diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/Makefile b/Makefile old mode 100644 new mode 100755 diff --git a/makegen.conf b/makegen.conf old mode 100644 new mode 100755 diff --git a/src/Common.h b/src/Common.h old mode 100644 new mode 100755 index b047f50..492b16b --- a/src/Common.h +++ b/src/Common.h @@ -12,7 +12,7 @@ // Release , should be backwards compatible with any minor version #define MAKEGEN_VERSION_RELEASE 0 // 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); diff --git a/src/ConfigFile.cpp b/src/ConfigFile.cpp old mode 100644 new mode 100755 index 7115264..85dbeae --- a/src/ConfigFile.cpp +++ b/src/ConfigFile.cpp @@ -8,7 +8,7 @@ #define FLAG_STRING 2 #define FLAG_BOOL 3 ConfigFile::ConfigFile() - : outputdir("bin"), outputname("out.a"),executable(true) + : outputdir("bin"), outputname("out.a"),executable(true), shared(true) { } @@ -74,6 +74,11 @@ ConfigFile ConfigFile::Load() b = &conf.executable; loadFlag = FLAG_BOOL; } + else if(line == "#shared") + { + b = &conf.shared; + loadFlag = FLAG_BOOL; + } else { LOG_ERROR("Invalid flag"); @@ -134,6 +139,18 @@ ConfigFile ConfigFile::Gen() InputMultiple("Enter library:", conf.libs,false); InputMultiple("Enter library directory:", conf.libdirs,true); } + else + { + while(input == "") + { + LOG_INFO("Should it be compiled as a shared library (y/n):"); + std::getline(std::cin, input); + if(input[0] != 'y' && input[0] != 'n') + input = ""; + } + conf.shared = input[0] == 'y'; + + } InputMultiple("Enter include directory:", conf.includedirs,true); InputMultiple("Enter source directories:", conf.srcdirs,true); InputMultiple("Enter preprocessor definitions:", conf.defines,false); @@ -191,5 +208,7 @@ void ConfigFile::Save() const file << outputname << std::endl; file << "#executable" << std::endl; file << (executable ? "true" : "false") << std::endl; + file << "#shared" << std::endl; + file << (shared ? "true" : "false") << std::endl; file.close(); } diff --git a/src/ConfigFile.h b/src/ConfigFile.h old mode 100644 new mode 100755 index 7cf4b76..8c045ee --- a/src/ConfigFile.h +++ b/src/ConfigFile.h @@ -15,6 +15,7 @@ class ConfigFile std::string outputname; std::string projectname; bool executable; + bool shared; public: ConfigFile(); void Save() const; diff --git a/src/IncludeDeps.cpp b/src/IncludeDeps.cpp old mode 100644 new mode 100755 diff --git a/src/IncludeDeps.h b/src/IncludeDeps.h old mode 100644 new mode 100755 diff --git a/src/Makefile.cpp b/src/Makefile.cpp old mode 100644 new mode 100755 index 091d7e2..6705c4b --- a/src/Makefile.cpp +++ b/src/Makefile.cpp @@ -45,7 +45,12 @@ void Makefile::Save(const ConfigFile& conf) outputFile << "# https://github.com/Thraix/MakeGen" << std::endl; outputFile << "CC=@g++" << std::endl; if(!conf.executable) - outputFile << "CO=@ar rs" << std::endl; + { + if(conf.shared) + outputFile << "CO=@g++ -shared -o" << std::endl; + else + outputFile << "CO=@g++ -o" << std::endl; + } else outputFile << "CO=@g++ -o" << std::endl; @@ -65,7 +70,14 @@ void Makefile::Save(const ConfigFile& conf) outputFile << "$(OBJPATH)/" << it->first.substr(slash, extensionPos - slash) << ".o "; } outputFile << std::endl; - outputFile << "CFLAGS=$(INCLUDES) -std=c++17 -c -w -g3 "; + if(conf.executable || !conf.shared) + { + outputFile << "CFLAGS=$(INCLUDES) -std=c++17 -c -w -g3 "; + } + else + { + outputFile << "CFLAGS=$(INCLUDES) -fPIC -std=c++17 -c -w -g3 "; + } for(auto it = conf.defines.begin();it!=conf.defines.end();++it) { outputFile << "-D" << *it << " "; @@ -149,5 +161,5 @@ void Makefile::PreSave(const ConfigFile& conf, std::map