Refer to "disk" instead of "hard disk" for the dap as flash based daps don't have...
[Rockbox.git] / tools / rockboxdev.sh
blob367f6077990af5c8b4133d83cf400d317a5041a4
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"
149 gccurl="http://www.rockbox.org/twiki/pub/Main/CrossCompiler"
150 gccpatch="thumb-interwork-4.0.3.diff"
153 echo "unsupported"
154 exit
156 esac
158 bindir="$prefix/$target/bin"
159 if test -n $pathadd; then
160 pathadd="$pathadd:$bindir"
161 else
162 pathadd="$bindir"
165 mkdir $builddir
166 cd $builddir
168 summary="summary-$1"
170 echo "== Summary ==" > $summary
171 echo "Target: $target" >> $summary
172 echo "gcc $gccver" >> $summary
173 if test -n "$gccpatch"; then
174 echo "gcc patch $gccpatch" >> $summary
176 echo "binutils $binutils" >> $summary
177 echo "install in $prefix/$target" >> $summary
178 echo "when complete, make your PATH include $bindir" >> $summary
180 cat $summary
182 if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then
183 echo "binutils $binutils already downloaded"
184 else
185 getfile binutils-$binutils.tar.bz2 ftp://ftp.gnu.org/pub/gnu/binutils
188 if test -f "$dlwhere/gcc-core-$gccver.tar.bz2"; then
189 echo "gcc $gccver already downloaded"
190 else
191 getfile gcc-core-$gccver.tar.bz2 ftp://ftp.gnu.org/pub/gnu/gcc/gcc-$gccver
194 if test -n "$gccpatch"; then
195 if test -f "$dlwhere/$gccpatch"; then
196 echo "$gccpatch already downloaded"
197 else
198 getfile "$gccpatch" "$gccurl"
202 echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir"
203 tar xjf $dlwhere/binutils-$binutils.tar.bz2
204 echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir"
205 tar xjf $dlwhere/gcc-core-$gccver.tar.bz2
207 if test -n "$gccpatch"; then
208 echo "ROCKBOXDEV: applying gcc patch"
209 patch -p0 < "$dlwhere/$gccpatch"
212 echo "ROCKBOXDEV: mkdir build-binu"
213 mkdir build-binu
214 echo "ROCKBOXDEV: cd build-binu"
215 cd build-binu
216 echo "ROCKBOXDEV: binutils/configure"
217 ../binutils-$binutils/configure --target=$target --prefix=$prefix/$target
218 echo "ROCKBOXDEV: binutils/make"
219 $make
220 echo "ROCKBOXDEV: binutils/make install to $prefix/$target"
221 $make install
222 cd .. # get out of build-binu
223 PATH="${PATH}:$bindir"
224 SHELL=/bin/sh # seems to be needed by the gcc build in some cases
226 echo "ROCKBOXDEV: mkdir build-gcc"
227 mkdir build-gcc
228 echo "ROCKBOXDEV: cd build-gcc"
229 cd build-gcc
230 echo "ROCKBOXDEV: gcc/configure"
231 ../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c
232 echo "ROCKBOXDEV: gcc/make"
233 $make
234 echo "ROCKBOXDEV: gcc/make install to $prefix/$target"
235 $make install
236 cd .. # get out of build-gcc
237 cd .. # get out of $builddir
239 # end of buildone() function
242 echo ""
243 echo "Select target arch:"
244 echo "s - sh (Archos models)"
245 echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)"
246 echo "a - arm (ipods, iriver H10, Sansa, etc)"
247 echo "all - all three compilers"
249 arch=`input`
251 case $arch in
252 [Ss])
253 buildone $arch
255 [Mm])
256 buildone $arch
258 [Aa])
259 buildone $arch
261 all)
262 echo "build ALL compilers!"
263 buildone s
264 cleardir $builddir
266 buildone m
267 cleardir $builddir
269 buildone a
271 # show the summaries:
272 cat $builddir/summary-*
275 echo "unsupported architecture option"
276 exit
278 esac
280 echo "done"
281 echo ""
282 echo "Make your PATH include $pathadd"