From a8777a4aa67b1cf60d7053635d1a3edadca5779e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 29 Jun 2022 09:25:52 +0200 Subject: Make sure we generate common pkg-config file for only liba{}/libs{} --- libbuild2/algorithm.hxx | 3 +++ libbuild2/algorithm.ixx | 11 +++++++++++ libbuild2/cc/link-rule.cxx | 21 +++++++++++++++++++-- libbuild2/dyndep.cxx | 3 +-- libbuild2/target.hxx | 14 ++++++++++---- 5 files changed, 44 insertions(+), 8 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/algorithm.hxx b/libbuild2/algorithm.hxx index 300016f..0f981a9 100644 --- a/libbuild2/algorithm.hxx +++ b/libbuild2/algorithm.hxx @@ -78,6 +78,9 @@ namespace build2 pair search_locked (const target&, const target_type&, const prerequisite_key&); + const target* + search_exsiting (context&, const target_type&, const prerequisite_key&); + const target& search_new (context&, const target_type&, const prerequisite_key&); diff --git a/libbuild2/algorithm.ixx b/libbuild2/algorithm.ixx index ea4241e..8fc5390 100644 --- a/libbuild2/algorithm.ixx +++ b/libbuild2/algorithm.ixx @@ -45,6 +45,17 @@ namespace build2 k.proj, {&tt, k.tk.dir, k.tk.out, k.tk.name, k.tk.ext}, k.scope}); } + inline const target* + search_exsiting (context& ctx, + const target_type& tt, + const prerequisite_key& k) + { + return search_existing ( + ctx, + prerequisite_key { + k.proj, {&tt, k.tk.dir, k.tk.out, k.tk.name, k.tk.ext}, k.scope}); + } + inline const target& search_new (context& ctx, const target_type& tt, diff --git a/libbuild2/cc/link-rule.cxx b/libbuild2/cc/link-rule.cxx index 71d2055..da9cca4 100644 --- a/libbuild2/cc/link-rule.cxx +++ b/libbuild2/cc/link-rule.cxx @@ -1596,6 +1596,13 @@ namespace build2 // we will use its bin.lib to decide what will be installed and in // perform_update() we will confirm that it is actually installed. // + // This, of course, works only if we actually have explicit lib{}. + // But the user could only have liba{} (common in testing frameworks + // that provide main()) or only libs{} (e.g., plugin that can also + // be linked). It's also theoretically possible to have both liba{} + // and libs{} but no lib{}, in which case it feels correct not to + // generate the common file at all. + // if (ot != otype::e) { // Note that here we always use the lib name prefix, even on @@ -1607,7 +1614,13 @@ namespace build2 // Note also that the order in which we are adding these members // is important (see add_addhoc_member() for details). // - if (ot == otype::a || !link_members (rs).a) + if (t.group->decl >= target_decl::implied + ? (ot == otype::a || !link_members (rs).a) + : search_existing (ctx, + ot == otype::a + ? libs::static_type + : liba::static_type, + t.dir, t.out, t.name) == nullptr) { auto& pc (add_adhoc_member (t)); @@ -2786,8 +2799,12 @@ namespace build2 if (!m->is_a (la ? pca::static_type : pcs::static_type)) { - if (t.group->matched (a)) + if (t.group->decl >= target_decl::implied + ? t.group->matched (a) + : true) + { pkgconfig_save (a, t, la, true /* common */, binless); + } else // Mark as non-existent not to confuse the install rule. // diff --git a/libbuild2/dyndep.cxx b/libbuild2/dyndep.cxx index bc307f6..bbbf807 100644 --- a/libbuild2/dyndep.cxx +++ b/libbuild2/dyndep.cxx @@ -542,8 +542,7 @@ namespace build2 // implied ones because pre-entered members of a target group // (e.g., cli.cxx) are implied. // - if (x->decl == target_decl::real || - x->decl == target_decl::implied) + if (x->decl >= target_decl::implied) { r = x; break; diff --git a/libbuild2/target.hxx b/libbuild2/target.hxx index 1a7abfc..038552f 100644 --- a/libbuild2/target.hxx +++ b/libbuild2/target.hxx @@ -267,12 +267,18 @@ namespace build2 // enum class target_decl: uint8_t { - prereq_new, // Created from prerequisite (create_new_target()). - prereq_file, // Created from prerequisite/file (search_existing_file ()). - implied, // Target-spec variable assignment, implicitly-entered, etc. - real // Real dependency declaration. + prereq_new = 1, // Created from prerequisite (create_new_target()). + prereq_file, // Created from prerequisite/file (search_existing_file()). + implied, // Target-spec variable assignment, implicitly-entered, etc. + real // Real dependency declaration. }; + inline bool + operator>= (target_decl l, target_decl r) + { + return static_cast (l) >= static_cast (r); + } + class LIBBUILD2_SYMEXPORT target { public: -- cgit v1.1