summaryrefslogtreecommitdiff
path: root/tools/build/v2/build/ac.jam
blob: 6768f358c22fc807b81aff06f9aac2fd79f57b02 (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
# Copyright (c) 2010 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)

import property-set ;
import path ;
import modules ;
import "class" ; 
import errors ;
import configure ;

rule find-include-path ( variable : properties : header 
    : provided-path ? )
{
    # FIXME: document which properties affect this function by
    # default.
    local target-os = [ $(properties).get <target-os> ] ;
    properties = [ property-set.create <target-os>$(toolset) ] ;    
    if $($(variable)-$(properties))
    {
        return $($(variable)-$(properties)) ;
    }
    else
    {
        provided-path ?= [ modules.peek : $(variable) ] ;
        includes = $(provided-path) ;
        includes += [ $(properties).get <include> ] ;
        if [ $(properties).get <target-os> ] != windows
        {
            # FIXME: use sysroot
            includes += /usr/include ;
        }
        
        local result ;
        while ! $(result) && $(includes)
        {            
            local f = [ path.root $(header) $(includes[1]) ] ;
            ECHO "Checking " $(f) ;
            if [ path.exists $(f) ]
            {
                result = $(includes[1]) ;
            }
            else if $(provided-path)
            {
                errors.user-error "Could not find header" $(header)
                  : "in the user-specified directory" $(provided-path) ;
            }            
            includes = $(includes[2-]) ;                
        }        
        $(variable)-$(properties) = $(result) ;
        return $(result) ;
    }        
}

rule find-library ( variable : properties : names + : provided-path ? )
{
    local target-os = [ $(properties).get <target-os> ] ;
    properties = [ property-set.create <target-os>$(toolset) ] ;
    if $($(variable)-$(properties))
    {
        return $($(variable)-$(properties)) ;
    }
    else
    {
        provided-path ?= [ modules.peek : $(variable) ] ;
        paths = $(provided-path) ;
        paths += [ $(properties).get <library-path> ] ;
        if [ $(properties).get <target-os> ] != windows
        {
            paths += /usr/lib /usr/lib32 /usr/lib64 ;
        }
        
        local result ;               
        while ! $(result) && $(paths)
        {   
            while ! $(result) && $(names)
            {
                local f ;
                if $(target-os) = windows
                {         
                    f = $(paths[1])/$(names[1]).lib ;                
                    if [ path.exists $(f) ] 
                    {
                        result = $(f) ;
                    }
                }
                else
                {
                    # FIXME: check for .a as well, depending on
                    # the 'link' feature.
                    f = $(paths[1])/lib$(names[1]).so ;                
                    ECHO "CHECKING $(f) " ;
                    if [ path.exists $(f) ] 
                    {
                        result = $(f) ;
                    }
                }
                if ! $(result) && $(provided-path)
                {
                    errors.user-error "Could not find either of: " $(names)
                      : "in the user-specified directory" $(provided-path) ;
                    
                }                
                names = $(names[2-]) ;
            }
            paths = $(paths[2-]) ;
        }        
        $(variable)-$(properties) = $(result) ;
        return $(result) ;
    }
}

class ac-library : basic-target
{
    import errors ;
    import indirect ;
    import virtual-target ;
    import ac ;
    import configure ;

    rule __init__ ( name : project : * : * )
    {
        basic-target.__init__ $(name) : $(project) : $(sources)
          : $(requirements) ;
        
        reconfigure $(3) : $(4) : $(5) : $(6) : $(7) : $(8) : $(9) ; 
    }
    
    rule set-header ( header )
    {
        self.header = $(header) ; 
    }
        
    rule set-default-names ( names + )
    {
        self.default-names = $(names) ;
    }
        
    rule reconfigure ( * : * )
    {
        ECHO "XXX" $(1) ;
        if ! $(1)
        {
            # This is 'using xxx ;'. Nothing to configure, really.
        }
        else
        {
            for i in 1 2 3 4 5 6 7 8 9             
            {
                # FIXME: this naming is inconsistent with XXX_INCLUDE/XXX_LIBRARY
                if ! ( $($(i)[1]) in root include-path library-path library-name condition )
                {
                    errors.user-error "Invalid named parameter" $($(i)[1]) ;
                }   
                local name = $($(i)[1]) ;
                local value = $($(i)[2-]) ;
                if $($(name)) && $($(name)) != $(value)
                {
                    errors.user-error "Attempt to change value of '$(name)'" ;
                }
                $(name) = $(value) ;
            }
            
            include-path ?= $(root)/include ;
            library-path ?= $(root)/lib ;            
        }        
    }
    
    rule construct ( name : sources * : property-set )
    {
        # FIXME: log results.
        local libnames = $(library-name) ;
        if ! $(libnames) && ! $(include-path) && ! $(library-path)
        {
            libnames = [ modules.peek : $(name:U)_NAME ] ;
            # Backward compatibility only.
            libnames ?= [ modules.peek : $(name:U)_BINARY ] ;
        }
        libnames ?= $(self.default-names) ;
                        
        local includes = [ 
          ac.find-include-path $(name:U)_INCLUDE : $(property-set) : $(self.header) : $(include-path) ] ;
        local library = [ ac.find-library $(name:U)_LIBRARY : $(property-set) : $(libnames) : $(library-path) ] ;
        if $(includes) && $(library)
        {
            library = [ virtual-target.from-file $(library) : . : $(self.project) ] ;
            configure.log-library-search-result $(name) : "found" ;
            return [ property-set.create <include>$(includes) <source>$(library) ] ;
        }
        else
        {
            configure.log-library-search-result $(name) : "no found" ;
        }        
    }
}