summaryrefslogtreecommitdiff
path: root/install
blob: 6ee689644e9dbb7c4c77cae61a5b51f81aa7e672 (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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#! /usr/bin/env bash

# Test installation of the build2 toolchain distribution. Essentially, this
# is an automated build2-toolchain/INSTALL.
#
# Usage: install [options] <build2-toolchain-archive> <build2-repo>
#
# -i <dir>
#    Target installation directory instead of default /tmp/build2-install.
#
# -l <dir>
#    Prerequisite library (libodb, libodb-sqlite) installation directory
#    instead of default /usr/local.
#
# -s
#    Use sudo when installing.
#
# -t
#    Build and install toolchain only, no extras (brep).
#
# --cxx <path>
#    C++ compiler to use, g++ by default.
#
# --cxxflags <flags>
#    C++ compiler flags to use, -W -Wall -Wno-unknown-pragmas by default.
#
# --cppflags <flags>
#    Extra C++ preprocessor flags to use.
#
# --bpkgflags <flags>
#    Extra flags to pass to bpkg.
#
# For example:
#
# install /tmp/build2-toolchain-0.1.0.tar.gz https://pkg.cppget.org/1/alpha
#
usage="usage: $0 [options] <build2-toolchain-archive> <build2-repo>"

owd=`pwd`
trap "{ cd $owd; exit 1; }" ERR
set -o errtrace # Trap in functions.

function info () { echo "$*" 1>&2; }
function error () { info "$*"; exit 1; }

tca=
rep=
tmp=/tmp
lib="/usr/local"           # Library (libodb, etc) installation directory.
ins="$tmp/build2-install"  # Our installation directory.
sudo=
extras=brep                # Extras to build.
extras_show=brep-load      # Extra programs (in bin/) to test with --version.
pmc="build2-toolchain"     # bpkg configuration directory
cxx="g++"
cxxflags="-W -Wall -Wno-unknown-pragmas"
cppflags=
bpkgflags=

while [ $# -gt 0 ]; do
  case $1 in
    -s)
      sudo=sudo
      shift
      ;;
    -i)
      shift
      ins=${1%/}
      shift
      ;;
    -l)
      shift
      lib=${1%/}
      shift
      ;;
    -t)
      extras=
      shift
      ;;
    --cxx)
      shift
      cxx=$1
      shift
      ;;
    --cxxflags)
      shift
      cxxflags="$1"
      shift
      ;;
    --cppflags)
      shift
      cppflags="$1"
      shift
      ;;
    --bpkgflags)
      shift
      bpkgflags="$1"
      shift
      ;;
    *)
      if [ -z "$tca" ]; then
        tca=${1%/}; shift
      else
        rep=$1; break
      fi
      ;;
  esac
done

if [ -z "$tca" ]; then
  error $usage
fi

if [ -z "$rep" ]; then
  error $usage
fi

cd $tmp

# Download archive if it is an HTTP URL.
#
if [[ $tca == http://* || $tca == https://* ]]; then
  url=$tca
  tca=`echo "$url" | sed -e 's%^.*/\(.*\)$%\1%' -`
  if [ -z "$tca" ]; then
    error "unable to extract archive name from $url"
  fi
  rm -f $tca
  wget $url
elif [[ $tca != /* ]]; then
  tca=$owd/$tca
fi

if [[ $rep != http://* && $rep != https://* && $rep != /* ]]; then
  rep=$owd/$rep
fi

if [[ $ins != /* ]]; then
  ins=$owd/$ins
fi

# Warm sudo up so that the rest of this script can continue unattended.
#
if [ "$sudo" ]; then
  $sudo echo >/dev/null
fi

tcb=`basename $tca .tar.gz`

# Remove installation directories so that any old stuff doesn't affect
# us due to rpath.
#
$sudo rm -rf $ins $ins-boot

# Unpack.
#
rm -rf $tcb
rm -rf $tcb.disabled
tar xfz $tca

# Bootstrap.
#
cd $tcb/build2
./bootstrap --cxx $cxx --cxxflags "$cxxflags"
cd ..

./build2/build2/b-boot                      \
  "!config.cxx=$cxx"                        \
  "!config.cxx.coptions=$cxxflags"          \
  "!config.bin.rpath=$ins-boot/lib" build2/

./build2/build2/b                                \
  config.cxx=$cxx                                \
  config.cxx.coptions="$cxxflags"                \
  config.cxx.poptions="$cppflags -I$lib/include" \
  config.cxx.loptions=-L$lib/lib                 \
  config.bin.rpath="$ins-boot/lib $lib/lib"      \
  config.install.root=$ins-boot                  \
  config.install.root.sudo=$sudo                 \
  configure

./build2/build2/b
./build2/build2/b install

function show () # <dir> <prog>...
{
  local d=$1; shift
  for p in $*; do
    if [ "`which $p`" != "$d/bin/$p" ]; then
      error "wrong $p path: `which $p`"
    fi

    $p --version 1>&2
  done
}

# Disable any rpaths that may still be pointing inside the build directory.
#
cd $tmp
mv $tcb $tcb.disabled

OLDPATH="$PATH"
PATH="$ins-boot/bin:$OLDPATH"
show $ins-boot b bpkg

# Rebuild via the package manager.
#
mkdir -p $pmc
rm -rf $pmc/*
rm -rf $pmc.disabled
cd $pmc

bpkg $bpkgflags create                           \
  cxx                                            \
  config.cxx=$cxx                                \
  config.cxx.coptions="$cxxflags"                \
  config.cxx.poptions="$cppflags -I$lib/include" \
  config.cxx.loptions=-L$lib/lib                 \
  config.bin.rpath="$ins/lib $lib/lib"           \
  config.install.root=$ins                       \
  config.install.root.sudo=$sudo                 \

bpkg $bpkgflags add $rep
bpkg $bpkgflags fetch
bpkg $bpkgflags build --yes build2 bpkg

bpkg $bpkgflags install build2 bpkg

cd $tmp
mv $pmc $pmc.disabled

PATH="$ins/bin:$OLDPATH"
show $ins b bpkg

mv $pmc.disabled $pmc

# Build extras using the bpkg-built toolchain.
#
if [ ! -z "$extras" ]; then
  cd $pmc
  bpkg $bpkgflags build --yes $extras
  bpkg $bpkgflags install $extras
  cd $tmp

  mv $pmc $pmc.disabled
  show $ins $extras_show
  mv $pmc.disabled $pmc
fi

mv $tcb.disabled $tcb

cd $owd