From 41b9672a828dbe3aa6a6dbdcd786a6d6402eda7b Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Thu, 2 Jun 2005 07:19:11 +0000 Subject: [PATCH] Improve "linking" of libraries into static libraries. When a library is present in sources of a static library, return it to dependents via usage requirements, not by adding it to the list of created targets. [SVN r29362] --- src/tools/builtin.jam | 25 +++++++++++++++++++++---- src/tools/unix.jam | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/tools/builtin.jam b/src/tools/builtin.jam index b81c08b41..593f50ae1 100644 --- a/src/tools/builtin.jam +++ b/src/tools/builtin.jam @@ -695,21 +695,38 @@ class archive-generator : generator local result = [ generator.run $(project) $(name) : $(property-set) : $(sources) ] ; - # For static linking, we can't directly link to libraries. + # For static linking, if we get a library in source, we can't + # directly link to it. So, we need to cause our dependencies + # to link to that library. There are two approaches: + # - adding the library to the list of returned targets. + # - using the usage requirements. + # The problem with the first is: + # + # lib a1 : : liba1.a ; + # lib a2 : a2.cpp a1 : static ; + # install dist : a2 ; + # + # here we'll try to install 'a1', even though it's not necessary in + # the general case. + # With the second approaches, even indirect dependents will link to + # the library, but it should not cause any harm. # So, return all LIB sources together with created targets, # so that dependents link to them. + local usage-requirements ; if [ $(property-set).get ] = static { for local t in $(sources) { if [ type.is-derived [ $(t).type ] LIB ] { - result += $(t) ; + usage-requirements += $(t) ; } } } - - return $(result) ; + + usage-requirements = [ property-set.create $(usage-requirements) ] ; + + return $(usage-requirements) $(result) ; } } diff --git a/src/tools/unix.jam b/src/tools/unix.jam index b85ef5809..4e5d7697f 100644 --- a/src/tools/unix.jam +++ b/src/tools/unix.jam @@ -86,7 +86,7 @@ class unix-archive-generator : archive-generator local result = [ archive-generator.run $(project) $(name) : $(property-set) : $(sources) ] ; - unix.set-library-order $(sources) : $(property-set) : $(result) ; + unix.set-library-order $(sources) : $(property-set) : $(result[2-]) ; return $(result) ;