summaryrefslogtreecommitdiff
path: root/libcppbuild.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-06-19 09:18:26 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-06-19 09:18:26 +0200
commita2be8eba3aaf11a9a73092793d27d6d46b4270cd (patch)
treeec8d463fe0537785337b4632e0c59bc1185b68dc /libcppbuild.cc
parent80290e7d65dc498e9ea5e64aa6cbc65282072deb (diff)
Add .so target. Fix ready state checks.
Diffstat (limited to 'libcppbuild.cc')
-rw-r--r--libcppbuild.cc76
1 files changed, 63 insertions, 13 deletions
diff --git a/libcppbuild.cc b/libcppbuild.cc
index 7f0a355..69d23ba 100644
--- a/libcppbuild.cc
+++ b/libcppbuild.cc
@@ -10,10 +10,13 @@
#include <algorithm>
#include <list>
+#include <getoptpp/getoptpp.hpp>
+
#include "libcppbuild.h"
#include "task_cc.h"
#include "task_ld.h"
#include "task_ar.h"
+#include "task_so.h"
#include "settings.h"
#include <unistd.h>
@@ -23,6 +26,8 @@ using namespace std::chrono_literals;
std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config,
const Settings& settings)
{
+ std::filesystem::path targetFile(config.target);
+
std::vector<std::string> objects;
std::list<std::shared_ptr<Task>> tasks;
for(const auto& file : config.sources)
@@ -31,19 +36,28 @@ std::list<std::shared_ptr<Task>> taskFactory(const BuildConfiguration& config,
objects.push_back(tasks.back()->target());
}
- std::filesystem::path targetFile(config.target);
if(targetFile.extension() == ".a")
{
// static lib
tasks.emplace_back(std::make_shared<TaskAR>(config, settings, config.target,
objects));
}
+ else if(targetFile.extension() == ".so")
+ {
+ if(targetFile.stem().string().substr(0, 3) != "lib")
+ {
+ std::cerr << "Dynamic library target must have 'lib' prefix\n";
+ exit(1);
+ }
+ // dynamic lib
+ tasks.emplace_back(std::make_shared<TaskSO>(config, settings, config.target,
+ objects));
+ }
else
{
- // binary
+ // executable
tasks.emplace_back(std::make_shared<TaskLD>(config, settings, config.target,
objects));
-
}
return tasks;
@@ -68,10 +82,9 @@ std::shared_ptr<Task> getNextTask(const std::list<std::shared_ptr<Task>>& allTas
return nullptr;
}
-int main(int argc, const char* argv[])
+int main(int argc, char* argv[])
{
Settings settings;
-
// TODO: Set from commandline
settings.builddir = "build/foo";
@@ -80,6 +93,40 @@ int main(int argc, const char* argv[])
settings.verbose = 0;
+ dg::Options opt;
+
+ opt.add("jobs", required_argument, 'j',
+ "Number of parallel jobs.",
+ [&]() {
+ try
+ {
+ settings.parallel_processes = std::stoi(optarg);
+ }
+ catch(...)
+ {
+ std::cerr << "Not a number\n";
+ return 1;
+ }
+ return 0;
+ });
+
+ opt.add("verbose", no_argument, 'v',
+ "Be verbose.",
+ [&]() {
+ settings.verbose++;
+ return 0;
+ });
+
+ opt.add("help", no_argument, 'h',
+ "Print this help text.",
+ [&]() {
+ std::cout << "usage stuff\n";
+ opt.help();
+ return 0;
+ });
+
+ opt.process(argc, argv);
+
std::filesystem::path builddir(settings.builddir);
std::filesystem::create_directories(builddir);
@@ -106,19 +153,22 @@ int main(int argc, const char* argv[])
}
}
- if(argc == 2 && std::string(argv[1]) == "clean")
+ for(auto const &arg : opt.arguments())
{
- std::cout << "Cleaning\n";
- //std::filesystem::remove_all(builddir);
- for(auto& task : tasks)
+ if(arg == "clean")
{
- if(task->clean() != 0)
+ std::cout << "Cleaning\n";
+ //std::filesystem::remove_all(builddir);
+ for(auto& task : tasks)
{
- return 1;
+ if(task->clean() != 0)
+ {
+ return 1;
+ }
}
- }
- return 0;
+ return 0;
+ }
}
std::cout << "Building\n";