summaryrefslogtreecommitdiff
path: root/src/libctor.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/libctor.cc')
-rw-r--r--src/libctor.cc114
1 files changed, 112 insertions, 2 deletions
diff --git a/src/libctor.cc b/src/libctor.cc
index 6e6bcaf..230662a 100644
--- a/src/libctor.cc
+++ b/src/libctor.cc
@@ -66,6 +66,7 @@ int main(int argc, char* argv[])
bool list_targets{false};
bool no_relaunch{false}; // true means no re-launch after rebuild.
bool run_unittests{false};
+ bool install{false};
std::vector<std::string> arguments;
arg::Parser<int, std::string> opt(argc, argv);
opt.set_pos_cb(
@@ -504,7 +505,11 @@ Options:
archive_write_close(a); // Note 4
archive_write_free(a); // Note 5
}
- return 0;
+ }
+ else if(arg == "install")
+ {
+ install = true;
+ build_all = true;
}
else
{
@@ -562,7 +567,112 @@ Options:
if(run_unittests)
{
- return runUnitTests(all_tasks, settings);
+ auto ret = runUnitTests(all_tasks, settings);
+ if(ret != 0)
+ {
+ return ret;
+ }
+ }
+
+ if(install)
+ {
+ auto destdir_env = std::getenv("DESTDIR");
+ if(!destdir_env)
+ {
+ std::cerr << "No DESTDIR provided!\n";
+ return 1;
+ }
+ std::filesystem::path destdir = destdir_env;
+ if(!destdir.is_absolute())
+ {
+ std::cerr << "DESTDIR must be absolute!\n";
+ return 1;
+ }
+ std::cout << "Installing in DESTDIR: " << destdir.string() << "\n";
+ std::string prefix = "/usr";
+ for(const auto& task : all_tasks)
+ {
+ auto install_target = task->buildConfig().install;
+ if(!task->derived() && install_target.do_install)
+ {
+ std::string target_dir{};
+ if(!install_target.path.empty())
+ {
+ target_dir = install_target.path;
+ }
+ else
+ {
+ switch(task->targetType())
+ {
+ case ctor::target_type::unit_test:
+ case ctor::target_type::unit_test_library:
+ case ctor::target_type::object:
+ case ctor::target_type::function:
+ case ctor::target_type::automatic:
+ case ctor::target_type::unknown:
+ // Ignore
+ continue;
+ break;
+ case ctor::target_type::executable:
+ target_dir = "bin";
+ break;
+ case ctor::target_type::shared_library:
+ case ctor::target_type::static_library:
+ case ctor::target_type::module:
+ target_dir = "lib";
+ break;
+ }
+ }
+ std::filesystem::path target;
+ target = prefix;
+ target /= target_dir;
+ target /= task->target();
+ if(destdir_env)
+ {
+ if(target.is_absolute())
+ {
+ target = destdir / target.relative_path();
+ }
+ else
+ {
+ target = destdir / target;
+ }
+ }
+ std::cout << "Bin install " << task->target() <<
+ " -> " << target.string() << "\n";
+ }
+ }
+
+ auto& targets = getTargets(settings);
+ for(const auto& target : targets)
+ {
+ for(const auto& header : target.config.headers)
+ {
+ if(header.install.do_install)
+ {
+ std::filesystem::path target_file = prefix;
+ target_file /= "include";
+ if(!header.install.path.empty())
+ {
+ target_file /= header.install.path;
+ }
+ target_file /= std::filesystem::path(header.file).filename();
+ if(destdir_env)
+ {
+ if(target_file.is_absolute())
+ {
+ target_file = destdir / target_file.relative_path();
+ }
+ else
+ {
+ target_file = destdir / target_file;
+ }
+ }
+ std::cout << "Include/header install " << header.file <<
+ " -> " << target_file.string() << "\n";
+ }
+ }
+ }
}
return 0;