This file is indexed.

/usr/share/boost-build/build-system.jam is in libboost1.49-dev 1.49.0-3.2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   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
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
# Copyright 2003, 2005, 2007 Dave Abrahams
# Copyright 2006, 2007 Rene Rivera
# Copyright 2003, 2004, 2005, 2006 Vladimir Prus
# Distributed under 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 is part of Boost Build version 2. You can think of it as forming the
# main() routine. It is invoked by the bootstrapping code in bootstrap.jam.

import build-request ;
import builtin ;
import "class" : new ;
import errors ;
import feature ;
import make ;
import modules ;
import os ;
import path ;
import project ;
import property-set ;
import regex ;
import sequence ;
import targets ;
import toolset ;
import utility ;
import version ;
import virtual-target ;
import generators ;
import configure ;

################################################################################
#
# Module global data.
#
################################################################################

# Shortcut used in this module for accessing used command-line parameters.
.argv = [ modules.peek : ARGV ] ;

# Flag indicating we should display additional debugging information related to
# locating and loading Boost Build configuration files.
.debug-config = [ MATCH ^(--debug-configuration)$ : $(.argv) ] ;

# Legacy option doing too many things, some of which are not even documented.
# Should be phased out.
#   * Disables loading site and user configuration files.
#   * Disables auto-configuration for toolsets specified explicitly on the
#     command-line.
#   * Causes --toolset command-line options to be ignored.
#   * Prevents the default toolset from being used even if no toolset has been
#     configured at all.
.legacy-ignore-config = [ MATCH ^(--ignore-config)$ : $(.argv) ] ;

# The cleaning is tricky. Say, if user says 'bjam --clean foo' where 'foo' is a
# directory, then we want to clean targets which are in 'foo' as well as those
# in any children Jamfiles under foo but not in any unrelated Jamfiles. To
# achieve this we collect a list of projects under which cleaning is allowed.
.project-targets = ;

# Virtual targets obtained when building main targets references on the command
# line. When running 'bjam --clean main_target' we want to clean only files
# belonging to that main target so we need to record which targets are produced
# for it.
.results-of-main-targets = ;

# Was an XML dump requested?
.out-xml = [ MATCH ^--out-xml=(.*)$ : $(.argv) ] ;

# Default toolset & version to be used in case no other toolset has been used
# explicitly by either the loaded configuration files, the loaded project build
# scripts or an explicit toolset request on the command line. If not specified,
# an arbitrary default will be used based on the current host OS. This value,
# while not strictly necessary, has been added to allow testing Boost-Build's
# default toolset usage functionality.
.default-toolset = ;
.default-toolset-version = ;


################################################################################
#
# Public rules.
#
################################################################################

# Returns the property set with the free features from the currently processed
# build request.
#
rule command-line-free-features ( )
{
    return $(.command-line-free-features) ;
}


# Returns the location of the build system. The primary use case is building
# Boost where it is sometimes needed to get the location of other components
# (e.g. BoostBook files) and it is convenient to use locations relative to the
# Boost Build path.
#
rule location ( )
{
    local r = [ modules.binding build-system ] ;
    return $(r:P) ;
}


# Sets the default toolset & version to be used in case no other toolset has
# been used explicitly by either the loaded configuration files, the loaded
# project build scripts or an explicit toolset request on the command line. For
# more detailed information see the comment related to used global variables.
#
rule set-default-toolset ( toolset : version ? )
{
    .default-toolset = $(toolset) ;
    .default-toolset-version = $(version) ;
}

rule set-pre-build-hook ( function )
{
    .pre-build-hook = $(function) ;
}

rule set-post-build-hook ( function )
{
    .post-build-hook = $(function) ;
}

################################################################################
#
# Local rules.
#
################################################################################

# Returns actual Jam targets to be used for executing a clean request.
#
local rule actual-clean-targets ( )
{
    # Construct a list of projects explicitly detected as targets on this build
    # system run. These are the projects under which cleaning is allowed.
    for local t in $(targets)
    {
        if [ class.is-a $(t) : project-target ]
        {
            .project-targets += [ $(t).project-module ] ;
        }
    }

    # Construct a list of targets explicitly detected on this build system run
    # as a result of building main targets.
    local targets-to-clean ;
    for local t in $(.results-of-main-targets)
    {
        # Do not include roots or sources.
        targets-to-clean += [ virtual-target.traverse $(t) ] ;
    }
    targets-to-clean = [ sequence.unique $(targets-to-clean) ] ;

    local to-clean ;
    for local t in [ virtual-target.all-targets ]
    {
        local p = [ $(t).project ] ;

        # Remove only derived targets.
        if [ $(t).action ]
        {
            if $(t) in $(targets-to-clean) ||
                [ should-clean-project [ $(p).project-module ] ] = true
            {
                to-clean += $(t) ;
            }
        }
    }

    local to-clean-actual ;
    for local t in $(to-clean)
    {
        to-clean-actual += [ $(t).actualize ] ;
    }
    return $(to-clean-actual) ;
}


# Given a target id, try to find and return the corresponding target. This is
# only invoked when there is no Jamfile in ".". This code somewhat duplicates
# code in project-target.find but we can not reuse that code without a
# project-targets instance.
#
local rule find-target ( target-id )
{
    local split = [ MATCH (.*)//(.*) : $(target-id) ] ;

    local pm ;
    if $(split)
    {
        pm = [ project.find $(split[1]) : "." ] ;
    }
    else
    {
        pm = [ project.find $(target-id) : "." ] ;
    }

    local result ;
    if $(pm)
    {
        result = [ project.target $(pm) ] ;
    }

    if $(split)
    {
        result = [ $(result).find $(split[2]) ] ;
    }

    return $(result) ;
}


# Initializes a new configuration module.
#
local rule initialize-config-module ( module-name : location ? )
{
    project.initialize $(module-name) : $(location) ;
    if USER_MODULE in [ RULENAMES ]
    {
        USER_MODULE $(module-name) ;
    }
}


# Helper rule used to load configuration files. Loads the first configuration
# file with the given 'filename' at 'path' into module with name 'module-name'.
# Not finding the requested file may or may not be treated as an error depending
# on the must-find parameter. Returns a normalized path to the loaded
# configuration file or nothing if no file was loaded.
#
local rule load-config ( module-name : filename : path + : must-find ? )
{
    if $(.debug-config)
    {
        ECHO "notice: Searching" "$(path)" "for" "$(module-name)"
            "configuration file" "$(filename)" "." ;
    }
    local where = [ GLOB $(path) : $(filename) ] ;
    if $(where)
    {
        where = [ NORMALIZE_PATH $(where[1]) ] ;
        if $(.debug-config)
        {
            ECHO "notice: Loading" "$(module-name)" "configuration file"
                "$(filename)" "from" $(where) "." ;
        }

        # Set source location so that path-constant in config files
        # with relative paths work. This is of most importance
        # for project-config.jam, but may be used in other
        # config files as well.
        local attributes = [ project.attributes $(module-name) ] ;
        $(attributes).set source-location : $(where:D) : exact ;
        modules.load $(module-name) : $(filename) : $(path) ;
        project.load-used-projects $(module-name) ;
    }
    else
    {
        if $(must-find)
        {
            errors.user-error "Configuration file" "$(filename)" "not found in"
                "$(path)" "." ;
        }
        if $(.debug-config)
        {
            ECHO "notice:" "Configuration file" "$(filename)" "not found in"
                "$(path)" "." ;
        }
    }
    return $(where) ;
}


# Loads all the configuration files used by Boost Build in the following order:
#
#   -- test-config --
#   Loaded only if specified on the command-line using the --test-config
# command-line parameter. It is ok for this file not to exist even if specified.
# If this configuration file is loaded, regular site and user configuration
# files will not be. If a relative path is specified, file is searched for in
# the current folder.
#
#   -- site-config --
#   Always named site-config.jam. Will only be found if located on the system
# root path (Windows), /etc (non-Windows), user's home folder or the Boost Build
# path, in that order. Not loaded in case the test-config configuration file is
# loaded or either the --ignore-site-config or the --ignore-config command-line
# option is specified.
#
#   -- user-config --
#   Named user-config.jam by default or may be named explicitly using the
# --user-config command-line option or the BOOST_BUILD_USER_CONFIG environment
# variable. If named explicitly the file is looked for from the current working
# directory and if the default one is used then it is searched for in the
# user's home directory and the Boost Build path, in that order. Not loaded in
# case either the test-config configuration file is loaded, --ignore-config
# command-line option is specified or an empty file name is explicitly
# specified. If the file name has been given explicitly then the file must
# exist.
#
# Test configurations have been added primarily for use by Boost Build's
# internal unit testing system but may be used freely in other places as well.
#
local rule load-configuration-files
{
    # Flag indicating that site configuration should not be loaded.
    local ignore-site-config =
        [ MATCH ^(--ignore-site-config)$ : $(.argv) ] ;

    if $(.legacy-ignore-config) && $(.debug-config)
    {
        ECHO "notice: Regular site and user configuration files will be ignored" ;
        ECHO "notice: due to the --ignore-config command-line option." ;
    }

    initialize-config-module test-config ;
    local test-config = [ MATCH ^--test-config=(.*)$ : $(.argv) ] ;
    local uq = [ MATCH \"(.*)\" : $(test-config) ] ;
    if $(uq)
    {
        test-config = $(uq) ;
    }
    if $(test-config)
    {
        local where =
            [ load-config test-config : $(test-config:BS) : $(test-config:D) ] ;
        if $(where)
        {
            if $(.debug-config) && ! $(.legacy-ignore-config)
            {
                ECHO "notice: Regular site and user configuration files will" ;
                ECHO "notice: be ignored due to the test configuration being"
                    "loaded." ;
            }
        }
        else
        {
            test-config = ;
        }
    }

    local user-path = [ os.home-directories ] [ os.environ BOOST_BUILD_PATH ] ;
    local site-path = /etc $(user-path) ;
    if [ os.name ] in NT CYGWIN
    {
        site-path = [ modules.peek : SystemRoot ] $(user-path) ;
    }

    if $(ignore-site-config) && !$(.legacy-ignore-config)
    {
        ECHO "notice: Site configuration files will be ignored due to the" ;
        ECHO "notice: --ignore-site-config command-line option." ;
    }

    initialize-config-module site-config ;
    if ! $(test-config) && ! $(ignore-site-config) && ! $(.legacy-ignore-config)
    {
        load-config site-config : site-config.jam : $(site-path) ;
    }

    initialize-config-module user-config ;
    if ! $(test-config) && ! $(.legacy-ignore-config)
    {
        local user-config = [ MATCH ^--user-config=(.*)$ : $(.argv) ] ;
        user-config = $(user-config[-1]) ;
        user-config ?= [ os.environ BOOST_BUILD_USER_CONFIG ] ;
        # Special handling for the case when the OS does not strip the quotes
        # around the file name, as is the case when using Cygwin bash.
        user-config = [ utility.unquote $(user-config) ] ;
        local explicitly-requested = $(user-config) ;
        user-config ?= user-config.jam ;

        if $(user-config)
        {
            if $(explicitly-requested)
            {
                # Treat explicitly entered user paths as native OS path
                # references and, if non-absolute, root them at the current
                # working directory.
                user-config = [ path.make $(user-config) ] ;
                user-config = [ path.root $(user-config) [ path.pwd ] ] ;
                user-config = [ path.native $(user-config) ] ;

                if $(.debug-config)
                {
                    ECHO "notice: Loading explicitly specified user"
                        "configuration file:" ;
                    ECHO "    $(user-config)" ;
                }

                load-config user-config : $(user-config:BS) : $(user-config:D)
                    : must-exist ;
            }
            else
            {
                load-config user-config : $(user-config) : $(user-path) ;
            }
        }
        else if $(.debug-config)
        {
            ECHO "notice: User configuration file loading explicitly disabled." ;
        }
    }
        
    # We look for project-config.jam from "." upward.
    # I am not sure this is 100% right decision, we might as well check for
    # it only alonside the Jamroot file. However:
    #
    # - We need to load project-root.jam before Jamroot
    # - We probably would need to load project-root.jam even if there's no
    #   Jamroot - e.g. to implement automake-style out-of-tree builds.
    local file = [ path.glob "." : project-config.jam ] ;
    if ! $(file)
    {
        file = [ path.glob-in-parents "." : project-config.jam ] ;
    }
    if $(file)
    {
        initialize-config-module project-config : $(file:D) ;
        load-config project-config : project-config.jam : $(file:D) ;        
    }   
}


# Autoconfigure toolsets based on any instances of --toolset=xx,yy,...zz or
# toolset=xx,yy,...zz in the command line. May return additional properties to
# be processed as if they had been specified by the user.
#
local rule process-explicit-toolset-requests
{
    local extra-properties ;

    local option-toolsets  = [ regex.split-list [ MATCH ^--toolset=(.*)$ : $(.argv) ] : "," ] ;
    local feature-toolsets = [ regex.split-list [ MATCH   ^toolset=(.*)$ : $(.argv) ] : "," ] ;

    for local t in $(option-toolsets) $(feature-toolsets)
    {
        # Parse toolset-version/properties.
        local (t-v,t,v) = [ MATCH (([^-/]+)-?([^/]+)?)/?.* : $(t) ] ;
        local toolset-version = $((t-v,t,v)[1]) ;
        local toolset = $((t-v,t,v)[2]) ;
        local version = $((t-v,t,v)[3]) ;

        if $(.debug-config)
        {
            ECHO notice: [cmdline-cfg] Detected command-line request for
                $(toolset-version): "toolset=" $(toolset) "version="
                $(version) ;
        }

        # If the toolset is not known, configure it now.
        local known ;
        if $(toolset) in [ feature.values <toolset> ]
        {
            known = true ;
        }
        if $(known) && $(version) && ! [ feature.is-subvalue toolset
            : $(toolset) : version : $(version) ]
        {
            known = ;
        }
        # TODO: we should do 'using $(toolset)' in case no version has been
        # specified and there are no versions defined for the given toolset to
        # allow the toolset to configure its default version. For this we need
        # to know how to detect whether a given toolset has any versions
        # defined. An alternative would be to do this whenever version is not
        # specified but that would require that toolsets correctly handle the
        # case when their default version is configured multiple times which
        # should be checked for all existing toolsets first.

        if ! $(known)
        {
            if $(.debug-config)
            {
                ECHO "notice: [cmdline-cfg] toolset $(toolset-version) not"
                    "previously configured; attempting to auto-configure now" ;
            }
            toolset.using $(toolset) : $(version) ;
        }
        else
        {
            if $(.debug-config)
            {
                ECHO notice: [cmdline-cfg] toolset $(toolset-version) already
                    configured ;
            }
        }

        # Make sure we get an appropriate property into the build request in
        # case toolset has been specified using the "--toolset=..." command-line
        # option form.
        if ! $(t) in $(.argv) && ! $(t) in $(feature-toolsets)
        {
            if $(.debug-config)
            {
                ECHO notice: [cmdline-cfg] adding toolset=$(t) to the build
                    request. ;
            }
            extra-properties += toolset=$(t) ;
        }
    }

    return $(extra-properties) ;
}


# Returns 'true' if the given 'project' is equal to or is a (possibly indirect)
# child to any of the projects requested to be cleaned in this build system run.
# Returns 'false' otherwise. Expects the .project-targets list to have already
# been constructed.
#
local rule should-clean-project ( project )
{
    if ! $(.should-clean-project.$(project))
    {
        local r = false ;
        if $(project) in $(.project-targets)
        {
            r = true ;
        }
        else
        {
            local parent = [ project.attribute $(project) parent-module ] ;
            if $(parent) && $(parent) != user-config
            {
                r = [ should-clean-project $(parent) ] ;
            }
        }
        .should-clean-project.$(project) = $(r) ;
    }

    return $(.should-clean-project.$(project)) ;
}


################################################################################
#
# main()
# ------
#
################################################################################

{    
    if --version in $(.argv)
    {
        version.print ;
        EXIT ;
    }
    
    version.verify-engine-version ;    
    
    load-configuration-files ;

    local extra-properties ;
    # Note that this causes --toolset options to be ignored if --ignore-config
    # is specified.
    if ! $(.legacy-ignore-config)
    {
        extra-properties = [ process-explicit-toolset-requests ] ;
    }


    # We always load project in "." so that 'use-project' directives have any
    # chance of being seen. Otherwise, we would not be able to refer to
    # subprojects using target ids.
    local current-project ;
    if [ project.find "." : "." ]
    {
        current-project = [ project.target [ project.load "." ] ] ;
    }


    # In case there are no toolsets currently defined makes the build run using
    # the default toolset.
    if ! $(.legacy-ignore-config) && ! [ feature.values <toolset> ]
    {
        local default-toolset = $(.default-toolset) ;
        local default-toolset-version = ;
        if $(default-toolset)
        {
            default-toolset-version = $(.default-toolset-version) ;
        }
        else
        {
            default-toolset = gcc ;
            if [ os.name ] = NT
            {
                default-toolset = msvc ;
            }
            else if [ os.name ] = MACOSX
            {
                default-toolset = darwin ;
            }                        
        }

        ECHO "warning: No toolsets are configured." ;
        ECHO "warning: Configuring default toolset" \"$(default-toolset)\". ;
        ECHO "warning: If the default is wrong, your build may not work correctly." ;
        ECHO "warning: Use the \"toolset=xxxxx\" option to override our guess." ;
        ECHO "warning: For more configuration options, please consult" ;
        ECHO "warning: http://boost.org/boost-build2/doc/html/bbv2/advanced/configuration.html" ;

        toolset.using $(default-toolset) : $(default-toolset-version) ;
    }


    # Parse command line for targets and properties. Note that this requires
    # that all project files already be loaded.
    local build-request = [ build-request.from-command-line $(.argv)
        $(extra-properties) ] ;
    local target-ids = [ $(build-request).get-at 1 ] ;
    local properties = [ $(build-request).get-at 2 ] ;


    # Expand properties specified on the command line into multiple property
    # sets consisting of all legal property combinations. Each expanded property
    # set will be used for a single build run. E.g. if multiple toolsets are
    # specified then requested targets will be built with each of them.
    if $(properties)
    {
        expanded = [ build-request.expand-no-defaults $(properties) ] ;
        local xexpanded ;
        for local e in $(expanded)
        {
            xexpanded += [ property-set.create [ feature.split $(e) ] ] ;
        }
        expanded = $(xexpanded) ;
    }
    else
    {
        expanded = [ property-set.empty ] ;
    }


    # Check that we actually found something to build.
    if ! $(current-project) && ! $(target-ids)
    {
        errors.user-error "error: no Jamfile in current directory found, and no"
            "target references specified." ;
        EXIT ;
    }


    # Flags indicating that this build system run has been started in order to
    # clean existing instead of create new targets. Note that these are not the
    # final flag values as they may get changed later on due to some special
    # targets being specified on the command line.
    local clean    ; if "--clean"     in $(.argv) { clean    = true ; }
    local cleanall ; if "--clean-all" in $(.argv) { cleanall = true ; }


    # List of explicitly requested files to build. Any target references read
    # from the command line parameter not recognized as one of the targets
    # defined in the loaded Jamfiles will be interpreted as an explicitly
    # requested file to build. If any such files are explicitly requested then
    # only those files and the targets they depend on will be built and they
    # will be searched for among targets that would have been built had there
    # been no explicitly requested files.
    local explicitly-requested-files


    # List of Boost Build meta-targets, virtual-targets and actual Jam targets
    # constructed in this build system run.
    local targets ;
    local virtual-targets ;
    local actual-targets ;


    # Process each target specified on the command-line and convert it into
    # internal Boost Build target objects. Detect special clean target. If no
    # main Boost Build targets were explictly requested use the current project
    # as the target.
    for local id in $(target-ids)
    {
        if $(id) = clean
        {
            clean = true ;
        }
        else
        {
            local t ;
            if $(current-project)
            {
                t = [ $(current-project).find $(id) : no-error ] ;
            }
            else
            {
                t = [ find-target $(id) ] ;
            }

            if ! $(t)
            {
                ECHO "notice: could not find main target" $(id) ;
                ECHO "notice: assuming it is a name of file to create." ;
                explicitly-requested-files += $(id) ;
            }
            else
            {
                targets += $(t) ;
            }
        }
    }
    if ! $(targets)
    {
        targets += [ project.target [ project.module-name "." ] ] ;
    }
    
    if [ option.get dump-generators : : true ] 
    {
        generators.dump ;
    }
    
    # We wish to put config.log in the build directory corresponding
    # to Jamroot, so that the location does not differ depending on
    # directory where we do build.  The amount of indirection necessary
    # here is scary.
    local first-project = [ $(targets[0]).project ] ;
    local first-project-root-location = [ $(first-project).get project-root ] ;
    local first-project-root-module = [ project.load $(first-project-root-location) ] ;
    local first-project-root = [ project.target  $(first-project-root-module) ] ;
    local first-build-build-dir = [ $(first-project-root).build-dir ] ;
    configure.set-log-file $(first-build-build-dir)/config.log ;
    
    # Now that we have a set of targets to build and a set of property sets to
    # build the targets with, we can start the main build process by using each
    # property set to generate virtual targets from all of our listed targets
    # and any of their dependants.
    for local p in $(expanded)
    {
        .command-line-free-features = [ property-set.create [ $(p).free ] ] ;
        for local t in $(targets)
        {
            local g = [ $(t).generate $(p) ] ;
            if ! [ class.is-a $(t) : project-target ]
            {
                .results-of-main-targets += $(g[2-]) ;
            }
            virtual-targets += $(g[2-]) ;
        }
    }


    # Convert collected virtual targets into actual raw Jam targets.
    for t in $(virtual-targets)
    {
        actual-targets += [ $(t).actualize ] ;
    }


    # If XML data output has been requested prepare additional rules and targets
    # so we can hook into Jam to collect build data while its building and have
    # it trigger the final XML report generation after all the planned targets
    # have been built.
    if $(.out-xml)
    {
        # Get a qualified virtual target name.
        rule full-target-name ( target )
        {
            local name = [ $(target).name ] ;
            local project = [ $(target).project ] ;
            local project-path = [ $(project).get location ] ;
            return $(project-path)//$(name) ;
        }

        # Generate an XML file containing build statistics for each constituent.
        #
        rule out-xml ( xml-file : constituents * )
        {
            # Prepare valid XML header and footer with some basic info.
            local nl = "
" ;
            local os        = [ modules.peek : OS OSPLAT JAMUNAME ] "" ;
            local timestamp = [ modules.peek : JAMDATE ] ;
            local cwd       = [ PWD ] ;
            local command   = $(.argv) ;
            local bb-version = [ version.boost-build ] ;
            .header on $(xml-file) =
                "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
                "$(nl)<build format=\"1.0\" version=\"$(bb-version)\">"
                "$(nl)  <os name=\"$(os[1])\" platform=\"$(os[2])\"><![CDATA[$(os[3-]:J= )]]></os>"
                "$(nl)  <timestamp><![CDATA[$(timestamp)]]></timestamp>"
                "$(nl)  <directory><![CDATA[$(cwd)]]></directory>"
                "$(nl)  <command><![CDATA[\"$(command:J=\" \")\"]]></command>"
                ;
            .footer on $(xml-file) =
                "$(nl)</build>" ;

            # Generate the target dependency graph.
            .contents on $(xml-file) +=
                "$(nl)  <targets>" ;
            for local t in [ virtual-target.all-targets ]
            {
                local action = [ $(t).action ] ;
                if $(action)
                    # If a target has no action, it has no dependencies.
                {
                    local name = [ full-target-name $(t) ] ;
                    local sources = [ $(action).sources ] ;
                    local dependencies ;
                    for local s in $(sources)
                    {
                        dependencies += [ full-target-name $(s) ] ;
                    }

                    local path = [ $(t).path ] ;
                    local jam-target = [ $(t).actual-name ] ;

                    .contents on $(xml-file) +=
                        "$(nl)    <target>"
                        "$(nl)      <name><![CDATA[$(name)]]></name>"
                        "$(nl)      <dependencies>"
                        "$(nl)        <dependency><![CDATA[$(dependencies)]]></dependency>"
                        "$(nl)      </dependencies>"
                        "$(nl)      <path><![CDATA[$(path)]]></path>"
                        "$(nl)      <jam-target><![CDATA[$(jam-target)]]></jam-target>"
                        "$(nl)    </target>"
                        ;
                }
            }
            .contents on $(xml-file) +=
                "$(nl)  </targets>" ;

            # Build $(xml-file) after $(constituents). Do so even if a
            # constituent action fails and regenerate the xml on every bjam run.
            INCLUDES $(xml-file) : $(constituents) ;
            ALWAYS $(xml-file) ;
            __ACTION_RULE__ on $(xml-file) = build-system.out-xml.generate-action ;
            out-xml.generate $(xml-file) ;
        }

        # The actual build actions are here; if we did this work in the actions
        # clause we would have to form a valid command line containing the
        # result of @(...) below (the name of the XML file).
        #
        rule out-xml.generate-action ( args * : xml-file
            : command status start end user system : output ? )
        {
            local contents =
                [ on $(xml-file) return $(.header) $(.contents) $(.footer) ] ;
            local f = @($(xml-file):E=$(contents)) ;
        }

        # Nothing to do here; the *real* actions happen in
        # out-xml.generate-action.
        actions quietly out-xml.generate { }

        # Define the out-xml file target, which depends on all the targets so
        # that it runs the collection after the targets have run.
        out-xml $(.out-xml) : $(actual-targets) ;

        # Set up a global __ACTION_RULE__ that records all the available
        # statistics about each actual target in a variable "on" the --out-xml
        # target.
        #
        rule out-xml.collect ( xml-file : target : command status start end user
            system : output ? )
        {
            local nl = "
" ;
            # Open the action with some basic info.
            .contents on $(xml-file) +=
                "$(nl)  <action status=\"$(status)\" start=\"$(start)\" end=\"$(end)\" user=\"$(user)\" system=\"$(system)\">" ;

            # If we have an action object we can print out more detailed info.
            local action = [ on $(target) return $(.action) ] ;
            if $(action)
            {
                local action-name    = [ $(action).action-name ] ;
                local action-sources = [ $(action).sources     ] ;
                local action-props   = [ $(action).properties  ] ;

                # The qualified name of the action which we created the target.
                .contents on $(xml-file) +=
                    "$(nl)    <name><![CDATA[$(action-name)]]></name>" ;

                # The sources that made up the target.
                .contents on $(xml-file) +=
                    "$(nl)    <sources>" ;
                for local source in $(action-sources)
                {
                    local source-actual = [ $(source).actual-name ] ;
                    .contents on $(xml-file) +=
                        "$(nl)      <source><![CDATA[$(source-actual)]]></source>" ;
                }
                .contents on $(xml-file) +=
                    "$(nl)    </sources>" ;

                # The properties that define the conditions under which the
                # target was built.
                .contents on $(xml-file) +=
                    "$(nl)    <properties>" ;
                for local prop in [ $(action-props).raw ]
                {
                    local prop-name = [ MATCH ^<(.*)>$ : $(prop:G) ] ;
                    .contents on $(xml-file) +=
                        "$(nl)      <property name=\"$(prop-name)\"><![CDATA[$(prop:G=)]]></property>" ;
                }
                .contents on $(xml-file) +=
                    "$(nl)    </properties>" ;
            }

            local locate = [ on $(target) return $(LOCATE) ] ;
            locate ?= "" ;
            .contents on $(xml-file) +=
                "$(nl)    <jam-target><![CDATA[$(target)]]></jam-target>"
                "$(nl)    <path><![CDATA[$(target:G=:R=$(locate))]]></path>"
                "$(nl)    <command><![CDATA[$(command)]]></command>"
                "$(nl)    <output><![CDATA[$(output)]]></output>" ;
            .contents on $(xml-file) +=
                "$(nl)  </action>" ;
        }

        # When no __ACTION_RULE__ is set "on" a target, the search falls back to
        # the global module.
        module
        {
            __ACTION_RULE__ = build-system.out-xml.collect
                [ modules.peek build-system : .out-xml ] ;
        }
        
        IMPORT
            build-system :
            out-xml.collect
            out-xml.generate-action
            : :
            build-system.out-xml.collect
            build-system.out-xml.generate-action
            ;
    }

    local j = [ option.get jobs ] ;
    if $(j)
    {
        modules.poke : PARALLELISM : $(j) ;
    }
    
    local k = [ option.get keep-going : true : true ] ;
    if $(k) in "on" "yes" "true"
    {
        modules.poke : KEEP_GOING : 1 ;
    }
    else if $(k) in "off" "no" "false"
    {
        modules.poke : KEEP_GOING : 0 ;
    }
    else
    {
        ECHO "error: Invalid value for the --keep-going option" ;
        EXIT ;
    }
                
    # The 'all' pseudo target is not strictly needed expect in the case when we
    # use it below but people often assume they always have this target
    # available and do not declare it themselves before use which may cause
    # build failures with an error message about not being able to build the
    # 'all' target.
    NOTFILE all ;

    # And now that all the actual raw Jam targets and all the dependencies
    # between them have been prepared all that is left is to tell Jam to update
    # those targets.
    if $(explicitly-requested-files)
    {
        # Note that this case can not be joined with the regular one when only
        # exact Boost Build targets are requested as here we do not build those
        # requested targets but only use them to construct the dependency tree
        # needed to build the explicitly requested files.
        UPDATE $(explicitly-requested-files:G=e) $(.out-xml) ;
    }
    else if $(cleanall)
    {
        UPDATE clean-all ;
    }
    else if $(clean)
    {
        common.Clean clean : [ actual-clean-targets ] ;
        UPDATE clean ;
    }
    else
    {      
        configure.print-configure-checks-summary ;        
        
        if $(.pre-build-hook)
        {
            $(.pre-build-hook) ;
        }
        
        DEPENDS all : $(actual-targets) ;
        if UPDATE_NOW in [ RULENAMES ]
        {            
            local ok = [ UPDATE_NOW all $(.out-xml) ] ;
            if $(.post-build-hook)
            {
                $(.post-build-hook) $(ok) ;
            }
            # Prevent automatic update of the 'all' target, now that
            # we have explicitly updated what we wanted.
            UPDATE ;
        }
        else
        {
            UPDATE all $(.out-xml) ;
        }            
    }
}