-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhake.sh
executable file
·258 lines (235 loc) · 6.82 KB
/
hake.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
#!/bin/sh
##########################################################################
# Copyright (c) 2009, 2011, 2013, 2015, ETH Zurich.
# All rights reserved.
#
# This file is distributed under the terms in the attached LICENSE file.
# If you do not find this file, copies can be found by writing to:
# ETH Zurich D-INFK, Universitaetstasse 6, CH-8092 Zurich. Attn: Systems Group.
##########################################################################
DFLTARCHS="\"armv8\""
RUN_HAKE="Yes"
HAKEDIR=$(dirname $0)
DEFAULT_JOBS=4
JOBS="$DEFAULT_JOBS"
CACHEDIR="$HOME/.cache/barrelfish"
HAGFISH_LOCATION="/home/netos/tftpboot/Hagfish.efi"
# Don't override the default toolchain unless asked to.
TOOLROOT=Nothing
ARM_TOOLSPEC=Nothing
AARCH64_TOOLSPEC=Nothing
THUMB_TOOLSPEC=Nothing
ARMEB_TOOLSPEC=Nothing
X86_TOOLSPEC=Nothing
K1OM_TOOLSPEC=Nothing
usage() {
echo "Usage: $0 <options>"
echo " -s|--source-dir: path to source tree (required)"
echo " -i|--install-dir: path to install directory (defaults to \`pwd\`)"
echo " -a|--architecture: specify archtitecture to build for (can be"
echo " given multiple times, default architectures are"
echo " $DFLTARCHS"
echo " -n|--no-hake: just rebuild hake itself, don't run it (only useful"
echo " for debugging hake)"
echo " -t|--toolchain <arch> <toolchain>: use <toolchain> to build for"
echo " <arch>."
echo " -r|--toolroot <path>: where should I look for toolchains (instead"
echo " of (/home/netos/tools)"
echo " -j|--jobs: Number of parallel jobs to run (default $DEFAULT_JOBS)."
echo " --hagfish: Location of Hagfish boot loader (default $HAGFISH_LOCATION)."
echo " --cachedir: Cache directory (default $CACHEDIR)."
echo " --help: Print this help."
echo ""
echo " The way you use this script is to create a new directory for your"
echo " build tree, cd into it, and run this script with the --source-dir"
echo " argument specifying the top of the source tree."
echo ""
echo " Known architectures may include: "
echo " x86_64 armv7 armv8 k1om"
exit 1;
}
#
# Legacy compatibility to avoid breaking the harness...
#
if test $# -eq 1 && test $1 != "-"*; then
echo "WARNING: old usage of hake.sh (sole argument gives the source directory) is"
echo "deprecated: please use --source-dir instead."
SRCDIR="$1"
shift
fi
#
# Parse args
#
while test $# -ne 0; do
case $1 in
"-a"|"--architecture")
if test -z "$NEWARCHS"; then
NEWARCHS="\"$2\""
else
NEWARCHS="$NEWARCHS, \"$2\""
fi
shift
;;
"-i"|"--install-dir")
INSTALLDIR="$2"
shift
;;
"-s"|"--source-dir")
SRCDIR="$2"
shift
;;
"-n"|"--no-hake")
RUN_HAKE="No"
;;
"-d"|"--no-deps")
NO_DEPS="No"
;;
"-t"|"--toolchain")
TC_ARCH="$2"
shift
TOOLSPEC="$2"
shift
case ${TC_ARCH} in
"arm")
ARM_TOOLSPEC="Just Tools.$TOOLSPEC"
;;
"aarch64")
AARCH64_TOOLSPEC="Just Tools.$TOOLSPEC"
;;
"thumb")
THUMB_TOOLSPEC="Just Tools.$TOOLSPEC"
;;
"armeb")
ARMEB_TOOLSPEC="Just Tools.$TOOLSPEC"
;;
"x86")
X86_TOOLSPEC="Just Tools.$TOOLSPEC"
;;
"k1om")
K1OM_TOOLSPEC="Just Tools.$TOOLSPEC"
;;
*)
echo "Unknown toolchain architecture: $TC_ARCH"
exit 1
;;
esac
;;
"-r"|"--toolroot")
TOOLROOT="Just \"$2\""
shift
;;
"-j"|"--jobs")
JOBS="$2"
shift
;;
"--cachedir")
CACHEDIR="$2"
shift
;;
"--hagfish")
HAGFISH_LOCATION="$2"
shift
;;
"--help")
usage
;;
*)
usage
;;
esac
shift
done
if test -z "$INSTALLDIR"; then
echo "Install directory defaulting to '.'"
INSTALLDIR="."
else
echo "Install directory is $INSTALLDIR"
fi
cd $INSTALLDIR
if test -z "$SRCDIR"; then
usage
fi
if test ! -f "$SRCDIR"/hake/Main.hs; then
echo "Can't find Hake in the source directory $SRCDIR."
echo "Did you specify the source directory correctly?"
usage
fi
echo "Source directory is $SRCDIR"
if test ! -z "$NEWARCHS"; then
ARCHS="$NEWARCHS"
else
ARCHS="$DFLTARCHS"
fi
echo "Architectures to build: $ARCHS"
if test ! -d "$CACHEDIR"; then
mkdir -p "$CACHEDIR"
chmod g+rw "$CACHEDIR"
fi
if test ! -d hake; then
echo "Creating a local hake directory..."
mkdir -p hake
touch hake/.marker
fi
echo "Setting up hake build directory..."
if test ! -f hake/Config.hs; then
echo "Bootstrapping Config.hs"
cp $SRCDIR/hake/Config.hs.template hake/Config.hs
cat >> hake/Config.hs <<EOF
-- Automatically added by hake.sh. Do NOT copy these definitions to the defaults
source_dir = "$SRCDIR"
architectures = [ $ARCHS ]
install_dir = "$INSTALLDIR"
toolroot = $TOOLROOT
arm_toolspec = $ARM_TOOLSPEC
aarch64_toolspec = $AARCH64_TOOLSPEC
thumb_toolspec = $THUMB_TOOLSPEC
armeb_toolspec = $ARMEB_TOOLSPEC
x86_toolspec = $X86_TOOLSPEC
k1om_toolspec = $K1OM_TOOLSPEC
cache_dir = "$CACHEDIR"
hagfish_location = "$HAGFISH_LOCATION"
EOF
else
echo "You already have Config.hs, leaving it as-is."
fi
# FIXME: do we really need this; doesn't ghc get the dependencies right? -AB
#rm -f hake/*.hi hake/*.o
# RTS parameters for hake. Tuned to perform well for the mid-2015 Barrelfish
# tree, building over NFS. Maximum heap size sits around 64MB, or a little
# more, so 128MB minimises collections. Parallelism is a balancing act
# between performance in the tree walk on NFS systems (which benefits heavily
# from parallelising the IO operations), and performance in Hakefile
# evaluation, which generally gets *slower* with more threads, as the GHC
# garbage collector ends up thrashing a lot.
HAKE_RTSOPTS="-H1024M -A4M -N4"
echo "Building hake..."
ghc -O2 --make \
-XDeriveDataTypeable \
-XStandaloneDeriving \
-XScopedTypeVariables \
-package ghc \
-package ghc-mtl \
-package ghc-paths \
-package bytestring-trie \
-o hake/hake \
-outputdir hake \
-i$SRCDIR/hake \
-ihake \
-rtsopts=all \
-with-rtsopts="$HAKE_RTSOPTS" \
-threaded \
$SRCDIR/hake/Main.hs $LDFLAGS || exit 1
# -eventlog \
if test "$RUN_HAKE" = "No"; then
echo "Not running hake as per your request."
exit
fi
echo "Running hake..."
./hake/hake --output-filename Makefile --source-dir "$SRCDIR/" --ghc-libdir "$(ghc --print-libdir)" || exit
if test "$NO_DEPS" = "No"; then
echo "Not running dependencies as per your request."
exit
fi
echo "Now running initial make to build dependencies."
echo "Running $JOBS jobs at once (-j N to change this)."
make -j "$JOBS" help