diff options
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 61 |
1 files changed, 57 insertions, 4 deletions
diff --git a/src/util.cc b/src/util.cc index ee56ede..601fd54 100644 --- a/src/util.cc +++ b/src/util.cc @@ -5,6 +5,15 @@ #include <iostream> #include <fstream> +#include <algorithm> +#include <cctype> + +std::string to_lower(const std::string& str) +{ + std::string out{str}; + std::transform(out.begin(), out.end(), out.begin(), ::tolower); + return out; +} std::string readFile(const std::string& fileName) { @@ -83,15 +92,23 @@ std::vector<std::string> readDeps(const std::string& depFile) ctor::language languageFromExtension(const std::filesystem::path& file) { auto ext = file.extension().string(); + + // First a few case sensitive comparisons if(ext == ".c") { return ctor::language::c; } - if(ext == ".C" || - ext == ".cc" || + if(ext == ".C") + { + return ctor::language::cpp; + } + + // The rest are compared in lowercase + ext = to_lower(ext); + + if(ext == ".cc" || ext == ".cpp" || - ext == ".CPP" || ext == ".c++" || ext == ".cp" || ext == ".cxx") @@ -100,7 +117,6 @@ ctor::language languageFromExtension(const std::filesystem::path& file) } if(ext == ".s" || - ext == ".S" || ext == ".asm") { return ctor::language::assembler; @@ -135,3 +151,40 @@ std::string cleanUp(const std::string& path) } return cleaned; } + +ctor::target_type target_type_from_extension(const std::filesystem::path& file) +{ + auto ext = to_lower(file.extension().string()); + // Loosely based on: + // https://en.wikipedia.org/wiki/List_of_file_formats#Object_code,_executable_files,_shared_and_dynamically_linked_libraries + if(ext == ".a" || + ext == ".lib") + { + return ctor::target_type::static_library; + } + + if(ext == ".so" || + ext == ".dll" || + ext == ".dylib") + { + return ctor::target_type::dynamic_library; + } + + if(ext == ".o" || + ext == ".obj") + { + return ctor::target_type::object; + } + + if(ext == "" || + ext == ".exe" || + ext == ".com" || + ext == ".bin" || + ext == ".run" || + ext == ".out") + { + return ctor::target_type::executable; + } + + return ctor::target_type::unknown; +} |