From c093758b4688fb5bae2cc7727b6c9b52b824043e Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 12 Jan 2023 15:49:16 +0100 Subject: Move tools opt to ctor.h and rename tool_chain to toolchain for consistency. --- src/ctor.h | 22 +++++++++++++++++++++ src/externals_manual.cc | 8 ++++---- src/rebuild.cc | 14 ++++++------- src/task_cc.cc | 15 +++++++------- src/task_ld.cc | 8 ++++---- src/task_so.cc | 8 ++++---- src/tools.cc | 52 ++++++++++++++++++++++++------------------------- src/tools.h | 28 +++----------------------- 8 files changed, 77 insertions(+), 78 deletions(-) (limited to 'src') diff --git a/src/ctor.h b/src/ctor.h index 8e0e28e..388ec1b 100644 --- a/src/ctor.h +++ b/src/ctor.h @@ -66,6 +66,28 @@ enum class toolchain clang, }; +enum class opt +{ + // gcc/clang + output, // -o + debug, // -g + strip, // -s + warn_all, // -Wall + warnings_as_errors, // -Werror + generate_dep_tree, // -MMD + no_link, // -c + include_path, // -I + library_path, // -L + link, // -l + cpp_std, // -std= + build_shared, // -shared + threads, // -pthread + optimization, // -O + position_independent_code, // -fPIC + position_independent_executable, // -fPIE + custom, // entire option taken verbatim from +}; + struct flags { std::vector cxxflags; // flags for c++ compiler diff --git a/src/externals_manual.cc b/src/externals_manual.cc index d6b519b..bc8e9d0 100644 --- a/src/externals_manual.cc +++ b/src/externals_manual.cc @@ -16,21 +16,21 @@ extern std::map external_libdir; int resolv(const ctor::settings& settings, const ctor::external_configuration& config, const ctor::external_manual& ext, ctor::flags& flags) { - auto tool_chain = getToolChain(config.system); + auto toolchain = getToolChain(config.system); flags = ext.flags; auto inc = external_includedir.find(config.name); if(inc != external_includedir.end()) { - append(flags.cflags, getOption(tool_chain, opt::include_path, inc->second)); - append(flags.cxxflags, getOption(tool_chain, opt::include_path, inc->second)); + append(flags.cflags, getOption(toolchain, ctor::opt::include_path, inc->second)); + append(flags.cxxflags, getOption(toolchain, ctor::opt::include_path, inc->second)); } auto lib = external_libdir.find(config.name); if(lib != external_libdir.end()) { - append(flags.ldflags, getOption(tool_chain, opt::library_path, lib->second)); + append(flags.ldflags, getOption(toolchain, ctor::opt::library_path, lib->second)); } return 0; diff --git a/src/rebuild.cc b/src/rebuild.cc index 0d610b5..dec7119 100644 --- a/src/rebuild.cc +++ b/src/rebuild.cc @@ -162,27 +162,27 @@ bool recompileCheck(const ctor::settings& global_settings, int argc, char* argv[ config.name = "ctor"; config.system = ctor::output_system::build; - auto tool_chain = getToolChain(config.system); + auto toolchain = getToolChain(config.system); append(config.flags.cxxflags, - getOption(tool_chain, opt::optimization, "3")); + getOption(toolchain, ctor::opt::optimization, "3")); append(config.flags.cxxflags, - getOption(tool_chain, opt::cpp_std, "c++20")); + getOption(toolchain, ctor::opt::cpp_std, "c++20")); const auto& c = ctor::get_configuration(); if(c.has(ctor::cfg::ctor_includedir)) { append(config.flags.cxxflags, - getOption(tool_chain, opt::include_path, + getOption(toolchain, ctor::opt::include_path, c.get(ctor::cfg::ctor_includedir))); } if(c.has(ctor::cfg::ctor_libdir)) { append(config.flags.ldflags, - getOption(tool_chain, opt::library_path, + getOption(toolchain, ctor::opt::library_path, c.get(ctor::cfg::ctor_libdir))); } - append(config.flags.ldflags, getOption(tool_chain, opt::link, "ctor")); - append(config.flags.ldflags, getOption(tool_chain, opt::threads)); + append(config.flags.ldflags, getOption(toolchain, ctor::opt::link, "ctor")); + append(config.flags.ldflags, getOption(toolchain, ctor::opt::threads)); ctor::settings settings{global_settings}; settings.verbose = -1; // Make check completely silent. diff --git a/src/task_cc.cc b/src/task_cc.cc index 7f69998..c15bd6a 100644 --- a/src/task_cc.cc +++ b/src/task_cc.cc @@ -281,22 +281,21 @@ std::string TaskCC::flagsString() const std::vector TaskCC::getCompilerArgs() const { - auto tool_chain = getToolChain(config.system); - + auto toolchain = getToolChain(config.system); auto compiler_flags = flags(); std::vector args; - append(args, getOption(tool_chain, opt::generate_dep_tree)); + append(args, getOption(toolchain, ctor::opt::generate_dep_tree)); if(std::filesystem::path(config.target).extension() == ".so") { // Add -fPIC arg to all contained object files - append(args, getOption(tool_chain, opt::position_independent_code)); + append(args, getOption(toolchain, ctor::opt::position_independent_code)); } - append(args, getOption(tool_chain, opt::no_link)); + append(args, getOption(toolchain, ctor::opt::no_link)); args.push_back(sourceFile.string()); - append(args, getOption(tool_chain, opt::output, targetFile().string())); + append(args, getOption(toolchain, ctor::opt::output, targetFile().string())); for(const auto& flag : compiler_flags) { @@ -304,13 +303,13 @@ std::vector TaskCC::getCompilerArgs() const switch(option.first) { // Relative include paths has to be altered to be relative to sourceDir - case opt::include_path: + case ctor::opt::include_path: { std::filesystem::path path(option.second); if(path.is_relative()) { path = (sourceDir / path).lexically_normal(); - append(args, getOption(tool_chain, opt::include_path, path.string())); + append(args, getOption(toolchain, ctor::opt::include_path, path.string())); } } continue; diff --git a/src/task_ld.cc b/src/task_ld.cc index 916f3ff..4915de9 100644 --- a/src/task_ld.cc +++ b/src/task_ld.cc @@ -82,7 +82,7 @@ bool TaskLD::dirtyInner() int TaskLD::runInner() { - auto tool_chain = getToolChain(config.system); + auto toolchain = getToolChain(config.system); std::vector args; for(const auto& dep : getDependsTasks()) @@ -90,10 +90,10 @@ int TaskLD::runInner() auto depFile = dep->targetFile(); if(depFile.extension() == ".so") { - append(args, getOption(tool_chain, opt::library_path, + append(args, getOption(toolchain, ctor::opt::library_path, targetFile().parent_path().string())); auto lib = depFile.stem().string().substr(3); // strip 'lib' prefix - append(args, getOption(tool_chain, opt::link, lib)); + append(args, getOption(toolchain, ctor::opt::link, lib)); } else if(depFile.extension() == ".a" || depFile.extension() == ".o") { @@ -102,7 +102,7 @@ int TaskLD::runInner() } append(args, config.flags.ldflags); - append(args, getOption(tool_chain, opt::output, targetFile().string())); + append(args, getOption(toolchain, ctor::opt::output, targetFile().string())); { // Write flags to file. std::ofstream flagsStream(flagsFile); diff --git a/src/task_so.cc b/src/task_so.cc index 0340ff1..93a5ddb 100644 --- a/src/task_so.cc +++ b/src/task_so.cc @@ -79,14 +79,14 @@ bool TaskSO::dirtyInner() int TaskSO::runInner() { - auto tool_chain = getToolChain(config.system); + auto toolchain = getToolChain(config.system); std::vector args; - append(args, getOption(tool_chain, opt::position_independent_code)); - append(args, getOption(tool_chain, opt::build_shared)); + append(args, getOption(toolchain, ctor::opt::position_independent_code)); + append(args, getOption(toolchain, ctor::opt::build_shared)); - append(args, getOption(tool_chain, opt::output, targetFile().string())); + append(args, getOption(toolchain, ctor::opt::output, targetFile().string())); for(const auto& task : getDependsTasks()) { diff --git a/src/tools.cc b/src/tools.cc index ddb1463..610a550 100644 --- a/src/tools.cc +++ b/src/tools.cc @@ -50,43 +50,43 @@ ctor::toolchain getToolChain(ctor::output_system system) namespace { -std::vector getOptionGcc(opt option, const std::string& arg) +std::vector getOptionGcc(ctor::opt option, const std::string& arg) { switch(option) { - case opt::output: + case ctor::opt::output: return {"-o", arg}; - case opt::debug: + case ctor::opt::debug: return {"-g"}; - case opt::strip: + case ctor::opt::strip: return {"-s"}; - case opt::warn_all: + case ctor::opt::warn_all: return {"-Wall"}; - case opt::warnings_as_errors: + case ctor::opt::warnings_as_errors: return {"-Werror"}; - case opt::generate_dep_tree: + case ctor::opt::generate_dep_tree: return {"-MMD"}; - case opt::no_link: + case ctor::opt::no_link: return {"-c"}; - case opt::include_path: + case ctor::opt::include_path: return {"-I" + arg}; - case opt::library_path: + case ctor::opt::library_path: return {"-L" + arg}; - case opt::link: + case ctor::opt::link: return {"-l" + arg}; - case opt::cpp_std: + case ctor::opt::cpp_std: return {"-std=" + arg}; - case opt::build_shared: + case ctor::opt::build_shared: return {"-shared"}; - case opt::threads: + case ctor::opt::threads: return {"-pthread"}; - case opt::optimization: + case ctor::opt::optimization: return {"-O" + arg}; - case opt::position_independent_code: + case ctor::opt::position_independent_code: return {"-fPIC"}; - case opt::position_independent_executable: + case ctor::opt::position_independent_executable: return {"-fPIE"}; - case opt::custom: + case ctor::opt::custom: return {arg}; } @@ -96,7 +96,7 @@ std::vector getOptionGcc(opt option, const std::string& arg) } std::vector getOption(ctor::toolchain toolchain, - opt option, + ctor::opt option, const std::string& arg) { switch(toolchain) @@ -114,28 +114,28 @@ std::vector getOption(ctor::toolchain toolchain, } namespace { -std::pair getOptionGcc(const std::string& flag) +std::pair getOptionGcc(const std::string& flag) { if(flag.substr(0, 2) == "-I") { std::string path = flag.substr(2); path.erase(0, path.find_first_not_of(' ')); - return { opt::include_path, path }; + return { ctor::opt::include_path, path }; } if(flag.substr(0, 2) == "-L") { std::string path = flag.substr(2); path.erase(0, path.find_first_not_of(' ')); - return { opt::library_path, path }; + return { ctor::opt::library_path, path }; } - return { opt::custom, flag }; + return { ctor::opt::custom, flag }; } } -std::pair getOption(const std::string& flag, - ctor::toolchain toolchain) +std::pair getOption(const std::string& flag, + ctor::toolchain toolchain) { switch(toolchain) { @@ -148,5 +148,5 @@ std::pair getOption(const std::string& flag, } std::cerr << "Unsupported tool-chain.\n"; - return { opt::custom, flag }; + return { ctor::opt::custom, flag }; } diff --git a/src/tools.h b/src/tools.h index bedb708..e6c2264 100644 --- a/src/tools.h +++ b/src/tools.h @@ -8,28 +8,6 @@ #include "ctor.h" -enum class opt -{ - // gcc/clang - output, // -o - debug, // -g - strip, // -s - warn_all, // -Wall - warnings_as_errors, // -Werror - generate_dep_tree, // -MMD - no_link, // -c - include_path, // -I - library_path, // -L - link, // -l - cpp_std, // -std= - build_shared, // -shared - threads, // -pthread - optimization, // -O - position_independent_code, // -fPIC - position_independent_executable, // -fPIE - custom, // entire option taken verbatim from -}; - //! Get tool-chain type from compiler path string ctor::toolchain getToolChain(const std::string& compiler); @@ -39,11 +17,11 @@ ctor::toolchain getToolChain(ctor::output_system system); //! Get tool argument(s) for specific option type matching the supplied //! tool-chain std::vector getOption(ctor::toolchain toolchain, - opt option, + ctor::opt option, const std::string& arg = {}); //! Get opt enum value and argument from string, //! ie. { opt::InludePath, "foo/bar" } from "-Ifoo/bar" //! Returns { opt::Custom, flag } if unknown. -std::pair getOption(const std::string& flag, - ctor::toolchain toolchain = ctor::toolchain::gcc); +std::pair getOption(const std::string& flag, + ctor::toolchain toolchain = ctor::toolchain::gcc); -- cgit v1.2.3