aboutsummaryrefslogtreecommitdiff
path: root/bootstrap.sh
blob: 7d6a895bcabc9cea371bb517b2cf15faf1c2b0c2 (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
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
#!/bin/sh

# file      : bootstrap.sh
# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license   : MIT; see accompanying LICENSE file

usage="Usage: $0 [-h] [--libbutl <dir>] [--host <triplet>] <cxx> [<cxx-option>...]"

diag ()
{
  echo "$*" 1>&2
}

cxx=
libbutl=
host=

while test $# -ne 0; do
  case "$1" in
    -h|--help)
      diag
      diag "$usage"
      diag
      diag "The script expects to find the libbutl/ or libbutl-*/ directory either"
      diag "in the current directory (build2 root) or one level up. The result is"
      diag "saved as build2/b-boot."
      diag
      diag "Example usage:"
      diag
      diag "$0 g++"
      diag
      diag "See the INSTALL file for details."
      diag
      exit 0
      ;;
    --libbutl)
      shift
      if test $# -eq 0; then
	diag "error: libbutl path expected after --libbutl"
	diag "$usage"
	exit 1
      fi
      if test ! -d "$1"; then
	diag "error: libbutl directory '$1' does not exist"
	exit 1
      fi
      libbutl="${1%/}"
      shift
      ;;
    --host)
      shift
      if test $# -eq 0; then
	diag "error: host triplet expected after --host"
	diag "$usage"
	exit 1
      fi
      host="$1"
      shift
      ;;
    *)
      cxx="$1"
      shift
      break
      ;;
  esac
done

if test -z "$cxx"; then
  diag "error: compiler executable expected"
  diag "$usage"
  exit 1
fi

if test -z "$host"; then
  if ! host="$(./config.guess)"; then
    diag "error: unable to guess host triplet"
    exit 1
  fi
else
  if ! chost="$(./config.sub "$host")"; then
    diag "error: unable to canonicalize host triplet '$host'"
    exit 1
  fi
  host="$chost"
fi

# See if there is libbutl or libbutl-* in the current directory and
# one directory up.
#
if test -z "$libbutl"; then
  if test -d libbutl; then
    libbutl="libbutl"
  else
    libbutl="$(echo libbutl-*/)"
    libbutl="${libbutl%/}"
    if test ! -d "$libbutl"; then
      libbutl=
    fi
  fi
fi

if test -z "$libbutl"; then
  if test -d ../libbutl; then
    libbutl="../libbutl"
  else
    libbutl="$(echo ../libbutl-*/)"
    libbutl="${libbutl%/}"
    if test ! -d "$libbutl"; then
      libbutl=
    fi
  fi
fi

if test -z "$libbutl"; then
  diag "error: unable to find libbutl, use --libbutl to specify its location"
  exit 1
fi

src="build2/*.cxx"
src="$src build2/bin/*.cxx"
src="$src build2/c/*.cxx"
src="$src build2/cc/*.cxx"
src="$src build2/cxx/*.cxx"

src="$src libbuild2/*.cxx"
src="$src libbuild2/config/*.cxx"
src="$src libbuild2/dist/*.cxx"
src="$src libbuild2/test/*.cxx"
src="$src libbuild2/test/script/*.cxx"
src="$src libbuild2/install/*.cxx"
src="$src libbuild2/version/*.cxx"
src="$src libbuild2/in/*.cxx"

src="$src $libbutl/libbutl/*.cxx"

# Filter out *.test.cxx sources.
#
r=
for f in $src; do
  if test -n "${f##*.test.cxx}"; then
    r="$r $f"
  fi
done

# Note that for as long as we support GCC 4.9 we have to compile in the C++14
# mode since 4.9 doesn't recognize c++1z.
#
set -x
"$cxx" "-I$libbutl" -I. -DBUILD2_BOOTSTRAP '-DBUILD2_HOST_TRIPLET="'"$host"'"' -std=c++1y "$@" -o build2/b-boot $r -lpthread -ldl