forked from mighty-gerbils/gerbil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·342 lines (291 loc) · 8.33 KB
/
build.sh
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
#!/bin/sh
set -eu
cd $(dirname "$0") # Change to this directory
#===============================================================================
# Assuming this script is run with: `cd $GERBIL_BASE/src && ./build.sh`
#===============================================================================
# utility to get number of cores from make -j
build_flags_cores() {
for x in $1; do
case $x in
-j*)
echo ${x##-j}
break
;;
*)
;;
esac
done
}
# Check for GERBIL_PREFIX being set
# This is necessary for the bach build script to set the correct RUNPATH in the
# gerbil binary.
if [ "x${GERBIL_PREFIX:-}" = "x" ]; then
echo "GERBIL_PREFIX is not set"
exit 1
fi
## global constants
readonly GERBIL_SOURCE="$(pwd -P)"
readonly GERBIL_BASE="$(dirname "${GERBIL_SOURCE}")"
readonly GERBIL_STAGE0="${GERBIL_BASE}/bootstrap"
export GERBIL_SOURCE GERBIL_STAGE0
## Build Environment
GERBIL_BUILD_PREFIX="${GERBIL_BASE}/build"
export GERBIL_BUILD_PREFIX
GERBIL_GSC="${GERBIL_BUILD_PREFIX}/bin/gsc"
export GERBIL_GSC
GERBIL_LOADPATH="${GERBIL_BUILD_PREFIX}/lib"
export GERBIL_LOADPATH
GAMBOPT="~~bin=${GERBIL_BUILD_PREFIX}/bin,~~lib=${GERBIL_BUILD_PREFIX}/lib,~~include=${GERBIL_BUILD_PREFIX}/include"
export GAMBOPT
PATH="${GERBIL_BUILD_PREFIX}/bin:${GERBIL_STAGE0}/bin:${PATH}"
export PATH
# required when --enable-shared
if [ "x${LD_LIBRARY_PATH:-}" = "x" ]; then
LD_LIBRARY_PATH="${GERBIL_BUILD_PREFIX}/lib"
else
LD_LIBRARY_PATH="${GERBIL_BUILD_PREFIX}/lib:${LD_LIBRARY_PATH}"
fi
export LD_LIBRARY_PATH
if [ "x${GERBIL_BUILD_FLAGS:-}" != "x" ]; then
num_cores=$(build_flags_cores "${GERBIL_BUILD_FLAGS}")
if [ "x${num_cores:-}" != "x" ]; then
GERBIL_BUILD_CORES=${num_cores}
export GERBIL_BUILD_CORES
fi
fi
if [ "x${GERBIL_BUILD_CORES:-}" != "x" ]; then
echo "--- using ${GERBIL_BUILD_CORES} cores for the build"
fi
#===============================================================================
## feedback
feedback_err() {
(1>&2 echo "*** ERROR; ${1}")
}
feedback_low() {
echo "[*] ${1}"
}
feedback_mid() {
echo ">>> ${1}"
}
die() {
local exitcode=$?
feedback_err "build failed"
exit $exitcode
}
target_setup() {
local target="${1}"
rm -rf "${target:?}/bin" # warning: `:?` necessary for safety
rm -rf "${target:?}/lib" # warning: `:?` necessary for safety
mkdir -p "${target}/bin"
mkdir -p "${target}/lib"
mkdir -p "${target}/include"
}
build_prepare() {
feedback_mid "Preparing build"
feedback_low "preparing ${GERBIL_STAGE0}"
target_setup "${GERBIL_STAGE0}"
feedback_low "preparing ${GERBIL_BUILD_PREFIX}"
target_setup "${GERBIL_BUILD_PREFIX}"
}
build_gambit() {
feedback_low "Building Gambit in ${GERBIL_BUILD_PREFIX}/gambit"
feedback_mid "Building core gambit"
(cd gambit && rm -rf boot gsc-boot) || die
(cd gambit && make -j ${GERBIL_BUILD_CORES:-1} core) || die
feedback_mid "Installing Gambit to ${GERBIL_BUILD_PREFIX}"
cp -v gambit/gsi/gsi "${GERBIL_STAGE0}/bin"
cp -v gambit/gsc/gsc gambit/bin/gambuild-C "${GERBIL_BUILD_PREFIX}/bin"
cp -v gambit/include/gambit.h gambit/include/gambit-not*.h "${GERBIL_BUILD_PREFIX}/include"
cp -v gambit/lib/*\#.scm "${GERBIL_BUILD_PREFIX}/lib"
cp -v gambit/lib/_define-syntax.scm "${GERBIL_BUILD_PREFIX}/lib"
cp -v gambit/gsc/*\#.scm "${GERBIL_BUILD_PREFIX}/lib"
cp -v gambit/lib/_gambit.c "${GERBIL_BUILD_PREFIX}/lib"
for f in lib/libgambit.so lib/libgambit.a \
gsi/libgambitgsi.so gsi/libgambitgsi.a \
gsc/libgambitgsc.so gsc/libgambitgsc.a;
do
if [ -e gambit/$f ]; then
cp -v gambit/$f "${GERBIL_BUILD_PREFIX}/lib"
fi
done
}
build_boot_gxi () {
feedback_low "Compiling bootstrap gxi shim"
(cd gerbil && ${CC:-cc} -O2 -o boot-gxi boot-gxi.c)
}
finalize_stage0 () {
local target_lib="${1}"
local target_bin="${2}"
cp -v gerbil/boot/*.scm \
"${target_lib}"
cp -v gerbil/boot-gxi \
"${target_bin}"
}
clean_stage0() {
## clean up stage0
feedback_low "Cleaning up bootstrap"
rm -rf "${GERBIL_STAGE0}"
}
finalize_stage1 () {
local target_lib="${1}"
local target_bin="${2}"
cp -v gerbil/interactive/*.ss \
"${target_lib}"
(cd "${target_bin}" && ln -sf gerbil gxi)
(cd "${target_bin}" && ln -sf gerbil gxc)
}
build_stage0 () {
local target_bin="${GERBIL_STAGE0}/bin"
local target_lib="${GERBIL_STAGE0}/lib"
## feedback
feedback_low "Building Gerbil bootstrap"
## gerbil bootstrap
feedback_mid "preparing bootstrap"
cp -R bootstrap/gerbil "${target_lib}"
find "${target_lib}" -name \*.scm > .build.stage0
feedback_mid "compiling bootstrap gerbil"
gsi ./build/build0.scm || die
## cleaning up
rm -f .build.stage0
## finalize build
feedback_mid "finalizing bootstrap"
finalize_stage0 "${target_lib}" "${target_bin}"
}
build_stage1 () {
## constants
local target_bin="${GERBIL_BUILD_PREFIX}/bin"
local target_lib="${GERBIL_BUILD_PREFIX}/lib"
local target_lib_gerbil="${GERBIL_BUILD_PREFIX}/lib/gerbil"
local target_lib_static="${GERBIL_BUILD_PREFIX}/lib/static"
## feedback
feedback_low "Building Gerbil core"
## stage1 build
feedback_mid "preparing core build"
mkdir -p "${target_lib_gerbil}"
cp -v gerbil/prelude/core.ssxi.ss "${target_lib_gerbil}"
mkdir -p "${target_lib_static}"
feedback_mid "updating gerbil version"
gsi ./build/build-version.scm || die
GERBIL_HOME="${GERBIL_STAGE0}" # required by boot-gxi
export GERBIL_HOME
feedback_mid "compiling gerbil core"
"${GERBIL_STAGE0}/bin/boot-gxi" ./build/build1.ss || die
feedback_mid "compiling gerbil bach"
"${GERBIL_STAGE0}/bin/boot-gxi" ./build/build-bach.ss || die
## unset GERBIL_HOME from its bootstrap value to avoid confusing the rest of the build
unset GERBIL_HOME
## finalize build
feedback_mid "finalizing build ${final:+${final_string}}"
finalize_stage1 "${target_lib}" "${target_bin}"
}
## commands
build_stdlib () {
feedback_low "Building stdlib"
(cd std && ./build.ss) || die
}
build_libgerbil () {
feedback_low "Building libgerbil"
./build/build-libgerbil.ss || die
}
build_lang () {
feedback_low "Building languages"
(cd lang && ./build.ss) || die
}
build_r7rs_large() {
feedback_low "Building R7RS large"
(cd r7rs-large && ./build.ss) || die
}
build_srfi() {
feedback_low "Building SRFI shims"
(cd srfi && ./build.ss) || die
}
build_tools () {
feedback_low "Building gerbil tools"
(cd tools && ./build.ss) || die
for tool in tools/gx*.ss; do
toolname=$(basename $tool .ss)
(cd "${GERBIL_BUILD_PREFIX}/bin" && ln -sf gerbil $toolname)
done
}
build_tags () {
feedback_low "Building gerbil TAGS"
gxtags gerbil std lang
}
build_doc () {
feedback_low "Building gerbil hyperspec"
(cd "${GERBIL_BASE}/doc" && npm install && node_modules/vuepress/cli.js dev)
}
#===============================================================================
## main
build_gerbil() {
feedback_low "Building Gerbil"
build_prepare || die
build_gambit || die
build_boot_gxi || die
build_stage0 || die
build_stage1 || die
build_stdlib || die
build_libgerbil || die
build_lang || die
build_r7rs_large || die
build_srfi || die
build_tools || die
build_tags || die
}
## handling command line
if [ "$#" -eq 0 ]; then
build_gerbil
else
case "$1" in
"prepare")
build_prepare || die
;;
"gambit")
build_gambit || die
;;
"boot-gxi")
build_boot_gxi || die
;;
"stage0")
build_stage0 || die
;;
"stage1")
build_stage1 || die
;;
"stdlib")
build_stdlib || die
;;
"libgerbil")
build_libgerbil || die
;;
"lang")
build_lang || die
;;
"r7rs-large")
build_r7rs_large || die
;;
"srfi")
build_srfi || die
;;
"tools")
build_tools || die
;;
"tags")
build_tags || die
;;
"doc")
build_doc || die
;;
"env")
$*
;;
*)
feedback_err "Unknown command."
feedback_err \
"Correct usage: ./build.sh [prepare|gambit|boot-gxi|stage0|stage1|stdlib|libgerbil|lang|r7rs-large|srfi|tools|tags]"
die
;;
esac
fi
feedback_low "Done"