Remove the check since it can fail if the chars to process were limited per command...
[kugel-rb/myfork.git] / tools / rockboxdev.sh
blobd322ef1a5053f35c9290b8ba56fbcce7093a531b
1 #!/bin/sh
3 # Abort execution as soon as an error is encountered
4 # That way the script do not let the user think the process completed correctly
5 # and leave the opportunity to fix the problem and restart compilation where
6 # it stopped
7 set -e
9 # this is where this script will store downloaded files and check for already
10 # downloaded files
11 dlwhere="${RBDEV_DOWNLOAD:-/tmp/rbdev-dl}"
13 # will append the target string to the prefix dir mentioned here
14 # Note that the user running this script must be able to do make install in
15 # this given prefix directory. Also make sure that this given root dir
16 # exists.
17 prefix="${RBDEV_PREFIX:-/usr/local}"
19 # This directory is used to extract all files and to build everything in. It
20 # must not exist before this script is invoked (as a security measure).
21 builddir="${RBDEV_BUILD:-/tmp/rbdev-build}"
23 # This script needs to use GNU Make. On Linux systems, GNU Make is invoked
24 # by running the "make" command, on most BSD systems, GNU Make is invoked
25 # by running the "gmake" command. Set the "make" variable accordingly.
26 if [ -f "`which gmake 2>/dev/null`" ]; then
27 make="gmake"
28 else
29 make="make"
32 if [ -z $GNU_MIRROR ] ; then
33 GNU_MIRROR=ftp://ftp.gnu.org/pub/gnu
36 # If detection fails, override the value of make manually:
37 # make="make"
39 ##############################################################################
42 # These are the tools this script requires and depends upon.
43 reqtools="gcc bzip2 make patch"
46 findtool(){
47 file="$1"
49 IFS=":"
50 for path in $PATH
52 # echo "Checks for $file in $path" >&2
53 if test -f "$path/$file"; then
54 echo "$path/$file"
55 return
57 done
60 input() {
61 read response
62 echo $response
65 #$1 file
66 #$2 URL"root
67 getfile() {
68 tool=`findtool curl`
69 if test -z "$tool"; then
70 tool=`findtool wget`
71 if test -n "$tool"; then
72 # wget download
73 echo "ROCKBOXDEV: Downloading $2/$1 using wget"
74 $tool -O $dlwhere/$1 $2/$1
76 else
77 # curl download
78 echo "ROCKBOXDEV: Downloading $2/$1 using curl"
79 $tool -Lo $dlwhere/$1 $2/$1
82 if [ $? -ne 0 ] ; then
83 echo "ROCKBOXDEV: couldn't download the file!"
84 echo "ROCKBOXDEV: check your internet connection"
85 exit
88 if test -z "$tool"; then
89 echo "ROCKBOXDEV: No downloader tool found!"
90 echo "ROCKBOXDEV: Please install curl or wget and re-run the script"
91 exit
95 for t in $reqtools; do
96 tool=`findtool $t`
97 if test -z "$tool"; then
98 echo "ROCKBOXDEV: $t is required for this script to work."
99 echo "ROCKBOXDEV: Please install $t and re-run the script."
100 exit
102 done
104 ###########################################################################
105 # Verify download directory or create it
106 if test -d "$dlwhere"; then
107 if ! test -w "$dlwhere"; then
108 echo "$dlwhere exists, but doesn't seem to be writable for you"
109 exit
111 else
112 mkdir $dlwhere
113 if test $? -ne 0; then
114 echo "$dlwhere is missing and we failed to create it!"
115 exit
117 echo "$dlwhere has been created to store downloads in"
120 echo "Download directory: $dlwhere (set RBDEV_DOWNLOAD to change dir)"
121 echo "Install prefix: $prefix/[target] (set RBDEV_PREFIX to change dir)"
122 echo "Build dir: $builddir (set RBDEV_BUILD to change dir)"
124 ###########################################################################
125 # Verify that we can write in the prefix dir, as otherwise we will hardly
126 # be able to install there!
127 if test ! -w $prefix; then
128 echo "WARNING: This script is set to install in $prefix but has no write permissions for it"
129 echo "Please fix this and re-run this script"
130 exit
135 cleardir () {
136 # $1 is the name of the build dir
137 # delete the build dirs and the source dirs
138 rm -rf $1/build-gcc $1/build-binu $1/gcc* $1/binutils*
141 buildone () {
143 arch=$1
144 gccpatch="" # default is no gcc patch
145 gccver="4.0.3" # default gcc version
146 binutils="2.16.1" # The binutils version to use
147 gccconfigure="" #default is nothing added to configure
148 binutilsconf="" #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 binutilsconf="--disable-werror"
187 # necessary to make binutils build on gcc 4.3+
188 case $system in
189 Interix)
190 gccpatch="gcc-4.1.2-interix.diff"
194 esac
197 echo "An unsupported architecture option: $arch"
198 exit
200 esac
202 bindir="$prefix/$target/bin"
203 if test -n $pathadd; then
204 pathadd="$pathadd:$bindir"
205 else
206 pathadd="$bindir"
209 summary="summary-$1"
211 echo "============================ Summary ============================" > $summary
212 echo "target: $target" >> $summary
213 echo "gcc version: $gccver" >> $summary
214 if test -n "$gccpatch"; then
215 echo "gcc patch: $gccpatch" >> $summary
217 echo "binutils: $binutils" >> $summary
218 echo "installation target: $prefix/$target" >> $summary
219 echo "" >> $summary
220 echo "When done, append $bindir to PATH" >> $summary
221 echo "=================================================================" >> $summary
223 cat $summary
225 echo ""
226 echo "In case you encounter a slow internet connection, you can use an alternative mirror."
227 echo "A list of other GNU mirrors is available here: http://www.gnu.org/prep/ftp.html"
228 echo ""
229 echo "Usage: GNU_MIRROR=[URL] ./rockboxdev.sh"
230 echo ""
231 echo "Example:"
232 echo "$ GNU_MIRROR=http://mirrors.kernel.org/gnu ./rockboxdev.sh"
233 echo ""
235 if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then
236 echo "binutils $binutils already downloaded"
237 else
238 getfile binutils-$binutils.tar.bz2 $GNU_MIRROR/binutils
241 if test -f "$dlwhere/gcc-core-$gccver.tar.bz2"; then
242 echo "gcc $gccver already downloaded"
243 else
244 getfile gcc-core-$gccver.tar.bz2 $GNU_MIRROR/gcc/gcc-$gccver
247 if test -n "$gccpatch"; then
248 if test -f "$dlwhere/$gccpatch"; then
249 echo "$gccpatch already downloaded"
250 else
251 getfile "$gccpatch" "$gccurl"
255 ###########################################################################
256 # If there's already a build dir, we don't overwrite it
257 if test -d $builddir; then
258 echo "You already have a $builddir directory!"
259 echo "Please remove it and re-run the script"
260 exit
261 else
262 mkdir -p $builddir
263 cd $builddir
267 echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir"
268 tar xjf $dlwhere/binutils-$binutils.tar.bz2
269 echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir"
270 tar xjf $dlwhere/gcc-core-$gccver.tar.bz2
272 if test -n "$gccpatch"; then
273 echo "ROCKBOXDEV: applying gcc patch"
274 patch -p0 < "$dlwhere/$gccpatch"
277 echo "ROCKBOXDEV: mkdir build-binu"
278 mkdir build-binu
279 echo "ROCKBOXDEV: cd build-binu"
280 cd build-binu
281 echo "ROCKBOXDEV: binutils/configure"
282 # we undefine _FORTIFY_SOURCE to make the binutils built run fine on recent
283 # Ubuntu installations
284 CFLAGS=-U_FORTIFY_SOURCE ../binutils-$binutils/configure --target=$target --prefix=$prefix/$target $binutilsconf
285 echo "ROCKBOXDEV: binutils/make"
286 $make
287 echo "ROCKBOXDEV: binutils/make install to $prefix/$target"
288 $make install
289 cd .. # get out of build-binu
290 PATH="${PATH}:$bindir"
291 SHELL=/bin/sh # seems to be needed by the gcc build in some cases
293 echo "ROCKBOXDEV: mkdir build-gcc"
294 mkdir build-gcc
295 echo "ROCKBOXDEV: cd build-gcc"
296 cd build-gcc
297 echo "ROCKBOXDEV: gcc/configure"
298 # we undefine _FORTIFY_SOURCE to make the gcc build go through fine on
299 # recent Ubuntu installations
300 CFLAGS=-U_FORTIFY_SOURCE ../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c $gccconfigure
301 echo "ROCKBOXDEV: gcc/make"
302 $make
303 echo "ROCKBOXDEV: gcc/make install to $prefix/$target"
304 $make install
305 cd .. # get out of build-gcc
306 cd .. # get out of $builddir
308 # end of buildone() function
311 echo ""
312 echo "Select target arch:"
313 echo "s - sh (Archos models)"
314 echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)"
315 echo "a - arm (ipods, iriver H10, Sansa, etc)"
316 echo "i - mips (Jz4740 and ATJ-based players)"
317 echo "separate multiple targets with spaces"
318 echo "(i.e. \"s m a\" will build sh, m86k and arm)"
319 echo ""
321 selarch=`input`
323 for arch in $selarch
325 echo ""
326 case $arch in
327 [Ss])
328 buildone $arch
330 [Ii])
331 buildone $arch
333 [Mm])
334 buildone $arch
336 [Aa])
337 buildone $arch
340 echo "An unsupported architecture option: $arch"
341 exit
343 esac
345 echo "Cleaning up build folder"
346 cleardir $builddir
347 echo ""
348 echo "Done!"
349 echo ""
350 echo "Make your PATH include $pathadd"
352 done
354 # show the summaries:
355 cat $builddir/summary-*