]> git.tdb.fi Git - builder.git/commitdiff
Use the architecture's patterns to remove prefix from libname
authorMikko Rasa <tdb@tdb.fi>
Mon, 2 Jan 2023 20:22:36 +0000 (22:22 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 2 Jan 2023 22:51:46 +0000 (00:51 +0200)
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
source/lib/sharedlibrary.cpp

index 8c623bda81eeac0036bc731ef2686d615ed459ef..5da52eb7d1f3a4786fcd76b5a8b0b47e742e563e 100644 (file)
@@ -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;
 
index dab6b8df8e70635231e6393bef172f1594eb5b33..aae366332c974944cf2503949a09bdab164e63aa 100644 (file)
@@ -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<SharedLibrary>().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<ObjectFile *> &objs):
@@ -22,8 +23,9 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const vector<Object
        libname(c.get_name()),
        import_lib(0)
 {
-       if(!libname.compare(0, 3, "lib"))
-               libname = libname.substr(3);
+       const string &lib_prefix = builder.get_current_arch().get_patterns<SharedLibrary>().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";