Correct the metadata's VBR flag for MP4 files. ALAC is native VBR, AAC very unlikely...
[maemo-rb.git] / tools / rockboxdev.sh
blobbeb6c4e299b456e8ac9aecaa1c41ece4bef569a8
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=http://mirrors.kernel.org/gnu
36 # These are the tools this script requires and depends upon.
37 reqtools="gcc bzip2 gzip make patch makeinfo"
39 ##############################################################################
40 # Functions:
42 findtool(){
43 file="$1"
45 IFS=":"
46 for path in $PATH
48 # echo "Checks for $file in $path" >&2
49 if test -f "$path/$file"; then
50 echo "$path/$file"
51 return
53 done
56 input() {
57 read response
58 echo $response
61 #$1 file
62 #$2 URL"root
63 getfile() {
64 tool=`findtool curl`
65 if test -z "$tool"; then
66 tool=`findtool wget`
67 if test -n "$tool"; then
68 # wget download
69 echo "ROCKBOXDEV: Downloading $2/$1 using wget"
70 $tool -O $dlwhere/$1 $2/$1
72 else
73 # curl download
74 echo "ROCKBOXDEV: Downloading $2/$1 using curl"
75 $tool -Lo $dlwhere/$1 $2/$1
78 if [ $? -ne 0 ] ; then
79 echo "ROCKBOXDEV: couldn't download the file!"
80 echo "ROCKBOXDEV: check your internet connection"
81 exit
84 if test -z "$tool"; then
85 echo "ROCKBOXDEV: No downloader tool found!"
86 echo "ROCKBOXDEV: Please install curl or wget and re-run the script"
87 exit
92 build() {
93 toolname="$1"
94 target="$2"
95 version="$3"
96 patch="$4"
97 configure_params="$5"
98 needs_libs="$6"
100 patch_url="http://www.rockbox.org/gcc"
102 case $toolname in
103 gcc)
104 file="gcc-core-$version.tar.bz2"
105 url="$GNU_MIRROR/gcc/gcc-$version"
108 binutils)
109 file="binutils-$version.tar.bz2"
110 url="$GNU_MIRROR/binutils"
114 echo "ROCKBOXDEV: Bad toolname $toolname"
115 exit
117 esac
119 # create build directory
120 if test -d $builddir; then
121 if test ! -w $builddir; then
122 echo "ROCKBOXDEV: No write permission for $builddir"
123 exit
125 else
126 mkdir -p $builddir
129 # download source tarball
130 if test ! -f "$dlwhere/$file"; then
131 getfile "$file" "$url"
134 # download patch
135 if test -n "$patch"; then
136 if test ! -f "$dlwhere/$patch"; then
137 getfile "$patch" "$patch_url"
141 cd $builddir
143 echo "ROCKBOXDEV: extracting $file"
144 tar xjf $dlwhere/$file
146 # do we have a patch?
147 if test -n "$patch"; then
148 echo "ROCKBOXDEV: applying patch $patch"
150 # apply the patch
151 (cd $builddir/$toolname-$version && patch -p1 < "$dlwhere/$patch")
153 # check if the patch applied cleanly
154 if [ $? -gt 0 ]; then
155 echo "ROCKBOXDEV: failed to apply patch $patch"
156 exit
160 # kludge to avoid having to install GMP, MPFR and MPC, for new gcc
161 if test -n "$needs_libs"; then
162 cd "gcc-$version"
163 if (echo $needs_libs | grep -q gmp && test ! -d gmp); then
164 echo "ROCKBOXDEV: Getting GMP"
165 if test ! -f $dlwhere/gmp-4.3.2.tar.bz2; then
166 getfile "gmp-4.3.2.tar.bz2" "$GNU_MIRROR/gmp"
168 tar xjf $dlwhere/gmp-4.3.2.tar.bz2
169 ln -s gmp-4.3.2 gmp
172 if (echo $needs_libs | grep -q mpfr && test ! -d mpfr); then
173 echo "ROCKBOXDEV: Getting MPFR"
174 if test ! -f $dlwhere/mpfr-2.4.2.tar.bz2; then
175 getfile "mpfr-2.4.2.tar.bz2" "$GNU_MIRROR/mpfr"
177 tar xjf $dlwhere/mpfr-2.4.2.tar.bz2
178 ln -s mpfr-2.4.2 mpfr
181 if (echo $needs_libs | grep -q mpc && test ! -d mpc); then
182 echo "ROCKBOXDEV: Getting MPC"
183 if test ! -f $dlwhere/mpc-0.8.1.tar.gz; then
184 getfile "mpc-0.8.1.tar.gz" "http://www.multiprecision.org/mpc/download"
186 tar xzf $dlwhere/mpc-0.8.1.tar.gz
187 ln -s mpc-0.8.1 mpc
189 cd $builddir
192 echo "ROCKBOXDEV: mkdir build-$toolname"
193 mkdir build-$toolname
195 echo "ROCKBOXDEV: cd build-$toolname"
196 cd build-$toolname
198 echo "ROCKBOXDEV: $toolname/configure"
199 CFLAGS=-U_FORTIFY_SOURCE ../$toolname-$version/configure --target=$target --prefix=$prefix --enable-languages=c --disable-libssp --disable-docs $configure_params
201 echo "ROCKBOXDEV: $toolname/make"
202 $make
204 echo "ROCKBOXDEV: $toolname/make install"
205 $make install
207 echo "ROCKBOXDEV: rm -rf build-$toolname $toolname-$version"
208 cd ..
209 rm -rf build-$toolname $toolname-$version
212 ##############################################################################
213 # Code:
215 # Verify required tools
216 for t in $reqtools; do
217 tool=`findtool $t`
218 if test -z "$tool"; then
219 echo "ROCKBOXDEV: \"$t\" is required for this script to work."
220 echo "ROCKBOXDEV: Please install \"$t\" and re-run the script."
221 exit
223 done
225 echo "Download directory : $dlwhere (set RBDEV_DOWNLOAD to change)"
226 echo "Install prefix : $prefix (set RBDEV_PREFIX to change)"
227 echo "Build dir : $builddir (set RBDEV_BUILD to change)"
228 echo "Make options : $MAKEFLAGS (set MAKEFLAGS to change)"
229 echo ""
231 # Verify download directory
232 if test -d "$dlwhere"; then
233 if ! test -w "$dlwhere"; then
234 echo "ROCKBOXDEV: No write permission for $dlwhere"
235 exit
237 else
238 mkdir $dlwhere
239 if test $? -ne 0; then
240 echo "ROCKBOXDEV: Failed creating directory $dlwhere"
241 exit
245 # Verify the prefix dir
246 if test ! -d $prefix; then
247 mkdir -p $prefix
248 if test $? -ne 0; then
249 echo "ROCKBOXDEV: Failed creating directory $prefix"
250 exit
253 if test ! -w $prefix; then
254 echo "ROCKBOXDEV: No write permission for $prefix"
255 exit
258 echo "Select target arch:"
259 echo "s - sh (Archos models)"
260 echo "m - m68k (iriver h1x0/h3x0, iaudio m3/m5/x5 and mpio hd200)"
261 echo "e - arm-eabi (ipods, iriver H10, Sansa, D2, Gigabeat, etc)"
262 echo "a - arm (older ARM toolchain, deprecated) "
263 echo "i - mips (Jz4740 and ATJ-based players)"
264 echo "separate multiple targets with spaces"
265 echo "(Example: \"s m a\" will build sh, m68k and arm)"
266 echo ""
268 selarch=`input`
269 system=`uname -s`
271 # add target dir to path to ensure the new binutils are used in gcc build
272 PATH="$prefix/bin:${PATH}"
274 for arch in $selarch
276 echo ""
277 case $arch in
278 [Ss])
279 build "binutils" "sh-elf" "2.16.1"
280 build "gcc" "sh-elf" "4.0.3" "gcc-4.0.3-rockbox-1.diff"
283 [Ii])
284 build "binutils" "mipsel-elf" "2.17" "" "--disable-werror"
285 patch=""
286 if [ "$system" = "Interix" ]; then
287 patch="gcc-4.1.2-interix.diff"
289 build "gcc" "mipsel-elf" "4.1.2" "$patch"
292 [Mm])
293 binopts=""
294 case $system in
295 Darwin)
296 binopts="--disable-werror"
298 esac
299 build "binutils" "m68k-elf" "2.20.1" "" "$binopts"
300 build "gcc" "m68k-elf" "4.5.2" "" "--with-arch=cf" "gmp mpfr mpc"
303 [Aa])
304 build "binutils" "arm-elf" "2.16.1"
305 build "gcc" "arm-elf" "4.0.3" "rockbox-multilibs-arm-elf-gcc-4.0.3_3.diff"
308 [Ee])
309 binopts=""
310 gccopts=""
311 case $system in
312 Darwin)
313 binopts="--disable-nls --disable-werror"
314 gccopts="--disable-nls"
316 esac
317 build "binutils" "arm-elf-eabi" "2.20.1" "binutils-2.20.1-ld-thumb-interwork-long-call.diff" "$binopts"
318 build "gcc" "arm-elf-eabi" "4.4.4" "rockbox-multilibs-noexceptions-arm-elf-eabi-gcc-4.4.2_1.diff" "$gccopts" "gmp mpfr"
322 echo "ROCKBOXDEV: Unsupported architecture option: $arch"
323 exit
325 esac
326 done
328 echo ""
329 echo "ROCKBOXDEV: Done!"
330 echo ""
331 echo "ROCKBOXDEV: Make sure your PATH includes $prefix/bin"
332 echo ""