1b(1)                        General Commands Manual                       b(1)
2
3
4

NAME

6       b - build system driver
7

SYNOPSIS

9       b --help
10       b --version
11       b [options] [variables] [buildspec]
12
13       buildspec = meta-operation(operation(target...[,parameters])...)...
14

DESCRIPTION

16       The build2 build system driver executes a set of meta-operations on op‐
17       erations on targets according to the build specification, or  buildspec
18       for short.  This process can be controlled by specifying driver options
19       and build system variables.
20
21       Note that options, variables, and buildspec fragments can be  specified
22       in  any order. To avoid treating an argument that starts with '-' as an
23       option, add the '--' separator. To avoid treating an argument that con‐
24       tains '=' as a variable, add the second '--' separator.
25
26       All  components  in  the buildspec can be omitted. If meta-operation is
27       omitted, then it defaults to perform. If operation is omitted, then  it
28       defaults  to the default operation for this meta-operation. For perform
29       it is update. Finally, if target is omitted, then it  defaults  to  the
30       current  working  directory. A meta-operation on operation is called an
31       action. Some operations and meta-operations may take additional parame‐
32       ters. For example:
33
34       $ b                       # perform(update(./))
35       $ b foo/                  # perform(update(foo/))
36       $ b foo/ bar/             # perform(update(foo/ bar/))
37       $ b update                # perform(update(./))
38       $ b 'clean(../)'          # perform(clean(../))
39       $ b perform               # perform(update(./))
40       $ b configure             # configure(?(./))
41       $ b 'configure(../)'      # configure(?(../))
42       $ b clean update          # perform(clean(./) update(./))
43       $ b configure update      # configure(?(./)) perform(update(./))
44       $ b 'create(conf/, cxx)'  # create(?(conf/), cxx)
45
46       Notice the question mark used to show the (imaginary) default operation
47       for the configure meta-operation. For configure the  default  operation
48       is  "all operations". That is, it will configure all the operations for
49       the specified target.
50
51       You can also "generate" multiple operations for the same  set  of  tar‐
52       gets.  Compare:
53
54       $ b 'clean(foo/ bar/)' 'update(foo/ bar/)'
55       $ b '{clean update}(foo/ bar/)'
56
57       Some more useful buildspec examples:
58
59       $ b '{clean update}(...)'        # rebuild
60       $ b '{clean update clean}(...)'  # make sure builds
61       $ b '{clean test clean}(...)'    # make sure passes tests
62       $ b '{clean disfigure}(...)'     # similar to distclean
63
64       In  POSIX  shells parenthesis are special characters and must be quoted
65       when used in a buildspec. Besides being  an  inconvenience  in  itself,
66       quoting also inhibits path auto-completion. To help with this situation
67       a shortcut syntax is available for  executing  a  single  operation  or
68       meta-operation, for example:
69
70       $ b clean: foo/ bar/                # clean(foo/ bar/)
71       $ b configure: src/@out/            # configure(src/@out/)
72       $ b create: conf/, cxx              # create(conf/, cxx)
73       $ b configure: config.cxx=g++ src/  # configure(src/) config.cxx=g++
74
75       To activate the shortcut syntax the first buildspec argument must start
76       with an operation or meta-operation name and end with a colon  (:).  To
77       transform  the shortcut syntax to the normal buildspec syntax the colon
78       is replaced with the opening parenthesis ('('), the rest of the  build‐
79       spec  arguments  are  treated  as is, and the final closing parenthesis
80       (')') is added.
81
82       For each target the driver expects to find buildfile either in the tar‐
83       get's  directory  or,  if  the  directory  is  part  of  the  out  tree
84       (out_base), in the corresponding src directory (src_base).
85
86       For example, assuming foo/ is the source directory of a project:
87
88       $ b foo/              # out_base=src_base=foo/
89       $ b foo-out/          # out_base=foo-out/ src_base=foo/
90       $ b foo-out/exe{foo}  # out_base=foo-out/ src_base=foo/
91
92       An exception to this requirement is a directory target in  which  case,
93       provided  the  directory  has subdirectories, an implied buildfile with
94       the following content is assumed:
95
96       # Implied directory buildfile: build all subdirectories.
97       #
98       ./: */
99
100       In the above example, we assumed that the build system driver was  able
101       to  determine  the  association  between out_base and src_base. In case
102       src_base and out_base are not the same directory, this is  achieved  in
103       one  of  two  ways:  the config module (which implements the configure,
104       disfigure, and create meta-operations) saves this association  as  part
105       of  the configuration process. If, however, the association hasn't been
106       saved, then we have to specify src_base explicitly using the  following
107       extended target syntax:
108
109       src-base/@target
110
111       Continuing with the previous example:
112
113       $ b foo/@foo-out/exe{foo}  # out_base=foo-out/ src_base=foo/
114
115       Normally, you would need to specify src_base explicitly only once, dur‐
116       ing configuration. For example, a typical usage would be:
117
118       $ b configure: foo/@foo-out/  # src_base is saved
119       $ b foo-out/                  # no need to specify src_base
120       $ b clean: foo-out/exe{foo}   # no need to specify src_base
121
122       Besides in and out of source builds, build2 also supports configuring a
123       project's source directory as forwarded to an out of source build. With
124       such a forwarded configuration in place, if we  run  the  build  system
125       driver  from  the  source directory, it will automatically build in the
126       output directory and backlink (using symlinks or another suitable mech‐
127       anism)  certain "interesting" targets (executables, documentation, etc)
128       to the source directory for easy access. Continuing with  the  previous
129       example:
130
131       $ b configure: foo/@foo-out/,forward  # foo/ forwarded to foo-out/
132       $ cd foo/
133       $ b                                   # build in foo-out/
134       $ ./foo                               # symlink to foo-out/foo
135
136       The  ability to specify build2 variables as part of the command line is
137       normally used to pass configuration values, for example:
138
139       $ b config.cxx=clang++ config.cxx.coptions=-O3
140
141       Similar to buildspec, POSIX shells often inhibit  path  auto-completion
142       on the right hand side of a variable assignment. To help with this sit‐
143       uation the assignment can be broken down into  three  separate  command
144       line arguments, for example:
145
146       $ b config.import.libhello = ../libhello/
147
148       The build system has the following built-in and pre-defined meta-opera‐
149       tions:
150
151       perform
152              Perform an operation.
153
154       configure
155              Configure all operations supported by a project and save the re‐
156              sult  in  the  project's build/config.build file. Implemented by
157              the config module. For example:
158
159              $ b configure                      \
160                  config.cxx=clang++             \
161                  config.cxx.coptions=-O3        \
162                  config.install.root=/usr/local \
163                  config.install.root.sudo=sudo
164
165              Use the forward parameter to instead configure a  source  direc‐
166              tory as forwarded to an out of source build. For example:
167
168              $ b configure: src/@out/,forward
169
170       disfigure
171              Disfigure  all  operations supported by a project and remove the
172              project's build/config.build file.  Implemented  by  the  config
173              module.
174
175              Use  the  forward parameter to instead disfigure forwarding of a
176              source directory to an out of source build. For example:
177
178              $ b disfigure: src/,forward
179
180       create
181              Create and configure a configuration project. Implemented by the
182              config module.
183
184              Normally  a  build2  project  is created manually by writing the
185              bootstrap.build and config.build files, adding source files, and
186              so on. However, a special kind of project, which we call config‐
187              uration, is often useful. Such a project doesn't have any source
188              files  of  its  own.   Instead, it serves as an amalgamation for
189              building other projects as part of it. Doing it this way has two
190              major benefits: sub-projects automatically resolve their imports
191              to other projects in the amalgamation and sub-projects  inherits
192              their  configuration  from  the  amalgamation (which means if we
193              want to change something, we only need to do it in one place).
194
195              As an example, let's assume we have two C++ projects:  the  lib‐
196              hello library in libhello/ and the hello executable that imports
197              it in hello/. And we want to build hello with clang++.
198
199              One way to do it would be to configure and build each project in
200              its own directory, for example:
201
202              $ b configure: libhello/@libhello-clang/ config.cxx=clang++
203              $ b configure: hello/@hello-clang/ config.cxx=clang++ \
204                  config.import.libhello=libhello-clang/
205
206              The  two  drawbacks, as mentioned above, are the need to explic‐
207              itly resolve the import and having to make changes  in  multiple
208              places  should,  for  example, we want to switch from clang++ to
209              g++.
210
211              We can, however, achieve the same end result but without any  of
212              the drawbacks using the configuration project:
213
214              $ b create: clang/,cxx config.cxx=clang++  # Creates clang/.
215              $ b configure: libhello/@clang/libhello/
216              $ b configure: hello/@clang/hello/
217
218              The targets passed to the create meta-operation must be directo‐
219              ries which should either not exist or be empty.  For  each  such
220              directory  create first initializes a project as described below
221              and then configures it by executing  the  configure  meta-opera‐
222              tion.
223
224              The first optional parameter to create is the list of modules to
225              load in root.build. By default, create appends  .config  to  the
226              names  of  these  modules  so that only their configurations are
227              loaded. You can override this behavior by specifying the  period
228              (.)   after the module name. You can also instruct create to use
229              the optional module load by prefixing the module name  with  the
230              question mark (?).
231
232              The  second optional parameter is the list of modules to load in
233              bootstrap.build. If not specified, then the test, dist, and  in‐
234              stall modules are loaded by default. The config module is always
235              loaded first.
236
237              Besides creating project's bootstrap.build and root.build,  cre‐
238              ate also writes the root buildfile with the following contents:
239
240              ./: {*/ -build/}
241
242              If  used,  this  buildfile  will build all the sub-projects cur‐
243              rently present in the configuration.
244
245       dist
246              Prepare a distribution containing all files necessary to perform
247              all operations in a project. Implemented by the dist module.
248
249       info
250              Print basic information (name, version, source and output direc‐
251              tories, etc) about one or more projects  to  STDOUT,  separating
252              multiple  projects with a blank line. Each project is identified
253              by its root directory target. For example:
254
255              $ b info: libfoo/ libbar/
256
257       The build system has the following built-in and pre-defined operations:
258
259       update
260              Update a target.
261
262       clean
263              Clean a target.
264
265       test
266              Test a target. Performs update as a  pre-operation.  Implemented
267              by the test module.
268
269       update-for-test
270              Update a target for testing. This operation is equivalent to the
271              update pre-operation as executed by the test operation  and  can
272              be  used  to  only  update what is necessary for testing. Imple‐
273              mented by the test module.
274
275       install
276              Install a target. Performs update  as  a  pre-operation.  Imple‐
277              mented by the install module.
278
279       uninstall
280              Uninstall  a  target. Performs update as a pre-operation. Imple‐
281              mented by the install module.
282
283       update-for-install
284              Update a target for installation. This operation  is  equivalent
285              to the update pre-operation as executed by the install operation
286              and can be used to only update what is necessary  for  installa‐
287              tion. Implemented by the install module.
288
289       Note  that  buildspec  and  command line variable values are treated as
290       buildfile fragments and so can use quoting and escaping as well as con‐
291       tain  variable  expansions and evaluation contexts. However, to be more
292       usable on various platforms, escaping in these two situations  is  lim‐
293       ited  to  the  effective  sequences  of \', \", \\, \$, and \( with all
294       other sequences interpreted as is. Together with double-quoting this is
295       sufficient to represent any value. For example:
296
297       $ b config.install.root=c:\projects\install
298       $ b "config.install.root='c:\Program Files (x86)\test\'"
299       $ b 'config.cxx.poptions=-DFOO_STR="foo"'
300

OPTIONS

302       -v     Print actual commands being executed. This options is equivalent
303              to --verbose 2.
304
305       -V     Print all underlying commands being executed.  This  options  is
306              equivalent to --verbose 3.
307
308       --quiet|-q
309              Run  quietly,  only printing error messages in most contexts. In
310              certain contexts (for example, while updating build system  mod‐
311              ules)  this  verbosity level may be ignored. Use --silent to run
312              quietly in all contexts.  This option is equivalent to --verbose
313              0.
314
315       --silent
316              Run quietly, only printing error messages in all contexts.
317
318       --verbose level
319              Set  the diagnostics verbosity to level between 0 and 6. Level 0
320              disables any non-error messages (but see the difference  between
321              --quiet  and  --silent)  while level 6 produces lots of informa‐
322              tion, with level 1 being the default. The  following  additional
323              types of diagnostics are produced at each level:
324
325              1.  High-level information messages.
326
327              2.  Essential underlying commands being executed.
328
329              3.  All underlying commands being executed.
330
331              4.  Information that could be helpful to the user.
332
333              5.  Information that could be helpful to the developer.
334
335              6.  Even more detailed information.
336
337       --stat Display build statistics.
338
339       --dump phase
340              Dump  the  build  system  state after the specified phase. Valid
341              phase values are load (after loading buildfiles) and match  (af‐
342              ter  matching  rules to targets). Repeat this option to dump the
343              state after multiple phases.
344
345       --progress
346              Display build progress. If printing to a terminal  the  progress
347              is  displayed  by  default  for  low verbosity levels. Use --no-
348              progress to suppress.
349
350       --no-progress
351              Don't display build progress.
352
353       --jobs|-j num
354              Number of active jobs to perform in parallel. This includes both
355              the  number of active threads inside the build system as well as
356              the  number  of  external  commands  (compilers,  linkers,  etc)
357              started but not yet finished. If this option is not specified or
358              specified with the 0 value, then the number of  available  hard‐
359              ware threads is used.
360
361       --max-jobs|-J num
362              Maximum  number  of  jobs (threads) to create. The default is 8x
363              the number of active jobs (--jobs|j) on 32-bit architectures and
364              32x on 64-bit. See the build system scheduler implementation for
365              details.
366
367       --queue-depth|-Q num
368              The queue depth as a multiplier over the number of active  jobs.
369              Normally we want a deeper queue if the jobs take long (for exam‐
370              ple, compilation) and shorter if they are  quick  (for  example,
371              simple  tests). The default is 4. See the build system scheduler
372              implementation for details.
373
374       --file-cache impl
375              File cache implementation to use for intermediate build results.
376              Valid  values  are noop (no caching or compression) and sync-lz4
377              (no caching with synchronous LZ4 on-disk compression).  If  this
378              option  is not specified, then a suitable default implementation
379              is used (currently sync-lz4).
380
381       --max-stack num
382              The maximum stack size in KBytes  to  allow  for  newly  created
383              threads. For pthreads-based systems the driver queries the stack
384              size of the main thread and uses the same size for creating  ad‐
385              ditional threads. This allows adjusting the stack size using fa‐
386              miliar mechanisms, such  as  ulimit.   Sometimes,  however,  the
387              stack  size  of  the main thread is excessively large.  As a re‐
388              sult, the driver checks if it is greater than a predefined limit
389              (64MB  on 64-bit systems and 32MB on 32-bit ones) and caps it to
390              a more sensible value (8MB) if that's the case. This option  al‐
391              lows  you to override this check with the special zero value in‐
392              dicating that the main thread stack size should be used as is.
393
394       --serial-stop|-s
395              Run serially and stop at the first error. This mode is useful to
396              investigate  build  failures that are caused by build system er‐
397              rors rather than compilation errors. Note that if you don't want
398              to  keep  going but still want parallel execution, add --jobs|-j
399              (for example -j 0 for default concurrency).
400
401       --dry-run|-n
402              Print commands without actually executing them. Note  that  com‐
403              mands  that  are required to create an accurate build state will
404              still be executed and the extracted auxiliary dependency  infor‐
405              mation  saved.  In other words, this is not the "don't touch the
406              filesystem" mode but rather "do minimum amount of work  to  show
407              what needs to be done". Note also that only the perform meta-op‐
408              eration supports this mode.
409
410       --match-only
411              Match the rules but do not execute the operation. This  mode  is
412              primarily useful for profiling.
413
414       --no-external-modules
415              Don't  load external modules during project bootstrap. Note that
416              this option can only be used with meta-operations  that  do  not
417              load the project's buildfiles, such as info.
418
419       --structured-result
420              Write  the  result  of  execution  in a structured form. In this
421              mode, instead of printing to STDERR diagnostics  messages  about
422              the  outcome  of executing actions on targets, the driver writes
423              to STDOUT a structured  result  description  one  line  per  the
424              buildspec  action/target  pair. Each line has the following for‐
425              mat:
426
427              state meta-operation operation target
428
429              Where state can be one of unchanged, changed, or failed. If  the
430              action  is  a pre or post operation, then the outer operation is
431              specified in parenthesis. For example:
432
433              unchanged perform update(test) /tmp/dir{hello/}
434              changed perform test /tmp/dir{hello/}
435
436              Note that only the perform meta-operation  supports  the  struc‐
437              tured result output.
438
439       --mtime-check
440              Perform  file  modification time sanity checks. These checks can
441              be helpful in diagnosing spurious rebuilds and  are  enabled  by
442              default  on  Windows  (which is known not to guarantee monotoni‐
443              cally increasing mtimes) and for the staged version of the build
444              system on other platforms. Use --no-mtime-check to disable.
445
446       --no-mtime-check
447              Don't perform file modification time sanity checks. See --mtime-
448              check for details.
449
450       --no-column
451              Don't print column numbers in diagnostics.
452
453       --no-line
454              Don't print line and column numbers in diagnostics.
455
456       --buildfile path
457              The alternative file to read build information from. The default
458              is  buildfile  or  build2file,  depending on the project's build
459              file/directory naming scheme. If path is  '-',  then  read  from
460              STDIN. Note that this option only affects the files read as part
461              of the buildspec processing. Specifically, it has no  effect  on
462              the  source  and include directives. As a result, this option is
463              primarily intended for testing rather than  changing  the  build
464              file names in real projects.
465
466       --config-guess path
467              The  path  to  the config.guess(1) script that should be used to
468              guess the host machine triplet. If this option is not specified,
469              then b will fall back on to using the target it was built for as
470              host.
471
472       --config-sub path
473              The path to the config.sub(1) script  that  should  be  used  to
474              canonicalize  machine triplets. If this option is not specified,
475              then b will use  its  built-in  canonicalization  support  which
476              should be sufficient for commonly-used platforms.
477
478       --pager path
479              The  pager  program  to be used to show long text. Commonly used
480              pager programs are less and more. You  can  also  specify  addi‐
481              tional  options  that should be passed to the pager program with
482              --pager-option. If an empty string is  specified  as  the  pager
483              program, then no pager will be used. If the pager program is not
484              explicitly specified, then b will try to use less. If it is  not
485              available, then no pager will be used.
486
487       --pager-option opt
488              Additional option to be passed to the pager program. See --pager
489              for more information on the pager program. Repeat this option to
490              specify multiple pager options.
491
492       --options-file file
493              Read  additional options from file. Each option should appear on
494              a separate line optionally followed by space or equal  sign  (=)
495              and  an  option value. Empty lines and lines starting with # are
496              ignored.  Option values can be enclosed in double (") or  single
497              (')  quotes to preserve leading and trailing whitespaces as well
498              as to specify empty values. If the value itself contains  trail‐
499              ing  or leading quotes, enclose it with an extra pair of quotes,
500              for example '"x"'. Non-leading and non-trailing quotes  are  in‐
501              terpreted as being part of the option value.
502
503              The  semantics  of  providing options in a file is equivalent to
504              providing the same set of options in the same order on the  com‐
505              mand line at the point where the --options-file option is speci‐
506              fied except that the shell escaping and quoting is not required.
507              Repeat this option to specify more than one options file.
508
509       --default-options dir
510              The directory to load additional default options files from.
511
512       --no-default-options
513              Don't load default options files.
514
515       --help Print usage information and exit.
516
517       --version
518              Print version and exit.
519

DEFAULT OPTIONS FILES

521       Instead of having a separate config file format for tool configuration,
522       the build2 toolchain uses default options files which contain the  same
523       options  as  what can be specified on the command line. The default op‐
524       tions files are like options files that one can specify with --options-
525       file except that they are loaded by default.
526
527       The  default options files for the build system driver are called b.op‐
528       tions and are searched for in the .build2/ subdirectory of the home di‐
529       rectory and in the system directory (for example, /etc/build2/) if con‐
530       figured. Note that besides options these files can also contain  global
531       variable overrides.
532
533       Once the search is complete, the files are loaded in the reverse order,
534       that is, beginning from the system directory (if any), followed by  the
535       home  directory,  and  finishing  off with the options specified on the
536       command line.  In other words, the  files  are  loaded  from  the  more
537       generic  to  the more specific with the command line options having the
538       ability to override any values specified in the default options files.
539
540       If a default  options  file  contains  --no-default-options,  then  the
541       search  is  stopped  at the directory containing this file and no outer
542       files are loaded. If this option is specified on the command line, then
543       none of the default options files are searched for or loaded.
544
545       An  additional directory containing default options files can be speci‐
546       fied with --default-options. Its configuration files are  loaded  after
547       the home directory.
548
549       The  order  in  which default options files are loaded is traced at the
550       verbosity level 3 (-V option) or higher.
551

EXIT STATUS

553       Non-zero exit status is returned in case of an error.
554

ENVIRONMENT

556       The HOME environment variable is used to determine the user's home  di‐
557       rectory. If it is not set, then getpwuid(3) is used instead. This value
558       is used to shorten paths printed in diagnostics by replacing  the  home
559       directory  with  ~/.  It  is  also made available to buildfile's as the
560       build.home variable.
561
562       The BUILD2_VAR_OVR environment variable is  used  to  propagate  global
563       variable overrides to nested build system driver invocations. Its value
564       is a list of global variable assignments separated with newlines.
565
566       The BUILD2_DEF_OPT environment variable is used to suppress loading  of
567       default  options  files  in nested build system driver invocations. Its
568       values are false or 0 to suppress and true or 1 to load.
569

BUGS

571       Send bug reports to the users@build2.org mailing list.
572
574       Copyright (c) 2014-2021 the build2 authors.
575
576       Permission is granted to copy, distribute and/or modify  this  document
577       under the terms of the MIT License.
578
579
580
581build2 0.14.0                    October 2021                             b(1)
Impressum