Slight improvement of the 'Rockboxed' WPS for the H300 by better placing the progressbar.
[Rockbox.git] / tools / rockboxdev.sh
blobdebf12cc347fd7cb3e2faea37e43b2a8d72d8d63
1 #!/bin/sh
3 # this is where this script will store downloaded files and check for already
4 # downloaded files
5 dlwhere="$HOME/tmp"
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.
11 prefix="/usr/local"
13 # 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).
15 builddir="$HOME/build-rbdev"
17 # This script needs to use GNU Make. On Linux systems, GNU Make is invoked
18 # by running the "make" command, on most BSD systems, GNU Make is invoked
19 # by running the "gmake" command. Set the "make" variable accordingly.
20 if [ -n "`which gmake`" ]; then
21 make="gmake"
22 else
23 make="make"
26 # If detection fails, override the value of make manually:
27 # make="make"
29 ##############################################################################
32 findtool(){
33 file="$1"
35 IFS=":"
36 for path in $PATH
38 # echo "checks for $file in $path" >&2
39 if test -f "$path/$file"; then
40 echo "$path/$file"
41 return
43 done
46 input() {
47 read response
48 echo $response
51 #$1 file
52 #$2 URL"root
53 getfile() {
54 tool=`findtool curl`
55 if test -z "$tool"; then
56 tool=`findtool wget`
57 if test -n "$tool"; then
58 # wget download
59 echo "ROCKBOXDEV: downloads $2/$1 using wget"
60 $tool -O $dlwhere/$1 $2/$1
62 else
63 # curl download
64 echo "ROCKBOXDEV: downloads $2/$1 using curl"
65 $tool -Lo $dlwhere/$1 $2/$1
67 if test -z "$tool"; then
68 echo "ROCKBOXDEV: couldn't find any downloader tool to use!"
69 echo "ROCKBOXDEV: install curl or wget and re-run the script"
70 exit
76 ###########################################################################
77 # Verify download directory or create it
78 if test -d "$dlwhere"; then
79 if ! test -w "$dlwhere"; then
80 echo "$dlwhere exists, but doesn't seem to be writable for you"
81 exit
83 else
84 mkdir $dlwhere
85 if test $? -ne 0; then
86 echo "$dlwhere is missing and we failed to create it!"
87 exit
89 echo "$dlwhere has been created to store downloads in"
92 echo "Download directory: $dlwhere (edit script to change dir)"
93 echo "Install prefix: $prefix/[target] (edit script to change dir)"
94 echo "Build dir: $builddir (edit script to change dir)"
96 ###########################################################################
97 # Verify that we can write in the prefix dir, as otherwise we will hardly
98 # be able to install there!
99 if test ! -w $prefix; then
100 echo "WARNING: this script is set to install in $prefix but has no"
101 echo "WARNING: write permission to do so! Please fix and re-run this script"
102 exit
106 ###########################################################################
107 # If there's already a build dir, we don't overwrite it
108 if test -d $builddir; then
109 echo "you have a $builddir dir already, please remove and rerun"
110 exit
113 cleardir () {
114 # $1 is the name of the build dir
115 # delete the build dirs and the source dirs
116 rm -rf $1/build-gcc $1/build-binu $1/gcc* $1/binutils*
119 buildone () {
121 gccpatch="" # default is no gcc patch
122 gccver="4.0.3" # default gcc version
123 binutils="2.16.1" # The binutils version to use
125 system=`uname -s`
127 case $1 in
128 [Ss])
129 target="sh-elf"
130 gccurl="http://www.rockbox.org/twiki/pub/Main/CrossCompiler"
131 gccpatch="gcc-4.0.3-rockbox-1.diff"
133 [Mm])
134 target="m68k-elf"
135 gccver="3.4.6"
136 case $system in
137 CYGWIN* | Darwin)
138 gccurl="http://www.rockbox.org/twiki/pub/Main/CrossCompiler"
139 gccpatch="gcc-3.4.6.patch"
141 Linux)
145 esac
147 [Aa])
148 target="arm-elf"
151 echo "unsupported"
152 exit
154 esac
156 bindir="$prefix/$target/bin"
157 if test -n $pathadd; then
158 pathadd="$pathadd:$bindir"
159 else
160 pathadd="$bindir"
163 mkdir $builddir
164 cd $builddir
166 summary="summary-$1"
168 echo "== Summary ==" > $summary
169 echo "Target: $target" >> $summary
170 echo "gcc $gccver" >> $summary
171 if test -n "$gccpatch"; then
172 echo "gcc patch $gccpatch" >> $summary
174 echo "binutils $binutils" >> $summary
175 echo "install in $prefix/$target" >> $summary
176 echo "when complete, make your PATH include $bindir" >> $summary
178 cat $summary
180 if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then
181 echo "binutils $binutils already downloaded"
182 else
183 getfile binutils-$binutils.tar.bz2 ftp://ftp.gnu.org/pub/gnu/binutils
186 if test -f "$dlwhere/gcc-$gccver.tar.bz2"; then
187 echo "gcc $gccver already downloaded"
188 else
189 getfile gcc-$gccver.tar.bz2 ftp://ftp.gnu.org/pub/gnu/gcc/gcc-$gccver
192 if test -n "$gccpatch"; then
193 if test -f "$dlwhere/$gccpatch"; then
194 echo "$gccpatch already downloaded"
195 else
196 getfile "$gccpatch" "$gccurl"
200 echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir"
201 tar xjf $dlwhere/binutils-$binutils.tar.bz2
202 echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir"
203 tar xjf $dlwhere/gcc-$gccver.tar.bz2
205 if test -n "$gccpatch"; then
206 echo "ROCKBOXDEV: applying gcc patch"
207 patch -p0 < "$dlwhere/$gccpatch"
210 echo "ROCKBOXDEV: mkdir build-binu"
211 mkdir build-binu
212 echo "ROCKBOXDEV: cd build-binu"
213 cd build-binu
214 echo "ROCKBOXDEV: binutils/configure"
215 ../binutils-$binutils/configure --target=$target --prefix=$prefix/$target
216 echo "ROCKBOXDEV: binutils/make"
217 $make
218 echo "ROCKBOXDEV: binutils/make install to $prefix/$target"
219 $make install
220 cd .. # get out of build-binu
221 PATH="${PATH}:$bindir"
222 SHELL=/bin/sh # seems to be needed by the gcc build in some cases
224 echo "ROCKBOXDEV: mkdir build-gcc"
225 mkdir build-gcc
226 echo "ROCKBOXDEV: cd build-gcc"
227 cd build-gcc
228 echo "ROCKBOXDEV: gcc/configure"
229 ../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c
230 echo "ROCKBOXDEV: gcc/make"
231 $make
232 echo "ROCKBOXDEV: gcc/make install to $prefix/$target"
233 $make install
234 cd .. # get out of build-gcc
235 cd .. # get out of $builddir
237 # end of buildone() function
240 echo ""
241 echo "Select target arch:"
242 echo "s - sh (Archos models)"
243 echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)"
244 echo "a - arm (ipods, iriver H10, Sansa, etc)"
245 echo "all - all three compilers"
247 arch=`input`
249 case $arch in
250 [Ss])
251 buildone $arch
253 [Mm])
254 buildone $arch
256 [Aa])
257 buildone $arch
259 all)
260 echo "build ALL compilers!"
261 buildone s
262 cleardir $builddir
264 buildone m
265 cleardir $builddir
267 buildone a
269 # show the summaries:
270 cat $builddir/summary-*
273 echo "unsupported architecture option"
274 exit
276 esac
278 echo "done"
279 echo ""
280 echo "Make your PATH include $pathadd"