summaryrefslogtreecommitdiff
path: root/libcppbuild.cc
diff options
context:
space:
mode:
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";