-
Notifications
You must be signed in to change notification settings - Fork 35
/
build-epiphany-sdk.sh
executable file
·329 lines (273 loc) · 8.86 KB
/
build-epiphany-sdk.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
#!/usr/bin/env bash
# Copyright (C) 2009-2014 Adapteva Inc
# Contributor Yaniv Sapir <[email protected]>
# Contributor Ben Chaco <[email protected]>
# Contributor Jeremy Bennett <[email protected]>
# This file is a script to download toolchain source.
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# Define the basedir
d=`dirname "$0"`
basedir=`(cd "$d/.." && pwd)`
# Common functions
. ${basedir}/sdk/common-functions
# Set the release parameters
. ${basedir}/sdk/define-release.sh
BRANCH=""
# Git branch name for build default
if [ -e ${basedir}/sdk/.git ] && which git >/dev/null; then
BRANCH=$(cd ${basedir}/sdk && git rev-parse --abbrev-ref HEAD || true)
fi
if [ "x${BRANCH}" = "x" ]; then
BRANCH="master"
fi
# Host architecture triplet for toolchain
# Likely value (with -c) if cross-building for Pubuntu is "arm-linux-gnueabihf"
TOOLCHAIN_CANONICAL_HOST=""
# Host e-hal e-loader etc. should be compiled for, e.g., Parallella.
ELIBS_CANONICAL_HOST="arm-linux-gnueabihf"
jobs_str=""
while getopts c:e:Cdj:r:Rt:h arg; do
case $arg in
c)
TOOLCHAIN_CANONICAL_HOST=$OPTARG
;;
e)
ELIBS_CANONICAL_HOST=$OPTARG
;;
C)
CLEAN=yes
;;
d)
DEBUG=yes
;;
j)
jobs_str="--jobs ${OPTARG}"
;;
r)
echo "Warning: -r is deprecated"
;;
R)
echo "Warning: -R is deprecated"
;;
t)
have_branch_arg="yes"
BRANCH=$OPTARG
;;
h)
echo "Usage: ${0}"
echo " [-c <host prefix>]: Tool-chain architecture prefix."
echo " Only needed for Canadian cross builds."
echo " [-e <host prefix>]: epiphany-libs architecture prefix."
echo " Default: ${ELIBS_CANONICAL_HOST}"
echo " [-C]: Clean before start building."
echo " [-d]: Enable building with debug symbols."
echo " [-j <count>]: Specify that parallel make should run at"
echo " most <count> jobs."
echo " [-t <tag_name>]: The tag name (or branch name) for the SDK sources."
echo " Default: $BRANCH"
echo " [-h]: Show usage"
echo ""
echo "Environment variables:"
echo " ESDK_BUILDROOT"
echo " ESDK_BUILD_TOOLCHAIN"
echo " ESDK_DESTDIR"
echo " PARALLELLA_LINUX_HOME"
echo ""
exit 0
;;
\?)
echo "Invalid Argument; $1"
exit 1
;;
esac
done
shift $((OPTIND-1))
if [ "x${ESDK_BUILDROOT}" = "x" ]; then
d=$(dirname "$0")
ESDK_BUILDROOT=$(cd "$d/.." && pwd)
fi
if [ "x${ESDK_DESTDIR}" = "x" ]; then
ESDK_DESTDIR="$(echo ${ESDK_BUILDROOT}/esdk.${RELEASE}/ | sed s,[/]*$,/,g)"
else
ESDK_DESTDIR="$(echo ${ESDK_DESTDIR}/ | sed s,[/]*$,/,g)"
fi
ESDK_PREFIX=/opt/adapteva
ESDK="${ESDK_PREFIX}/esdk.${RELEASE}"
HOSTNAME="host.$(getarch ${ELIBS_CANONICAL_HOST})"
HOST="${ESDK}/tools/${HOSTNAME}"
GNUNAME="e-gnu.$(getarch ${TOOLCHAIN_CANONICAL_HOST})"
GNU="${ESDK}/tools/${GNUNAME}"
echo '********************************************'
echo '************ Epiphany SDK Build ************'
echo '********************************************'
echo ""
echo "Environment settings:"
echo ""
echo " ESDK_BUILDROOT=${ESDK_BUILDROOT}"
echo " ESDK_DESTDIR=${ESDK_DESTDIR}"
echo ""
echo "Build settings:"
echo ""
echo " eSDK install directory: ${ESDK_DESTDIR}"
echo " eSDK prefix directory: ${ESDK}"
echo " Tool chain host prefix: ${TOOLCHAIN_CANONICAL_HOST}"
echo " epiphany-libs host prefix: ${ELIBS_CANONICAL_HOST}"
echo " Build version: ${RELEASE}"
echo " Build from branch or tag: ${BRANCH}"
echo ""
cd ${ESDK_BUILDROOT}/sdk || exit 1
# Create the SDK tree
echo "Creating the eSDK directory tree..."
mkdir -p ${ESDK_DESTDIR}${ESDK} ${ESDK_DESTDIR}${ESDK}/bsps ${ESDK_DESTDIR}${ESDK}/tools
mkdir -p ${ESDK_DESTDIR}${HOST}/lib ${ESDK_DESTDIR}${HOST}/include ${ESDK_DESTDIR}${HOST}/bin
mkdir -p ${ESDK_DESTDIR}${GNU}/epiphany-elf
# Create toolchain symbolic links (force overwrite if exists)
(
cd ${ESDK_DESTDIR}${ESDK}/..
ln -sTf esdk.${RELEASE} esdk
cd ${ESDK_DESTDIR}${ESDK}/tools
ln -sTf ${HOSTNAME} host
ln -sTf ${GNUNAME} e-gnu
cd ${ESDK_DESTDIR}${HOST}
ln -sTf ../${GNUNAME}/epiphany-elf epiphany-elf
)
# Sort out arg for cross compiling / Canadian cross
# Toolchain host architecture prefix
if [ "x${TOOLCHAIN_CANONICAL_HOST}" = "x" ]; then
host_str=""
else
host_str="--host ${TOOLCHAIN_CANONICAL_HOST}"
fi
# epiphany-libs host architecture prefix
if [ "x${ELIBS_CANONICAL_HOST}" = "x" ]; then
sdk_host_str=""
else
sdk_host_str="--host ${ELIBS_CANONICAL_HOST}"
fi
CFLAGS_FOR_TARGET=${CFLAGS_FOR_TARGET:-"-O2"}
CXXFLAGS_FOR_TARGET=${CXXFLAGS_FOR_TARGET:-"-O2"}
CFLAGS=${CFLAGS:-"-O2"}
CXXFLAGS=${CFLAGS:-"-O2"}
if [ "xyes" = "x$DEBUG" ]; then
export CFLAGS="-g ${CFLAGS}"
export CXXFLAGS="-g ${CXXFLAGS}"
sdk_debug_str="--debug"
else
sdk_debug_str=""
fi
export CFLAGS="-fdebug-prefix-map=${basedir}=${ESDK}/src ${CFLAGS}"
export CXXLAGS="-fdebug-prefix-map=${basedir}=${ESDK}/src ${CXXFLAGS}"
export CFLAGS_FOR_TARGET="-fdebug-prefix-map=${basedir}=${ESDK}/src ${CFLAGS_FOR_TARGET}"
export CXXLAGS_FOR_TARGET="-fdebug-prefix-map=${basedir}=${ESDK}/src ${CXXFLAGS_FOR_TARGET}"
if [ "xyes" = "x$CLEAN" ]; then
toolchain_clean_str="--clean-build --clean-host"
sdk_clean_str="--clean"
else
toolchain_clean_str=""
sdk_clean_str=""
fi
# If we're building for same host buildmachine the toolchain will naturally be
# installed to ${GNU}. Otherwise install into builds/
if [ "x${TOOLCHAIN_CANONICAL_HOST}" = "x" -o \
"x$(getarch ${TOOLCHAIN_CANONICAL_HOST})" = "x$(uname -m)" ]
then
id_buildarch_toolchain="${ESDK_DESTDIR}${GNU}"
buildarch_install_dir_str=""
else
id_buildarch_toolchain=${ESDK_BUILDROOT}/builds/id-$(uname -m)-${RELEASE}-toolchain
buildarch_install_dir_str="--install-dir-build ${id_buildarch_toolchain}"
fi
# install-sdk.sh must have an Epiphany toolchain in the PATH
export PATH="${id_buildarch_toolchain}/bin:${PATH}"
if ! ./download-components.sh --clone; then
printf "\nAborting...\n"
exit 1
fi
if [ "$ESDK_BUILD_TOOLCHAIN" != "no" ]; then
# Build the toolchain (this will take a while)
# TODO: Remove --enable-cgen-maint and --enable-werror
# before we release.
if ! ./build-toolchain.sh ${jobs_str} \
--install-dir-host ${GNU} \
--destdir ${ESDK_DESTDIR} \
--disable-werror \
--enable-cgen-maint \
${buildarch_install_dir_str} \
${host_str} ${toolchain_clean_str}; then
printf "The toolchain build failed!\n"
printf "\nAborting...\n"
exit 1
fi
fi
# Build order for dependencies is:
# 1. e-lib
# 2. pal (host + epiphany device)
# 4. e-hal (depends on pal) + the rest of epiphany-libs
# Build epiphany-libs (w/o e-hal == only e-lib)
# We must clean because we share build directory w/ e-hal build
# below (ugly but works !!!)
if ! ./build-epiphany-libs.sh \
${jobs_str} \
--install-dir-host ${HOST} \
--install-dir-target ${GNU}/epiphany-elf \
--install-dir-bsps ${ESDK}/bsps \
--destdir ${ESDK_DESTDIR} \
--clean \
--config-extra "--disable-ehal --enable-elib" \
${sdk_host_str};
then
printf "The epiphany-libs (elib) build failed!\n"
printf "\nAborting...\n"
exit 1
fi
# Build pal for host
export EPIPHANY_HOME=${ESDK_DESTDIR}/${ESDK}
if ! ./build-pal.sh \
${jobs_str} \
--install-dir-host ${HOST} \
--install-dir-target ${GNU}/epiphany-elf \
--destdir ${ESDK_DESTDIR} \
--config-extra "--enable-device-epiphany --enable-device-epiphany-sim" \
${sdk_host_str} \
${sdk_clean_str};
then
printf "The pal build failed!\n"
printf "\nAborting...\n"
exit 1
fi
unset EPIPHANY_HOME
# Build e-hal + rest of epiphany-libs
if ! CFLAGS="-I${HOST}/include ${CFLAGS}" LDFLAGS="-L${HOST}/lib ${LDFLAGS}" \
./build-epiphany-libs.sh \
${jobs_str} \
--install-dir-host ${HOST} \
--install-dir-target ${GNU}/epiphany-elf \
--install-dir-bsps ${ESDK}/bsps \
--destdir ${ESDK_DESTDIR} \
--clean \
--config-extra "--disable-elib --enable-ehal --enable-pal-target" \
${sdk_host_str};
then
printf "The epiphany-libs (e-hal) build failed!\n"
printf "\nAborting...\n"
exit 1
fi
# Copy top files
echo "Copying top files"
cp -d README ${ESDK_DESTDIR}${ESDK}
cp -d COPYING ${ESDK_DESTDIR}${ESDK}
cp -d setup.sh ${ESDK_DESTDIR}${ESDK}
cp -d setup.csh ${ESDK_DESTDIR}${ESDK}
echo "Creating tarball"
tar czf ${ESDK_BUILDROOT}/esdk.${RELEASE}.tar.gz -C ${ESDK_DESTDIR}${ESDK_PREFIX} esdk.${RELEASE}
printf "The Epiphany SDK Build Completed successfully\n"
exit 0