blob: 6afc8e7aa6218ed25aaba77a01fc59590a2b5228 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# Copyright 2002-2017 Rene Rivera
# Copyright 2002-2017 Vladimir Prus
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
import "class" : new ;
import generators ;
# The generator class for handling STATIC_LIB creation.
#
class archive-generator : generator
{
import generators ;
import property-set ;
rule __init__ ( id composing ? : source-types + : target-types +
: requirements * )
{
composing ?= true ;
generator.__init__ $(id) $(composing) : $(source-types)
: $(target-types) : $(requirements) ;
}
rule run ( project name ? : property-set : sources + )
{
sources += [ $(property-set).get <library> ] ;
property-set = [ $(property-set).add-raw <relevant>link ] ;
local result = [ generator.run $(project) $(name) : $(property-set)
: $(sources) ] ;
# For static linking, if we get a library in source, we can not 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 <library> usage requirements.
# The problem with the first is:
#
# lib a1 : : <file>liba1.a ;
# lib a2 : a2.cpp a1 : <link>static ;
# install dist : a2 ;
#
# here we will try to install 'a1', even though it is not necessary in
# the general case. With the second approach, even indirect dependants
# will link to the library, but it should not cause any harm. So, return
# all LIB sources together with created targets, so that dependants link
# to them.
local usage-requirements = <relevant>link ;
if [ $(property-set).get <link> ] = static
{
for local t in $(sources)
{
if [ $(t).type ] && [ type.is-derived [ $(t).type ] LIB ]
{
usage-requirements += <library>$(t) ;
}
}
}
return [ generators.add-usage-requirements $(result) : $(usage-requirements) ] ;
}
}
rule register-archiver ( id composing ? : source-types + : target-types +
: requirements * )
{
generators.register [ new archive-generator $(id) $(composing)
: $(source-types) : $(target-types) : $(requirements) ] ;
}
IMPORT $(__name__) : register-archiver : : generators.register-archiver ;
|