1 | # (C) Copyright David Abrahams 2001-2003. Permission to copy, use, |
---|
2 | # modify, sell and distribute this software is granted provided this |
---|
3 | # copyright notice appears in all copies. This software is provided |
---|
4 | # "as is" without express or implied warranty, and with no claim as |
---|
5 | # to its suitability for any purpose. |
---|
6 | |
---|
7 | # This file is part of Boost.Build version 2. You can think of it as |
---|
8 | # forming the main() routine. It is invoked by the bootstrapping code |
---|
9 | # in bootstrap.jam. |
---|
10 | # |
---|
11 | # The version of bootstrap.jam invoking this lives in |
---|
12 | # tools/build/kernel until BBv1 is retired, so that BBv1 can have its |
---|
13 | # bootstrap.jam in this directory. |
---|
14 | |
---|
15 | import project ; |
---|
16 | import targets ; |
---|
17 | import sequence ; |
---|
18 | import modules ; |
---|
19 | import feature ; |
---|
20 | import property-set ; |
---|
21 | import build-request ; |
---|
22 | import errors : error ; |
---|
23 | import "class" : new ; |
---|
24 | |
---|
25 | import builtin ; |
---|
26 | import make ; |
---|
27 | import os ; |
---|
28 | |
---|
29 | import version ; |
---|
30 | |
---|
31 | # Returns the location of the build system. The primary use case |
---|
32 | # is building Boost, where it's sometimes needed to get location |
---|
33 | # of other components (like BoostBook files), and it's convenient |
---|
34 | # to use location relatively to Boost.Build path. |
---|
35 | rule location ( ) |
---|
36 | { |
---|
37 | local r = [ modules.binding build-system ] ; |
---|
38 | return $(r:P) ; |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | # Check if we can load 'test-config.jam'. If we can, load it and |
---|
43 | # ignore user configs. |
---|
44 | local test-config = [ GLOB [ os.environ BOOST_BUILD_PATH ] : test-config.jam ] ; |
---|
45 | if $(test-config) |
---|
46 | { |
---|
47 | module test-config |
---|
48 | { |
---|
49 | import project : _using : using ; |
---|
50 | } |
---|
51 | import test-config ; |
---|
52 | } |
---|
53 | |
---|
54 | local ignore-config ; |
---|
55 | if $(test-config) || --ignore-config in [ modules.peek : ARGV ] |
---|
56 | { |
---|
57 | ignore-config = true ; |
---|
58 | } |
---|
59 | |
---|
60 | local user-path = [ os.home-directories ] [ os.environ BOOST_BUILD_PATH ] ; |
---|
61 | |
---|
62 | # Load site-config. |
---|
63 | module site-config |
---|
64 | { |
---|
65 | import project : initialize ; |
---|
66 | initialize site-config ; |
---|
67 | } |
---|
68 | |
---|
69 | if ! $(ignore-config) |
---|
70 | { |
---|
71 | local path ; |
---|
72 | if [ os.name ] in NT CYGWIN |
---|
73 | { |
---|
74 | path = [ modules.peek : SystemRoot ] $(user-path) ; |
---|
75 | } |
---|
76 | else |
---|
77 | { |
---|
78 | path = /etc $(user-path) ; |
---|
79 | } |
---|
80 | |
---|
81 | |
---|
82 | if --debug-configuration in [ modules.peek : ARGV ] |
---|
83 | { |
---|
84 | local where = [ GLOB $(path) : site-config.jam ] ; |
---|
85 | if $(where) |
---|
86 | { |
---|
87 | ECHO "notice: loading site-config.jam from" |
---|
88 | [ NORMALIZE_PATH $(where[1]) ] ; |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | modules.load site-config : : $(path) ; |
---|
93 | } |
---|
94 | |
---|
95 | |
---|
96 | # Load user-config. |
---|
97 | module user-config |
---|
98 | { |
---|
99 | import project : initialize ; |
---|
100 | initialize user-config ; |
---|
101 | } |
---|
102 | |
---|
103 | if ! $(ignore-config) |
---|
104 | { |
---|
105 | if --debug-configuration in [ modules.peek : ARGV ] |
---|
106 | { |
---|
107 | local where = [ GLOB $(user-path) : user-config.jam ] ; |
---|
108 | if $(where) |
---|
109 | { |
---|
110 | ECHO "notice: loading user-config.jam from" |
---|
111 | [ NORMALIZE_PATH $(where[1]) ] ; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | modules.load user-config : : $(user-path) ; |
---|
116 | |
---|
117 | } |
---|
118 | |
---|
119 | |
---|
120 | if USER_MODULE in [ RULENAMES ] |
---|
121 | { |
---|
122 | USER_MODULE site-config user-config ; |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | |
---|
127 | if --version in [ modules.peek : ARGV ] |
---|
128 | { |
---|
129 | version.print ; |
---|
130 | EXIT ; |
---|
131 | } |
---|
132 | |
---|
133 | # We always load project in "." so that 'use-project' directives has |
---|
134 | # any chance of been seen. Otherwise, we won't be able to refer to |
---|
135 | # subprojects using target ids. |
---|
136 | if [ project.find "." : "." ] |
---|
137 | { |
---|
138 | current-project = [ project.target [ project.load "." ] ] ; |
---|
139 | } |
---|
140 | |
---|
141 | if ! [ feature.values <toolset> ] |
---|
142 | { |
---|
143 | ECHO "warning: no toolsets are configured." ; |
---|
144 | ECHO "warning: you won't be able to build C++ programs." ; |
---|
145 | ECHO "warning: please consult the documentation." ; |
---|
146 | ECHO ; |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | |
---|
151 | build-request = [ build-request.from-command-line [ modules.peek : ARGV ] ] ; |
---|
152 | |
---|
153 | properties = [ $(build-request).get-at 2 ] ; |
---|
154 | |
---|
155 | if $(properties) |
---|
156 | { |
---|
157 | expanded = [ build-request.expand-no-defaults $(properties) ] ; |
---|
158 | local xexpanded ; |
---|
159 | for local e in $(expanded) |
---|
160 | { |
---|
161 | xexpanded += [ property-set.create [ feature.split $(e) ] ] ; |
---|
162 | } |
---|
163 | expanded = $(xexpanded) ; |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | local target-ids = [ $(build-request).get-at 1 ] ; |
---|
168 | local targets |
---|
169 | local clean ; |
---|
170 | |
---|
171 | |
---|
172 | if "--clean" in [ modules.peek : ARGV ] |
---|
173 | { |
---|
174 | clean = true ; |
---|
175 | } |
---|
176 | |
---|
177 | local bjam-targets ; |
---|
178 | |
---|
179 | # Given a target it, try to find and return corresponding target. |
---|
180 | # This is only invoked when there's no Jamfile in "." |
---|
181 | # This code somewhat duplicates code in project-target.find but we can't reuse |
---|
182 | # that code without project-targets instance. |
---|
183 | rule find-target ( target-id ) |
---|
184 | { |
---|
185 | local split = [ MATCH (.*)//(.*) : $(target-id) ] ; |
---|
186 | |
---|
187 | local pm ; |
---|
188 | if $(split) |
---|
189 | { |
---|
190 | pm = [ project.find $(split[1]) : "." ] ; |
---|
191 | } |
---|
192 | else |
---|
193 | { |
---|
194 | pm = [ project.find $(target-id) : "." ] ; |
---|
195 | } |
---|
196 | |
---|
197 | local result ; |
---|
198 | if $(pm) |
---|
199 | { |
---|
200 | result = [ project.target $(pm) ] ; |
---|
201 | } |
---|
202 | |
---|
203 | if $(split) |
---|
204 | { |
---|
205 | result = [ $(result).find $(split[2]) ] ; |
---|
206 | } |
---|
207 | |
---|
208 | return $(result) ; |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | if ! $(current-project) |
---|
214 | { |
---|
215 | if ! $(target-ids) |
---|
216 | { |
---|
217 | ECHO "error: no Jamfile in current directory found, and no target references specified." ; |
---|
218 | EXIT ; |
---|
219 | } |
---|
220 | } |
---|
221 | |
---|
222 | |
---|
223 | for local id in $(target-ids) |
---|
224 | { |
---|
225 | if $(id) = clean |
---|
226 | { |
---|
227 | clean = true ; |
---|
228 | } |
---|
229 | else |
---|
230 | { |
---|
231 | local t ; |
---|
232 | if $(current-project) |
---|
233 | { |
---|
234 | t = [ $(current-project).find $(id) : no-error ] ; |
---|
235 | } |
---|
236 | else |
---|
237 | { |
---|
238 | t = [ find-target $(id) ] ; |
---|
239 | } |
---|
240 | |
---|
241 | if ! $(t) |
---|
242 | { |
---|
243 | ECHO "notice: could not find main target " $(id) ; |
---|
244 | ECHO "notice: assuming it's a name of file to create " ; |
---|
245 | bjam-targets += $(id) ; |
---|
246 | } |
---|
247 | else |
---|
248 | { |
---|
249 | targets += $(t) ; |
---|
250 | } |
---|
251 | } |
---|
252 | } |
---|
253 | |
---|
254 | if ! $(targets) |
---|
255 | { |
---|
256 | targets += [ project.target [ project.module-name "." ] ] ; |
---|
257 | } |
---|
258 | |
---|
259 | virtual-targets = ; |
---|
260 | |
---|
261 | if $(expanded) |
---|
262 | { |
---|
263 | for local p in $(expanded) |
---|
264 | { |
---|
265 | for local t in $(targets) |
---|
266 | { |
---|
267 | local g = [ $(t).generate $(p) ] ; |
---|
268 | virtual-targets += $(g[2-]) ; |
---|
269 | } |
---|
270 | } |
---|
271 | } |
---|
272 | else |
---|
273 | { |
---|
274 | for local t in $(targets) |
---|
275 | { |
---|
276 | local g = [ $(t).generate [ property-set.empty ] ] ; |
---|
277 | virtual-targets += $(g[2-]) ; |
---|
278 | } |
---|
279 | } |
---|
280 | |
---|
281 | |
---|
282 | actual-targets = ; |
---|
283 | for t in $(virtual-targets) |
---|
284 | { |
---|
285 | actual-targets += [ $(t).actualize ] ; |
---|
286 | } |
---|
287 | NOTFILE all ; |
---|
288 | DEPENDS all : $(actual-targets) ; |
---|
289 | |
---|
290 | if $(bjam-targets) |
---|
291 | { |
---|
292 | UPDATE $(bjam-targets) ; |
---|
293 | } |
---|
294 | else if $(clean) |
---|
295 | { |
---|
296 | UPDATE clean ; |
---|
297 | } |
---|
298 | else |
---|
299 | { |
---|
300 | UPDATE all ; |
---|
301 | } |
---|
302 | |
---|
303 | |
---|
304 | |
---|