summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/build.cc25
-rw-r--r--src/configure.cc58
-rw-r--r--src/libctor.h3
-rw-r--r--src/rebuild.cc14
4 files changed, 89 insertions, 11 deletions
diff --git a/src/build.cc b/src/build.cc
index 1b70c5b..425ccd3 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -78,16 +78,19 @@ int build(const Settings& settings,
process != processes.end();
++process)
{
- if(process->valid())
+ if(process->valid() == false)
{
- if(process->get() != 0)
- {
- // TODO: Wait for other processes to finish before returning
- return 1;
- }
- processes.erase(process);
- break;
+ continue;
+ }
+
+ auto ret = process->get();
+ if(ret != 0)
+ {
+ // NOTE Wait for other processes to finish before returning
+ return ret;
}
+ processes.erase(process);
+ break;
}
if(started_one)
@@ -104,11 +107,15 @@ int build(const Settings& settings,
process != processes.end();
++process)
{
+ if(process->valid() == false)
+ {
+ continue;
+ }
process->wait();
auto ret = process->get();
if(ret != 0)
{
- return 1;
+ return ret;
}
}
diff --git a/src/configure.cc b/src/configure.cc
index b3517dc..9eca0d6 100644
--- a/src/configure.cc
+++ b/src/configure.cc
@@ -6,6 +6,7 @@
#include <iostream>
#include <filesystem>
#include <fstream>
+#include <optional>
#include <getoptpp/getoptpp.hpp>
@@ -13,6 +14,7 @@
#include "execute.h"
#include "libctor.h"
#include "tasks.h"
+#include "rebuild.h"
std::filesystem::path configurationFile("configuration.cc");
std::filesystem::path configHeaderFile("config.h");
@@ -23,8 +25,24 @@ const std::map<std::string, std::string>& __attribute__((weak)) configuration()
return default_configuration;
}
+namespace ctor
+{
+std::optional<std::string> includedir;
+std::optional<std::string> libdir;
+}
+
bool hasConfiguration(const std::string& key)
{
+ if(key == cfg::ctor_includedir && ctor::includedir)
+ {
+ return true;
+ }
+
+ if(key == cfg::ctor_libdir && ctor::libdir)
+ {
+ return true;
+ }
+
const auto& c = configuration();
return c.find(key) != c.end();
}
@@ -32,6 +50,16 @@ bool hasConfiguration(const std::string& key)
const std::string& getConfiguration(const std::string& key,
const std::string& defaultValue)
{
+ if(key == cfg::ctor_includedir && ctor::includedir)
+ {
+ return *ctor::includedir;
+ }
+
+ if(key == cfg::ctor_libdir && ctor::libdir)
+ {
+ return *ctor::libdir;
+ }
+
const auto& c = configuration();
if(hasConfiguration(key))
{
@@ -119,6 +147,8 @@ int configure(int argc, char* argv[])
std::string cxx_prog = "g++";
std::string ar_prog = "ar";
std::string ld_prog = "ld";
+ std::string ctor_includedir;
+ std::string ctor_libdir;
opt.add("build-dir", required_argument, 'b',
"Set output directory for build files (default: '" +
@@ -191,6 +221,20 @@ int configure(int argc, char* argv[])
return 0;
});
+ opt.add("ctor-includedir", required_argument, key++,
+ "Set path to ctor header file, used for re-compiling.",
+ [&]() {
+ ctor_includedir = optarg;
+ return 0;
+ });
+
+ opt.add("ctor-libdir", required_argument, key++,
+ "Set path to ctor library file, used for re-compiling.",
+ [&]() {
+ ctor_libdir = optarg;
+ return 0;
+ });
+
opt.add("help", no_argument, 'h',
"Print this help text.",
[&]() {
@@ -273,7 +317,7 @@ int configure(int argc, char* argv[])
std::cout << "Writing results to: " << configurationFile.string() << "\n";
{
std::ofstream istr(configurationFile);
- istr << "#include \"libctor.h\"\n\n";
+ istr << "#include <libctor.h>\n\n";
istr << "const std::map<std::string, std::string>& configuration()\n";
istr << "{\n";
istr << " static std::map<std::string, std::string> c =\n";
@@ -288,6 +332,16 @@ int configure(int argc, char* argv[])
istr << " { \"" << cfg::build_cxx << "\", \"" << build_cxx << "\" },\n";
istr << " { \"" << cfg::build_ar << "\", \"" << build_ar << "\" },\n";
istr << " { \"" << cfg::build_ld << "\", \"" << build_ld << "\" },\n";
+ if(!ctor_includedir.empty())
+ {
+ istr << " { \"" << cfg::ctor_includedir << "\", \"" << ctor_includedir << "\" },\n";
+ ctor::includedir = ctor_includedir;
+ }
+ if(!ctor_libdir.empty())
+ {
+ istr << " { \"" << cfg::ctor_libdir << "\", \"" << ctor_libdir << "\" },\n";
+ ctor::libdir = ctor_libdir;
+ }
istr << " };\n";
istr << " return c;\n";
istr << "}\n";
@@ -300,5 +354,7 @@ int configure(int argc, char* argv[])
istr << "//#define HAS_BAR 1\n";
}
+ recompileCheck(settings, 1, argv, true, false);
+
return 0;
}
diff --git a/src/libctor.h b/src/libctor.h
index 70c62a8..6903c6b 100644
--- a/src/libctor.h
+++ b/src/libctor.h
@@ -71,6 +71,9 @@ constexpr auto build_cc = "build-cc";
constexpr auto build_cxx = "build-cpp";
constexpr auto build_ar = "build-ar";
constexpr auto build_ld = "build-ld";
+
+constexpr auto ctor_includedir = "ctor-includedir";
+constexpr auto ctor_libdir = "ctor-libdir";
}
const std::map<std::string, std::string>& configuration();
diff --git a/src/rebuild.cc b/src/rebuild.cc
index 353beb0..7c90fca 100644
--- a/src/rebuild.cc
+++ b/src/rebuild.cc
@@ -60,12 +60,24 @@ int unreg(const char* location)
void recompileCheck(const Settings& settings, int argc, char* argv[],
bool force, bool relaunch_allowed)
{
+ using namespace std::string_literals;
+
bool dirty{force};
std::vector<std::string> args;
args.push_back("-s");
args.push_back("-O3");
args.push_back("-std=c++17");
+
+ if(hasConfiguration(cfg::ctor_includedir))
+ {
+ args.push_back("-I"s + getConfiguration(cfg::ctor_includedir));
+ }
+ if(hasConfiguration(cfg::ctor_libdir))
+ {
+ args.push_back("-L"s + getConfiguration(cfg::ctor_libdir));
+ }
+ args.push_back("-lctor");
args.push_back("-pthread");
std::filesystem::path binFile(argv[0]);
@@ -113,7 +125,7 @@ void recompileCheck(const Settings& settings, int argc, char* argv[],
args.push_back(location);
}
}
- args.push_back("libctor.a");
+
args.push_back("-o");
args.push_back(binFile.string());