1 | # Copyright 2003, 2005 Dave Abrahams |
---|
2 | # Copyright 2006 Rene Rivera |
---|
3 | # Copyright 2003, 2004, 2005, 2006 Vladimir Prus |
---|
4 | # Distributed under the Boost Software License, Version 1.0. |
---|
5 | # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) |
---|
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 virtual-target ; |
---|
24 | import "class" : new ; |
---|
25 | import toolset ; |
---|
26 | import regex ; |
---|
27 | |
---|
28 | import builtin ; |
---|
29 | import make ; |
---|
30 | import os ; |
---|
31 | |
---|
32 | import version ; |
---|
33 | |
---|
34 | # Returns the location of the build system. The primary use case |
---|
35 | # is building Boost, where it's sometimes needed to get location |
---|
36 | # of other components (like BoostBook files), and it's convenient |
---|
37 | # to use location relatively to Boost.Build path. |
---|
38 | rule location ( ) |
---|
39 | { |
---|
40 | local r = [ modules.binding build-system ] ; |
---|
41 | return $(r:P) ; |
---|
42 | } |
---|
43 | |
---|
44 | |
---|
45 | # Check if we can load 'test-config.jam'. If we can, load it and |
---|
46 | # ignore user configs. |
---|
47 | |
---|
48 | local argv = [ modules.peek : ARGV ] ; |
---|
49 | |
---|
50 | local test-config = [ GLOB [ os.environ BOOST_BUILD_PATH ] : test-config.jam ] ; |
---|
51 | |
---|
52 | local debug-config = [ MATCH ^(--debug-configuration)$ : [ modules.peek : ARGV ] ] ; |
---|
53 | |
---|
54 | if $(test-config) |
---|
55 | { |
---|
56 | if $(debug-config) |
---|
57 | { |
---|
58 | ECHO "notice: loading test-config.jam from" |
---|
59 | [ NORMALIZE_PATH $(test-config[1]) ] ; |
---|
60 | ECHO "notice: user-config.jam and site-config.jam will be ignored" ; |
---|
61 | } |
---|
62 | |
---|
63 | module test-config |
---|
64 | { |
---|
65 | import toolset : using : using ; |
---|
66 | } |
---|
67 | import test-config ; |
---|
68 | } |
---|
69 | |
---|
70 | local ignore-config ; |
---|
71 | if $(test-config) || --ignore-config in [ modules.peek : ARGV ] |
---|
72 | { |
---|
73 | ignore-config = true ; |
---|
74 | } |
---|
75 | |
---|
76 | local user-path = [ os.home-directories ] [ os.environ BOOST_BUILD_PATH ] ; |
---|
77 | |
---|
78 | # Unless ignore-config is set, load the configuration file in |
---|
79 | # $(path)/$(basename).jam |
---|
80 | local rule load-config ( basename : path + ) |
---|
81 | { |
---|
82 | if ! $(ignore-config) |
---|
83 | { |
---|
84 | if $(debug-config) |
---|
85 | { |
---|
86 | ECHO notice: searching \"$(path)\" for \"$(basename).jam\" ; |
---|
87 | local where = [ GLOB $(path) : $(basename).jam ] ; |
---|
88 | if $(where) |
---|
89 | { |
---|
90 | ECHO notice: loading $(basename).jam from |
---|
91 | [ NORMALIZE_PATH $(where[1]) ] ; |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | modules.load $(basename) : : $(path) ; |
---|
96 | project.load-used-projects $(basename) ; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | # |
---|
101 | # Load site-config. |
---|
102 | # |
---|
103 | module site-config |
---|
104 | { |
---|
105 | import project : initialize ; |
---|
106 | initialize site-config ; |
---|
107 | } |
---|
108 | |
---|
109 | local site-path = /etc $(user-path) ; |
---|
110 | |
---|
111 | if [ os.name ] in NT CYGWIN |
---|
112 | { |
---|
113 | site-path = [ modules.peek : SystemRoot ] $(user-path) ; |
---|
114 | } |
---|
115 | |
---|
116 | load-config site-config : $(site-path) ; |
---|
117 | |
---|
118 | # |
---|
119 | # Load user-config. |
---|
120 | # |
---|
121 | module user-config |
---|
122 | { |
---|
123 | import project : initialize ; |
---|
124 | initialize user-config ; |
---|
125 | } |
---|
126 | |
---|
127 | local user-config-path = [ MATCH ^--user-config=(.*) : $(argv) ] ; |
---|
128 | |
---|
129 | if $(user-config-path) |
---|
130 | { |
---|
131 | if $(debug-config) |
---|
132 | { |
---|
133 | ECHO "Loading explicitly specifier user configuration file:" ; |
---|
134 | ECHO " $(user-config-path)" ; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | modules.load user-config : $(user-config-path:BS) : $(user-config-path:D) ; |
---|
139 | project.load-used-projects user-config ; |
---|
140 | } |
---|
141 | else |
---|
142 | { |
---|
143 | load-config user-config : $(user-path) ; |
---|
144 | } |
---|
145 | |
---|
146 | |
---|
147 | # |
---|
148 | # Autoconfigure toolsets based on any instances of --toolset=xx,yy,...zz or |
---|
149 | # toolset=xx,yy,...zz in the command line |
---|
150 | # |
---|
151 | local option-toolsets = [ regex.split-list [ MATCH ^--toolset=(.*) : $(argv) ] : "," ] ; |
---|
152 | local feature-toolsets = [ regex.split-list [ MATCH ^toolset=(.*) : $(argv) ] : "," ] ; |
---|
153 | |
---|
154 | # if the user specified --toolset=..., we need to add toolset=... to |
---|
155 | # the build request |
---|
156 | local extra-build-request ; |
---|
157 | |
---|
158 | if ! $(ignore-config) |
---|
159 | { |
---|
160 | for local t in $(option-toolsets) $(feature-toolsets) |
---|
161 | { |
---|
162 | # Parse toolset-version/properties |
---|
163 | local (t-v,t,v) = [ MATCH (([^-/]+)-?([^/]+)?)/?.* : $(t) ] ; |
---|
164 | local toolset-version = $((t-v,t,v)[1]) ; |
---|
165 | local toolset = $((t-v,t,v)[2]) ; |
---|
166 | local version = $((t-v,t,v)[3]) ; |
---|
167 | |
---|
168 | if $(debug-config) |
---|
169 | { |
---|
170 | ECHO notice: [cmdline-cfg] Detected command-line request for |
---|
171 | $(toolset-version): toolset= \"$(toolset)\" "version= \""$(version)\" ; |
---|
172 | } |
---|
173 | |
---|
174 | local known ; |
---|
175 | |
---|
176 | # if the toolset isn't known, configure it now. |
---|
177 | if $(toolset) in [ feature.values <toolset> ] |
---|
178 | { |
---|
179 | known = true ; |
---|
180 | } |
---|
181 | |
---|
182 | if $(known) && $(version) |
---|
183 | && ! [ feature.is-subvalue toolset : $(toolset) : version : $(version) ] |
---|
184 | { |
---|
185 | known = ; |
---|
186 | } |
---|
187 | |
---|
188 | if ! $(known) |
---|
189 | { |
---|
190 | if $(debug-config) |
---|
191 | { |
---|
192 | ECHO notice: [cmdline-cfg] toolset $(toolset-version) |
---|
193 | not previously configured; configuring now ; |
---|
194 | } |
---|
195 | toolset.using $(toolset) : $(version) ; |
---|
196 | } |
---|
197 | else |
---|
198 | { |
---|
199 | if $(debug-config) |
---|
200 | { |
---|
201 | ECHO notice: [cmdline-cfg] toolset $(toolset-version) already configured ; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | # make sure we get an appropriate property into the build request in |
---|
206 | # case the user used the "--toolset=..." form |
---|
207 | if ! $(t) in $(argv) |
---|
208 | && ! $(t) in $(feature-toolsets) |
---|
209 | { |
---|
210 | if $(debug-config) |
---|
211 | { |
---|
212 | ECHO notice: [cmdline-cfg] adding toolset=$(t) "to build request." ; |
---|
213 | } |
---|
214 | extra-build-request += toolset=$(t) ; |
---|
215 | } |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | if USER_MODULE in [ RULENAMES ] |
---|
220 | { |
---|
221 | USER_MODULE site-config user-config ; |
---|
222 | } |
---|
223 | |
---|
224 | |
---|
225 | |
---|
226 | if --version in [ modules.peek : ARGV ] |
---|
227 | { |
---|
228 | version.print ; |
---|
229 | EXIT ; |
---|
230 | } |
---|
231 | |
---|
232 | |
---|
233 | |
---|
234 | # We always load project in "." so that 'use-project' directives has |
---|
235 | # any chance of been seen. Otherwise, we won't be able to refer to |
---|
236 | # subprojects using target ids. |
---|
237 | if [ project.find "." : "." ] |
---|
238 | { |
---|
239 | current-project = [ project.target [ project.load "." ] ] ; |
---|
240 | } |
---|
241 | |
---|
242 | if ! [ feature.values <toolset> ] |
---|
243 | { |
---|
244 | local default-toolset = gcc ; |
---|
245 | if [ os.name ] = NT |
---|
246 | { |
---|
247 | default-toolset = msvc ; |
---|
248 | } |
---|
249 | |
---|
250 | ECHO "warning: No toolsets are configured." ; |
---|
251 | ECHO "warning: Configuring default toolset" \"$(default-toolset)\". ; |
---|
252 | ECHO "warning: If the default is wrong, you may not be able to build C++ programs." ; |
---|
253 | ECHO "warning: Use the \"--toolset=xxxxx\" option to override our guess." ; |
---|
254 | ECHO "warning: For more configuration options, please consult" ; |
---|
255 | ECHO "warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html" ; |
---|
256 | |
---|
257 | |
---|
258 | if ! $(ignore-config) |
---|
259 | { |
---|
260 | toolset.using $(default-toolset) ; |
---|
261 | } |
---|
262 | } |
---|
263 | |
---|
264 | build-request = [ |
---|
265 | build-request.from-command-line [ |
---|
266 | modules.peek : ARGV |
---|
267 | ] $(extra-build-request) |
---|
268 | ] ; |
---|
269 | |
---|
270 | properties = [ $(build-request).get-at 2 ] ; |
---|
271 | |
---|
272 | if $(properties) |
---|
273 | { |
---|
274 | expanded = [ build-request.expand-no-defaults $(properties) ] ; |
---|
275 | local xexpanded ; |
---|
276 | for local e in $(expanded) |
---|
277 | { |
---|
278 | xexpanded += [ property-set.create [ feature.split $(e) ] ] ; |
---|
279 | } |
---|
280 | expanded = $(xexpanded) ; |
---|
281 | } |
---|
282 | else |
---|
283 | { |
---|
284 | expanded = [ property-set.empty ] ; |
---|
285 | } |
---|
286 | |
---|
287 | |
---|
288 | |
---|
289 | local target-ids = [ $(build-request).get-at 1 ] ; |
---|
290 | local targets |
---|
291 | local clean ; |
---|
292 | |
---|
293 | |
---|
294 | if "--clean-all" in [ modules.peek : ARGV ] |
---|
295 | { |
---|
296 | cleanall = true ; |
---|
297 | } |
---|
298 | |
---|
299 | if "--clean" in [ modules.peek : ARGV ] |
---|
300 | { |
---|
301 | clean = true ; |
---|
302 | } |
---|
303 | |
---|
304 | |
---|
305 | local bjam-targets ; |
---|
306 | |
---|
307 | # Given a target it, try to find and return corresponding target. |
---|
308 | # This is only invoked when there's no Jamfile in "." |
---|
309 | # This code somewhat duplicates code in project-target.find but we can't reuse |
---|
310 | # that code without project-targets instance. |
---|
311 | rule find-target ( target-id ) |
---|
312 | { |
---|
313 | local split = [ MATCH (.*)//(.*) : $(target-id) ] ; |
---|
314 | |
---|
315 | local pm ; |
---|
316 | if $(split) |
---|
317 | { |
---|
318 | pm = [ project.find $(split[1]) : "." ] ; |
---|
319 | } |
---|
320 | else |
---|
321 | { |
---|
322 | pm = [ project.find $(target-id) : "." ] ; |
---|
323 | } |
---|
324 | |
---|
325 | local result ; |
---|
326 | if $(pm) |
---|
327 | { |
---|
328 | result = [ project.target $(pm) ] ; |
---|
329 | } |
---|
330 | |
---|
331 | if $(split) |
---|
332 | { |
---|
333 | result = [ $(result).find $(split[2]) ] ; |
---|
334 | } |
---|
335 | |
---|
336 | return $(result) ; |
---|
337 | } |
---|
338 | |
---|
339 | |
---|
340 | |
---|
341 | if ! $(current-project) |
---|
342 | { |
---|
343 | if ! $(target-ids) |
---|
344 | { |
---|
345 | ECHO "error: no Jamfile in current directory found, and no target references specified." ; |
---|
346 | EXIT ; |
---|
347 | } |
---|
348 | } |
---|
349 | |
---|
350 | |
---|
351 | for local id in $(target-ids) |
---|
352 | { |
---|
353 | if $(id) = clean |
---|
354 | { |
---|
355 | clean = true ; |
---|
356 | } |
---|
357 | else |
---|
358 | { |
---|
359 | local t ; |
---|
360 | if $(current-project) |
---|
361 | { |
---|
362 | t = [ $(current-project).find $(id) : no-error ] ; |
---|
363 | } |
---|
364 | else |
---|
365 | { |
---|
366 | t = [ find-target $(id) ] ; |
---|
367 | } |
---|
368 | |
---|
369 | if ! $(t) |
---|
370 | { |
---|
371 | ECHO "notice: could not find main target " $(id) ; |
---|
372 | ECHO "notice: assuming it's a name of file to create " ; |
---|
373 | bjam-targets += $(id) ; |
---|
374 | } |
---|
375 | else |
---|
376 | { |
---|
377 | targets += $(t) ; |
---|
378 | } |
---|
379 | } |
---|
380 | } |
---|
381 | |
---|
382 | if ! $(targets) |
---|
383 | { |
---|
384 | targets += [ project.target [ project.module-name "." ] ] ; |
---|
385 | } |
---|
386 | |
---|
387 | virtual-targets = ; |
---|
388 | |
---|
389 | # Virtual targets obtained when building main targets references on |
---|
390 | # the command line. When running |
---|
391 | # |
---|
392 | # bjam --clean main_target |
---|
393 | # |
---|
394 | # we want to clean the files that belong only to that main target, |
---|
395 | # so we need to record which targets are produced. |
---|
396 | local results-of-main-targets ; |
---|
397 | |
---|
398 | for local p in $(expanded) |
---|
399 | { |
---|
400 | for local t in $(targets) |
---|
401 | { |
---|
402 | local g = [ $(t).generate $(p) ] ; |
---|
403 | if ! [ class.is-a $(t) : project-target ] |
---|
404 | { |
---|
405 | results-of-main-targets += $(g[2-]) ; |
---|
406 | } |
---|
407 | virtual-targets += $(g[2-]) ; |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | # The cleaning is tricky. Say, if |
---|
412 | # user says: |
---|
413 | # |
---|
414 | # bjam --clean foo |
---|
415 | # |
---|
416 | # where 'foo' is a directory, then we want to clean targets |
---|
417 | # which are in 'foo' or in any children Jamfiles, but not in any |
---|
418 | # unrelated Jamfiles. So, we collect the list of project under which |
---|
419 | # cleaning is allowed. |
---|
420 | # |
---|
421 | |
---|
422 | local projects-to-clean ; |
---|
423 | local targets-to-clean ; |
---|
424 | if $(clean) || $(clean-all) |
---|
425 | { |
---|
426 | for local t in $(targets) |
---|
427 | { |
---|
428 | if [ class.is-a $(t) : project-target ] |
---|
429 | { |
---|
430 | projects-to-clean += [ $(t).project-module ] ; |
---|
431 | } |
---|
432 | } |
---|
433 | |
---|
434 | local subvariants ; |
---|
435 | for local t in $(results-of-main-targets) |
---|
436 | { |
---|
437 | # Don't include roots or sources. |
---|
438 | targets-to-clean += [ virtual-target.traverse $(t) ] ; |
---|
439 | } |
---|
440 | targets-to-clean = [ sequence.unique $(targets-to-clean) ] ; |
---|
441 | } |
---|
442 | |
---|
443 | # Returns 'true' if 'project' is a child of 'current-project', |
---|
444 | # possibly indirect, or is equal to 'project'. |
---|
445 | # Returns 'false' otherwise. |
---|
446 | rule is-child ( project ) |
---|
447 | { |
---|
448 | if ! $(.is-child.$(project)) |
---|
449 | { |
---|
450 | local r = false ; |
---|
451 | if $(project) in $(projects-to-clean) |
---|
452 | { |
---|
453 | r = true ; |
---|
454 | } |
---|
455 | else |
---|
456 | { |
---|
457 | local parent = [ project.attribute $(project) parent-module ] ; |
---|
458 | if $(parent) && $(parent) != user-config |
---|
459 | { |
---|
460 | r = [ is-child $(parent) ] ; |
---|
461 | } |
---|
462 | } |
---|
463 | |
---|
464 | .is-child.$(project) = $(r) ; |
---|
465 | } |
---|
466 | |
---|
467 | return $(.is-child.$(project)) ; |
---|
468 | } |
---|
469 | |
---|
470 | |
---|
471 | |
---|
472 | |
---|
473 | actual-targets = ; |
---|
474 | for t in $(virtual-targets) |
---|
475 | { |
---|
476 | actual-targets += [ $(t).actualize ] ; |
---|
477 | } |
---|
478 | NOTFILE all ; |
---|
479 | DEPENDS all : $(actual-targets) ; |
---|
480 | |
---|
481 | if $(bjam-targets) |
---|
482 | { |
---|
483 | UPDATE $(bjam-targets:G=e) ; |
---|
484 | } |
---|
485 | else if $(cleanall) |
---|
486 | { |
---|
487 | UPDATE clean-all ; |
---|
488 | } |
---|
489 | else if $(clean) |
---|
490 | { |
---|
491 | local to-clean ; |
---|
492 | for local t in [ virtual-target.all-targets ] |
---|
493 | { |
---|
494 | local p = [ $(t).project ] ; |
---|
495 | |
---|
496 | # Remove only derived targets. |
---|
497 | if [ $(t).action ] |
---|
498 | { |
---|
499 | if $(t) in $(targets-to-clean) |
---|
500 | || [ is-child [ $(p).project-module ] ] = true |
---|
501 | { |
---|
502 | to-clean += $(t) ; |
---|
503 | } |
---|
504 | } |
---|
505 | } |
---|
506 | local to-clean-actual ; |
---|
507 | for local t in $(to-clean) |
---|
508 | { |
---|
509 | to-clean-actual += [ $(t).actualize ] ; |
---|
510 | } |
---|
511 | common.Clean clean : $(to-clean-actual) ; |
---|
512 | UPDATE clean ; |
---|
513 | |
---|
514 | |
---|
515 | } |
---|
516 | |
---|
517 | else |
---|
518 | { |
---|
519 | UPDATE all ; |
---|
520 | } |
---|
521 | |
---|
522 | |
---|
523 | |
---|