From fa06d5a76b02018980ccc12fcd52ea96bd894c81 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 9 May 2022 13:19:47 +0200 Subject: Use lld or gold if installed --- src/Linker.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/Linker.cpp (limited to 'src/Linker.cpp') diff --git a/src/Linker.cpp b/src/Linker.cpp new file mode 100644 index 0000000..7d90d46 --- /dev/null +++ b/src/Linker.cpp @@ -0,0 +1,49 @@ +#include "../include/Linker.hpp" +#include "../include/FileUtil.hpp" + +static void split_string(const std::string &str, char delimiter, std::function callback) { + size_t index = 0; + while(index < str.size()) { + const size_t end_index = str.find(delimiter, index); + if(end_index == std::string::npos) + break; + + if(!callback(&str[index], end_index - index)) + break; + + index = end_index + 1; + } +} + +namespace sibs +{ + static bool is_linker_installed(const char *linker_binary_name) { + const char *path = getenv("PATH"); + if(!path) + return false; + + bool linker_found = false; + split_string(path, ':', [&](const char *str, size_t size) { + std::string fullpath(str, size); + fullpath += "/"; + fullpath += linker_binary_name; + + if(getFileType(fullpath.c_str()) == FileType::REGULAR) { + linker_found = true; + return false; + } + + return true; + }); + + return linker_found; + } + + bool is_gold_linker_installed() { + return is_linker_installed("ld.gold"); + } + + bool is_lld_linker_installed() { + return is_linker_installed("ld.lld"); + } +} \ No newline at end of file -- cgit v1.2.3