From 8a4dfbbbe76a2aef35427b7915d6e28bab165c43 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 12 May 2024 16:07:53 +0200 Subject: Build static and dynamic libs --- LanguageSettings.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'LanguageSettings.cpp') diff --git a/LanguageSettings.cpp b/LanguageSettings.cpp index 8da144f..5eae731 100644 --- a/LanguageSettings.cpp +++ b/LanguageSettings.cpp @@ -74,7 +74,6 @@ std::string LanguageSettings::getLinkCommand(const std::filesystem::path& target const std::vector &inputs, const std::vector& link_libs) const { - std::string input_string{std::accumulate(inputs.begin(), inputs.end(), std::string{}, [](const std::string& sum, const fs::path& p){ return sum + " " + p.string(); })}; @@ -84,11 +83,10 @@ std::string LanguageSettings::getLinkCommand(const std::filesystem::path& target AR, target.string(), input_string); - } else { + } else if (is_executable_target(target) || is_dynamic_lib(target)) { // dynamic link: -shared -Wl,-soname,libXXX.so.N -o libXXX.so.N.M.O - std::string LDFLAGS_add{is_dynamic_lib(target) ? fmt::format(" -shared -Wl,-soname,{} -o {}", - soname_shorter(target.string()).string(), - target.string()) : ""s}; + std::string LDFLAGS_add{is_dynamic_lib(target) ? fmt::format(" -shared -Wl,-soname,{}", + soname_shorter(target.string()).string()) : ""s}; std::string link_libs_string{std::accumulate(link_libs.begin(), link_libs.end(), std::string(), [](const std::string& sum, const std::string& i){ return sum + " -l" + i; })}; @@ -103,6 +101,14 @@ std::string LanguageSettings::getLinkCommand(const std::filesystem::path& target LIBS.empty() ? ""s : (" "s + LIBS), link_libs_string, target.string()); + } else if (is_dynamic_lib_link(target)) { + // special case for dynamic libs: add links + if (inputs.size() != 1) { + throw std::runtime_error("For symlink "s + target.string() + ", can link to exactly one file, found "s + std::to_string(inputs.size())); + } + return fmt::format("ln -sf {} {}", inputs[0].filename().string(), target.string()); + } else { + throw std::runtime_error("No implementation for target type: "s + target.string()); } } @@ -116,8 +122,6 @@ std::string LanguageSettings::getDepCommand(const std::filesystem::path& target, // variables: // CC // CFLAGS -// AR // ARFLAGS // AS // ASFLAGS -// dynamic lib: -- cgit v1.2.3