]> git.tdb.fi Git - builder.git/commitdiff
Use a separate category for import library filename patterns
authorMikko Rasa <tdb@tdb.fi>
Tue, 31 Aug 2021 18:14:53 +0000 (21:14 +0300)
committerMikko Rasa <tdb@tdb.fi>
Tue, 31 Aug 2021 18:14:53 +0000 (21:14 +0300)
source/architecture.cpp
source/importlibrary.cpp
source/importlibrary.h
source/virtualfilesystem.cpp

index a3f3b132447f3213ce7d5f0f797751f90beae79b..75a64607a395f7726357d52887fb06e65953277c 100644 (file)
@@ -4,6 +4,7 @@
 #include "architecture.h"
 #include "builder.h"
 #include "executable.h"
+#include "importlibrary.h"
 #include "objectfile.h"
 #include "sharedlibrary.h"
 #include "staticlibrary.h"
@@ -146,9 +147,7 @@ Architecture::Architecture(Builder &b, const string &spec):
        {
                add_pattern<SharedLibrary>("%.dll");
                add_pattern<SharedLibrary>("lib%.dll");
-               /* XXX Hack: Consider import libraries (*.dll.a) as dynamic libraries,
-               even though technically they are linked statically. */
-               add_pattern<SharedLibrary>("lib%.dll.a");
+               add_pattern<ImportLibrary>("lib%.dll.a");
                add_pattern<StaticLibrary>("lib%.a");
                add_pattern<StaticLibrary>("%.lib");
                add_pattern<Executable>("%.exe");
index 1e6650fdac1ee648ebae4fbf642ef2cf498a1c6e..3cdc103f8ef190aa0cd6d672f1cf985ea620c1cd 100644 (file)
@@ -1,4 +1,6 @@
 #include <msp/strings/format.h>
+#include "architecture.h"
+#include "builder.h"
 #include "component.h"
 #include "exportdefinitions.h"
 #include "importlibrary.h"
@@ -14,7 +16,7 @@ ImportLibrary::ImportLibrary(Builder &b, const FS::Path &p):
 { }
 
 ImportLibrary::ImportLibrary(Builder &b, const Component &c, SharedLibrary &sl, ExportDefinitions &exp):
-       FileTarget(b, c.get_package(), c.get_package().get_output_directory()/format("lib%s.dll.a", sl.get_libname())),
+       FileTarget(b, c.get_package(), c.get_package().get_output_directory()/generate_filename(c, sl)),
        shared_lib(&sl)
 {
        component = &c;
@@ -25,5 +27,14 @@ ImportLibrary::ImportLibrary(Builder &b, const Component &c, SharedLibrary &sl,
 
        const string &version = component->get_package().get_interface_version();
        if(!version.empty())
-               install_filename = format("lib%s-%s.dll.a", sl.get_libname(), version);
+       {
+               const Architecture &arch = builder.get_current_arch();
+               install_filename = arch.create_filename<ImportLibrary>(format("%s-%s", sl.get_libname(), version));
+       }
+}
+
+string ImportLibrary::generate_filename(const Component &comp, const SharedLibrary &sl)
+{
+       const Architecture &arch = comp.get_package().get_builder().get_current_arch();
+       return arch.create_filename<ImportLibrary>(sl.get_libname());
 }
index aac11f94f18ae04c78f907a33f2918f59c9a72b6..7f7167b7ed3acdf8d0156cc248b5c070e16b0a23 100644 (file)
@@ -18,7 +18,10 @@ private:
 public:
        ImportLibrary(Builder &, const Msp::FS::Path &);
        ImportLibrary(Builder &, const Component &, SharedLibrary &, ExportDefinitions &);
+private:
+       static std::string generate_filename(const Component &, const SharedLibrary &);
 
+public:
        virtual const char *get_type() const { return "ImportLibrary"; }
 
        SharedLibrary *get_shared_library() const { return shared_lib; }
index b5142266edf639203755f1733598df20abc9cf8b..36fe1c129190e83ebd7736e7557a2619d27e9db8 100644 (file)
@@ -85,8 +85,13 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath
        const Architecture &arch = builder.get_current_arch();
 
        list<string> shared_names;
+       bool use_import_lib = false;
        if(mode!=BuildInfo::FORCE_STATIC)
-               shared_names = Pattern::apply_list(arch.get_patterns<SharedLibrary>(), lib);
+       {
+               shared_names = Pattern::apply_list(arch.get_patterns<ImportLibrary>(), lib);
+               if(!(use_import_lib = !shared_names.empty()))
+                       shared_names = Pattern::apply_list(arch.get_patterns<SharedLibrary>(), lib);
+       }
 
        list<string> static_names;
        if(mode!=BuildInfo::FORCE_DYNAMIC)
@@ -108,10 +113,7 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath
                                builder.get_logger().log("vfs", format("Library %s (%s) found in %s", lib, *j, i->str()));
                                if(cur_names==&shared_names)
                                {
-                                       /* XXX Hack: create ImportLibraries here; they should be handled
-                                       separately, but I need a more generic way of handling all these
-                                       filename patterns */
-                                       if(FS::extpart(*j)==".a")
+                                       if(use_import_lib)
                                                return new ImportLibrary(builder, filename);
                                        return new SharedLibrary(builder, filename);
                                }