bit of code police
[kugel-rb.git] / tools / rockboxdev.sh
bloba55ad8df3d6da2b21b20e931b9e3976d2db06604
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 | Interix)
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"
186 case $system in
187 Interix)
188 gccpatch="gcc-4.1.2-interix.diff"
192 esac
195 echo "An unsupported architecture option: $arch"
196 exit
198 esac
200 bindir="$prefix/$target/bin"
201 if test -n $pathadd; then
202 pathadd="$pathadd:$bindir"
203 else
204 pathadd="$bindir"
207 mkdir -p $builddir
208 cd $builddir
210 summary="summary-$1"
212 echo "============================ Summary ============================" > $summary
213 echo "target: $target" >> $summary
214 echo "gcc version: $gccver" >> $summary
215 if test -n "$gccpatch"; then
216 echo "gcc patch: $gccpatch" >> $summary
218 echo "binutils: $binutils" >> $summary
219 echo "installation target: $prefix/$target" >> $summary
220 echo "" >> $summary
221 echo "When done, append $bindir to PATH" >> $summary
222 echo "=================================================================" >> $summary
224 cat $summary
226 echo ""
227 echo "In case you encounter a slow internet connection, you can use an alternative mirror."
228 echo "A list of other GNU mirrors is available here: http://www.gnu.org/prep/ftp.html"
229 echo ""
230 echo "Usage: GNU_MIRROR=[URL] ./rockboxdev.sh"
231 echo ""
232 echo "Example:"
233 echo "$ GNU_MIRROR=http://mirrors.kernel.org/gnu ./rockboxdev.sh"
234 echo ""
236 if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then
237 echo "binutils $binutils already downloaded"
238 else
239 getfile binutils-$binutils.tar.bz2 $GNU_MIRROR/binutils
242 if test -f "$dlwhere/gcc-core-$gccver.tar.bz2"; then
243 echo "gcc $gccver already downloaded"
244 else
245 getfile gcc-core-$gccver.tar.bz2 $GNU_MIRROR/gcc/gcc-$gccver
248 if test -n "$gccpatch"; then
249 if test -f "$dlwhere/$gccpatch"; then
250 echo "$gccpatch already downloaded"
251 else
252 getfile "$gccpatch" "$gccurl"
256 echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir"
257 tar xjf $dlwhere/binutils-$binutils.tar.bz2
258 echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir"
259 tar xjf $dlwhere/gcc-core-$gccver.tar.bz2
261 if test -n "$gccpatch"; then
262 echo "ROCKBOXDEV: applying gcc patch"
263 patch -p0 < "$dlwhere/$gccpatch"
266 echo "ROCKBOXDEV: mkdir build-binu"
267 mkdir build-binu
268 echo "ROCKBOXDEV: cd build-binu"
269 cd build-binu
270 echo "ROCKBOXDEV: binutils/configure"
271 ../binutils-$binutils/configure --target=$target --prefix=$prefix/$target
272 echo "ROCKBOXDEV: binutils/make"
273 $make
274 echo "ROCKBOXDEV: binutils/make install to $prefix/$target"
275 $make install
276 cd .. # get out of build-binu
277 PATH="${PATH}:$bindir"
278 SHELL=/bin/sh # seems to be needed by the gcc build in some cases
280 echo "ROCKBOXDEV: mkdir build-gcc"
281 mkdir build-gcc
282 echo "ROCKBOXDEV: cd build-gcc"
283 cd build-gcc
284 echo "ROCKBOXDEV: gcc/configure"
285 ../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c $gccconfigure
286 echo "ROCKBOXDEV: gcc/make"
287 $make
288 echo "ROCKBOXDEV: gcc/make install to $prefix/$target"
289 $make install
290 cd .. # get out of build-gcc
291 cd .. # get out of $builddir
293 # end of buildone() function
296 echo ""
297 echo "Select target arch:"
298 echo "s - sh (Archos models)"
299 echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)"
300 echo "a - arm (ipods, iriver H10, Sansa, etc)"
301 echo "i - mips (Jz4740 and ATJ-based players)"
302 echo "separate multiple targets with spaces"
303 echo "(i.e. \"s m a\" will build sh, m86k and arm)"
304 echo ""
306 selarch=`input`
308 for arch in $selarch
310 echo ""
311 case $arch in
312 [Ss])
313 buildone $arch
315 [Ii])
316 buildone $arch
318 [Mm])
319 buildone $arch
321 [Aa])
322 buildone $arch
325 echo "An unsupported architecture option: $arch"
326 exit
328 esac
330 echo "Cleaning up build folder"
331 cleardir $builddir
332 echo ""
333 echo "Done!"
334 echo ""
335 echo "Make your PATH include $pathadd"
337 done
339 # show the summaries:
340 cat $builddir/summary-*