diff options
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r-- | libcppbuild.cc | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc index 69d23ba..b400061 100644 --- a/libcppbuild.cc +++ b/libcppbuild.cc @@ -18,6 +18,7 @@ #include "task_ar.h" #include "task_so.h" #include "settings.h" +#include "execute.h" #include <unistd.h> @@ -82,8 +83,60 @@ std::shared_ptr<Task> getNextTask(const std::list<std::shared_ptr<Task>>& allTas return nullptr; } +namespace +{ +// Hack to get command-line args for re-launch +int g_argc; +char** g_argv; +} + +// TODO: Use c++20 when ready, somehing like this: +//void reg(const std::source_location location = +// std::source_location::current()) +void reg(const std::string& location) +{ + std::filesystem::path configFile(location); + std::filesystem::path binFile(configFile.stem()); + if(std::filesystem::last_write_time(binFile) <= + std::filesystem::last_write_time(configFile)) + { + std::cout << "Rebuilding config\n"; + auto ret = execute("/usr/bin/g++", + { + "-s", + "-O3", + "-std=c++17", + "-pthread", + configFile.string(), + "libcppbuild.a", + "-o", + binFile.string(), + }); + if(ret != 0) + { + std::cerr << "Failed.\n"; + exit(1); + } + else + { + std::cout << "Re-launch\n"; + std::vector<std::string> args; + for(int i = 1; i < g_argc; ++i) + { + args.push_back(g_argv[i]); + } + exit(execute(g_argv[0], args)); + } + } + +// g++ -s -O3 -std=c++17 -pthread $0 libcppbuild.a -o cppbuild +} + int main(int argc, char* argv[]) { + g_argc = argc; + g_argv = argv; + Settings settings; // TODO: Set from commandline settings.builddir = "build/foo"; |