diff options
Diffstat (limited to 'src/tools.h')
-rw-r--r-- | src/tools.h | 146 |
1 files changed, 109 insertions, 37 deletions
diff --git a/src/tools.h b/src/tools.h index 39118d2..188d49f 100644 --- a/src/tools.h +++ b/src/tools.h @@ -5,48 +5,120 @@ #include <vector> #include <string> +#include <ostream> +#include <filesystem> -#include "libctor.h" - -enum class ToolChain -{ - gcc, - 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<arg> - library_path, // -L<arg> - link, // -l<arg> - cpp_std, // -std=<arg> - build_shared, // -shared - threads, // -pthread - optimization, // -O<arg> - position_independent_code, // -fPIC - position_independent_executable, // -fPIE - custom, // entire option taken verbatim from <arg> -}; +#include "ctor.h" + + +std::ostream& operator<<(std::ostream& stream, const ctor::c_opt& opt); +std::ostream& operator<<(std::ostream& stream, const ctor::cxx_opt& opt); +std::ostream& operator<<(std::ostream& stream, const ctor::ld_opt& opt); +std::ostream& operator<<(std::ostream& stream, const ctor::ar_opt& opt); +std::ostream& operator<<(std::ostream& stream, const ctor::asm_opt& opt); + +std::string get_arch(ctor::output_system system); +ctor::arch get_arch(ctor::output_system system, const std::string& str); + +//! Get tool-chain type from compiler path string +ctor::toolchain getToolChain(const std::string& compiler); //! Get tool-chain type from output system (via configuration) -ToolChain getToolChain(OutputSystem system); +ctor::toolchain getToolChain(ctor::output_system system); + + + +//! Get tool argument(s) for specific option type matching the supplied +//! tool-chain +std::vector<std::string> c_option(ctor::toolchain toolchain, + ctor::c_opt option, + const std::string& arg = {}); + +//! Get tool argument(s) for specific option type matching the supplied +//! tool-chain +std::vector<std::string> cxx_option(ctor::toolchain toolchain, + ctor::cxx_opt option, + const std::string& arg = {}); + +//! Get tool argument(s) for specific option type matching the supplied +//! tool-chain +std::vector<std::string> ld_option(ctor::toolchain toolchain, + ctor::ld_opt option, + const std::string& arg = {}); //! Get tool argument(s) for specific option type matching the supplied //! tool-chain -std::vector<std::string> getOption(ToolChain tool_chain, - opt option, +std::vector<std::string> ar_option(ctor::toolchain toolchain, + ctor::ar_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<opt, std::string> getOption(const std::string& flag, - ToolChain tool_chain = ToolChain::gcc); +//! Get tool argument(s) for specific option type matching the supplied +//! tool-chain +std::vector<std::string> asm_option(ctor::toolchain toolchain, + ctor::asm_opt option, + const std::string& arg = {}); + + + +//! Get ctor::c_opt enum value and argument from string, +//! ie. { ctor::c_opt::inlude_path, "foo/bar" } from "-Ifoo/bar" +//! Returns { ctor::c_opt::custom, flag } if unknown. +ctor::c_flag c_option(const std::string& flag, ctor::toolchain toolchain); + +//! Get ctor::cxx_opt enum value and argument from string, +//! ie. { ctor::cxx_opt::inlude_path, "foo/bar" } from "-Ifoo/bar" +//! Returns { ctor::cxx_opt::custom, flag } if unknown. +ctor::cxx_flag cxx_option(const std::string& flag, ctor::toolchain toolchain); + +//! Get ctor::ld_opt enum value and argument from string, +//! ie. { ctor::ld_opt::inlude_path, "foo/bar" } from "-Ifoo/bar" +//! Returns { ctor::ld_opt::custom, flag } if unknown. +ctor::ld_flag ld_option(const std::string& flag, ctor::toolchain toolchain); + +//! Get ctor::ar_opt enum value and argument from string, +//! ie. { ctor::ar_opt::inlude_path, "foo/bar" } from "-Ifoo/bar" +//! Returns { ctor::ar_opt::custom, flag } if unknown. +ctor::ar_flag ar_option(const std::string& flag, ctor::toolchain toolchain); + +//! Get ctor::asm_opt enum value and argument from string, +//! ie. { ctor::asm_opt::inlude_path, "foo/bar" } from "-Ifoo/bar" +//! Returns { ctor::asm_opt::custom, flag } if unknown. +ctor::asm_flag asm_option(const std::string& flag, ctor::toolchain toolchain); + + + +std::vector<std::string> to_strings(ctor::toolchain toolchain, + const ctor::cxx_flag& flag); +std::vector<std::string> to_strings(ctor::toolchain toolchain, + const ctor::c_flag& flag); +std::vector<std::string> to_strings(ctor::toolchain toolchain, + const ctor::ld_flag& flag); +std::vector<std::string> to_strings(ctor::toolchain toolchain, + const ctor::ar_flag& flag); +std::vector<std::string> to_strings(ctor::toolchain toolchain, + const ctor::asm_flag& flag); + + +// Get target type from file extension +// If toolchain is not ::any only extensions for that toolchain will be accepted +// If no match is found ::unknown will be returned. +ctor::target_type target_type_from_extension(ctor::toolchain toolchain, + const std::filesystem::path& file); + + +// Get appropriate extension from original extension and target type using +// the toolchain. +// ie. { gcc, static_lib, ".lib" } will return ".a" +// { msvc, dynamic_lib, ".dylib" } will return ".dll" +// ... +// If the supplied extension is normal for the supplied type and toolchain, then this is used, otherwise a conversion to the default extension to the given toolchain and type is given. +// The defaults for the toolchains are as follows: +// toolchain executable static-lib dynamic-lib +// gcc (none) .a .so(.dylib on macos) +// clang (none) .a .so(.dylib on macos) +// msvc .exe .lib .dll +// mingw .exe .lib .dll +std::filesystem::path extension(ctor::toolchain toolchain, + ctor::target_type target_type, + ctor::output_system system, + const std::filesystem::path& file); |