2006-05-15 13:26:59 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2008-10-29 16:02:06 +00:00
|
|
|
# Abort execution as soon as an error is encountered
|
|
|
|
# That way the script do not let the user think the process completed correctly
|
|
|
|
# and leave the opportunity to fix the problem and restart compilation where
|
|
|
|
# it stopped
|
|
|
|
set -e
|
|
|
|
|
2006-05-15 13:26:59 +00:00
|
|
|
# this is where this script will store downloaded files and check for already
|
|
|
|
# downloaded files
|
2009-01-08 20:00:10 +00:00
|
|
|
dlwhere="${RBDEV_DOWNLOAD:-/tmp/rbdev-dl}"
|
2006-05-15 13:26:59 +00:00
|
|
|
|
|
|
|
# will append the target string to the prefix dir mentioned here
|
|
|
|
# Note that the user running this script must be able to do make install in
|
|
|
|
# this given prefix directory. Also make sure that this given root dir
|
|
|
|
# exists.
|
2009-01-08 20:00:10 +00:00
|
|
|
prefix="${RBDEV_PREFIX:-/usr/local}"
|
2006-05-15 13:26:59 +00:00
|
|
|
|
2006-05-30 08:38:02 +00:00
|
|
|
# This directory is used to extract all files and to build everything in. It
|
|
|
|
# must not exist before this script is invoked (as a security measure).
|
2009-01-08 20:00:10 +00:00
|
|
|
builddir="${RBDEV_BUILD:-/tmp/rbdev-build}"
|
2006-05-15 13:26:59 +00:00
|
|
|
|
2006-11-22 09:07:45 +00:00
|
|
|
# This script needs to use GNU Make. On Linux systems, GNU Make is invoked
|
|
|
|
# by running the "make" command, on most BSD systems, GNU Make is invoked
|
|
|
|
# by running the "gmake" command. Set the "make" variable accordingly.
|
2008-12-01 13:24:33 +00:00
|
|
|
if [ -f "`which gmake 2>/dev/null`" ]; then
|
2006-11-22 09:07:45 +00:00
|
|
|
make="gmake"
|
|
|
|
else
|
|
|
|
make="make"
|
|
|
|
fi
|
|
|
|
|
2008-07-30 15:46:13 +00:00
|
|
|
if [ -z $GNU_MIRROR ] ; then
|
|
|
|
GNU_MIRROR=ftp://ftp.gnu.org/pub/gnu
|
|
|
|
fi
|
|
|
|
|
2006-11-22 09:07:45 +00:00
|
|
|
# If detection fails, override the value of make manually:
|
|
|
|
# make="make"
|
|
|
|
|
2006-05-15 13:26:59 +00:00
|
|
|
##############################################################################
|
|
|
|
|
2007-05-24 19:58:17 +00:00
|
|
|
#
|
|
|
|
# These are the tools this script requires and depends upon.
|
|
|
|
reqtools="gcc bzip2 make patch"
|
|
|
|
|
2006-11-22 09:07:45 +00:00
|
|
|
|
2006-05-15 13:26:59 +00:00
|
|
|
findtool(){
|
|
|
|
file="$1"
|
|
|
|
|
|
|
|
IFS=":"
|
|
|
|
for path in $PATH
|
|
|
|
do
|
2008-08-01 11:19:29 +00:00
|
|
|
# echo "Checks for $file in $path" >&2
|
2006-05-15 13:26:59 +00:00
|
|
|
if test -f "$path/$file"; then
|
|
|
|
echo "$path/$file"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
input() {
|
|
|
|
read response
|
|
|
|
echo $response
|
|
|
|
}
|
|
|
|
|
|
|
|
#$1 file
|
|
|
|
#$2 URL"root
|
|
|
|
getfile() {
|
|
|
|
tool=`findtool curl`
|
|
|
|
if test -z "$tool"; then
|
|
|
|
tool=`findtool wget`
|
|
|
|
if test -n "$tool"; then
|
|
|
|
# wget download
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "ROCKBOXDEV: Downloading $2/$1 using wget"
|
2006-05-15 13:26:59 +00:00
|
|
|
$tool -O $dlwhere/$1 $2/$1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
# curl download
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "ROCKBOXDEV: Downloading $2/$1 using curl"
|
2006-05-15 13:26:59 +00:00
|
|
|
$tool -Lo $dlwhere/$1 $2/$1
|
|
|
|
fi
|
2008-08-01 11:19:29 +00:00
|
|
|
|
2008-08-10 14:36:18 +00:00
|
|
|
if [ $? -ne 0 ] ; then
|
|
|
|
echo "ROCKBOXDEV: couldn't download the file!"
|
|
|
|
echo "ROCKBOXDEV: check your internet connection"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2006-05-15 13:26:59 +00:00
|
|
|
if test -z "$tool"; then
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "ROCKBOXDEV: No downloader tool found!"
|
|
|
|
echo "ROCKBOXDEV: Please install curl or wget and re-run the script"
|
2006-05-15 13:26:59 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2007-05-24 19:58:17 +00:00
|
|
|
for t in $reqtools; do
|
|
|
|
tool=`findtool $t`
|
|
|
|
if test -z "$tool"; then
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "ROCKBOXDEV: $t is required for this script to work."
|
|
|
|
echo "ROCKBOXDEV: Please install $t and re-run the script."
|
2007-05-24 19:58:17 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2006-05-29 22:23:00 +00:00
|
|
|
###########################################################################
|
|
|
|
# Verify download directory or create it
|
|
|
|
if test -d "$dlwhere"; then
|
|
|
|
if ! test -w "$dlwhere"; then
|
|
|
|
echo "$dlwhere exists, but doesn't seem to be writable for you"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
mkdir $dlwhere
|
|
|
|
if test $? -ne 0; then
|
|
|
|
echo "$dlwhere is missing and we failed to create it!"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
echo "$dlwhere has been created to store downloads in"
|
|
|
|
fi
|
|
|
|
|
2009-01-08 20:00:10 +00:00
|
|
|
echo "Download directory: $dlwhere (set RBDEV_DOWNLOAD to change dir)"
|
|
|
|
echo "Install prefix: $prefix/[target] (set RBDEV_PREFIX to change dir)"
|
|
|
|
echo "Build dir: $builddir (set RBDEV_BUILD to change dir)"
|
2006-05-29 22:23:00 +00:00
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# Verify that we can write in the prefix dir, as otherwise we will hardly
|
|
|
|
# be able to install there!
|
|
|
|
if test ! -w $prefix; then
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "WARNING: This script is set to install in $prefix but has no write permissions for it"
|
|
|
|
echo "Please fix this and re-run this script"
|
2006-09-26 21:17:23 +00:00
|
|
|
exit
|
2006-05-29 22:23:00 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
###########################################################################
|
|
|
|
# If there's already a build dir, we don't overwrite it
|
2006-05-30 08:38:02 +00:00
|
|
|
if test -d $builddir; then
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "You already have a $builddir directory!"
|
|
|
|
echo "Please remove it and re-run the script"
|
2006-05-29 22:23:00 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2006-05-30 08:38:02 +00:00
|
|
|
cleardir () {
|
|
|
|
# $1 is the name of the build dir
|
|
|
|
# delete the build dirs and the source dirs
|
|
|
|
rm -rf $1/build-gcc $1/build-binu $1/gcc* $1/binutils*
|
|
|
|
}
|
2006-05-15 13:26:59 +00:00
|
|
|
|
2006-05-30 08:38:02 +00:00
|
|
|
buildone () {
|
2006-05-15 13:26:59 +00:00
|
|
|
|
2008-08-01 11:19:29 +00:00
|
|
|
arch=$1
|
2006-05-30 08:38:02 +00:00
|
|
|
gccpatch="" # default is no gcc patch
|
|
|
|
gccver="4.0.3" # default gcc version
|
|
|
|
binutils="2.16.1" # The binutils version to use
|
2008-07-17 10:24:41 +00:00
|
|
|
gccconfigure="" #default is nothing added to configure
|
2008-10-11 10:16:50 +00:00
|
|
|
binutilsconf="" #default is nothing added to configure
|
2006-05-30 08:38:02 +00:00
|
|
|
|
2006-08-13 18:27:31 +00:00
|
|
|
system=`uname -s`
|
2007-10-19 07:33:39 +00:00
|
|
|
gccurl="http://www.rockbox.org/gcc"
|
2006-08-13 18:27:31 +00:00
|
|
|
|
2008-08-01 11:19:29 +00:00
|
|
|
case $arch in
|
2006-05-15 13:26:59 +00:00
|
|
|
[Ss])
|
|
|
|
target="sh-elf"
|
2006-05-25 23:44:51 +00:00
|
|
|
gccpatch="gcc-4.0.3-rockbox-1.diff"
|
2006-05-15 13:26:59 +00:00
|
|
|
;;
|
|
|
|
[Mm])
|
|
|
|
target="m68k-elf"
|
|
|
|
gccver="3.4.6"
|
2006-08-13 18:27:31 +00:00
|
|
|
case $system in
|
2008-09-28 21:48:33 +00:00
|
|
|
CYGWIN* | Darwin | FreeBSD | Interix)
|
2006-08-13 18:27:31 +00:00
|
|
|
gccpatch="gcc-3.4.6.patch"
|
|
|
|
;;
|
|
|
|
Linux)
|
2007-06-29 11:35:35 +00:00
|
|
|
machine=`uname -m`
|
|
|
|
case $machine in
|
|
|
|
x86_64)
|
|
|
|
gccpatch="gcc-3.4.6-amd64.patch"
|
|
|
|
;;
|
|
|
|
esac
|
2006-08-13 18:27:31 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
2006-05-15 13:26:59 +00:00
|
|
|
;;
|
|
|
|
[Aa])
|
|
|
|
target="arm-elf"
|
2008-04-28 15:37:06 +00:00
|
|
|
gccpatch="rockbox-multilibs-arm-elf-gcc-4.0.3_2.diff"
|
2006-05-15 13:26:59 +00:00
|
|
|
;;
|
2008-07-08 07:13:05 +00:00
|
|
|
[Ii])
|
|
|
|
target="mipsel-elf"
|
2008-07-14 15:03:10 +00:00
|
|
|
gccver="4.1.2"
|
|
|
|
binutils="2.17"
|
2008-07-17 10:24:41 +00:00
|
|
|
gccconfigure="--disable-libssp"
|
2008-10-11 10:16:50 +00:00
|
|
|
binutilsconf="--disable-werror"
|
|
|
|
# necessary to make binutils build on gcc 4.3+
|
2008-09-29 20:31:31 +00:00
|
|
|
case $system in
|
|
|
|
Interix)
|
|
|
|
gccpatch="gcc-4.1.2-interix.diff"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
2008-07-08 07:13:05 +00:00
|
|
|
;;
|
2006-05-15 13:26:59 +00:00
|
|
|
*)
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "An unsupported architecture option: $arch"
|
2006-05-15 13:26:59 +00:00
|
|
|
exit
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
bindir="$prefix/$target/bin"
|
2006-05-30 08:38:02 +00:00
|
|
|
if test -n $pathadd; then
|
|
|
|
pathadd="$pathadd:$bindir"
|
|
|
|
else
|
|
|
|
pathadd="$bindir"
|
2006-05-25 23:44:51 +00:00
|
|
|
fi
|
2006-05-15 13:26:59 +00:00
|
|
|
|
2008-09-07 22:01:29 +00:00
|
|
|
mkdir -p $builddir
|
2006-05-30 08:38:02 +00:00
|
|
|
cd $builddir
|
2006-05-29 22:23:00 +00:00
|
|
|
|
2006-05-30 08:38:02 +00:00
|
|
|
summary="summary-$1"
|
|
|
|
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "============================ Summary ============================" > $summary
|
|
|
|
echo "target: $target" >> $summary
|
|
|
|
echo "gcc version: $gccver" >> $summary
|
2006-05-30 08:38:02 +00:00
|
|
|
if test -n "$gccpatch"; then
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "gcc patch: $gccpatch" >> $summary
|
2006-05-30 08:38:02 +00:00
|
|
|
fi
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "binutils: $binutils" >> $summary
|
|
|
|
echo "installation target: $prefix/$target" >> $summary
|
|
|
|
echo "" >> $summary
|
|
|
|
echo "When done, append $bindir to PATH" >> $summary
|
|
|
|
echo "=================================================================" >> $summary
|
2006-05-30 08:38:02 +00:00
|
|
|
|
|
|
|
cat $summary
|
2006-05-15 13:26:59 +00:00
|
|
|
|
2008-08-01 11:19:29 +00:00
|
|
|
echo ""
|
|
|
|
echo "In case you encounter a slow internet connection, you can use an alternative mirror."
|
|
|
|
echo "A list of other GNU mirrors is available here: http://www.gnu.org/prep/ftp.html"
|
|
|
|
echo ""
|
|
|
|
echo "Usage: GNU_MIRROR=[URL] ./rockboxdev.sh"
|
|
|
|
echo ""
|
|
|
|
echo "Example:"
|
|
|
|
echo "$ GNU_MIRROR=http://mirrors.kernel.org/gnu ./rockboxdev.sh"
|
|
|
|
echo ""
|
|
|
|
|
2006-05-15 13:26:59 +00:00
|
|
|
if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then
|
|
|
|
echo "binutils $binutils already downloaded"
|
|
|
|
else
|
2008-07-30 15:46:13 +00:00
|
|
|
getfile binutils-$binutils.tar.bz2 $GNU_MIRROR/binutils
|
2006-05-15 13:26:59 +00:00
|
|
|
fi
|
|
|
|
|
2007-02-26 16:10:53 +00:00
|
|
|
if test -f "$dlwhere/gcc-core-$gccver.tar.bz2"; then
|
2006-05-15 13:26:59 +00:00
|
|
|
echo "gcc $gccver already downloaded"
|
|
|
|
else
|
2008-07-30 15:46:13 +00:00
|
|
|
getfile gcc-core-$gccver.tar.bz2 $GNU_MIRROR/gcc/gcc-$gccver
|
2006-05-15 13:26:59 +00:00
|
|
|
fi
|
|
|
|
|
2006-05-25 23:44:51 +00:00
|
|
|
if test -n "$gccpatch"; then
|
|
|
|
if test -f "$dlwhere/$gccpatch"; then
|
|
|
|
echo "$gccpatch already downloaded"
|
|
|
|
else
|
|
|
|
getfile "$gccpatch" "$gccurl"
|
|
|
|
fi
|
|
|
|
fi
|
2006-05-15 13:26:59 +00:00
|
|
|
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir"
|
2006-05-15 13:26:59 +00:00
|
|
|
tar xjf $dlwhere/binutils-$binutils.tar.bz2
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir"
|
2007-02-26 16:10:53 +00:00
|
|
|
tar xjf $dlwhere/gcc-core-$gccver.tar.bz2
|
2006-05-15 13:26:59 +00:00
|
|
|
|
2006-05-25 23:44:51 +00:00
|
|
|
if test -n "$gccpatch"; then
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: applying gcc patch"
|
2006-05-25 23:44:51 +00:00
|
|
|
patch -p0 < "$dlwhere/$gccpatch"
|
|
|
|
fi
|
|
|
|
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: mkdir build-binu"
|
2006-05-15 13:26:59 +00:00
|
|
|
mkdir build-binu
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: cd build-binu"
|
2006-05-15 13:26:59 +00:00
|
|
|
cd build-binu
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: binutils/configure"
|
2008-10-30 20:54:46 +00:00
|
|
|
# we undefine _FORTIFY_SOURCE to make the binutils built run fine on recent
|
|
|
|
# Ubuntu installations
|
|
|
|
CFLAGS=-U_FORTIFY_SOURCE ../binutils-$binutils/configure --target=$target --prefix=$prefix/$target $binutilsconf
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: binutils/make"
|
2006-11-22 09:07:45 +00:00
|
|
|
$make
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: binutils/make install to $prefix/$target"
|
2006-11-22 09:07:45 +00:00
|
|
|
$make install
|
2006-05-30 08:38:02 +00:00
|
|
|
cd .. # get out of build-binu
|
2006-05-15 13:26:59 +00:00
|
|
|
PATH="${PATH}:$bindir"
|
|
|
|
SHELL=/bin/sh # seems to be needed by the gcc build in some cases
|
|
|
|
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: mkdir build-gcc"
|
2006-05-15 13:26:59 +00:00
|
|
|
mkdir build-gcc
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: cd build-gcc"
|
2006-05-15 13:26:59 +00:00
|
|
|
cd build-gcc
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: gcc/configure"
|
2008-10-29 08:32:34 +00:00
|
|
|
# we undefine _FORTIFY_SOURCE to make the gcc build go through fine on
|
|
|
|
# recent Ubuntu installations
|
2008-10-30 20:54:46 +00:00
|
|
|
CFLAGS=-U_FORTIFY_SOURCE ../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c $gccconfigure
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: gcc/make"
|
2006-11-22 09:07:45 +00:00
|
|
|
$make
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "ROCKBOXDEV: gcc/make install to $prefix/$target"
|
2006-11-22 09:07:45 +00:00
|
|
|
$make install
|
2006-05-30 08:38:02 +00:00
|
|
|
cd .. # get out of build-gcc
|
|
|
|
cd .. # get out of $builddir
|
|
|
|
|
|
|
|
# end of buildone() function
|
|
|
|
}
|
|
|
|
|
|
|
|
echo ""
|
|
|
|
echo "Select target arch:"
|
2006-08-10 06:46:56 +00:00
|
|
|
echo "s - sh (Archos models)"
|
|
|
|
echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)"
|
|
|
|
echo "a - arm (ipods, iriver H10, Sansa, etc)"
|
2008-08-02 11:20:20 +00:00
|
|
|
echo "i - mips (Jz4740 and ATJ-based players)"
|
2008-09-07 22:01:29 +00:00
|
|
|
echo "separate multiple targets with spaces"
|
|
|
|
echo "(i.e. \"s m a\" will build sh, m86k and arm)"
|
2008-08-01 11:19:29 +00:00
|
|
|
echo ""
|
2006-05-30 08:38:02 +00:00
|
|
|
|
2008-09-07 22:01:29 +00:00
|
|
|
selarch=`input`
|
2006-05-30 08:38:02 +00:00
|
|
|
|
2008-09-07 22:01:29 +00:00
|
|
|
for arch in $selarch
|
|
|
|
do
|
2008-08-01 11:19:29 +00:00
|
|
|
echo ""
|
2006-05-30 08:38:02 +00:00
|
|
|
case $arch in
|
|
|
|
[Ss])
|
|
|
|
buildone $arch
|
|
|
|
;;
|
2008-07-08 07:13:05 +00:00
|
|
|
[Ii])
|
|
|
|
buildone $arch
|
|
|
|
;;
|
2006-05-30 08:38:02 +00:00
|
|
|
[Mm])
|
|
|
|
buildone $arch
|
|
|
|
;;
|
|
|
|
[Aa])
|
|
|
|
buildone $arch
|
|
|
|
;;
|
|
|
|
*)
|
2008-08-01 11:19:29 +00:00
|
|
|
echo "An unsupported architecture option: $arch"
|
2006-05-30 08:38:02 +00:00
|
|
|
exit
|
|
|
|
;;
|
|
|
|
esac
|
2006-05-15 13:26:59 +00:00
|
|
|
|
2008-09-07 22:01:29 +00:00
|
|
|
echo "Cleaning up build folder"
|
|
|
|
cleardir $builddir
|
2008-08-01 11:19:29 +00:00
|
|
|
echo ""
|
|
|
|
echo "Done!"
|
2006-05-29 22:23:00 +00:00
|
|
|
echo ""
|
2006-05-30 08:38:02 +00:00
|
|
|
echo "Make your PATH include $pathadd"
|
2008-09-07 22:01:29 +00:00
|
|
|
|
|
|
|
done
|
|
|
|
|
|
|
|
# show the summaries:
|
|
|
|
cat $builddir/summary-*
|