aboutsummaryrefslogtreecommitdiff
path: root/build2/buildfile
blob: cfc46e516fafd411f20499a3b9fc34d50c2dec96 (plain)
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
# file      : build2/buildfile
# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

import libs = libbutl%lib{butl}

include ../libbuild2/
libs += ../libbuild2/lib{build2}

for m: bash bin cc in version
{
  include ../libbuild2/$m/
  libs += ../libbuild2/$m/lib{build2-$m}
}

./: exe{b}: {hxx ixx txx cxx}{+b} libue{b}

libue{b}: {hxx ixx txx cxx}{** -b -b-options -**.test...} \
          {hxx ixx cxx}{b-options}                        \
          $libs

# Unit tests.
#
exe{*.test}:
{
  test = true
  install = false
}

for t: cxx{**.test...}
{
  d = $directory($t)
  n = $name($t)...
  b = $path.base($name($t))

  ./: $d/exe{$n}: $t $d/{hxx ixx txx}{+$n} $d/testscript{+$n +$b+*.test...}
  $d/exe{$n}: libue{b}: bin.whole = false
}

# Build options.
#
# Pass our compiler target to be used as build2 host.
#
obj{b}: cxx.poptions += -DBUILD2_HOST_TRIPLET=\"$cxx.target\"

# Pass native C and C++ compiler paths (not forgetting to escape backslashes
# on Windows). These are used as defaults for BUILD2_DEFAULT_*.
#
if ($cxx.target == $build.host)
{
  c/obj{init}: cxx.poptions += \
    -DBUILD2_NATIVE_C=\"$regex.replace($recall($c.path), '\\', '\\\\')\"

  cxx/obj{init}: cxx.poptions += \
    -DBUILD2_NATIVE_CXX=\"$regex.replace($recall($cxx.path), '\\', '\\\\')\"
}

if ($cxx.target.class != 'windows')
{
  if ($cxx.target.class == 'linux')
  {
    # Make sure backtrace includes function names.
    #
    cxx.loptions += -rdynamic

    # Make sure we use RPATH and not RUNPATH since the latter messes up
    # dlopen().
    #
    cxx.loptions += -Wl,--disable-new-dtags
  }

  cxx.libs += -lpthread
}
else
{
  # Adjust stack size (affects all threads).
  #
  if ($cxx.target.cpu == "x86_64")
    stack_size = 8388608 # 8M
  else
    stack_size = 4194304 # 4M

  if ($cxx.class == 'msvc')
    cxx.loptions += "/STACK:$stack_size"
  else
    cxx.loptions += "-Wl,--stack,$stack_size"
}

# Generated options parser.
#
if $cli.configured
{
  cli.cxx{b-options}: cli{b}

  cli.options += --std c++11 -I $src_root --include-with-brackets \
--include-prefix build2 --guard-prefix BUILD2 \
--cxx-prologue "#include <build2/types-parsers.hxx>" \
--cli-namespace build2::cl --generate-file-scanner --keep-separator \
--generate-parse --generate-merge --generate-specifier

  # Usage options.
  #
  cli.options += --suppress-undocumented --long-usage --ansi-color \
--page-usage 'build2::print_$name$_' --option-length 21

  cli.cxx{*}:
  {
    # Include the generated cli files into the distribution and don't remove
    # them when cleaning in src (so that clean results in a state identical to
    # distributed).
    #
    dist  = true
    clean = ($src_root != $out_root)

    # We keep the generated code in the repository so copy it back to src in
    # case of a forwarded configuration.
    #
    backlink = overwrite
  }
}