forked from travisg/toolchains
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoit
executable file
·219 lines (189 loc) · 5.25 KB
/
doit
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
#!/usr/bin/env bash
set -e
OS=$(uname)
HOSTARCH=$(uname -m)
if [ ! -n "$FETCH" ]; then
FETCH=1
fi
if [ ! -n "$GNU_FTP" ]; then
GNU_FTP="ftp://ftp.gnu.org/gnu"
fi
if [ ! -n "$ARCHES" ]; then
echo need to specify architectures to build in the ARCHES environment variable
echo ie. ARCHES=\"arm sh\"
exit 1
fi
if [ ! -n "$PREFIX" ]; then
PREFIX="/usr/local"
fi
if [ -e "$PREFIX" ] && [ ! -d "$PREFIX" ]; then
echo Install prefix $PREFIX is a non-directory
exit 1
elif [ ! -e "$PREFIX" ]; then
if mkdir -p "$PREFIX"; then
:
else
echo Unable to make prefix $PREFIX
exit 1
fi
fi
if [ ! -n $PARALLEL ]; then
if [ "$OS" = "Linux" ]; then
COUNT=$(grep processor /proc/cpuinfo | wc -l)
PARALLEL=-j$(expr $COUNT + $COUNT)
elif [ "$OS" = "Darwin"]; then
COUNT=$(hwprefs cpu_count)
PARALLEL=-j$(expr $COUNT + $COUNT)
else
PARALLEL=-j4
fi
fi
if [ "$OS" = "Darwin" ]; then
export CPPFLAGS=-I/opt/local/include
export LDFLAGS=-L/opt/local/lib
fi
if [ "$OS" = "FreeBSD" ]; then
export CPPFLAGS=-I/usr/local/include
export LDFLAGS=-L/usr/local/lib
fi
if [ ! -n "$MAKE" ]; then
MAKE=make
if [ "$OS" = "FreeBSD" ]; then
MAKE=gmake
fi
fi
if [ "$HOSTARCH" = "amd64" ]; then
HOSTARCH=x86_64
fi
# load GCCVER and BINVER
. toolvers
mkdir -p archives
if [ "$FETCH" = "1" ]; then
pushd archives
if [ ! -f binutils-$BINVER.tar.bz2 ]; then
wget -N $GNU_FTP/binutils/binutils-$BINVER.tar.bz2
fi
if [ ! -f gcc-$GCCVER.tar.bz2 ]; then
wget -N $GNU_FTP/gcc/gcc-$GCCVER/gcc-$GCCVER.tar.bz2
fi
if [ ! -f gdb-$GDBVER.tar.bz2 ]; then
wget -N $GNU_FTP/gdb/gdb-$GDBVER.tar.bz2
fi
if [ ! -f mpfr-$MPFRVER.tar.bz2 ]; then
wget -N $GNU_FTP/mpfr/mpfr-$MPFRVER.tar.bz2
fi
if [ ! -f mpc-$MPCVER.tar.gz ]; then
wget -N $GNU_FTP/mpc/mpc-$MPCVER.tar.gz
fi
if [ ! -f gmp-$GMPVER.tar.bz2 ]; then
# XXX Hack because 6.0.0a
#wget -N $GNU_FTP/gmp/gmp-$GMPVER.tar.bz2
wget -N $GNU_FTP/gmp/gmp-6.0.0a.tar.bz2
mv gmp-6.0.0a.tar.bz2 gmp-6.0.0.tar.bz2
fi
popd
fi
# Usage: extract-tool name version archiveType patch-dir
function extract-tool()
{
#echo "extract-tool " $1 $2 $3 $4
TARFILE=archives/${1}-${2}.tar$3
TARGETDIR=${1}-${2}
if [ -f ${TARGETDIR}/.extracted ]; then
echo "$TARFILE already extracted into $TARGETDIR, skipping"
return 0
fi
if [ ! -f $TARFILE ]; then
echo "error, missing $TARFILE"
echo "Set FETCH=1 to fetch automatically"
exit 1
fi
echo "-- extracting $TARFILE"
rm -rf $TARGETDIR
if [ "$3" = ".gz" ]; then
CAT="gzcat"
elif [ "$3" = ".bz2" ]; then
CAT="bzcat"
else
echo "Unknown archive type ''$3'"
exit 1
fi
$CAT $TARFILE | tar x
if [ ! -z "$4" ]; then
echo "-- patching $1"
for f in $4/*.patch; do
echo " patch $f"
patch -d $TARGETDIR -p1 < "$f"
done
fi
touch $TARGETDIR/.extracted
}
if [ ! -f .extracted-stamp ]; then
extract-tool binutils $BINVER .bz2 binutils-patches
extract-tool gcc $GCCVER .bz2 gcc-patches
extract-tool gdb $GDBVER .bz2 gdb-patches
extract-tool gmp $GMPVER .bz2
extract-tool mpc $MPCVER .gz
extract-tool mpfr $MPFRVER .bz2
touch .extracted-stamp
fi
# link the last three libs into gcc
pushd gcc-$GCCVER
ln -sf ../gmp-$GMPVER gmp
ln -sf ../mpc-$MPCVER mpc
ln -sf ../mpfr-$MPFRVER mpfr
popd
for ARCH in $ARCHES; do
echo "== Doing build for $ARCH"
if [ "$ARCH" == "arm" ]; then
TARGET=arm-eabi
else
TARGET=$ARCH-elf
fi
BINBUILDPATH=build-binutils-$BINVER-$ARCH-$OS-$HOSTARCH
GCCBUILDPATH=build-gcc-$GCCVER-$ARCH-$OS-$HOSTARCH
GDBBUILDPATH=build-gdb-$GDBVER-$ARCH-$OS-$HOSTARCH
export PATH=$INSTALLPATH/bin:$PATH
if [ ! -f $BINBUILDPATH/built.txt ]; then
echo "- Binutils..."
mkdir -p $BINBUILDPATH || exit 1
pushd $BINBUILDPATH
if [ ! -f Makefile ]; then
../binutils-$BINVER/configure --target=$TARGET --prefix=$PREFIX --disable-werror
fi
$MAKE $PARALLEL &&
$MAKE install &&
touch built.txt
popd
fi
if [ ! -f $GCCBUILDPATH/built.txt ]; then
echo "- GCC..."
ARCH_OPTIONS=
if [ $ARCH == "arm" ]; then
ARCH_OPTIONS="--with-cpu=arm926ej-s --with-fpu=vfp"
fi
mkdir -p $GCCBUILDPATH || exit 1
pushd $GCCBUILDPATH
if [ ! -f Makefile ]; then
../gcc-$GCCVER/configure --target=$TARGET --prefix=$PREFIX --enable-languages=c,c++ $ARCH_OPTIONS --disable-werror || exit 1
fi
$MAKE all-gcc $PARALLEL &&
$MAKE all-target-libgcc $PARALLEL &&
$MAKE install-gcc &&
$MAKE install-target-libgcc &&
touch built.txt
popd
fi
if [ ! -f $GDBBUILDPATH/built.txt ]; then
echo "- GDB..."
mkdir -p $GDBBUILDPATH || exit 1
pushd $GDBBUILDPATH
if [ ! -f Makefile ]; then
../gdb-$GDBVER/configure --target=$TARGET --prefix=$PREFIX --disable-werror || exit 1
fi
make $PARALLEL &&
make install &&
touch built.txt
popd
fi
done