From 5529b296834965afd9736b941aa2c094ff2f4648 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 2 Sep 2021 20:22:58 +0200 Subject: Rename project to ctor. --- src/configure.cc | 4 +- src/libcppbuild.cc | 316 ----------------------------------------------------- src/libcppbuild.h | 76 ------------- src/libctor.cc | 316 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/libctor.h | 76 +++++++++++++ src/rebuild.cc | 4 +- src/rebuild.h | 2 +- src/task.h | 2 +- src/task_ar.cc | 2 +- src/task_cc.cc | 2 +- src/task_ld.cc | 2 +- src/task_so.cc | 2 +- src/tasks.cc | 2 +- 13 files changed, 403 insertions(+), 403 deletions(-) delete mode 100644 src/libcppbuild.cc delete mode 100644 src/libcppbuild.h create mode 100644 src/libctor.cc create mode 100644 src/libctor.h (limited to 'src') diff --git a/src/configure.cc b/src/configure.cc index ab2f837..1598251 100644 --- a/src/configure.cc +++ b/src/configure.cc @@ -8,7 +8,7 @@ #include "settings.h" #include "execute.h" -#include "libcppbuild.h" +#include "libctor.h" #include "tasks.h" std::filesystem::path configurationFile("configuration.cc"); @@ -270,7 +270,7 @@ int configure(int argc, char* argv[]) std::cout << "Writing results to: " << configurationFile.string() << "\n"; { std::ofstream istr(configurationFile); - istr << "#include \"libcppbuild.h\"\n\n"; + istr << "#include \"libctor.h\"\n\n"; istr << "const std::map& configuration()\n"; istr << "{\n"; istr << " static std::map c =\n"; diff --git a/src/libcppbuild.cc b/src/libcppbuild.cc deleted file mode 100644 index d3d8a51..0000000 --- a/src/libcppbuild.cc +++ /dev/null @@ -1,316 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "libcppbuild.h" -#include "settings.h" -#include "configure.h" -#include "rebuild.h" -#include "tasks.h" -#include "build.h" -int main(int argc, char* argv[]) -{ - if(argc > 1 && std::string(argv[1]) == "configure") - { - return configure(argc, argv); - } - - Settings settings{}; - - settings.builddir = getConfiguration(cfg::builddir, "build"); - settings.parallel_processes = - std::max(1u, std::thread::hardware_concurrency() * 2 - 1); - settings.verbose = 0; - - bool write_compilation_database{false}; - std::string compilation_database; - bool print_configure_cmd{false}; - bool print_configure_db{false}; - std::vector add_files; - std::vector remove_files; - bool list_files{false}; - bool list_targets{false}; - bool no_relaunch{false}; // true means no re-launch after rebuild. - - dg::Options opt; - int key{128}; - - opt.add("jobs", required_argument, 'j', - "Number of parallel jobs. (default: cpucount * 2 - 1)", - [&]() { - try - { - settings.parallel_processes = std::stoi(optarg); - } - catch(...) - { - std::cerr << "Not a number\n"; - return 1; - } - return 0; - }); - - opt.add("build-dir", required_argument, 'b', - "Overload output directory for build files (default: '" + - settings.builddir + "').", - [&]() { - settings.builddir = optarg; - return 0; - }); - - opt.add("verbose", no_argument, 'v', - "Be verbose. Add multiple times for more verbosity.", - [&]() { - settings.verbose++; - return 0; - }); - - opt.add("add", required_argument, 'a', - "Add specified file to the build configurations.", - [&]() { - no_relaunch = true; - add_files.push_back(optarg); - return 0; - }); - - opt.add("remove", required_argument, 'r', - "Remove specified file from the build configurations.", - [&]() { - no_relaunch = true; - remove_files.push_back(optarg); - return 0; - }); - - opt.add("list-files", no_argument, 'L', - "List files in the build configurations.", - [&]() { - no_relaunch = true; - list_files = true; - return 0; - }); - - opt.add("list-targets", no_argument, 'l', - "List targets.", - [&]() { - no_relaunch = true; - list_targets = true; - return 0; - }); - - opt.add("configure-cmd", no_argument, key++, - "Print commandline for last configure.", - [&]() { - no_relaunch = true; - print_configure_cmd = true; - return 0; - }); - - opt.add("configure-db", no_argument, key++, - "Print entire configure parameter database.", - [&]() { - no_relaunch = true; - print_configure_db = true; - return 0; - }); - - opt.add("database", required_argument, 'd', - "Write compilation database json file.", - [&]() { - no_relaunch = true; - write_compilation_database = true; - compilation_database = optarg; - return 0; - }); - - opt.add("help", no_argument, 'h', - "Print this help text.", - [&]() { - std::cout << "Usage: " << argv[0] << " [options] [target] ...\n"; - std::cout << -R"_( where target can be either: - configure - run configuration step (cannot be used with other targets). - clean - clean all generated files. - all - build all targets (default) - or the name of a target which will be built along with its dependencies. - Use '-l' to see a list of possible target names. - -Options: -)_"; - opt.help(); - exit(0); - return 0; - }); - - opt.process(argc, argv); - - auto verbose_env = std::getenv("V"); - if(verbose_env) - { - settings.verbose = std::atoi(verbose_env); - } - - if(list_files) - { - std::set files; - for(std::size_t i = 0; i < numConfigFiles; ++i) - { - files.insert(configFiles[i].file); - } - - for(const auto& file : files) - { - std::cout << file << "\n"; - } - } - - if(!add_files.empty() || !remove_files.empty()) - { - for(const auto& add_file : add_files) - { - reg(add_file.data(), [](){ return std::vector{};}); - } - - for(const auto& remove_file : remove_files) - { - unreg(remove_file.data()); - } - - // Force rebuild if files were added - recompileCheck(settings, 1, argv, true, no_relaunch == false); - } - - recompileCheck(settings, argc, argv); - - std::filesystem::path builddir(settings.builddir); - std::filesystem::create_directories(builddir); - - auto all_tasks = getTasks(settings); - - if(list_targets) - { - for(const auto& task : all_tasks) - { - if(task->targetType() != TargetType::Object) - { - std::cout << task->name() << "\n"; - } - } - } - - if(write_compilation_database) - { - std::ofstream istr(compilation_database); - istr << "["; - bool first{true}; - for(auto task : all_tasks) - { - auto s = task->toJSON(); - if(!s.empty()) - { - if(!first) - { - istr << ",\n"; - } - else - { - istr << "\n"; - } - first = false; - istr << s; - } - } - istr << "\n]\n"; - } - - if(print_configure_cmd) - { - std::cout << getConfiguration("cmd") << "\n"; - } - - if(print_configure_db) - { - const auto& c = configuration(); - for(const auto& config : c) - { - std::cout << config.first << ": " << config.second << "\n"; - } - } - - for(auto task : all_tasks) - { - if(task->registerDepTasks(all_tasks)) - { - return 1; - } - } - - bool build_all{true}; - for(const auto& arg : opt.arguments()) - { - if(arg == "configure") - { - std::cerr << "The 'configure' target must be the first argument.\n"; - return 1; - } - - if(arg == "clean") - { - build_all = false; - - std::cout << "Cleaning\n"; - for(auto& task : all_tasks) - { - if(task->clean() != 0) - { - return 1; - } - } - } - else - { - build_all = false; - - if(arg == "all") - { - auto ret = build(settings, "all", all_tasks, all_tasks); - if(ret != 0) - { - return ret; - } - } - else - { - auto ret = build(settings, arg, all_tasks); - if(ret != 0) - { - return ret; - } - } - } - } - - if(build_all) - { - auto ret = build(settings, "all", all_tasks, all_tasks); - if(ret != 0) - { - return ret; - } - } - - return 0; -} diff --git a/src/libcppbuild.h b/src/libcppbuild.h deleted file mode 100644 index d0a0080..0000000 --- a/src/libcppbuild.h +++ /dev/null @@ -1,76 +0,0 @@ -// -*- c++ -*- -#pragma once - -#include -#include -#include - -enum class TargetType -{ - Auto, // Default - deduce from target name and sources extensions - - Executable, - StaticLibrary, - DynamicLibrary, - Object, -}; - -enum class Language -{ - Auto, // Default - deduce language from source extensions - - C, - Cpp, - Asm, -}; - -enum class OutputSystem -{ - Host, // Output for the target system - Build, // Internal tool during cross-compilation -}; - -struct BuildConfiguration -{ - TargetType type{TargetType::Auto}; - Language language{Language::Auto}; - OutputSystem system{OutputSystem::Host}; - std::string target; - std::vector sources; // source list - std::vector depends; // internal dependencies - std::vector cxxflags; // flags for c++ compiler - std::vector cflags; // flags for c compiler - std::vector ldflags; // flags for linker - std::vector asmflags; // flags for asm translator -}; - -using BuildConfigurations = std::vector; - -int reg(const char* location, BuildConfigurations (*cb)()); - -// Convenience macro - ugly but keeps things simple(r) -#define CONCAT(a, b) CONCAT_INNER(a, b) -#define CONCAT_INNER(a, b) a ## b -#define UNIQUE_NAME(base) CONCAT(base, __LINE__) -#define REG(cb) namespace { int UNIQUE_NAME(unique) = reg(__FILE__, cb); } - -// Predefined configuration keys -namespace cfg -{ -constexpr auto builddir = "builddir"; - -constexpr auto host_cc = "host-cc"; -constexpr auto host_cxx = "host-cpp"; -constexpr auto host_ar = "host-ar"; -constexpr auto host_ld = "host-ld"; - -constexpr auto build_cc = "build-cc"; -constexpr auto build_cxx = "build-cpp"; -constexpr auto build_ar = "build-ar"; -constexpr auto build_ld = "build-ld"; -} - -const std::map& configuration(); -bool hasConfiguration(const std::string& key); -const std::string& getConfiguration(const std::string& key, - const std::string& defaultValue = {}); diff --git a/src/libctor.cc b/src/libctor.cc new file mode 100644 index 0000000..9860440 --- /dev/null +++ b/src/libctor.cc @@ -0,0 +1,316 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "libctor.h" +#include "settings.h" +#include "configure.h" +#include "rebuild.h" +#include "tasks.h" +#include "build.h" +int main(int argc, char* argv[]) +{ + if(argc > 1 && std::string(argv[1]) == "configure") + { + return configure(argc, argv); + } + + Settings settings{}; + + settings.builddir = getConfiguration(cfg::builddir, "build"); + settings.parallel_processes = + std::max(1u, std::thread::hardware_concurrency() * 2 - 1); + settings.verbose = 0; + + bool write_compilation_database{false}; + std::string compilation_database; + bool print_configure_cmd{false}; + bool print_configure_db{false}; + std::vector add_files; + std::vector remove_files; + bool list_files{false}; + bool list_targets{false}; + bool no_relaunch{false}; // true means no re-launch after rebuild. + + dg::Options opt; + int key{128}; + + opt.add("jobs", required_argument, 'j', + "Number of parallel jobs. (default: cpucount * 2 - 1)", + [&]() { + try + { + settings.parallel_processes = std::stoi(optarg); + } + catch(...) + { + std::cerr << "Not a number\n"; + return 1; + } + return 0; + }); + + opt.add("build-dir", required_argument, 'b', + "Overload output directory for build files (default: '" + + settings.builddir + "').", + [&]() { + settings.builddir = optarg; + return 0; + }); + + opt.add("verbose", no_argument, 'v', + "Be verbose. Add multiple times for more verbosity.", + [&]() { + settings.verbose++; + return 0; + }); + + opt.add("add", required_argument, 'a', + "Add specified file to the build configurations.", + [&]() { + no_relaunch = true; + add_files.push_back(optarg); + return 0; + }); + + opt.add("remove", required_argument, 'r', + "Remove specified file from the build configurations.", + [&]() { + no_relaunch = true; + remove_files.push_back(optarg); + return 0; + }); + + opt.add("list-files", no_argument, 'L', + "List files in the build configurations.", + [&]() { + no_relaunch = true; + list_files = true; + return 0; + }); + + opt.add("list-targets", no_argument, 'l', + "List targets.", + [&]() { + no_relaunch = true; + list_targets = true; + return 0; + }); + + opt.add("configure-cmd", no_argument, key++, + "Print commandline for last configure.", + [&]() { + no_relaunch = true; + print_configure_cmd = true; + return 0; + }); + + opt.add("configure-db", no_argument, key++, + "Print entire configure parameter database.", + [&]() { + no_relaunch = true; + print_configure_db = true; + return 0; + }); + + opt.add("database", required_argument, 'd', + "Write compilation database json file.", + [&]() { + no_relaunch = true; + write_compilation_database = true; + compilation_database = optarg; + return 0; + }); + + opt.add("help", no_argument, 'h', + "Print this help text.", + [&]() { + std::cout << "Usage: " << argv[0] << " [options] [target] ...\n"; + std::cout << +R"_( where target can be either: + configure - run configuration step (cannot be used with other targets). + clean - clean all generated files. + all - build all targets (default) + or the name of a target which will be built along with its dependencies. + Use '-l' to see a list of possible target names. + +Options: +)_"; + opt.help(); + exit(0); + return 0; + }); + + opt.process(argc, argv); + + auto verbose_env = std::getenv("V"); + if(verbose_env) + { + settings.verbose = std::atoi(verbose_env); + } + + if(list_files) + { + std::set files; + for(std::size_t i = 0; i < numConfigFiles; ++i) + { + files.insert(configFiles[i].file); + } + + for(const auto& file : files) + { + std::cout << file << "\n"; + } + } + + if(!add_files.empty() || !remove_files.empty()) + { + for(const auto& add_file : add_files) + { + reg(add_file.data(), [](){ return std::vector{};}); + } + + for(const auto& remove_file : remove_files) + { + unreg(remove_file.data()); + } + + // Force rebuild if files were added + recompileCheck(settings, 1, argv, true, no_relaunch == false); + } + + recompileCheck(settings, argc, argv); + + std::filesystem::path builddir(settings.builddir); + std::filesystem::create_directories(builddir); + + auto all_tasks = getTasks(settings); + + if(list_targets) + { + for(const auto& task : all_tasks) + { + if(task->targetType() != TargetType::Object) + { + std::cout << task->name() << "\n"; + } + } + } + + if(write_compilation_database) + { + std::ofstream istr(compilation_database); + istr << "["; + bool first{true}; + for(auto task : all_tasks) + { + auto s = task->toJSON(); + if(!s.empty()) + { + if(!first) + { + istr << ",\n"; + } + else + { + istr << "\n"; + } + first = false; + istr << s; + } + } + istr << "\n]\n"; + } + + if(print_configure_cmd) + { + std::cout << getConfiguration("cmd") << "\n"; + } + + if(print_configure_db) + { + const auto& c = configuration(); + for(const auto& config : c) + { + std::cout << config.first << ": " << config.second << "\n"; + } + } + + for(auto task : all_tasks) + { + if(task->registerDepTasks(all_tasks)) + { + return 1; + } + } + + bool build_all{true}; + for(const auto& arg : opt.arguments()) + { + if(arg == "configure") + { + std::cerr << "The 'configure' target must be the first argument.\n"; + return 1; + } + + if(arg == "clean") + { + build_all = false; + + std::cout << "Cleaning\n"; + for(auto& task : all_tasks) + { + if(task->clean() != 0) + { + return 1; + } + } + } + else + { + build_all = false; + + if(arg == "all") + { + auto ret = build(settings, "all", all_tasks, all_tasks); + if(ret != 0) + { + return ret; + } + } + else + { + auto ret = build(settings, arg, all_tasks); + if(ret != 0) + { + return ret; + } + } + } + } + + if(build_all) + { + auto ret = build(settings, "all", all_tasks, all_tasks); + if(ret != 0) + { + return ret; + } + } + + return 0; +} diff --git a/src/libctor.h b/src/libctor.h new file mode 100644 index 0000000..d0a0080 --- /dev/null +++ b/src/libctor.h @@ -0,0 +1,76 @@ +// -*- c++ -*- +#pragma once + +#include +#include +#include + +enum class TargetType +{ + Auto, // Default - deduce from target name and sources extensions + + Executable, + StaticLibrary, + DynamicLibrary, + Object, +}; + +enum class Language +{ + Auto, // Default - deduce language from source extensions + + C, + Cpp, + Asm, +}; + +enum class OutputSystem +{ + Host, // Output for the target system + Build, // Internal tool during cross-compilation +}; + +struct BuildConfiguration +{ + TargetType type{TargetType::Auto}; + Language language{Language::Auto}; + OutputSystem system{OutputSystem::Host}; + std::string target; + std::vector sources; // source list + std::vector depends; // internal dependencies + std::vector cxxflags; // flags for c++ compiler + std::vector cflags; // flags for c compiler + std::vector ldflags; // flags for linker + std::vector asmflags; // flags for asm translator +}; + +using BuildConfigurations = std::vector; + +int reg(const char* location, BuildConfigurations (*cb)()); + +// Convenience macro - ugly but keeps things simple(r) +#define CONCAT(a, b) CONCAT_INNER(a, b) +#define CONCAT_INNER(a, b) a ## b +#define UNIQUE_NAME(base) CONCAT(base, __LINE__) +#define REG(cb) namespace { int UNIQUE_NAME(unique) = reg(__FILE__, cb); } + +// Predefined configuration keys +namespace cfg +{ +constexpr auto builddir = "builddir"; + +constexpr auto host_cc = "host-cc"; +constexpr auto host_cxx = "host-cpp"; +constexpr auto host_ar = "host-ar"; +constexpr auto host_ld = "host-ld"; + +constexpr auto build_cc = "build-cc"; +constexpr auto build_cxx = "build-cpp"; +constexpr auto build_ar = "build-ar"; +constexpr auto build_ld = "build-ld"; +} + +const std::map& configuration(); +bool hasConfiguration(const std::string& key); +const std::string& getConfiguration(const std::string& key, + const std::string& defaultValue = {}); diff --git a/src/rebuild.cc b/src/rebuild.cc index 43c4c98..5559349 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -7,7 +7,7 @@ #include "execute.h" #include "configure.h" #include "settings.h" -#include "libcppbuild.h" +#include "libctor.h" std::array configFiles; std::size_t numConfigFiles{0}; @@ -110,7 +110,7 @@ void recompileCheck(const Settings& settings, int argc, char* argv[], args.push_back(location); } } - args.push_back("libcppbuild.a"); + args.push_back("libctor.a"); args.push_back("-o"); args.push_back(binFile.string()); diff --git a/src/rebuild.h b/src/rebuild.h index bc5d889..1b29bbd 100644 --- a/src/rebuild.h +++ b/src/rebuild.h @@ -4,7 +4,7 @@ #include #include -#include "libcppbuild.h" +#include "libctor.h" class Settings; diff --git a/src/task.h b/src/task.h index 98363a1..acbefb3 100644 --- a/src/task.h +++ b/src/task.h @@ -7,7 +7,7 @@ #include #include -#include "libcppbuild.h" +#include "libctor.h" enum class State { diff --git a/src/task_ar.cc b/src/task_ar.cc index 5568629..980d8b4 100644 --- a/src/task_ar.cc +++ b/src/task_ar.cc @@ -3,7 +3,7 @@ #include #include -#include "libcppbuild.h" +#include "libctor.h" #include "settings.h" #include "execute.h" diff --git a/src/task_cc.cc b/src/task_cc.cc index af9cf7a..0f85bf6 100644 --- a/src/task_cc.cc +++ b/src/task_cc.cc @@ -3,7 +3,7 @@ #include #include -#include "libcppbuild.h" +#include "libctor.h" #include "settings.h" #include "execute.h" diff --git a/src/task_ld.cc b/src/task_ld.cc index 91f3316..4a77c72 100644 --- a/src/task_ld.cc +++ b/src/task_ld.cc @@ -3,7 +3,7 @@ #include #include -#include "libcppbuild.h" +#include "libctor.h" #include "settings.h" #include "execute.h" diff --git a/src/task_so.cc b/src/task_so.cc index eaf6a85..ca7883f 100644 --- a/src/task_so.cc +++ b/src/task_so.cc @@ -3,7 +3,7 @@ #include #include -#include "libcppbuild.h" +#include "libctor.h" #include "settings.h" #include "execute.h" diff --git a/src/tasks.cc b/src/tasks.cc index 93e5a8b..2d8f46e 100644 --- a/src/tasks.cc +++ b/src/tasks.cc @@ -5,7 +5,7 @@ #include #include "settings.h" -#include "libcppbuild.h" +#include "libctor.h" #include "task.h" #include "task_cc.h" #include "task_ld.h" -- cgit v1.2.3