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
=ftp://ftp.gnu.org
/pub
/gnu
36 # If detection fails, override the value of make manually:
39 ##############################################################################
42 # These are the tools this script requires and depends upon.
43 reqtools
="gcc bzip2 make patch"
52 # echo "Checks for $file in $path" >&2
53 if test -f "$path/$file"; then
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"
95 for t
in $reqtools; do
97 if test -z "$tool"; then
98 echo "ROCKBOXDEV: \"$t\" is required for this script to work."
99 echo "ROCKBOXDEV: Please install \"$t\" and re-run the script."
104 ###########################################################################
105 # Verify download directory or create it
106 if test -d "$dlwhere"; then
107 if ! test -w "$dlwhere"; then
108 echo "$dlwhere exists, but doesn't seem to be writable for you"
113 if test $?
-ne 0; then
114 echo "$dlwhere is missing and we failed to create it!"
117 echo "$dlwhere has been created to store downloads in"
120 echo "Download directory: $dlwhere (set RBDEV_DOWNLOAD to change dir)"
121 echo "Install prefix: $prefix/[target] (set RBDEV_PREFIX to change dir)"
122 echo "Build dir: $builddir (set RBDEV_BUILD to change dir)"
124 ###########################################################################
125 # Verify that the prefix dir exists and that we can write to it,
126 # as otherwise we will hardly be able to install there!
127 if test ! -d $prefix; then
128 echo "ERROR: The installation destination does not exist."
129 echo "Please create it and re-run this script"
132 if test ! -w $prefix; then
133 echo "ERROR: This script is set to install in $prefix but has no write permissions for it"
134 echo "Please fix this and re-run this script"
141 # $1 is the name of the build dir
143 # delete the build dirs and the source dirs
144 echo "Cleaning up build folder"
145 rm -rf $1/build-gcc-
$2 $1/build-binu-
$2
151 gccpatch
="" # default is no gcc patch
152 gccver
="4.0.3" # default gcc version
153 binutils
="2.16.1" # The binutils version to use
154 gccconfigure
="" #default is nothing added to configure
155 binutilsconf
="" #default is nothing added to configure
156 gcctarget
="" #default make target
157 gccinstalltarget
="install" #default install target
160 gccurl
="http://www.rockbox.org/gcc"
165 gccpatch
="gcc-4.0.3-rockbox-1.diff"
171 CYGWIN
* | Darwin | FreeBSD | Interix
)
172 gccpatch
="gcc-3.4.6.patch"
178 gccpatch
="gcc-3.4.6-amd64.patch"
188 gccpatch
="rockbox-multilibs-arm-elf-gcc-4.0.3_3.diff"
191 target
="arm-elf-eabi"
192 gccpatch
="rockbox-multilibs-noexceptions-arm-elf-eabi-gcc-4.4.2_1.diff"
193 binutilsconf
="--disable-werror"
195 # needed to build a bare-metal gcc-4.4.2
196 gcctarget
="all-gcc all-target-libgcc"
197 gccinstalltarget
="install-gcc install-target-libgcc"
204 gccconfigure
="--disable-libssp"
205 binutilsconf
="--disable-werror"
206 # necessary to make binutils build on gcc 4.3+
209 gccpatch
="gcc-4.1.2-interix.diff"
216 echo "An unsupported architecture option: $arch"
221 bindir
="$prefix/$target/bin"
222 if test -n $pathadd; then
223 pathadd
="$pathadd:$bindir"
229 echo "In case you encounter a slow internet connection, you can use an alternative mirror."
230 echo "A list of other GNU mirrors is available here: http://www.gnu.org/prep/ftp.html"
232 echo "Usage: GNU_MIRROR=[URL] ./rockboxdev.sh"
235 echo "$ GNU_MIRROR=http://mirrors.kernel.org/gnu ./rockboxdev.sh"
238 if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then
239 echo "binutils $binutils already downloaded"
241 getfile binutils-
$binutils.
tar.bz2
$GNU_MIRROR/binutils
244 if test -f "$dlwhere/gcc-core-$gccver.tar.bz2"; then
245 echo "gcc $gccver already downloaded"
247 getfile gcc-core-
$gccver.
tar.bz2
$GNU_MIRROR/gcc
/gcc-
$gccver
250 if test -n "$gccpatch"; then
251 if test -f "$dlwhere/$gccpatch"; then
252 echo "$gccpatch already downloaded"
254 getfile
"$gccpatch" "$gccurl"
258 ###########################################################################
259 # If there's already a build dir, we don't overwrite or delete it
260 if test -d $builddir; then
261 if test ! -w $builddir; then
262 echo "ERROR: No write permissions for the build directory!"
271 ###########################################################################
272 # Create a summary file for each toolchain, containing info about the version
273 # and a remainder to append the compiler path to PATH
277 echo "============================ Summary ============================" > $summary
278 echo "target: $target" >> $summary
279 echo "gcc version: $gccver" >> $summary
280 if test -n "$gccpatch"; then
281 echo "gcc patch: $gccpatch" >> $summary
283 echo "binutils: $binutils" >> $summary
284 echo "installation target: $prefix/$target" >> $summary
286 echo "When done, append $bindir to PATH" >> $summary
287 echo "=================================================================" >> $summary
291 echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir"
292 tar xjf
$dlwhere/binutils-
$binutils.
tar.bz2
293 echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir"
294 tar xjf
$dlwhere/gcc-core-
$gccver.
tar.bz2
296 if test -n "$gccpatch"; then
297 echo "ROCKBOXDEV: applying gcc patch"
298 patch -p0 < "$dlwhere/$gccpatch"
301 echo "ROCKBOXDEV: mkdir build-binu-$1"
303 echo "ROCKBOXDEV: cd build-binu-$1"
305 echo "ROCKBOXDEV: binutils/configure"
306 # we undefine _FORTIFY_SOURCE to make the binutils built run fine on recent
307 # Ubuntu installations
308 CFLAGS
=-U_FORTIFY_SOURCE ..
/binutils-
$binutils/configure
--target=$target --prefix=$prefix/$target $binutilsconf
309 echo "ROCKBOXDEV: binutils/make"
310 # We add -r when building binutils to fix compilation on OSX - Apple's make has
311 # extra built-ins which cause problems.
313 echo "ROCKBOXDEV: binutils/make install to $prefix/$target"
315 cd ..
# get out of build-binu-$1
316 PATH
="$bindir:${PATH}"
317 SHELL
=/bin
/sh
# seems to be needed by the gcc build in some cases
319 echo "ROCKBOXDEV: mkdir build-gcc-$1"
321 echo "ROCKBOXDEV: cd build-gcc-$1"
323 echo "ROCKBOXDEV: gcc/configure"
324 # we undefine _FORTIFY_SOURCE to make the gcc build go through fine on
325 # recent Ubuntu installations
326 CFLAGS
=-U_FORTIFY_SOURCE ..
/gcc-
$gccver/configure
--target=$target --prefix=$prefix/$target --enable-languages=c
$gccconfigure
327 echo "ROCKBOXDEV: gcc/make"
329 echo "ROCKBOXDEV: gcc/make install to $prefix/$target"
330 $make $gccinstalltarget
331 cd ..
# get out of build-gcc
332 cd ..
# get out of $builddir
337 echo "Select target arch:"
338 echo "s - sh (Archos models)"
339 echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)"
340 echo "a - arm (ipods, iriver H10, Sansa, etc)"
341 echo "e - arm-eabi (same as above, new testing toolchain)"
342 echo "i - mips (Jz4740 and ATJ-based players)"
343 echo "separate multiple targets with spaces"
344 echo "(Example: \"s m a\" will build sh, m86k and arm)"
355 cleardir
$builddir $arch
359 cleardir
$builddir $arch
363 cleardir
$builddir $arch
367 cleardir
$builddir $arch
371 cleardir
$builddir $arch
374 echo "An unsupported architecture option: $arch"
380 # show the summaries:
381 cat $builddir/summary-
*
382 rm $builddir/summary-
*
387 echo "Make your PATH include $pathadd"