summaryrefslogtreecommitdiffhomepage
path: root/file.cpp
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2024-05-10 21:15:30 +0200
committerRoland Reichwein <mail@reichwein.it>2024-05-10 21:15:30 +0200
commita7e016c2c633667b561a0f26ebde88cb26571d1c (patch)
tree7c66727de7022d5d962448be365dd059bb0ecac1 /file.cpp
parentbfdb4e9d2cfc7890c5f194e670039fa76c391330 (diff)
Build static and dynamic libs
Diffstat (limited to 'file.cpp')
-rw-r--r--file.cpp63
1 files changed, 62 insertions, 1 deletions
diff --git a/file.cpp b/file.cpp
index 3149f63..6de8b07 100644
--- a/file.cpp
+++ b/file.cpp
@@ -1,5 +1,7 @@
#include "file.h"
+#include <algorithm>
+#include <string>
#include <unordered_set>
#include <libreichwein/stringhelper.h>
@@ -7,13 +9,14 @@
#include "env.h"
namespace fs = std::filesystem;
+using namespace std::string_literals;
const fs::path YMakefile{"YMakefile"};
// type of file can be built from dependencies
bool is_buildable_by_extension(const fs::path& p) {
fs::path ext{p.extension()};
- return ext.empty() || ext == ".o";
+ return ext.empty() || ext == ".o" || is_dynamic_lib(p) || is_static_lib(p) ;
}
namespace {
@@ -26,6 +29,64 @@ bool is_compile_unit_source_by_extension(const fs::path& p) {
return compile_unit_source_types.find(ext) != compile_unit_source_types.end();
}
+// e.g. libxyz.so.1.2.3 (the shorter versions are links to this one)
+bool is_dynamic_lib(const std::filesystem::path& p)
+{
+ std::string name{p.filename()};
+ return name.find(".so.") != name.npos && std::count(name.begin(), name.end(), '.') == 4;
+}
+
+// in: libxyz.so.1.2.3
+// out: libxyz.so.1
+std::filesystem::path soname_shorter(const std::filesystem::path& p)
+{
+ std::string name{p.filename()};
+
+ if (std::count(name.begin(), name.end(), '.') != 4) {
+ throw std::runtime_error("Unexpected soname: "s + name + ", 4 dots expected.");
+ }
+
+ size_t pos{0};
+ for (int i = 0; i < 3; ++i) {
+ pos = name.find('.', pos);
+ ++pos;
+ }
+
+ name = name.substr(0, pos - 1);
+
+ fs::path result{p};
+ result.replace_filename(name);
+ return result;
+}
+
+// in: libxyz.so.1.2.3
+// out: libxyz.so
+std::filesystem::path soname_short(const std::filesystem::path& p)
+{
+ std::string name{p.filename()};
+
+ if (std::count(name.begin(), name.end(), '.') != 4) {
+ throw std::runtime_error("Unexpected soname: "s + name + ", 4 dots expected.");
+ }
+
+ size_t pos{0};
+ for (int i = 0; i < 2; ++i) {
+ pos = name.find('.', pos);
+ ++pos;
+ }
+
+ name = name.substr(0, pos - 1);
+
+ fs::path result{p};
+ result.replace_filename(name);
+ return result;
+}
+
+bool is_static_lib(const std::filesystem::path& p)
+{
+ return p.extension() == ".a";
+}
+
std::filesystem::path simplified_path(const std::filesystem::path& p)
{
if (p.string().substr(0, 2) == "./") {