This repository has been archived by the owner on Apr 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBuild.sh
executable file
·390 lines (279 loc) · 9.39 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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
#!/bin/bash
#
#
#set -x
#
# Build script for BA2 toolchain
#
#note you need to modify the prefixes in the script to your particular folder layout for it to
#work and add in the relevant cd to each folder between each component etc..
#also unless you have a dual quad core dev machine i suggest that you take
#the '-j5' option out of the make command
#
#running order for x-compilers is
#1. make binutils so that you can build your stuff
#2. make newlibs as they need to be incorporated into gcc when you build it in part 3
#3. build gcc
#4. build gdb
#
#the basim and bamon have their own instructions which are found in the relevant readme file
#
#all you have to do then is extract it to wherever you see fit and stick it in your environment path..
#
# build/release no. of toolchain
RELEASENO=r36379
export RELEASENO
function usage {
echo "Build script usage"
echo "./Build <Prefix to installation directory> <Optional chost that the toolchain will run on>"
}
PREFIX=$1
HOST=$2
if [ "$PREFIX" = "" ]; then
echo "You must specify the prefix to the installation directory"
usage
exit 1
fi
if [ -n $HOST ]; then
echo "Building for host system type $HOST"
HOST=--host=$HOST
fi
# Number of make processes. This should typically be set to num processors + 1
MAKEJOBS=3
# Remember where we were started
RUNDIR=`pwd`
# Export the path so that gcc can find binutils, etc
export PATH=$PREFIX/bin/:$PATH
# Initialise build log.
BUILDSTART=`date`
echo "Build started at $BUILDSTART" > $RUNDIR/build.log
###############################
# Set version numbers of components
#
BINUTILSVERSION=2.22
GCCVERSION=4.7.4
GDBVERSION=7.5.1
NEWLIBVERSION=2.0.0
GMPVERSION=4.3.2
MPFRVERSION=2.4.2
MPCVERSION=0.8.1
###############################
# Names of components
BINUTILSNAME=binutils-$BINUTILSVERSION-ba-r33675
GCCNAME=gcc-$GCCVERSION-ba-r36379
GDBNAME=gdb-$GDBVERSION-ba-r34135
JTAGNAME=jtag-r34432
NEWLIBNAME=newlib-$NEWLIBVERSION-ba-r33675
GMPNAME=gmp-$GMPVERSION
MPFRNAME=mpfr-$MPFRVERSION
MPCNAME=mpc-$MPCVERSION
LIBFTDINAME=libftdi_0.20_devkit_mingw32_08April2012
###############################
# Filenames for components
BINUTILSFILE=./$BINUTILSNAME.tar.xz
GCCFILE=./$GCCNAME.tar.xz
GDBFILE=./$GDBNAME.tar.xz
JTAGFILE=./$JTAGNAME.tar.xz
NEWLIBFILE=./$NEWLIBNAME.tar.xz
GMPFILE=./$GMPNAME.tar.xz
MPFRFILE=./$MPFRNAME.tar.xz
MPCFILE=./$MPCNAME.tar.xz
LIBFTDIFILE=./$LIBFTDINAME.zip
###############################
# Build direcotry names for components
BINUTILSBUILD=./$BINUTILSNAME-build
GCCBUILD=./$GCCNAME-build
NEWLIBBUILD=./$NEWLIBNAME
GDBBUILD=./$GDBNAME
JTAGBUILD=./$JTAGNAME
###############################
# Utility functions
# Clean up build directories and installation direcotry for a clean build
function build_clean {
# Remove old source files and builds
echo "Removing old build directories"
rm -rf $BINUTILSBUILD $NEWLIBBUILD $GCCBUILD $GDBNAME $GDBBUILD $GCCNAME $BINUTILSNAME $JTAGNAME
# Remove old output directory
echo "Removing contents of installation directory"
#rm -rf $PREFIX/*
# Check if target prefix directory exists and create if not
if [ ! -e "$PREFIX" ]
then
echo "Creating installation directory", $PREFIX
mkdir -p $PREFIX/bin
fi
}
# Ensure that the installation bin directory is added to the path.
PATH=$PATH:$PREFIX/bin
# Utility function to extract an archive file.
function extract {
FILENAME=$1
echo $FILENAME
if [ `echo $FILENAME | grep ".zip" -` ]; then
echo "Extracting zip $FILENAME"
unzip -o $FILENAME
elif [ `echo $FILENAME | grep ".tar.gz" -` ]; then
echo "Extracting gzip'd tar $FILENAME"
tar -xzvf $FILENAME
elif [ `echo $FILENAME | grep ".tar.bz2" -` ]; then
echo "Extracting bzip'd tar $FILENAME"
tar -xjvf $FILENAME
elif [ `echo $FILENAME | grep ".tar.xz" -` ]; then
echo "Extracting xz'd tar $FILENAME"
tar -xJvf $FILENAME
fi
}
# Function to apply patches from a directory given as first parameter
function apply_patches {
PATCH_DIR=$1
if [ -d "$PATCH_DIR" ]; then
status "Applying patches from $PATCH_DIR"
for f in `ls "$PATCH_DIR"`; do
p="$PATCH_DIR/$f"
echo "Applying patch $p"
patch -p0 < $p
done
fi
}
# Function to display status and update xterm window title as appropriate
function status {
STATUS=$1
echo -ne "\033]0;${STATUS}\007"
echo $STATUS
echo $STATUS >> $RUNDIR/build.log
}
###############################
# binutils:
function build_binutils {
status "Extracting Binutils $BINUTILSVERSION Release $RELEASENO"
extract $BINUTILSFILE
cd $BINUTILSNAME
# Fix up broken zip permissions
chmod +x ./configure ./config ./missing ./mkdep ./mkinstalldirs
chmod 660 ./config/*
# Apply any patches
apply_patches "../$BINUTILSNAME-patches"
cd $RUNDIR
rm -rf $BINUTILSBUILD
mkdir -p $BINUTILSBUILD
cd $BINUTILSBUILD
status "Configuring Binutils $BINUTILSVERSION Release $RELEASENO in $BINUTILSBUILD"
../$BINUTILSNAME/configure $HOST --target=ba-elf --prefix=$PREFIX --disable-werror
if [ "$?" -ne "0" ]; then echo "Configure failed!"; exit 1; fi
status "Building Binutils $BINUTILSVERSION Release $RELEASENO in $BINUTILSBUILD"
make -j$MAKEJOBS all
if [ "$?" -ne "0" ]; then echo "Build failed!"; exit 1; fi
status "Installing Binutils $BINUTILSVERSION Release $RELEASENO in $BINUTILSBUILD"
make install
if [ "$?" -ne "0" ]; then echo "Install failed!"; exit 1; fi
echo "Completed binutils build in $BINUTILSBUILD"
cd $RUNDIR
}
###############################
# Gcc + newlib:
function build_gcc {
status "Using Newlib version $NEWLIBVERSION"
status "Using GMP version $GMPVERSION"
status "Using MPFR version $MPFRVERSION"
status "Using MPC version $MPCVERSION"
status "Extracting GCC $GCCVERSION Release $RELEASENO"
extract $GCCFILE
extract $NEWLIBFILE
extract $GMPFILE
extract $MPFRFILE
extract $MPCFILE
# Move newlib and libgloss into gcc directory
rm -rf $GCCNAME/newlib
rm -rf $GCCNAME/libgloss
rm -rf $GCCNAME/gmp
rm -rf $GCCNAME/mpfr
rm -rf $GCCNAME/mpc
mv -f ./$NEWLIBNAME/newlib $GCCNAME
mv -f ./$NEWLIBNAME/libgloss $GCCNAME
mv -f ./$GMPNAME $GCCNAME/gmp
mv -f ./$MPFRNAME $GCCNAME/mpfr
mv -f ./$MPCNAME $GCCNAME/mpc
cd $GCCNAME
# Fix up broken zip permissions
chmod +x ./configure ./config ./missing ./mkdep ./mkinstalldirs ./move-if-change
chmod 660 ./config/*
# Apply any patches
apply_patches "../$GCCNAME-patches"
cd $RUNDIR
status "Configuring GCC $GCCVERSION Release $RELEASENO in $GCCBUILD"
rm -rf $GCCBUILD
mkdir -p $GCCBUILD
cd $GCCBUILD
../$GCCNAME/configure $HOST --target=ba-elf --prefix=$PREFIX --enable-languages=c,c++,lto --with-gnu-as \
--with-gnu-ld --with-newlib --enable-target-optspace --disable-libssp --disable-__cxa_atexit \
--with-gxx-include-dir=$PREFIX/ba-elf/include
if [ "$?" -ne "0" ]; then echo "Configure failed!"; exit 1; fi
status "Building GCC $GCCVERSION Release $RELEASENO in $GCCBUILD"
make -j$MAKEJOBS all
if [ "$?" -ne "0" ]; then echo "Build failed!"; exit 1; fi
status "Installing GCC $GCCVERSION Release $RELEASENO in $GCCBUILD"
make install
if [ "$?" -ne "0" ]; then echo "Install failed!"; exit 1; fi
status "Completed GCC build in $GCCBUILD"
cd $RUNDIR
}
###############################
# GDB:
function build_gdb {
status "Extracting GDB $GDBVERSION Release $RELEASENO"
extract $GDBFILE
cd $GDBNAME/
# Apply any patches
apply_patches "../$GDBNAME-patches"
status "Configuring GDB $GDBVERSION Release $RELEASENO"
./configure $HOST --target=ba-elf --prefix=$PREFIX
if [ "$?" -ne "0" ]; then echo "Configure failed!"; exit 1; fi
status "Building GDB $GDBVERSION Release $RELEASENO"
make -j$MAKEJOBS all
if [ "$?" -ne "0" ]; then echo "Build failed!"; exit 1; fi
status "Installing GDB $GDBVERSION Release $RELEASENO"
make install
if [ "$?" -ne "0" ]; then echo "Install failed!"; exit 1; fi
status "Completed GDB build"
cd $RUNDIR
}
###############################
# JTAG:
function build_jtag {
if uname | grep -q MINGW
then
status "Set up libFTDI"
extract $LIBFTDIFILE
cp ./$LIBFTDINAME/bin/*.dll $PREFIX/bin/
fi
status "Extracting JTAG Release $RELEASENO"
extract $JTAGFILE
cd $JTAGNAME/
# Apply any patches
apply_patches "../$JTAGNAME-patches"
status "Configuring JTAG Release $RELEASENO"
if uname | grep -q MINGW
then
CFLAGS="-I../$LIBFTDINAME/include/"
LDFLAGS="-L../$LIBFTDINAME/lib/"
CONFIG_ARGS=" --enable-staticlibs"
fi
CFLAGS=$CFLAGS LDFLAGS=$LDFLAGS ./configure --prefix=$PREFIX $CONFIG_ARGS
if [ "$?" -ne "0" ]; then echo "Configure failed!"; exit 1; fi
status "Building JTAG Release $RELEASENO"
make -j$MAKEJOBS all
if [ "$?" -ne "0" ]; then echo "Build failed!"; exit 1; fi
status "Installing JTAG Release $RELEASENO"
make install
if [ "$?" -ne "0" ]; then echo "Install failed!"; exit 1; fi
status "Completed JTAG build"
cd $RUNDIR
}
###############################
# Build each component of the toolchain:
build_clean
build_binutils
build_gcc
build_gdb
build_jtag
echo "Toolchain built successfully and installed to $PREFIX"