From 75e33019504dd0748690f89cffeee298c18278f4 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 2 Jan 2023 22:22:36 +0200 Subject: [PATCH] Use the architecture's patterns to remove prefix from libname With the MSVC toolchain a lib prefix is not added automatically when searching for libraries, so removing it could result in a mismatch. --- source/lib/pattern.h | 3 +++ source/lib/sharedlibrary.cpp | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/source/lib/pattern.h b/source/lib/pattern.h index 8c623bd..5da52eb 100644 --- a/source/lib/pattern.h +++ b/source/lib/pattern.h @@ -20,6 +20,9 @@ public: one percent sign (%) to separate the prefix and suffix. */ Pattern(const std::string &); + const std::string &get_prefix() const { return prefix; } + const std::string &get_suffix() const { return suffix; } + /** Applies the pattern to a body string. */ std::string apply(const std::string &) const; diff --git a/source/lib/sharedlibrary.cpp b/source/lib/sharedlibrary.cpp index dab6b8d..aae3663 100644 --- a/source/lib/sharedlibrary.cpp +++ b/source/lib/sharedlibrary.cpp @@ -10,11 +10,12 @@ using namespace std; using namespace Msp; SharedLibrary::SharedLibrary(Builder &b, const Msp::FS::Path &p): - Binary(b, p) + Binary(b, p), + libname(FS::basepart(FS::basename(p))) { - libname = FS::basepart(FS::basename(path)); - if(!libname.compare(0, 3, "lib")) - libname = libname.substr(3); + const string &lib_prefix = builder.get_current_arch().get_patterns().front().get_prefix(); + if(!libname.compare(0, lib_prefix.size(), lib_prefix)) + libname = libname.substr(lib_prefix.size()); } SharedLibrary::SharedLibrary(Builder &b, const Component &c, const vector &objs): @@ -22,8 +23,9 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const vector().front().get_prefix(); + if(!libname.compare(0, lib_prefix.size(), lib_prefix)) + libname = libname.substr(lib_prefix.size()); if(builder.get_current_arch().get_system()=="windows") install_location = "bin"; -- 2.43.0