From e59b4fc15eef3b3d0af5b81190b1e54f270ee2d2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 28 Sep 2022 16:39:03 +0200 Subject: Omit -l for binless libraries, metadata from common .pc file Having -l options for binless (header-only) libraries makes it unusable from other build systems. But omitting them could make the metadata incomplete (for example, importable headers), so we omit that as well. --- libbuild2/cc/link-rule.cxx | 1 - libbuild2/cc/pkgconfig.cxx | 29 ++++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/libbuild2/cc/link-rule.cxx b/libbuild2/cc/link-rule.cxx index 60d3718..8bc073a 100644 --- a/libbuild2/cc/link-rule.cxx +++ b/libbuild2/cc/link-rule.cxx @@ -870,7 +870,6 @@ namespace build2 (type[p += 19] == '\0' || type[p] == ',')); } - recipe link_rule:: apply (action a, target& xt, match_extra&) const { diff --git a/libbuild2/cc/pkgconfig.cxx b/libbuild2/cc/pkgconfig.cxx index f36a7a7..5efab0d 100644 --- a/libbuild2/cc/pkgconfig.cxx +++ b/libbuild2/cc/pkgconfig.cxx @@ -1281,6 +1281,11 @@ namespace build2 // file must be generated based on the static library to get accurate // Libs.private. // + // The other things that we omit from the common variant are -l options + // for binless libraries (so that it's usable from other build systems) as + // well as metadata (which could become incomplete due the previous + // omissions; for example, importable headers metadata). + // void link_rule:: pkgconfig_save (action a, const file& l, @@ -1562,7 +1567,8 @@ namespace build2 appended_libraries* pls; // Previous. appended_libraries* ls; // Current. strings& args; - } d {os, nullptr, &ls, args}; + bool common; + } d {os, nullptr, &ls, args, common}; auto imp = [&priv] (const target&, bool la) {return priv && la;}; @@ -1606,7 +1612,17 @@ namespace build2 if (l != nullptr) { if (l->is_a () || l->is_a ()) // See through libux. - d.args.push_back (save_library_target (*l)); + { + // Omit binless libraries from the common .pc file (see + // above). + // + // Note that in this case we still want to recursively + // traverse such libraries since they may still link to some + // non-binless system libraries (-lm, etc). + // + if (!d.common || !l->path ().empty ()) + d.args.push_back (save_library_target (*l)); + } } else { @@ -1687,8 +1703,15 @@ namespace build2 } } - // Save metadata. + // Save metadata unless this is the common .pc file (see above). // + if (common) + { + os.close (); + arm.cancel (); + return; + } + // The build2.metadata variable is a general indication of the // metadata being present. Its value is the metadata version // optionally followed by the user metadata variable prefix and -- cgit v1.1