-
Notifications
You must be signed in to change notification settings - Fork 7
/
buildit.sh
373 lines (326 loc) · 10.8 KB
/
buildit.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
#!/bin/sh
# Copyright (C) 2007 Segher Boessenkool <segher@kernel.crashing.org>
# Copyright (C) 2009 Hector Martin "marcan" <hector@marcansoft.com>
# Copyright (C) 2009 Andre Heider "dhewg" <dhewg@V850brew.org>
# Copyright (C) 2010 Alex Marshall "trap15" <trap15@raidenii.net>
# Released under the terms of the GNU GPL, version 2
GNU_FTP="http://ftp.gnu.org/gnu"
#GNU_FTP="ftp://mirrors.usc.edu/pub/gnu"
BINUTILS_VER=2.20
BINUTILS_DIR="binutils-$BINUTILS_VER"
BINUTILS_TARBALL="binutils-$BINUTILS_VER.tar.bz2"
BINUTILS_URI="$GNU_FTP/binutils/$BINUTILS_TARBALL"
GMP_VER=5.0.1
GMP_DIR="gmp-$GMP_VER"
GMP_TARBALL="gmp-$GMP_VER.tar.bz2"
GMP_URI="$GNU_FTP/gmp/$GMP_TARBALL"
MPFR_VER=2.4.2
MPFR_DIR="mpfr-$MPFR_VER"
MPFR_TARBALL="mpfr-$MPFR_VER.tar.bz2"
MPFR_URI="http://www.mpfr.org/mpfr-$MPFR_VER/$MPFR_TARBALL"
#MPFR_URI="ftp://mirrors.usc.edu/pub/gnu/mpfr/$MPFR_TARBALL"
MPC_VER=0.8.2
MPC_DIR="mpc-$MPC_VER"
MPC_TARBALL="mpc-$MPC_VER.tar.gz"
MPC_URI="http://www.multiprecision.org/mpc/download/$MPC_TARBALL"
GCC_VER=4.5.1
GCC_DIR="gcc-$GCC_VER"
GCC_TARBALL="gcc-$GCC_VER.tar.bz2"
GCC_URI="$GNU_FTP/gcc/gcc-$GCC_VER/$GCC_TARBALL"
GDB_VER=7.1
GDB_DIR="gdb-$GDB_VER"
GDB_TARBALL="gdb-$GDB_VER.tar.bz2"
GDB_URI="$GNU_FTP/gdb/$GDB_TARBALL"
NEWLIB_VER=1.18.0
NEWLIB_DIR="newlib-$NEWLIB_VER"
NEWLIB_TARBALL="newlib-$NEWLIB_VER.tar.gz"
NEWLIB_URI="ftp://sources.redhat.com/pub/newlib/$NEWLIB_TARBALL"
CRT_DIR="crt"
PATCHDIR=patches
BUILDTYPE=$1
SPU_TARGET=spu
SPU_NEWLIB_TARGET=$SPU_TARGET
PPU_TARGET=powerpc64-linux
PPU_NEWLIB_TARGET=ppc64
if [ -z $MAKEOPTS ]; then
MAKEOPTS=-j3
fi
# End of configuration section.
case `uname -s` in
*BSD*)
MAKE=gmake
;;
*)
MAKE=make
esac
export PATH=$PS3DEV/bin:$PATH
die() {
echo $@
exit 1
}
cleansrc() {
[ -e $PS3DEV/$BINUTILS_DIR ] && rm -rf $PS3DEV/$BINUTILS_DIR
[ -e $PS3DEV/$GCC_DIR ] && rm -rf $PS3DEV/$GCC_DIR
[ -e $PS3DEV/$GDB_DIR ] && rm -rf $PS3DEV/$GDB_DIR
[ -e $PS3DEV/$CRT_DIR ] && rm -rf $PS3DEV/$CRT_DIR
[ -e $PS3DEV/$NEWLIB_DIR ] && rm -rf $PS3DEV/$NEWLIB_DIR
}
cleanbuild() {
[ -e $PS3DEV/build_binutils ] && rm -rf $PS3DEV/build_binutils
[ -e $PS3DEV/build_gcc ] && rm -rf $PS3DEV/build_gcc
[ -e $PS3DEV/build_crt ] && rm -rf $PS3DEV/build_crt
[ -e $PS3DEV/build_gdb ] && rm -rf $PS3DEV/build_gdb
[ -e $PS3DEV/build_newlib ] && rm -rf $PS3DEV/build_newlib
}
download() {
DL=1
if [ -f "$PS3DEV/$2" ]; then
echo "Testing $2..."
# Check bz2 and gz
tar tjf "$PS3DEV/$2" >/dev/null 2>&1 && DL=0
if [ $DL -eq 1 ]; then
tar tzf "$PS3DEV/$2" >/dev/null 2>&1 && DL=0
fi
fi
if [ $DL -eq 1 ]; then
echo "Downloading $2..."
wget "$1" -c -O "$PS3DEV/$2" || die "Could not download $2"
fi
}
extract() {
echo "Extracting $1..."
tar xf "$PS3DEV/$1" -C "$2" || die "Error unpacking $1"
}
extract_archives() {
cleansrc
extract "$BINUTILS_TARBALL" "$PS3DEV"
extract "$GCC_TARBALL" "$PS3DEV"
extract "$NEWLIB_TARBALL" "$PS3DEV"
extract "$GDB_TARBALL" "$PS3DEV"
extract "$GMP_TARBALL" "$PS3DEV/$GCC_DIR"
mv "$PS3DEV/$GCC_DIR/$GMP_DIR" "$PS3DEV/$GCC_DIR/gmp" || die "Error renaming $GMP_DIR -> gmp"
extract "$MPFR_TARBALL" "$PS3DEV/$GCC_DIR"
mv "$PS3DEV/$GCC_DIR/$MPFR_DIR" "$PS3DEV/$GCC_DIR/mpfr" || die "Error renaming $MPFR_DIR -> mpfr"
extract "$MPC_TARBALL" "$PS3DEV/$GCC_DIR"
mv "$PS3DEV/$GCC_DIR/$MPC_DIR" "$PS3DEV/$GCC_DIR/mpc" || die "Error renaming $MPC_DIR -> mpc"
cp -r "$CRT_DIR" "$PS3DEV/" || die "Unable to copy crt to build dir"
}
create_syms() {
TARGET=$1
FOLDER=$2
ln -s $PS3DEV/$FOLDER/bin/$TARGET-addr2line $PS3DEV/$FOLDER/bin/$FOLDER-addr2line >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-ar $PS3DEV/$FOLDER/bin/$FOLDER-ar >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-as $PS3DEV/$FOLDER/bin/$FOLDER-as >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-c++ $PS3DEV/$FOLDER/bin/$FOLDER-c++ >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-c++filt $PS3DEV/$FOLDER/bin/$FOLDER-c++filt >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-cpp $PS3DEV/$FOLDER/bin/$FOLDER-cpp >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-embedspu $PS3DEV/$FOLDER/bin/$FOLDER-embedspu >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-g++ $PS3DEV/$FOLDER/bin/$FOLDER-g++ >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-gcc $PS3DEV/$FOLDER/bin/$FOLDER-gcc >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-gcc-4.5.1 $PS3DEV/$FOLDER/bin/$FOLDER-gcc-4.5.1 >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-gccbug $PS3DEV/$FOLDER/bin/$FOLDER-gccbug >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-gcov $PS3DEV/$FOLDER/bin/$FOLDER-gcov >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-gdb $PS3DEV/$FOLDER/bin/$FOLDER-gdb >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-gdbtui $PS3DEV/$FOLDER/bin/$FOLDER-gdbtui >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-gprof $PS3DEV/$FOLDER/bin/$FOLDER-gprof >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-ld $PS3DEV/$FOLDER/bin/$FOLDER-ld >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-nm $PS3DEV/$FOLDER/bin/$FOLDER-nm >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-objcopy $PS3DEV/$FOLDER/bin/$FOLDER-objcopy >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-objdump $PS3DEV/$FOLDER/bin/$FOLDER-objdump >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-ranlib $PS3DEV/$FOLDER/bin/$FOLDER-ranlib >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-readelf $PS3DEV/$FOLDER/bin/$FOLDER-readelf >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-size $PS3DEV/$FOLDER/bin/$FOLDER-size >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-strings $PS3DEV/$FOLDER/bin/$FOLDER-strings >/dev/null
ln -s $PS3DEV/$FOLDER/bin/$TARGET-strip $PS3DEV/$FOLDER/bin/$FOLDER-strip >/dev/null
}
makedirs() {
mkdir -p $PS3DEV/build_binutils || die "Error making binutils build directory $PS3DEV/build_binutils"
mkdir -p $PS3DEV/build_gcc || die "Error making gcc build directory $PS3DEV/build_gcc"
mkdir -p $PS3DEV/build_crt || die "Error making crt build directory $PS3DEV/build_crt"
mkdir -p $PS3DEV/build_gdb || die "Error making gdb build directory $PS3DEV/build_gdb"
mkdir -p $PS3DEV/build_newlib || die "Error making newlib build directory $PS3DEV/build_newlib"
}
copy_makerules() {
TARGET=$1
cp common.mk $PS3DEV/
cp common_pre.mk $PS3DEV/
cp $TARGET.mk $PS3DEV/
}
buildbinutils() {
TARGET=$1
FOLDER=$2
(
cd $PS3DEV/build_binutils && \
$PS3DEV/$BINUTILS_DIR/configure --target=$TARGET --disable-multilib \
--prefix=$PS3DEV/$FOLDER --disable-werror && \
$MAKE $MAKEOPTS && \
$MAKE install
) || die "Error building binutils for target $TARGET"
}
buildnewlib() {
TARGET=$1
NEWLIBTARGET=$2
FOLDER=$3
PREFIX=$PS3DEV/$FOLDER/bin/$TARGET
(
export CC_FOR_TARGET=$PREFIX-gcc
export GCC_FOR_TARGET=$PREFIX-gcc
export CXX_FOR_TARGET=$PREFIX-g++
export LD_FOR_TARGET=$PREFIX-ld
export AS_FOR_TARGET=$PREFIX-as
export AR_FOR_TARGET=$PREFIX-ar
export RANLIB_FOR_TARGET=$PREFIX-ranlib
export NM_FOR_TARGET=$PREFIX-nm
export STRIP_FOR_TARGET=$PREFIX-strip
export OBJDUMP_FOR_TARGET=$PREFIX-objdump
export OBJCOPY_FOR_TARGET=$PREFIX-objcopy
cd $PS3DEV/build_newlib && \
$PS3DEV/$NEWLIB_DIR/configure --target=$NEWLIBTARGET --disable-multilib \
--prefix=$PS3DEV/$FOLDER && \
$MAKE $MAKEOPTS && \
$MAKE install
) || die "Error building newlib for target $TARGET"
(
if [ "$TARGET" != "$NEWLIBTARGET" ]; then
cp -r $PS3DEV/$FOLDER/$NEWLIBTARGET/lib $PS3DEV/$FOLDER/$TARGET/ && \
cp -r $PS3DEV/$FOLDER/$NEWLIBTARGET/include $PS3DEV/$FOLDER/$TARGET/ && \
rm -rf $PS3DEV/$FOLDER/$NEWLIBTARGET
fi
) || die "Error copying newlib for target $TARGET"
}
buildcrt() {
TARGET=$1
FOLDER=$2
(
cd $PS3DEV/build_crt && \
$PS3DEV/$FOLDER/bin/$TARGET-gcc -c $PS3DEV/$CRT_DIR/$TARGET/crti.S -o crti.o && \
$PS3DEV/$FOLDER/bin/$TARGET-gcc -c $PS3DEV/$CRT_DIR/$TARGET/crtn.S -o crtn.o && \
$PS3DEV/$FOLDER/bin/$TARGET-gcc -c $PS3DEV/$CRT_DIR/$TARGET/crt0.S -o crt0.o && \
$PS3DEV/$FOLDER/bin/$TARGET-gcc -c $PS3DEV/$CRT_DIR/$TARGET/crt1.c -o crt.o && \
$PS3DEV/$FOLDER/bin/$TARGET-ld -r crt0.o crt.o -o crt1.o && \
mkdir -p $PS3DEV/$FOLDER/$TARGET/lib && \
cp crti.o crtn.o crt0.o crt1.o $PS3DEV/$FOLDER/$TARGET/lib/ && \
mkdir -p $PS3DEV/$FOLDER/$TARGET/include && \
cp $PS3DEV/$CRT_DIR/fenv.h $PS3DEV/$FOLDER/$TARGET/include/
) || die "Error building crt for target $TARGET"
}
buildgcc() {
TARGET=$1
FOLDER=$2
CPUFLAG=$3
(
cd $PS3DEV/build_gcc && \
$PS3DEV/$GCC_DIR/configure \
--target=$TARGET \
--disable-multilib \
--disable-threads \
--disable-libgomp \
--disable-shared \
--with-newlib \
--enable-languages="c,c++" \
--enable-checking=release \
--prefix=$PS3DEV/$FOLDER \
$EXTRAFLAGS \
$CPUFLAG && \
$MAKE all-gcc $MAKEOPTS && \
$MAKE install-gcc
) || die "Error building gcc for target $TARGET"
}
continuegcc() {
TARGET=$1
(
cd $PS3DEV/build_gcc && \
$MAKE all $MAKEOPTS && \
$MAKE install
) || die "Error building gcc support libs for target $TARGET"
}
buildgdb() {
TARGET=$1
FOLDER=$2
(
cd $PS3DEV/build_gdb && \
$PS3DEV/$GDB_DIR/configure --target=$TARGET --disable-multilib \
--prefix=$PS3DEV/$FOLDER --disable-werror \
--disable-sim && \
$MAKE $MAKEOPTS && \
$MAKE install
) || die "Error building gdb for target $TARGET"
}
buildspu() {
extract_archives
cleanbuild
makedirs
copy_makerules spu
echo "******* Building SPU binutils"
buildbinutils $SPU_TARGET spu
echo "******* Building SPU GCC"
buildgcc $SPU_TARGET spu
echo "******* Building SPU Newlib"
buildnewlib $SPU_TARGET $SPU_NEWLIB_TARGET spu
echo "******* Building SPU GCC"
continuegcc $SPU_TARGET
echo "******* Building SPU GDB"
buildgdb $SPU_TARGET spu
echo "******* SPU toolchain built and installed"
}
buildppu() {
extract_archives
cleanbuild
makedirs
copy_makerules ppu
echo "******* Building PPU binutils"
buildbinutils $PPU_TARGET ppu
echo "******* Building PPU GCC"
buildgcc $PPU_TARGET ppu --with-cpu=cell
echo "******* Building PPU Newlib"
buildnewlib $PPU_TARGET $PPU_NEWLIB_TARGET ppu
echo "******* Building PPU CRT"
buildcrt $PPU_TARGET ppu
echo "******* Building PPU GCC"
continuegcc $PPU_TARGET
echo "******* Building PPU GDB"
buildgdb $PPU_TARGET ppu
echo "******* Creating symlinks!"
create_syms $PPU_TARGET ppu
echo "******* PPU toolchain built and installed"
}
if [ -z "$PS3DEV" ]; then
die "Please set PS3DEV in your environment."
fi
if [ $# -eq 0 ]; then
die "Please specify build type(s) (all/ppu/spu/clean)"
fi
if [ "$BUILDTYPE" = "clean" ]; then
cleanbuild
cleansrc
exit 0
fi
#cp -R $PATCHDIR $PS3DEV
download "$BINUTILS_URI" "$BINUTILS_TARBALL"
download "$GMP_URI" "$GMP_TARBALL"
download "$MPFR_URI" "$MPFR_TARBALL"
download "$MPC_URI" "$MPC_TARBALL"
download "$GCC_URI" "$GCC_TARBALL"
download "$NEWLIB_URI" "$NEWLIB_TARBALL"
download "$GDB_URI" "$GDB_TARBALL"
if [ "$1" = "all" ]; then
buildppu
buildspu
cleanbuild
cleansrc
exit 0
fi
while true; do
if [ $# -eq 0 ]; then
exit 0
fi
case $1 in
ppu) buildppu ;;
spu) buildspu ;;
clean) cleanbuild; cleansrc; exit 0 ;;
*)
die "Unknown build type $1"
;;
esac
shift;
done