3 # Abort execution as soon as an error is encountered
4 # That way the script do not let the user think the process completed correctly
5 # and leave the opportunity to fix the problem and restart compilation where
9 # this is where this script will store downloaded files and check for already
11 dlwhere
="${RBDEV_DOWNLOAD:-/tmp/rbdev-dl}"
13 # will append the target string to the prefix dir mentioned here
14 # Note that the user running this script must be able to do make install in
15 # this given prefix directory. Also make sure that this given root dir
17 prefix
="${RBDEV_PREFIX:-/usr/local}"
19 # This directory is used to extract all files and to build everything in. It
20 # must not exist before this script is invoked (as a security measure).
21 builddir
="${RBDEV_BUILD:-/tmp/rbdev-build}"
23 # This script needs to use GNU Make. On Linux systems, GNU Make is invoked
24 # by running the "make" command, on most BSD systems, GNU Make is invoked
25 # by running the "gmake" command. Set the "make" variable accordingly.
26 if [ -f "`which gmake 2>/dev/null`" ]; then
32 if [ -z $GNU_MIRROR ] ; then
33 GNU_MIRROR
=http
://www.nic.funet.fi
/pub
/gnu
/ftp.gnu.org
/pub
/gnu
36 # These are the tools this script requires and depends upon.
37 reqtools
="gcc bzip2 gzip make patch makeinfo"
39 ##############################################################################
48 # echo "Checks for $file in $path" >&2
49 if test -f "$path/$file"; then
64 if test -f $dlwhere/$1; then
65 echo "ROCKBOXDEV: Skipping download of $2/$1: File already exists"
69 if test -z "$tool"; then
71 if test -n "$tool"; then
73 echo "ROCKBOXDEV: Downloading $2/$1 using wget"
74 $tool -O $dlwhere/$1 $2/$1
78 echo "ROCKBOXDEV: Downloading $2/$1 using curl"
79 $tool -Lo $dlwhere/$1 $2/$1
82 if [ $?
-ne 0 ] ; then
83 echo "ROCKBOXDEV: couldn't download the file!"
84 echo "ROCKBOXDEV: check your internet connection"
88 if test -z "$tool"; then
89 echo "ROCKBOXDEV: No downloader tool found!"
90 echo "ROCKBOXDEV: Please install curl or wget and re-run the script"
101 configure_params
="$5"
104 patch_url
="http://www.rockbox.org/gcc"
108 file="gcc-core-$version.tar.bz2"
109 url
="$GNU_MIRROR/gcc/gcc-$version"
113 file="binutils-$version.tar.bz2"
114 url
="$GNU_MIRROR/binutils"
118 file="crosstool-ng-$version.tar.bz2"
119 url
="http://crosstool-ng.org/download/crosstool-ng"
122 echo "ROCKBOXDEV: Bad toolname $toolname"
127 # create build directory
128 if test -d $builddir; then
129 if test ! -w $builddir; then
130 echo "ROCKBOXDEV: No write permission for $builddir"
137 # download source tarball
138 if test ! -f "$dlwhere/$file"; then
139 getfile
"$file" "$url"
143 if test -n "$patch"; then
144 if test ! -f "$dlwhere/$patch"; then
145 getfile
"$patch" "$patch_url"
151 echo "ROCKBOXDEV: extracting $file"
152 tar xjf
$dlwhere/$file
154 # do we have a patch?
155 if test -n "$patch"; then
156 echo "ROCKBOXDEV: applying patch $patch"
159 (cd $builddir/$toolname-$version && patch -p1 < "$dlwhere/$patch")
161 # check if the patch applied cleanly
162 if [ $?
-gt 0 ]; then
163 echo "ROCKBOXDEV: failed to apply patch $patch"
168 # kludge to avoid having to install GMP, MPFR and MPC, for new gcc
169 if test -n "$needs_libs"; then
171 if (echo $needs_libs |
grep -q gmp
&& test ! -d gmp
); then
172 echo "ROCKBOXDEV: Getting GMP"
173 if test ! -f $dlwhere/gmp-4.3
.2.
tar.bz2
; then
174 getfile
"gmp-4.3.2.tar.bz2" "$GNU_MIRROR/gmp"
176 tar xjf
$dlwhere/gmp-4.3
.2.
tar.bz2
180 if (echo $needs_libs |
grep -q mpfr
&& test ! -d mpfr
); then
181 echo "ROCKBOXDEV: Getting MPFR"
182 if test ! -f $dlwhere/mpfr-2.4
.2.
tar.bz2
; then
183 getfile
"mpfr-2.4.2.tar.bz2" "$GNU_MIRROR/mpfr"
185 tar xjf
$dlwhere/mpfr-2.4
.2.
tar.bz2
186 ln -s mpfr-2.4
.2 mpfr
189 if (echo $needs_libs |
grep -q mpc
&& test ! -d mpc
); then
190 echo "ROCKBOXDEV: Getting MPC"
191 if test ! -f $dlwhere/mpc-0.8
.1.
tar.gz
; then
192 getfile
"mpc-0.8.1.tar.gz" "http://www.multiprecision.org/mpc/download"
194 tar xzf
$dlwhere/mpc-0.8
.1.
tar.gz
200 echo "ROCKBOXDEV: mkdir build-$toolname"
201 mkdir build-
$toolname
203 echo "ROCKBOXDEV: cd build-$toolname"
206 echo "ROCKBOXDEV: $toolname/configure"
208 ctng
) # ct-ng doesnt support out-of-tree build and the src folder is named differently
209 toolname
="crosstool-ng"
210 cp -r ..
/$toolname-$version/* ..
/$toolname-$version/.version .
211 .
/configure
--prefix=$prefix $configure_params
214 CFLAGS
=-U_FORTIFY_SOURCE ..
/$toolname-$version/configure
--target=$target --prefix=$prefix --enable-languages=c
--disable-libssp --disable-docs $configure_params
218 echo "ROCKBOXDEV: $toolname/make"
221 echo "ROCKBOXDEV: $toolname/make install"
224 echo "ROCKBOXDEV: rm -rf build-$toolname $toolname-$version"
226 rm -rf build-
$toolname $toolname-$version
231 if test -f "`which ct-ng 2>/dev/null`"; then
237 if test ! -n "$ctng"; then
238 if test ! -f "$prefix/bin/ct-ng"; then # look if we build it already
239 build
"ctng" "" "1.13.2"
242 ctng
=`PATH=$prefix/bin:$PATH which ct-ng`
253 dlurl
="http://www.rockbox.org/gcc/$ctng_target"
256 getfile
"ct-ng-config" "$dlurl"
258 test -n "$extra" && getfile
"$extra" "$dlurl"
260 # create build directory
261 if test -d $builddir; then
262 if test ! -w $builddir; then
263 echo "ROCKBOXDEV: No write permission for $builddir"
270 # copy config and cd to $builddir
271 mkdir
$builddir/build-
$ctng_target
272 ctng_config
="$builddir/build-$ctng_target/.config"
273 cat "$dlwhere/ct-ng-config" |
sed -e "s,\(CT_PREFIX_DIR=\).*,\1$prefix," > $ctng_config
274 cd $builddir/build-
$ctng_target
279 if test -e "$dlwhere/$extra"; then
280 # verify the toolchain has sysroot support
281 if test -n `cat $ctng_config | grep CT_USE_SYSROOT\=y`; then
282 sysroot
=`cat $ctng_config | grep CT_SYSROOT_NAME | sed -e 's,CT_SYSROOT_NAME\=\"\([a-zA-Z0-9]*\)\",\1,'`
283 tar xf
"$dlwhere/$extra" -C "$prefix/$tc_arch-$ctng_target-$tc_host/$sysroot"
289 rm -rf $builddir/build-
$ctng_target
292 ##############################################################################
295 # Verify required tools
296 for t
in $reqtools; do
298 if test -z "$tool"; then
299 echo "ROCKBOXDEV: \"$t\" is required for this script to work."
300 echo "ROCKBOXDEV: Please install \"$t\" and re-run the script."
305 echo "Download directory : $dlwhere (set RBDEV_DOWNLOAD to change)"
306 echo "Install prefix : $prefix (set RBDEV_PREFIX to change)"
307 echo "Build dir : $builddir (set RBDEV_BUILD to change)"
308 echo "Make options : $MAKEFLAGS (set MAKEFLAGS to change)"
311 # Verify download directory
312 if test -d "$dlwhere"; then
313 if ! test -w "$dlwhere"; then
314 echo "ROCKBOXDEV: No write permission for $dlwhere"
319 if test $?
-ne 0; then
320 echo "ROCKBOXDEV: Failed creating directory $dlwhere"
326 # Verify the prefix dir
327 if test ! -d $prefix; then
329 if test $?
-ne 0; then
330 echo "ROCKBOXDEV: Failed creating directory $prefix"
334 if test ! -w $prefix; then
335 echo "ROCKBOXDEV: No write permission for $prefix"
339 echo "Select target arch:"
340 echo "s - sh (Archos models)"
341 echo "m - m68k (iriver h1x0/h3x0, iaudio m3/m5/x5 and mpio hd200)"
342 echo "a - arm (ipods, iriver H10, Sansa, D2, Gigabeat, etc)"
343 echo "i - mips (Jz4740 and ATJ-based players)"
344 echo "r - arm-app (Samsung ypr0)"
345 echo "separate multiple targets with spaces"
346 echo "(Example: \"s m a\" will build sh, m68k and arm)"
352 # add target dir to path to ensure the new binutils are used in gcc build
353 PATH
="$prefix/bin:${PATH}"
360 # For binutils 2.16.1 builtin rules conflict on some systems with a
361 # default rule for Objective C. Disable the builtin make rules. See
362 # http://sourceware.org/ml/binutils/2005-12/msg00259.html
363 export MAKEFLAGS
="-r $MAKEFLAGS"
364 build
"binutils" "sh-elf" "2.16.1" "" "--disable-werror"
365 build
"gcc" "sh-elf" "4.0.3" "gcc-4.0.3-rockbox-1.diff"
369 build
"binutils" "mipsel-elf" "2.17" "" "--disable-werror"
371 if [ "$system" = "Interix" ]; then
372 patch="gcc-4.1.2-interix.diff"
374 build
"gcc" "mipsel-elf" "4.1.2" "$patch"
378 build
"binutils" "m68k-elf" "2.20.1" "" "--disable-werror"
379 build
"gcc" "m68k-elf" "4.5.2" "" "--with-arch=cf" "gmp mpfr mpc"
387 binopts
="--disable-nls"
388 gccopts
="--disable-nls"
391 build
"binutils" "arm-elf-eabi" "2.20.1" "binutils-2.20.1-ld-thumb-interwork-long-call.diff" "$binopts --disable-werror"
392 build
"gcc" "arm-elf-eabi" "4.4.4" "rockbox-multilibs-noexceptions-arm-elf-eabi-gcc-4.4.2_1.diff" "$gccopts" "gmp mpfr"
395 build_ctng
"ypr0" "alsalib.tar.gz" "arm" "linux-gnueabi"
398 echo "ROCKBOXDEV: Unsupported architecture option: $arch"
405 echo "ROCKBOXDEV: Done!"
407 echo "ROCKBOXDEV: Make sure your PATH includes $prefix/bin"