-
Notifications
You must be signed in to change notification settings - Fork 2
/
toolchain-uclibc.sh
executable file
·343 lines (320 loc) · 9.86 KB
/
toolchain-uclibc.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
# !/usr/bin/env bash
if [ "$top" == "" ]; then
echo "top variable is empty. It should point to top of the build trees. Please add it to your environment"
exit 1
fi
if [ "$src" == "" ]; then
echo "src variable is empty. It should point to top dir where all source trees are. Please add it to your enviroment"
exit 1
fi
if [ "$defconfig_dir" == "" ]; then
echo "defconfig_dir variable is empty. It should point to dir where all uclibc defconfigs are usually in uClibc-defconfigs dir under the ct-scripts tree you cloned. Please add it to your enviroment"
exit 1
fi
if [ $# -lt 1 ]; then
echo -en "
Usage: `basename $0` <arch> {<config name>}
Example: `basename $0` ppc64 config.lt.mine
config.lt.mine is searched in $defconfig_dir
if no config name is specified then it will
contruct a config name config.<thread model>.<arch>
e.g. config.nptl.arm will be used if building
for arm using nptl and config.lt.arm will be
used if building for arm using linuxthreads
available configs are:
"
ls $defconfig_dir
exit 0
fi
# change these versions depending upon
# what you want your toolchain based on
#binutilsv=2.18.50
#linuxv=2.6.24
#gccv=4.2
#libcv=glibc
#threadv=lt
binutilsv=binutils-gdb
linuxv=linux
gccv=gcc
libcv=uClibc
download_src=no
host=`uname --machine`
build=${host}-linux-gnu
host=$build
cpus=`cat /proc/cpuinfo | grep '^processor' | wc -l`
proc_per_cpu=2
parallelism=$(($cpus * $proc_per_cpu))
extra_gcc_configure_opts=
extra_binutils_configure_opts=
extra_eglibc_configure_opts=
arch=$1
defconfig=$2
threadv=nptl
case $arch in
ppc)
target=powerpc-linux-uclibc
linux_arch=powerpc
extra_binutils_configure_opts="--disable-werror"
extra_gcc_configure_opts="--disable-multilib"
;;
ppc64)
target=powerpc64-linux-uclibc
linux_arch=powerpc
extra_binutils_configure_opts="--enable-targets=powerpc-linux-uclibc --disable-werror"
;;
arm)
target=arm-linux-uclibcgnueabi
linux_arch=arm
extra_binutils_configure_opts="--disable-werror"
;;
x86)
target=i586-linux-uclibc
linux_arch=x86
extra_gcc_configure_opts="$extra_gcc_configure_opts --with-arch=i586 --disable-libquadmath"
;;
x86_64)
target=x86_64-linux-uclibc
linux_arch=x86
extra_gcc_configure_opts="$extra_gcc_configure_opts --disable-libquadmath --disable-multilib"
;;
mips|mipsel|mips64)
target=$arch-linux-uclibc
linux_arch=mips
extra_binutils_configure_opts="--disable-werror"
;;
mpc)
target=powerpc-linux-uclibcspe
linux_arch=powerpc
extra_binutils_configure_opts="--disable-werror"
;;
sh3|sh4|sh64)
target=$arch-linux-uclibc
linux_arch=sh
;;
*)
echo "Specify one of {arm x86 x86_64 ppc mpc mips mips64 sh3 sh4 sh64} architecture to build."
exit 1
;;
esac
top=$top/$target
obj=$top/obj
tools=$top/tools
sysroot=$top/sysroot
if [ "$defconfig" == "" ]; then
defconfig=$defconfig_dir/config.$threadv.$arch
fi
check_return () {
if [ $? -ne 0 ]
then
echo "Something went wrong in $1. Please check"
echo "exiting .... "
exit
fi
}
download () {
mkdir -p $src
local currdir=$PWD
cd $src
rm -rf *
wget -q http://www.kernel.org/pub/linux/kernel/v2.6/linux-$linuxv.tar.bz2
tar -xjf linux-$linuxv.tar.bz2
wget -q ftp://mirrors.kernel.org/sources.redhat.com/gcc/snapshots/LATEST-$gccv/gcc-[0-9]*.tar.bz2
gccv=`ls gcc-*.tar.bz2`
gccv=${gccv:4:12}
tar -xjf gcc-$gccv.tar.bz2
wget -q ftp://mirrors.kernel.org/sources.redhat.com/binutils/snapshots/binutils-$binutilsv.tar.bz2
tar -xjf binutils-$binutilsv.tar.bz2
# svn co -q svn://svn.eglibc.org/trunk eglibc
# cd $libcv/libc
# ln -s ../ports .
# popd
cp -a ~/work/$libcv .
cd $libcv/libc
ln -s ../ports
# do not generate configure scripts. You dont know if your
# autoconf version is right or not.
find . -name configure -exec touch '{}' ';'
cd $currdir
}
#if [ $download_src = "yes" ]; then
#download
#else
#gccv=`ls $src/gcc-*.tar.bz2|xargs basename`
#gccv=${gccv:4:12}
#fi
#rm -rf $top/*
echo "Doing Binutils ..."
mkdir -p $obj/binutils
cd $obj/binutils
if [ ! -e .configured ]; then
$src/$binutilsv/configure \
--target=$target \
--prefix=$tools \
--with-sysroot=$sysroot \
$extra_binutils_configure_opts \
&& touch .configured
# --enable-targets=all
fi
if [ ! -e .compiled ]; then
make -j $parallelism all-binutils all-ld all-gas && touch .compiled
check_return "binutils compile"
fi
if [ ! -e .installed ]; then
make -j $parallelism install-ld install-gas install-binutils && touch .installed
check_return "binutils install"
fi
echo "Doing GCC phase 1 ..."
mkdir -p $obj/gcc1
cd $obj/gcc1
if [ ! -e .configured ]; then
$src/$gccv/configure \
--target=$target \
--prefix=$tools \
--without-headers --with-newlib \
--disable-shared --disable-threads --disable-libssp \
--disable-libgomp --disable-libmudflap --disable-libquadmath \
--enable-languages=c $extra_gcc_configure_opts \
&& touch .configured
fi
if [ ! -e .compiled ]; then
PATH=$tools/bin:$PATH make -j $parallelism all-gcc && touch .compiled
check_return "gcc1 compile"
fi
if [ ! -e .installed ]; then
PATH=$tools/bin:$PATH make -j $parallelism install-gcc && touch .installed
check_return "gcc1 install"
fi
echo "Doing kernel headers ..."
#cp -r $src/$linuxv $obj/linux
mkdir -p $obj/linux
cd $src/$linuxv
if [ ! -e $obj/linux/.installed ]; then
PATH=$tools/bin:$PATH \
make -j $parallelism headers_install \
ARCH=$linux_arch CROSS_COMPILE=$target- \
INSTALL_HDR_PATH=$sysroot/usr \
O=$obj/linux \
&& touch $obj/linux/.installed
check_return "linux kernel headers install"
fi
echo "Doing uclibc headers ..."
mkdir -p $obj/uclibc-headers
cd $src/$libcv
if [ ! -e $obj/uclibc-headers/.configured ]; then
PATH=$tools/bin:$PATH make CROSS=$target- PREFIX=$sysroot \
O=$obj/uclibc-headers allnoconfig \
KCONFIG_ALLCONFIG=$defconfig \
&& touch $obj/uclibc-headers/.configured
check_return "uclibc oldconfig"
# replace the sysroot/usr/include into KERNEL_HEADERS in .config
kern_headers=$sysroot/usr/include
sed -e "s,^KERNEL_HEADERS=.*,KERNEL_HEADERS=\"$kern_headers\"," < $obj/uclibc-headers/.config >$obj/uclibc-headers/.config.tmp
mv $obj/uclibc-headers/.config.tmp $obj/uclibc-headers/.config
fi
if [ ! -e $obj/uclibc-headers/.installed ]; then
PATH=$tools/bin:$PATH make CROSS=$target- PREFIX=$sysroot \
O=$obj/uclibc-headers install_headers install_startfiles \
&& touch $obj/uclibc-headers/.installed
check_return "uclibc install_headers"
mkdir -p $sysroot/usr/lib
$tools/bin/$target-gcc -nostdlib -nostartfiles -shared -x c /dev/null \
-o $sysroot/usr/lib/libc.so
fi
echo "Doing GCC phase 2 ..."
# --disable-decimal-float
mkdir -p $obj/gcc2
cd $obj/gcc2
if [ ! -e .configured ]; then
$src/$gccv/configure \
--target=$target \
--prefix=$tools \
--with-sysroot=$sysroot \
--disable-libssp --disable-libgomp \
--disable-libmudflap --disable-libquadmath \
--enable-languages=c $extra_gcc_configure_opts \
&& touch .configured
fi
if [ ! -e .compiled ]; then
PATH=$tools/bin:$PATH make -j $parallelism && touch .compiled
check_return "gcc2 compile"
fi
if [ ! -e .installed ]; then
PATH=$tools/bin:$PATH make -j $parallelism install && touch .installed
check_return "gcc2 install"
fi
echo "Doing uclibc ..."
mkdir -p $obj/uclibc
cd $src/$libcv
#(cd $obj; ln -sf $src/$libcv uclibc)
#cp -a $src/$libcv/* $obj/uclibc/
#cd $obj/uclibc
if [ ! -e $obj/uclibc/.configured ]; then
PATH=$tools/bin:$PATH make CROSS=$target- PREFIX=$sysroot \
O=$obj/uclibc allnoconfig \
KCONFIG_ALLCONFIG=$defconfig \
&& touch $obj/uclibc/.configured
# replace the sysroot/usr/include into KERNEL_HEADERS in .config
kern_headers=$sysroot/usr/include
sed -e "s,^KERNEL_HEADERS=.*,KERNEL_HEADERS=\"$kern_headers\"," < $obj/uclibc/.config >$obj/uclibc/.config.tmp
mv $obj/uclibc/.config.tmp $obj/uclibc/.config
fi
if [ ! -e $obj/uclibc/.compiled ]; then
PATH=$tools/bin:$PATH make CROSS=$target- PREFIX=$sysroot \
STRIPTOOL=true O=$obj/uclibc all \
&& touch $obj/uclibc/.compiled
check_return "uclibc compile"
fi
if [ ! -e $obj/uclibc/.installed ]; then
PATH=$tools/bin:$PATH make CROSS=$target- PREFIX=$sysroot \
STRIPTOOL=true O=$obj/uclibc install \
&& touch $obj/uclibc/.installed
check_return "uclibc install"
fi
echo "Doing GCC phase 3 ..."
mkdir -p $obj/gcc3
cd $obj/gcc3
if [ ! -e .configured ]; then
$src/$gccv/configure \
--target=$target \
--prefix=$tools \
--with-sysroot=$sysroot \
--enable-__cxa_atexit \
--disable-libssp --disable-libgomp --disable-libmudflap \
--enable-languages=c,c++ $extra_gcc_configure_opts \
&& touch .configured
fi
if [ ! -e .compiled ]; then
PATH=$tools/bin:$PATH make -j $parallelism && touch .compiled
fi
if [ ! -e .installed ]; then
check_return "gcc3 compile"
PATH=$tools/bin:$PATH make -j $parallelism install && touch .installed
check_return "gcc3 install"
case $arch in
ppc64)
cp -d $tools/$target/lib64/libgcc_s.so* $sysroot/lib64
cp -d $tools/$target/lib64/libstdc++.so* $sysroot/usr/lib64
cp -d $tools/$target/lib/libgcc_s.so* $sysroot/lib
cp -d $tools/$target/lib/libstdc++.so* $sysroot/usr/lib
;;
x86_64)
# cp -d $tools/$target/lib/libgcc_s.so* $sysroot/lib
# cp -d $tools/$target/lib/libstdc++.so* $sysroot/usr/lib
cp -d $tools/$target/lib64/libgcc_s.so* $sysroot/lib64
cp -d $tools/$target/lib64/libstdc++.so* $sysroot/usr/lib64
;;
mips64)
cp -d $tools/$target/lib64/libgcc_s.so* $sysroot/lib64
cp -d $tools/$target/lib64/libgcc_s.so* $sysroot/lib64
cp -d $tools/$target/lib32/libstdc++.so* $sysroot/usr/lib32
cp -d $tools/$target/lib32/libstdc++.so* $sysroot/usr/lib32
cp -d $tools/$target/lib/libgcc_s.so* $sysroot/lib
cp -d $tools/$target/lib/libstdc++.so* $sysroot/usr/lib
;;
*)
cp -d $tools/$target/lib/libgcc_s.so* $sysroot/lib
cp -d $tools/$target/lib/libstdc++.so* $sysroot/usr/lib
;;
esac
fi
echo "!!! All Done !!!"