From 650560b14cac4bb35589b5b8db99197c5e1345cc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 31 Aug 2021 21:14:53 +0300 Subject: [PATCH] Use a separate category for import library filename patterns --- source/architecture.cpp | 5 ++--- source/importlibrary.cpp | 15 +++++++++++++-- source/importlibrary.h | 3 +++ source/virtualfilesystem.cpp | 12 +++++++----- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/source/architecture.cpp b/source/architecture.cpp index a3f3b13..75a6460 100644 --- a/source/architecture.cpp +++ b/source/architecture.cpp @@ -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("%.dll"); add_pattern("lib%.dll"); - /* XXX Hack: Consider import libraries (*.dll.a) as dynamic libraries, - even though technically they are linked statically. */ - add_pattern("lib%.dll.a"); + add_pattern("lib%.dll.a"); add_pattern("lib%.a"); add_pattern("%.lib"); add_pattern("%.exe"); diff --git a/source/importlibrary.cpp b/source/importlibrary.cpp index 1e6650f..3cdc103 100644 --- a/source/importlibrary.cpp +++ b/source/importlibrary.cpp @@ -1,4 +1,6 @@ #include +#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(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(sl.get_libname()); } diff --git a/source/importlibrary.h b/source/importlibrary.h index aac11f9..7f7167b 100644 --- a/source/importlibrary.h +++ b/source/importlibrary.h @@ -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; } diff --git a/source/virtualfilesystem.cpp b/source/virtualfilesystem.cpp index b514226..36fe1c1 100644 --- a/source/virtualfilesystem.cpp +++ b/source/virtualfilesystem.cpp @@ -85,8 +85,13 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath const Architecture &arch = builder.get_current_arch(); list shared_names; + bool use_import_lib = false; if(mode!=BuildInfo::FORCE_STATIC) - shared_names = Pattern::apply_list(arch.get_patterns(), lib); + { + shared_names = Pattern::apply_list(arch.get_patterns(), lib); + if(!(use_import_lib = !shared_names.empty())) + shared_names = Pattern::apply_list(arch.get_patterns(), lib); + } list 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); } -- 2.43.0