summaryrefslogtreecommitdiff
path: root/jam-files/boost-build/tools/unix.jam
blob: 75949851a0cb9b453a404df0d27ed4272cc5601a (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#  Copyright (c) 2004 Vladimir Prus.
#
#  Use, modification and distribution is subject to the Boost Software
#  License Version 1.0. (See accompanying file LICENSE_1_0.txt or
#  http://www.boost.org/LICENSE_1_0.txt)

#  This file implements linking semantic common to all unixes. On unix, static
#  libraries must be specified in a fixed order on the linker command line. Generators
#  declared there store information about the order and use it property.

import feature ;
import "class" : new ;
import generators ;
import type ;
import set ;
import order ;
import builtin ;

class unix-linking-generator : linking-generator
{
    import property-set ;
    import type ;
    import unix ;
    
    rule __init__ ( id 
        composing ? : # Specify if generator is composing. The generator will be
        # composing if non-empty string is passed, or parameter is
        # not given. To make generator non-composing, pass empty
        # string ("")
        source-types + : target-types + : 
        requirements * )
    {
        composing ?= true ;
        generator.__init__ $(id) $(composing) : $(source-types) : $(target-types) :
          $(requirements) ;
    }
    
    rule run ( project name ? : property-set : sources + )
    {   
        local result = [ linking-generator.run $(project) $(name) : $(property-set)
          : $(sources) ] ;
        
        unix.set-library-order $(sources) : $(property-set) : $(result[2-]) ;
                                
        return $(result) ;
    }
    
    rule generated-targets ( sources + : property-set : project name ? )
    {
        local sources2 ;
        local libraries ;
        for local l in $(sources)
        {
            if [ type.is-derived [ $(l).type ] LIB ]
            {
                libraries += $(l) ;
            }
            else
            {
                sources2 += $(l) ;
            }            
        }
        
        sources = $(sources2) [ unix.order-libraries $(libraries) ] ;
        
        return [ linking-generator.generated-targets $(sources) : $(property-set)
          : $(project) $(name) ] ;
    }
    
} 

class unix-archive-generator : archive-generator
{
    import unix ; 

    rule __init__ ( id composing ? : source-types + : target-types + : 
        requirements * )
    {
        composing ?= true ;
        archive-generator.__init__ $(id) $(composing) : $(source-types) : $(target-types) :
          $(requirements) ;
    }
        
    rule run ( project name ? : property-set : sources + )
    {                                
        local result = [ archive-generator.run $(project) $(name) : $(property-set)
          : $(sources) ] ;
        
        unix.set-library-order $(sources) : $(property-set) : $(result[2-]) ;
        
        return $(result) ;

    }    
}

class unix-searched-lib-generator : searched-lib-generator
{
    import unix ;
    rule __init__ ( * : * )
    { 
        generator.__init__ 
          $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
    }
    
    rule optional-properties ( )
    {
        return $(self.requirements) ;
    }
              
    rule run ( project name ? : property-set : sources * )
    {
        local result = [ searched-lib-generator.run $(project) $(name) 
          : $(property-set) : $(sources) ] ;
        
        unix.set-library-order $(sources) : $(property-set) : $(result[2-]) ;
        
        return $(result) ;
    }    
}

class unix-prebuilt-lib-generator : generator
{
    import unix ;
    rule __init__ ( * : * )
    {
        generator.__init__ $(1) : $(2) : $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ;
    }

    rule run ( project name ? : property-set : sources * )
    {
        local f = [ $(property-set).get <file> ] ;
        unix.set-library-order-aux $(f) : $(sources) ;
        return $(f) $(sources) ;
    }    
}

generators.register 
  [ new unix-prebuilt-lib-generator unix.prebuilt : : LIB 
      : <file> <toolset>unix ] ;

generators.override unix.prebuilt : builtin.lib-generator ;


# Declare generators
generators.register [ new unix-linking-generator unix.link : LIB OBJ : EXE 
    : <toolset>unix ] ;

generators.register [ new unix-archive-generator unix.archive : OBJ : STATIC_LIB 
    : <toolset>unix ] ;

generators.register [ new unix-linking-generator unix.link.dll : LIB OBJ : SHARED_LIB 
    : <toolset>unix ] ;

generators.register [ new unix-searched-lib-generator 
   unix.searched-lib-generator : : SEARCHED_LIB : <toolset>unix ] ;


# The derived toolset must specify their own actions.
actions link {
}

actions link.dll {
}

actions archive {    
}

actions searched-lib-generator {    
}

actions prebuilt {
}

    



.order = [ new order ] ;

rule set-library-order-aux ( from * : to * )
{        
    for local f in $(from)
    {
        for local t in $(to)
        {            
            if $(f) != $(t)
            {                
                $(.order).add-pair $(f) $(t) ;
            }            
        }        
    }    
}

rule set-library-order ( sources * : property-set : result * )
{
    local used-libraries ;
    local deps = [ $(property-set).dependency ] ;        
    for local l in $(sources) $(deps:G=)        
    {
        if [ $(l).type ] && [ type.is-derived [ $(l).type ] LIB ]
        {
            used-libraries += $(l) ;
        }
    }

    local created-libraries ;
    for local l in $(result)
    {
        if [ $(l).type ] && [ type.is-derived [ $(l).type ] LIB ] 
        {
            created-libraries += $(l) ;
        }            
    }
    
    created-libraries = [ set.difference $(created-libraries) : $(used-libraries) ] ;
    set-library-order-aux $(created-libraries) : $(used-libraries) ;
}

rule order-libraries ( libraries * )
{
    local r = [ $(.order).order $(libraries) ] ;
    return $(r) ;
}