Replaced TAB characters by spaces in sansapatcher
[kugel-rb.git] / tools / rockboxdev.sh
blob016fc65f7a4dc21b33cb932f086a7b0250b6b131
1 #!/bin/sh
3 # this is where this script will store downloaded files and check for already
4 # downloaded files
5 dlwhere="/tmp/rbdev-dl"
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="/tmp/rbdev-build"
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 [ -f "`which gmake`" ]; then
21 make="gmake"
22 else
23 make="make"
26 if [ -z $GNU_MIRROR ] ; then
27 GNU_MIRROR=ftp://ftp.gnu.org/pub/gnu
30 # If detection fails, override the value of make manually:
31 # make="make"
33 ##############################################################################
36 # These are the tools this script requires and depends upon.
37 reqtools="gcc bzip2 make patch"
40 findtool(){
41 file="$1"
43 IFS=":"
44 for path in $PATH
46 # echo "Checks for $file in $path" >&2
47 if test -f "$path/$file"; then
48 echo "$path/$file"
49 return
51 done
54 input() {
55 read response
56 echo $response
59 #$1 file
60 #$2 URL"root
61 getfile() {
62 tool=`findtool curl`
63 if test -z "$tool"; then
64 tool=`findtool wget`
65 if test -n "$tool"; then
66 # wget download
67 echo "ROCKBOXDEV: Downloading $2/$1 using wget"
68 $tool -O $dlwhere/$1 $2/$1
70 else
71 # curl download
72 echo "ROCKBOXDEV: Downloading $2/$1 using curl"
73 $tool -Lo $dlwhere/$1 $2/$1
76 if [ $? -ne 0 ] ; then
77 echo "ROCKBOXDEV: couldn't download the file!"
78 echo "ROCKBOXDEV: check your internet connection"
79 exit
82 if test -z "$tool"; then
83 echo "ROCKBOXDEV: No downloader tool found!"
84 echo "ROCKBOXDEV: Please install curl or wget and re-run the script"
85 exit
89 for t in $reqtools; do
90 tool=`findtool $t`
91 if test -z "$tool"; then
92 echo "ROCKBOXDEV: $t is required for this script to work."
93 echo "ROCKBOXDEV: Please install $t and re-run the script."
94 exit
96 done
98 ###########################################################################
99 # Verify download directory or create it
100 if test -d "$dlwhere"; then
101 if ! test -w "$dlwhere"; then
102 echo "$dlwhere exists, but doesn't seem to be writable for you"
103 exit
105 else
106 mkdir $dlwhere
107 if test $? -ne 0; then
108 echo "$dlwhere is missing and we failed to create it!"
109 exit
111 echo "$dlwhere has been created to store downloads in"
114 echo "Download directory: $dlwhere (edit script to change dir)"
115 echo "Install prefix: $prefix/[target] (edit script to change dir)"
116 echo "Build dir: $builddir (edit script to change dir)"
118 ###########################################################################
119 # Verify that we can write in the prefix dir, as otherwise we will hardly
120 # be able to install there!
121 if test ! -w $prefix; then
122 echo "WARNING: This script is set to install in $prefix but has no write permissions for it"
123 echo "Please fix this and re-run this script"
124 exit
128 ###########################################################################
129 # If there's already a build dir, we don't overwrite it
130 if test -d $builddir; then
131 echo "You already have a $builddir directory!"
132 echo "Please remove it and re-run the script"
133 exit
136 cleardir () {
137 # $1 is the name of the build dir
138 # delete the build dirs and the source dirs
139 rm -rf $1/build-gcc $1/build-binu $1/gcc* $1/binutils*
142 buildone () {
144 arch=$1
145 gccpatch="" # default is no gcc patch
146 gccver="4.0.3" # default gcc version
147 binutils="2.16.1" # The binutils version to use
148 gccconfigure="" #default is nothing added to configure
150 system=`uname -s`
151 gccurl="http://www.rockbox.org/gcc"
153 case $arch in
154 [Ss])
155 target="sh-elf"
156 gccpatch="gcc-4.0.3-rockbox-1.diff"
158 [Mm])
159 target="m68k-elf"
160 gccver="3.4.6"
161 case $system in
162 CYGWIN* | Darwin | FreeBSD)
163 gccpatch="gcc-3.4.6.patch"
165 Linux)
166 machine=`uname -m`
167 case $machine in
168 x86_64)
169 gccpatch="gcc-3.4.6-amd64.patch"
171 esac
175 esac
177 [Aa])
178 target="arm-elf"
179 gccpatch="rockbox-multilibs-arm-elf-gcc-4.0.3_2.diff"
181 [Ii])
182 target="mipsel-elf"
183 gccver="4.1.2"
184 binutils="2.17"
185 gccconfigure="--disable-libssp"
188 echo "An unsupported architecture option: $arch"
189 exit
191 esac
193 bindir="$prefix/$target/bin"
194 if test -n $pathadd; then
195 pathadd="$pathadd:$bindir"
196 else
197 pathadd="$bindir"
200 mkdir $builddir
201 cd $builddir
203 summary="summary-$1"
205 echo "============================ Summary ============================" > $summary
206 echo "target: $target" >> $summary
207 echo "gcc version: $gccver" >> $summary
208 if test -n "$gccpatch"; then
209 echo "gcc patch: $gccpatch" >> $summary
211 echo "binutils: $binutils" >> $summary
212 echo "installation target: $prefix/$target" >> $summary
213 echo "" >> $summary
214 echo "When done, append $bindir to PATH" >> $summary
215 echo "=================================================================" >> $summary
217 cat $summary
219 echo ""
220 echo "In case you encounter a slow internet connection, you can use an alternative mirror."
221 echo "A list of other GNU mirrors is available here: http://www.gnu.org/prep/ftp.html"
222 echo ""
223 echo "Usage: GNU_MIRROR=[URL] ./rockboxdev.sh"
224 echo ""
225 echo "Example:"
226 echo "$ GNU_MIRROR=http://mirrors.kernel.org/gnu ./rockboxdev.sh"
227 echo ""
229 if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then
230 echo "binutils $binutils already downloaded"
231 else
232 getfile binutils-$binutils.tar.bz2 $GNU_MIRROR/binutils
235 if test -f "$dlwhere/gcc-core-$gccver.tar.bz2"; then
236 echo "gcc $gccver already downloaded"
237 else
238 getfile gcc-core-$gccver.tar.bz2 $GNU_MIRROR/gcc/gcc-$gccver
241 if test -n "$gccpatch"; then
242 if test -f "$dlwhere/$gccpatch"; then
243 echo "$gccpatch already downloaded"
244 else
245 getfile "$gccpatch" "$gccurl"
249 echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir"
250 tar xjf $dlwhere/binutils-$binutils.tar.bz2
251 echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir"
252 tar xjf $dlwhere/gcc-core-$gccver.tar.bz2
254 if test -n "$gccpatch"; then
255 echo "ROCKBOXDEV: applying gcc patch"
256 patch -p0 < "$dlwhere/$gccpatch"
259 echo "ROCKBOXDEV: mkdir build-binu"
260 mkdir build-binu
261 echo "ROCKBOXDEV: cd build-binu"
262 cd build-binu
263 echo "ROCKBOXDEV: binutils/configure"
264 ../binutils-$binutils/configure --target=$target --prefix=$prefix/$target
265 echo "ROCKBOXDEV: binutils/make"
266 $make
267 echo "ROCKBOXDEV: binutils/make install to $prefix/$target"
268 $make install
269 cd .. # get out of build-binu
270 PATH="${PATH}:$bindir"
271 SHELL=/bin/sh # seems to be needed by the gcc build in some cases
273 echo "ROCKBOXDEV: mkdir build-gcc"
274 mkdir build-gcc
275 echo "ROCKBOXDEV: cd build-gcc"
276 cd build-gcc
277 echo "ROCKBOXDEV: gcc/configure"
278 ../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c $gccconfigure
279 echo "ROCKBOXDEV: gcc/make"
280 $make
281 echo "ROCKBOXDEV: gcc/make install to $prefix/$target"
282 $make install
283 cd .. # get out of build-gcc
284 cd .. # get out of $builddir
286 # end of buildone() function
289 echo ""
290 echo "Select target arch:"
291 echo "s - sh (Archos models)"
292 echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)"
293 echo "a - arm (ipods, iriver H10, Sansa, etc)"
294 echo "all - all three compilers above"
295 echo "i - mips (Jz4740 and ATJ-based players)"
296 echo ""
298 arch=`input`
300 echo ""
301 case $arch in
302 [Ss])
303 buildone $arch
305 [Ii])
306 buildone $arch
308 [Mm])
309 buildone $arch
311 [Aa])
312 buildone $arch
314 all)
315 echo "Building all compilers..."
316 echo ""
317 buildone s
318 cleardir $builddir
320 buildone m
321 cleardir $builddir
323 buildone a
325 # include this when we want MIPS added in the "build all"
326 #buildone i
328 # show the summaries:
329 cat $builddir/summary-*
332 echo "An unsupported architecture option: $arch"
333 exit
335 esac
337 echo ""
338 echo "Done!"
339 echo ""
340 echo "Make your PATH include $pathadd"