blob: 3e0d5ffbc59e9f788a40f4d11b51e7f3dbb01975 [file] [log] [blame]
Daniel Stenbergcce0d652006-05-15 13:26:59 +00001#!/bin/sh
2
3# this is where this script will store downloaded files and check for already
4# downloaded files
5dlwhere="$HOME/tmp"
6
7# will append the target string to the prefix dir mentioned here
8# Note that the user running this script must be able to do make install in
9# this given prefix directory. Also make sure that this given root dir
10# exists.
11prefix="/usr/local"
12
Daniel Stenberg2731afa2006-05-30 08:38:02 +000013# This directory is used to extract all files and to build everything in. It
14# must not exist before this script is invoked (as a security measure).
15builddir="$HOME/build-rbdev"
Daniel Stenbergcce0d652006-05-15 13:26:59 +000016
17##############################################################################
18
19findtool(){
20 file="$1"
21
22 IFS=":"
23 for path in $PATH
24 do
25 # echo "checks for $file in $path" >&2
26 if test -f "$path/$file"; then
27 echo "$path/$file"
28 return
29 fi
30 done
31}
32
33input() {
34 read response
35 echo $response
36}
37
38#$1 file
39#$2 URL"root
40getfile() {
41 tool=`findtool curl`
42 if test -z "$tool"; then
43 tool=`findtool wget`
44 if test -n "$tool"; then
45 # wget download
Daniel Stenberg19fe37d2006-08-10 06:46:56 +000046 echo "ROCKBOXDEV: downloads $2/$1 using wget"
Daniel Stenbergcce0d652006-05-15 13:26:59 +000047 $tool -O $dlwhere/$1 $2/$1
48 fi
49 else
50 # curl download
Daniel Stenberg19fe37d2006-08-10 06:46:56 +000051 echo "ROCKBOXDEV: downloads $2/$1 using curl"
Daniel Stenbergcce0d652006-05-15 13:26:59 +000052 $tool -Lo $dlwhere/$1 $2/$1
53 fi
54 if test -z "$tool"; then
Daniel Stenberg19fe37d2006-08-10 06:46:56 +000055 echo "ROCKBOXDEV: couldn't find downloader tool to use!"
Daniel Stenbergcce0d652006-05-15 13:26:59 +000056 exit
57 fi
58
59
60}
61
Daniel Stenberg9a3902f2006-05-29 22:23:00 +000062###########################################################################
63# Verify download directory or create it
64if test -d "$dlwhere"; then
65 if ! test -w "$dlwhere"; then
66 echo "$dlwhere exists, but doesn't seem to be writable for you"
67 exit
68 fi
69else
70 mkdir $dlwhere
71 if test $? -ne 0; then
72 echo "$dlwhere is missing and we failed to create it!"
73 exit
74 fi
75 echo "$dlwhere has been created to store downloads in"
76fi
77
78echo "Download directory: $dlwhere (edit script to change dir)"
79echo "Install prefix: $prefix/[target] (edit script to change dir)"
Daniel Stenberg2731afa2006-05-30 08:38:02 +000080echo "Build dir: $builddir (edit script to change dir)"
Daniel Stenberg9a3902f2006-05-29 22:23:00 +000081
82###########################################################################
83# Verify that we can write in the prefix dir, as otherwise we will hardly
84# be able to install there!
85if test ! -w $prefix; then
86 echo "WARNING: this script is set to install in $prefix but has no"
87 echo "WARNING: write permission to do so!"
88fi
89
90
91###########################################################################
92# If there's already a build dir, we don't overwrite it
Daniel Stenberg2731afa2006-05-30 08:38:02 +000093if test -d $builddir; then
94 echo "you have a $builddir dir already, please remove and rerun"
Daniel Stenberg9a3902f2006-05-29 22:23:00 +000095 exit
96fi
97
Daniel Stenberg2731afa2006-05-30 08:38:02 +000098cleardir () {
99 # $1 is the name of the build dir
100 # delete the build dirs and the source dirs
101 rm -rf $1/build-gcc $1/build-binu $1/gcc* $1/binutils*
102}
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000103
Daniel Stenberg2731afa2006-05-30 08:38:02 +0000104buildone () {
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000105
Daniel Stenberg2731afa2006-05-30 08:38:02 +0000106gccpatch="" # default is no gcc patch
107gccver="4.0.3" # default gcc version
108binutils="2.16.1" # The binutils version to use
109
Daniel Stenbergb91b4102006-08-13 18:27:31 +0000110system=`uname -s`
111
Daniel Stenberg2731afa2006-05-30 08:38:02 +0000112case $1 in
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000113 [Ss])
114 target="sh-elf"
Daniel Stenberg7d1cd162006-05-25 23:44:51 +0000115 gccurl="http://www.rockbox.org/twiki/pub/Main/CrossCompiler"
116 gccpatch="gcc-4.0.3-rockbox-1.diff"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000117 ;;
118 [Mm])
119 target="m68k-elf"
120 gccver="3.4.6"
Daniel Stenbergb91b4102006-08-13 18:27:31 +0000121 case $system in
122 CYGWIN* | Darwin)
123 gccurl="http://www.rockbox.org/twiki/pub/Main/CrossCompiler"
124 gccpatch="gcc-3.4.6.patch"
125 ;;
126 Linux)
127 ;;
128 *)
129 ;;
130 esac
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000131 ;;
132 [Aa])
133 target="arm-elf"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000134 ;;
135 *)
136 echo "unsupported"
137 exit
138 ;;
139esac
140
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000141bindir="$prefix/$target/bin"
Daniel Stenberg2731afa2006-05-30 08:38:02 +0000142if test -n $pathadd; then
143 pathadd="$pathadd:$bindir"
144else
145 pathadd="$bindir"
Daniel Stenberg7d1cd162006-05-25 23:44:51 +0000146fi
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000147
Daniel Stenberg2731afa2006-05-30 08:38:02 +0000148mkdir $builddir
149cd $builddir
Daniel Stenberg9a3902f2006-05-29 22:23:00 +0000150
Daniel Stenberg2731afa2006-05-30 08:38:02 +0000151summary="summary-$1"
152
153echo "== Summary ==" > $summary
154echo "Target: $target" >> $summary
155echo "gcc $gccver" >> $summary
156if test -n "$gccpatch"; then
157 echo "gcc patch $gccpatch" >> $summary
158fi
159echo "binutils $binutils" >> $summary
160echo "install in $prefix/$target" >> $summary
161echo "when complete, make your PATH include $bindir" >> $summary
162
163cat $summary
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000164
165if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then
166 echo "binutils $binutils already downloaded"
167else
168 getfile binutils-$binutils.tar.bz2 ftp://ftp.gnu.org/pub/gnu/binutils
169fi
170
171if test -f "$dlwhere/gcc-$gccver.tar.bz2"; then
172 echo "gcc $gccver already downloaded"
173else
174 getfile gcc-$gccver.tar.bz2 ftp://ftp.gnu.org/pub/gnu/gcc/gcc-$gccver
175fi
176
Daniel Stenberg7d1cd162006-05-25 23:44:51 +0000177if test -n "$gccpatch"; then
178 if test -f "$dlwhere/$gccpatch"; then
179 echo "$gccpatch already downloaded"
180 else
181 getfile "$gccpatch" "$gccurl"
182 fi
183fi
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000184
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000185echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000186tar xjf $dlwhere/binutils-$binutils.tar.bz2
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000187echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir"
Linus Nielsen Feltzingad7fe4f2006-05-30 10:21:13 +0000188tar xjf $dlwhere/gcc-$gccver.tar.bz2
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000189
Daniel Stenberg7d1cd162006-05-25 23:44:51 +0000190if test -n "$gccpatch"; then
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000191 echo "ROCKBOXDEV: applying gcc patch"
Daniel Stenberg7d1cd162006-05-25 23:44:51 +0000192 patch -p0 < "$dlwhere/$gccpatch"
193fi
194
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000195echo "ROCKBOXDEV: mkdir build-binu"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000196mkdir build-binu
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000197echo "ROCKBOXDEV: cd build-binu"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000198cd build-binu
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000199echo "ROCKBOXDEV: binutils/configure"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000200../binutils-$binutils/configure --target=$target --prefix=$prefix/$target
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000201echo "ROCKBOXDEV: binutils/make"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000202make
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000203echo "ROCKBOXDEV: binutils/make install to $prefix/$target"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000204make install
Daniel Stenberg2731afa2006-05-30 08:38:02 +0000205cd .. # get out of build-binu
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000206PATH="${PATH}:$bindir"
207SHELL=/bin/sh # seems to be needed by the gcc build in some cases
208
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000209echo "ROCKBOXDEV: mkdir build-gcc"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000210mkdir build-gcc
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000211echo "ROCKBOXDEV: cd build-gcc"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000212cd build-gcc
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000213echo "ROCKBOXDEV: gcc/configure"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000214../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000215echo "ROCKBOXDEV: gcc/make"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000216make
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000217echo "ROCKBOXDEV: gcc/make install to $prefix/$target"
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000218make install
Daniel Stenberg2731afa2006-05-30 08:38:02 +0000219cd .. # get out of build-gcc
220cd .. # get out of $builddir
221
222 # end of buildone() function
223}
224
225echo ""
226echo "Select target arch:"
Daniel Stenberg19fe37d2006-08-10 06:46:56 +0000227echo "s - sh (Archos models)"
228echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)"
229echo "a - arm (ipods, iriver H10, Sansa, etc)"
Daniel Stenberg2731afa2006-05-30 08:38:02 +0000230echo "all - all three compilers"
231
232arch=`input`
233
234case $arch in
235 [Ss])
236 buildone $arch
237 ;;
238 [Mm])
239 buildone $arch
240 ;;
241 [Aa])
242 buildone $arch
243 ;;
244 all)
245 echo "build ALL compilers!"
246 buildone s
247 cleardir $builddir
248
249 buildone m
250 cleardir $builddir
251
252 buildone a
253
254 # show the summaries:
255 cat $builddir/summary-*
256 ;;
257 *)
258 echo "unsupported architecture option"
259 exit
260 ;;
261esac
Daniel Stenbergcce0d652006-05-15 13:26:59 +0000262
263echo "done"
Daniel Stenberg9a3902f2006-05-29 22:23:00 +0000264echo ""
Daniel Stenberg2731afa2006-05-30 08:38:02 +0000265echo "Make your PATH include $pathadd"