• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 Rene Rivera
2# Copyright 2017 Steven Watanabe
3# Copyright 2016 Vladimir Prus
4# Copyright 2017 Edward Diener
5# Distributed under the Boost Software License, Version 1.0.
6# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
7
8import "class" : new ;
9import bison ;
10import errors ;
11import feature ;
12import indirect ;
13import os ;
14# import package ;
15import path ;
16import set ;
17import stage : add-install-dir ;
18import toolset ;
19import type ;
20import virtual-target ;
21
22path-constant SELF : . ;
23
24project b2
25    : build-dir .build
26    : requirements
27        <cxxstd>11
28        <toolset>msvc:<define>_CRT_SECURE_NO_WARNINGS=1
29        <toolset>msvc:<define>_CRT_NONSTDC_NO_DEPRECATE=1
30    ;
31
32#|
33Build the engine and its dependencies outside of the simple core build scripts.
34This allows us to keep the core build scripts as simple as possible. And lets
35us support more functionality for development of the engine core.
36|#
37
38#|
39Define custom yyacc tool.
40|#
41
42feature.feature yyacc : : dependency free ;
43toolset.flags yyacc TOOL <yyacc> ;
44
45exe yyacc
46    :   src/engine/yyacc.cpp
47    :   ;
48explicit yyacc ;
49
50rule yyacc-gen ( project name : property-set : sources * )
51{
52    local relevant = [ toolset.relevant $(__name__).yyacc ] ;
53    local a = [ new action $(sources[1]) : $(__name__).yyacc : [ $(property-set).add $(relevant) ] ] ;
54    local targets ;
55    for local n in $(name:S=).y $(name:S=)tab.h
56    {
57        targets += [ virtual-target.register
58            [ new file-target $(n) exact : [ type.type $(n) ]
59                : $(project) : $(a)
60                ] ] ;
61    }
62    return $(targets) ;
63}
64
65actions yyacc bind TOOL
66{
67    "$(TOOL)" "$(<)" "$(>)"
68}
69
70generate jamgram.y
71    :   src/engine/jamgram.yy
72    :   <generating-rule>@yyacc-gen
73        <location>src/engine
74        <yyacc>yyacc <dependency>yyacc
75    ;
76explicit jamgram.y ;
77
78#|
79Define grammar translation with Bison.
80|#
81
82BISON = [ os.environ BISON ] ;
83BISON ?= bison ;
84local BISON_IN_PATH = [ path.glob [ os.executable-path ] : $(BISON[1]) $(BISON[1]).* ] ;
85
86rule grammar ( target : source : properties * )
87{
88    # LOCATE on $(target) = $(source:D) ;
89    BISON on $(target) = $(BISON) ;
90}
91
92actions grammar
93{
94    "$(BISON)" --yacc --defines -o "$(<[1])" "$(>)"
95}
96
97if $(BISON_IN_PATH)
98{
99    make jamgram.cpp
100        :   src/engine/jamgram.y
101        :   @grammar
102        :   <dependency>jamgram.y
103            <location>src/engine ;
104}
105else
106{
107    errors.warning "Bison generator program '$(BISON:J= )' not found. Skipping grammar build." ;
108    alias jamgram.cpp
109        :   src/engine/jamgram.cpp ;
110}
111explicit jamgram.cpp ;
112
113#|
114Define the b2 executable. Sources are based on platform.
115TODO: Make platform specific source be no-ops when not needed.
116|#
117
118local python-exe = [ MATCH --with-python=(.*) : [ modules.peek : ARGV ] ] ;
119local python-include ;
120local python-ldlib ;
121if $(python-exe)
122{
123    python-include = [ SHELL
124        "$(python-exe) -c \"import sysconfig; print(sysconfig.get_path('include'));\""
125        : strip-eol ] ;
126    python-libdir = [ SHELL
127        "$(python-exe) -c \"import sysconfig; import os.path; print(sysconfig.get_config_var('LIBDIR'));\""
128        : strip-eol ] ;
129    python-ldlib = [ MATCH ".*(python.*)" : [ SHELL
130        "$(python-exe) -c \"import sysconfig; import os.path; print(sysconfig.get_config_var('LIBRARY'));\""
131        : strip-eol ] ] ;
132    python-ldlib = $(python-ldlib:S=) ;
133
134    lib python
135        :
136        : <name>$(python-ldlib) <search>$(python-libdir)
137        :
138        : <include>$(python-include) <define>HAVE_PYTHON ;
139}
140else
141{
142    alias python ;
143}
144
145local b2_src =
146    [ glob src/engine/*.cpp src/engine/modules/*.cpp :
147        src/engine/*nt.cpp src/engine/*unix.cpp src/engine/*vms.cpp
148        src/engine/yyacc.cpp src/engine/mkjambase.cpp
149        src/engine/check_cxx11.cpp
150        ] ;
151local b2_src_nt = [ glob src/engine/*nt.cpp ] ;
152local b2_src_unix = [ glob src/engine/*unix.cpp ] ;
153local b2_src_vms = [ glob src/engine/*vms.cpp ] ;
154local unix_os = [ set.difference [ feature.values <target-os> ] : windows vms ] ;
155
156exe b2
157    :   $(b2_src)
158        python
159    :   <target-os>windows:<source>$(b2_src_nt)
160        <target-os>vms:<source>$(b2_src_vms)
161        <target-os>$(unix_os):<source>$(b2_src_unix)
162        <dependency>jamgram.cpp
163        <toolset>msvc:<find-static-library>kernel32
164        <toolset>msvc:<find-static-library>advapi32
165        <toolset>msvc:<find-static-library>user32
166    ;
167explicit b2 ;
168
169#|
170Installation of the engine, build, and example files.
171|#
172
173feature.feature b2-install-layout : standard portable : incidental propagated ;
174
175add-install-dir b2prefix-standard : : prefix ;
176add-install-dir b2bindir-standard : : bindir ;
177add-install-dir b2coredir-standard : boost-build/src : datarootdir ;
178add-install-dir b2examplesdir-standard : boost-build/examples : datarootdir ;
179
180add-install-dir b2prefix-portable : : prefix ;
181add-install-dir b2bindir-portable : : b2prefix-portable ;
182add-install-dir b2coredir-portable : .b2 : b2prefix-portable ;
183add-install-dir b2examplesdir-portable : .b2/examples : b2prefix-portable ;
184
185local ext = "" ;
186if [ os.on-windows ] || [ os.on-vms ]
187{
188    ext = ".exe" ;
189}
190
191install b2-engine
192    :   $(SELF)/src/engine/b2$(ext)
193    :   <b2-install-layout>standard:<location>(b2bindir-standard)
194        <b2-install-layout>portable:<location>(b2bindir-portable)
195    ;
196explicit b2-engine ;
197
198local examples ;
199for local e in [ glob-tree-ex $(SELF)/example : * : . .svn ]
200{
201    if [ CHECK_IF_FILE [ path.native $(e) ] ]
202    {
203        examples += $(e) ;
204    }
205}
206install b2-examples
207    : # What to install
208        $(examples)
209    :   # What is the root of the directory
210        <install-source-root>example
211        # Which subdir of $prefix/share
212        <b2-install-layout>standard:<location>(b2examplesdir-standard)
213        <b2-install-layout>portable:<location>(b2examplesdir-portable)
214    ;
215explicit b2-examples ;
216
217local .core-sources =
218    $(SELF)/src/build-system.jam
219    [ path.glob-tree $(SELF)/src/build : *.jam ]
220    [ path.glob-tree $(SELF)/src/contrib : *.jam ]
221    [ path.glob-tree $(SELF)/src/kernel : *.jam ]
222    [ path.glob-tree $(SELF)/src/options : *.jam ]
223    [ path.glob-tree $(SELF)/src/util : *.jam ]
224    [ path.glob-tree $(SELF)/src/tools : *.jam *.xml *.xsl *.doxyfile *.hpp doxproc.py ]
225    ;
226if $(python-exe)
227{
228    .core-sources +=
229        [ path.glob-tree $(SELF)/src/build : *.py ]
230        [ path.glob-tree $(SELF)/src/contrib : *.py ]
231        [ path.glob-tree $(SELF)/src/kernel : *.py ]
232        [ path.glob-tree $(SELF)/src/options : *.py ]
233        [ path.glob-tree $(SELF)/src/util : *.py ]
234        [ path.glob-tree $(SELF)/src/tools : *.py : doxproc.py ]
235        ;
236}
237
238install b2-core
239    :   # What to install
240        $(.core-sources)
241    :   # What is the root of the directory
242        <install-source-root>src
243        # Which subdir of $prefix/share
244        <b2-install-layout>standard:<location>(b2coredir-standard)
245        <b2-install-layout>portable:<location>(b2coredir-portable)
246    ;
247explicit b2-core ;
248
249#|
250Only install example files when requested to avoid bloating install footprint.
251|#
252if --with-examples in [ modules.peek : ARGV ]
253{
254    alias install : b2-engine b2-core b2-examples ;
255}
256else
257{
258    alias install : b2-engine b2-core ;
259}
260explicit install ;
261