aboutsummaryrefslogtreecommitdiff
path: root/src/Linker.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Linker.cpp')
-rw-r--r--src/Linker.cpp49
1 files changed, 49 insertions, 0 deletions
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<bool(const char*,size_t)> 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