1#
2# /+\
3# +\    Copyright 1993, 2000 Christopher Seiwald.
4# \+/
5#
6# This file is part of Jam - see jam.c for Copyright information.
7#
8
9# This file is ALSO:
10# Copyright 2001-2004 David Abrahams.
11# Copyright 2002-2004 Rene Rivera.
12# Copyright 2015 Artur Shepilko.
13# Distributed under the Boost Software License, Version 1.0.
14# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
15
16if $(NT)
17{
18    SLASH ?= \\ ;
19}
20SLASH ?= / ;
21
22
23# Glob for patterns in the directories starting from the given start directory,
24# up to and including the root of the file-system. We stop globbing as soon as
25# we find at least one match.
26#
27rule find-to-root ( dir : patterns + )
28{
29    local globs = [ GLOB $(dir) : $(patterns) ] ;
30    while ! $(globs) && $(dir:P) != $(dir)
31    {
32        dir = $(dir:P) ;
33        globs = [ GLOB $(dir) : $(patterns) ] ;
34    }
35    return $(globs) ;
36}
37
38
39# This global will hold the location of the user's boost-build.jam file.
40.boost-build-file = ;
41
42# This global will hold the location of the build system bootstrap file.
43.bootstrap-file = ;
44
45# Remember the value of $(BOOST_BUILD_PATH) supplied to us by the user.
46BOOST_BUILD_PATH.user-value = $(BOOST_BUILD_PATH) ;
47
48# On Unix only, when BOOST_BUILD_PATH is not supplied by the user, set it to a
49# sensible default value. This allows Boost.Build to work without any
50# environment variables, which is good in itself and also required by the Debian
51# Policy.
52if ! $(BOOST_BUILD_PATH) && $(UNIX)
53{
54    BOOST_BUILD_PATH = /usr/share/boost-build ;
55}
56
57
58rule _poke ( module-name ? : variables + : value * )
59{
60    module $(<)
61    {
62        $(>) = $(3) ;
63    }
64}
65
66
67# This rule can be invoked from an optional user's boost-build.jam file to both
68# indicate where to find the build system files, and to load them. The path
69# indicated is relative to the location of the boost-build.jam file.
70#
71rule boost-build ( dir ? )
72{
73    if $(.bootstrap-file)
74    {
75        ECHO "Error: Illegal attempt to re-bootstrap the build system by invoking" ;
76        ECHO ;
77        ECHO "   'boost-build" $(dir) ";'" ;
78        ECHO ;
79        EXIT "Please consult the documentation at 'http://www.boost.org'." ;
80    }
81
82    # Add the given directory to the path so we can find the build system. If
83    # dir is empty, has no effect.
84    BOOST_BUILD_PATH = $(dir:R=$(.boost-build-file:D)) $(BOOST_BUILD_PATH) ;
85
86    # We might have just modified the *global* value of BOOST_BUILD_PATH. The
87    # code that loads the rest of Boost.Build, in particular the site-config.jam
88    # and user-config.jam configuration files uses os.environ, so we need to
89    # update the value there.
90    _poke .ENVIRON : BOOST_BUILD_PATH : $(BOOST_BUILD_PATH) ;
91
92    # Try to find the build system bootstrap file 'bootstrap.jam'.
93    local bootstrap-file = [ GLOB $(BOOST_BUILD_PATH) : bootstrap.jam ] ;
94    .bootstrap-file = $(bootstrap-file[1]) ;
95
96    # There is no bootstrap.jam we can find, exit with an error.
97    if ! $(.bootstrap-file)
98    {
99        ECHO "Unable to load Boost.Build: could not find build system." ;
100        ECHO --------------------------------------------------------- ;
101        ECHO "$(.boost-build-file) attempted to load the build system by invoking" ;
102        ECHO ;
103        ECHO "   'boost-build" $(dir) ";'" ;
104        ECHO ;
105        ECHO "but we were unable to find \"bootstrap.jam\" in the specified directory" ;
106        ECHO "or in BOOST_BUILD_PATH (searching "$(BOOST_BUILD_PATH:J=", ")")." ;
107        ECHO ;
108        EXIT "Please consult the documentation at 'http://www.boost.org'." ;
109    }
110
111    if [ MATCH .*(--debug-configuration).* : $(ARGV) ]
112    {
113        ECHO "notice: loading Boost.Build from"
114            [ NORMALIZE_PATH $(.bootstrap-file:D) ] ;
115    }
116
117    # Load the build system, now that we know where to start from.
118    include $(.bootstrap-file) ;
119}
120
121
122{
123    # We attempt to load "boost-build.jam" by searching from the current
124    # invocation directory up to the root of the file-system.
125    #
126    # boost-build.jam is expected to invoke the "boost-build" rule to load the
127    # Boost.Build files.
128
129    local search-path = $(BOOST_BUILD_PATH) $(BOOST_ROOT) ;
130    local self = [ SELF_PATH ] ;
131    local boost-build-relative = ../../share/boost-build ;
132    local self-based-path = [ NORMALIZE_PATH $(boost-build-relative:R=$(self)) ] ;
133
134    local boost-build-files =
135        [ find-to-root [ PWD ] : boost-build.jam ]
136        [ GLOB $(self-based-path) : boost-build.jam ]
137        # Another temporary measure so Jam works with Boost.Build v1.
138        [ GLOB $(search-path) : boost-build.jam ] ;
139
140    .boost-build-file = $(boost-build-files[1]) ;
141
142    # There is no boost-build.jam we can find, exit with an error, and
143    # information.
144    if ! $(.boost-build-file)
145    {
146        ECHO "Unable to load Boost.Build: could not find \"boost-build.jam\"" ;
147        ECHO --------------------------------------------------------------- ;
148
149        if ! [ MATCH .*(bjam).* : $(ARGV[1]:BL) ]
150        {
151            ECHO "BOOST_ROOT must be set, either in the environment, or " ;
152            ECHO "on the command-line with -sBOOST_ROOT=..., to the root" ;
153            ECHO "of the boost installation." ;
154            ECHO ;
155        }
156
157        ECHO "Attempted search from" [ PWD ] "up to the root" ;
158        ECHO "at" $(self-based-path) ;
159        ECHO "and in these directories from BOOST_BUILD_PATH and BOOST_ROOT: "$(search-path:J=", ")"." ;
160        EXIT "Please consult the documentation at 'http://www.boost.org'." ;
161    }
162
163    if [ MATCH .*(--debug-configuration).* : $(ARGV) ]
164    {
165        ECHO "notice: found boost-build.jam at"
166            [ NORMALIZE_PATH $(.boost-build-file) ] ;
167    }
168
169    # Now load the boost-build.jam to get the build system loaded. This
170    # incidentaly loads the users jamfile and attempts to build targets.
171    #
172    # We also set it up so we can tell whether we are loading the new V2 system
173    # or the the old V1 system.
174    include $(.boost-build-file) ;
175
176    # Check that, at minimum, the bootstrap file was found.
177    if ! $(.bootstrap-file)
178    {
179        ECHO "Unable to load Boost.Build" ;
180        ECHO -------------------------- ;
181        ECHO "\"$(.boost-build-file)\" was found by searching from" [ PWD ] "up to the root" ;
182        ECHO "and in these directories from BOOST_BUILD_PATH and BOOST_ROOT: "$(search-path:J=", ")"." ;
183        ECHO ;
184        ECHO "However, it failed to call the \"boost-build\" rule to indicate" ;
185        ECHO "the location of the build system." ;
186        ECHO ;
187        EXIT "Please consult the documentation at 'http://www.boost.org'." ;
188    }
189}
190