Change the manual tabe colours so that we have a darker blue for the header, then...
[kugel-rb.git] / tools / rockboxdev.sh
blob3257d524ec63fef21c66383668585f0084347dc2
1 #!/bin/sh
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
6 # it stopped
7 set -e
9 # this is where this script will store downloaded files and check for already
10 # downloaded files
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
16 # exists.
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
27 make="gmake"
28 else
29 make="make"
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:
37 # make="make"
39 ##############################################################################
42 # These are the tools this script requires and depends upon.
43 reqtools="gcc bzip2 make patch"
46 findtool(){
47 file="$1"
49 IFS=":"
50 for path in $PATH
52 # echo "Checks for $file in $path" >&2
53 if test -f "$path/$file"; then
54 echo "$path/$file"
55 return
57 done
60 input() {
61 read response
62 echo $response
65 #$1 file
66 #$2 URL"root
67 getfile() {
68 tool=`findtool curl`
69 if test -z "$tool"; then
70 tool=`findtool wget`
71 if test -n "$tool"; then
72 # wget download
73 echo "ROCKBOXDEV: Downloading $2/$1 using wget"
74 $tool -O $dlwhere/$1 $2/$1
76 else
77 # curl download
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"
85 exit
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"
91 exit
95 for t in $reqtools; do
96 tool=`findtool $t`
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."
100 exit
102 done
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"
109 exit
111 else
112 mkdir $dlwhere
113 if test $? -ne 0; then
114 echo "$dlwhere is missing and we failed to create it!"
115 exit
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"
130 exit
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"
135 exit
140 cleardir () {
141 # $1 is the name of the build dir
142 # $2 is the arch
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
148 buildone () {
150 arch=$1
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
157 system=`uname -s`
158 gccurl="http://www.rockbox.org/gcc"
160 case $arch in
161 [Ss])
162 target="sh-elf"
163 gccpatch="gcc-4.0.3-rockbox-1.diff"
165 [Mm])
166 target="m68k-elf"
167 gccver="3.4.6"
168 case $system in
169 CYGWIN* | Darwin | FreeBSD | Interix)
170 gccpatch="gcc-3.4.6.patch"
172 Linux)
173 machine=`uname -m`
174 case $machine in
175 x86_64)
176 gccpatch="gcc-3.4.6-amd64.patch"
178 esac
182 esac
184 [Aa])
185 target="arm-elf"
186 gccpatch="rockbox-multilibs-arm-elf-gcc-4.0.3_3.diff"
188 [Ii])
189 target="mipsel-elf"
190 gccver="4.1.2"
191 binutils="2.17"
192 gccconfigure="--disable-libssp"
193 binutilsconf="--disable-werror"
194 # necessary to make binutils build on gcc 4.3+
195 case $system in
196 Interix)
197 gccpatch="gcc-4.1.2-interix.diff"
201 esac
204 echo "An unsupported architecture option: $arch"
205 exit
207 esac
209 bindir="$prefix/$target/bin"
210 if test -n $pathadd; then
211 pathadd="$pathadd:$bindir"
212 else
213 pathadd="$bindir"
216 echo ""
217 echo "In case you encounter a slow internet connection, you can use an alternative mirror."
218 echo "A list of other GNU mirrors is available here: http://www.gnu.org/prep/ftp.html"
219 echo ""
220 echo "Usage: GNU_MIRROR=[URL] ./rockboxdev.sh"
221 echo ""
222 echo "Example:"
223 echo "$ GNU_MIRROR=http://mirrors.kernel.org/gnu ./rockboxdev.sh"
224 echo ""
226 if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then
227 echo "binutils $binutils already downloaded"
228 else
229 getfile binutils-$binutils.tar.bz2 $GNU_MIRROR/binutils
232 if test -f "$dlwhere/gcc-core-$gccver.tar.bz2"; then
233 echo "gcc $gccver already downloaded"
234 else
235 getfile gcc-core-$gccver.tar.bz2 $GNU_MIRROR/gcc/gcc-$gccver
238 if test -n "$gccpatch"; then
239 if test -f "$dlwhere/$gccpatch"; then
240 echo "$gccpatch already downloaded"
241 else
242 getfile "$gccpatch" "$gccurl"
246 ###########################################################################
247 # If there's already a build dir, we don't overwrite or delete it
248 if test -d $builddir; then
249 if test ! -w $builddir; then
250 echo "ERROR: No write permissions for the build directory!"
251 exit
253 else
254 mkdir -p $builddir
257 cd $builddir
259 ###########################################################################
260 # Create a summary file for each toolchain, containing info about the version
261 # and a remainder to append the compiler path to PATH
263 summary="summary-$1"
265 echo "============================ Summary ============================" > $summary
266 echo "target: $target" >> $summary
267 echo "gcc version: $gccver" >> $summary
268 if test -n "$gccpatch"; then
269 echo "gcc patch: $gccpatch" >> $summary
271 echo "binutils: $binutils" >> $summary
272 echo "installation target: $prefix/$target" >> $summary
273 echo "" >> $summary
274 echo "When done, append $bindir to PATH" >> $summary
275 echo "=================================================================" >> $summary
277 cat $summary
279 echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir"
280 tar xjf $dlwhere/binutils-$binutils.tar.bz2
281 echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir"
282 tar xjf $dlwhere/gcc-core-$gccver.tar.bz2
284 if test -n "$gccpatch"; then
285 echo "ROCKBOXDEV: applying gcc patch"
286 patch -p0 < "$dlwhere/$gccpatch"
289 echo "ROCKBOXDEV: mkdir build-binu-$1"
290 mkdir build-binu-$1
291 echo "ROCKBOXDEV: cd build-binu-$1"
292 cd build-binu-$1
293 echo "ROCKBOXDEV: binutils/configure"
294 # we undefine _FORTIFY_SOURCE to make the binutils built run fine on recent
295 # Ubuntu installations
296 CFLAGS=-U_FORTIFY_SOURCE ../binutils-$binutils/configure --target=$target --prefix=$prefix/$target $binutilsconf
297 echo "ROCKBOXDEV: binutils/make"
298 # We add -r when building binutils to fix compilation on OSX - Apple's make has
299 # extra built-ins which cause problems.
300 $make -r
301 echo "ROCKBOXDEV: binutils/make install to $prefix/$target"
302 $make install
303 cd .. # get out of build-binu-$1
304 PATH="$bindir:${PATH}"
305 SHELL=/bin/sh # seems to be needed by the gcc build in some cases
307 echo "ROCKBOXDEV: mkdir build-gcc-$1"
308 mkdir build-gcc-$1
309 echo "ROCKBOXDEV: cd build-gcc-$1"
310 cd build-gcc-$1
311 echo "ROCKBOXDEV: gcc/configure"
312 # we undefine _FORTIFY_SOURCE to make the gcc build go through fine on
313 # recent Ubuntu installations
314 CFLAGS=-U_FORTIFY_SOURCE ../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c $gccconfigure
315 echo "ROCKBOXDEV: gcc/make"
316 $make
317 echo "ROCKBOXDEV: gcc/make install to $prefix/$target"
318 $make install
319 cd .. # get out of build-gcc
320 cd .. # get out of $builddir
322 } # buildone()
324 echo ""
325 echo "Select target arch:"
326 echo "s - sh (Archos models)"
327 echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)"
328 echo "a - arm (ipods, iriver H10, Sansa, etc)"
329 echo "i - mips (Jz4740 and ATJ-based players)"
330 echo "separate multiple targets with spaces"
331 echo "(Example: \"s m a\" will build sh, m86k and arm)"
332 echo ""
334 selarch=`input`
336 for arch in $selarch
338 echo ""
339 case $arch in
340 [Ss])
341 buildone $arch
342 cleardir $builddir $arch
344 [Ii])
345 buildone $arch
346 cleardir $builddir $arch
348 [Mm])
349 buildone $arch
350 cleardir $builddir $arch
352 [Aa])
353 buildone $arch
354 cleardir $builddir $arch
357 echo "An unsupported architecture option: $arch"
358 exit
360 esac
361 done
363 # show the summaries:
364 cat $builddir/summary-*
365 rm $builddir/summary-*
367 echo ""
368 echo "Done!"
369 echo ""
370 echo "Make your PATH include $pathadd"
371 echo ""