diff options
Diffstat (limited to 'tools/rockboxdev.sh')
-rwxr-xr-x | tools/rockboxdev.sh | 453 |
1 files changed, 184 insertions, 269 deletions
diff --git a/tools/rockboxdev.sh b/tools/rockboxdev.sh index ffdaa21d02..82536df349 100755 --- a/tools/rockboxdev.sh +++ b/tools/rockboxdev.sh | |||
@@ -30,18 +30,14 @@ else | |||
30 | fi | 30 | fi |
31 | 31 | ||
32 | if [ -z $GNU_MIRROR ] ; then | 32 | if [ -z $GNU_MIRROR ] ; then |
33 | GNU_MIRROR=ftp://ftp.gnu.org/pub/gnu | 33 | GNU_MIRROR=http://mirrors.kernel.org/gnu |
34 | fi | 34 | fi |
35 | 35 | ||
36 | # If detection fails, override the value of make manually: | ||
37 | # make="make" | ||
38 | |||
39 | ############################################################################## | ||
40 | |||
41 | # | ||
42 | # These are the tools this script requires and depends upon. | 36 | # These are the tools this script requires and depends upon. |
43 | reqtools="gcc bzip2 make patch" | 37 | reqtools="gcc bzip2 make patch" |
44 | 38 | ||
39 | ############################################################################## | ||
40 | # Functions: | ||
45 | 41 | ||
46 | findtool(){ | 42 | findtool(){ |
47 | file="$1" | 43 | file="$1" |
@@ -92,306 +88,225 @@ getfile() { | |||
92 | fi | 88 | fi |
93 | } | 89 | } |
94 | 90 | ||
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 | ||
101 | fi | ||
102 | done | ||
103 | 91 | ||
104 | ########################################################################### | 92 | build() { |
105 | # Verify download directory or create it | 93 | toolname="$1" |
106 | if test -d "$dlwhere"; then | 94 | target="$2" |
107 | if ! test -w "$dlwhere"; then | 95 | version="$3" |
108 | echo "$dlwhere exists, but doesn't seem to be writable for you" | 96 | patch="$4" |
109 | exit | 97 | configure_params="$5" |
110 | fi | 98 | needs_gmp="$6" |
111 | else | ||
112 | mkdir $dlwhere | ||
113 | if test $? -ne 0; then | ||
114 | echo "$dlwhere is missing and we failed to create it!" | ||
115 | exit | ||
116 | fi | ||
117 | echo "$dlwhere has been created to store downloads in" | ||
118 | fi | ||
119 | 99 | ||
120 | echo "Download directory: $dlwhere (set RBDEV_DOWNLOAD to change dir)" | 100 | patch_url="http://www.rockbox.org/gcc" |
121 | echo "Install prefix: $prefix/[target] (set RBDEV_PREFIX to change dir)" | ||
122 | echo "Build dir: $builddir (set RBDEV_BUILD to change dir)" | ||
123 | 101 | ||
124 | ########################################################################### | 102 | case $toolname in |
125 | # Verify that the prefix dir exists and that we can write to it, | 103 | gcc) |
126 | # as otherwise we will hardly be able to install there! | 104 | file="gcc-core-$version.tar.bz2" |
127 | if test ! -d $prefix; then | 105 | url="$GNU_MIRROR/gcc/gcc-$version" |
128 | echo "ERROR: The installation destination does not exist." | 106 | ;; |
129 | echo "Please create it and re-run this script" | ||
130 | exit | ||
131 | fi | ||
132 | if test ! -w $prefix; then | ||
133 | echo "ERROR: This script is set to install in $prefix but has no write permissions for it" | ||
134 | echo "Please fix this and re-run this script" | ||
135 | exit | ||
136 | fi | ||
137 | 107 | ||
108 | binutils) | ||
109 | file="binutils-$version.tar.bz2" | ||
110 | url="$GNU_MIRROR/binutils" | ||
111 | ;; | ||
138 | 112 | ||
113 | *) | ||
114 | echo "ROCKBOXDEV: Bad toolname $toolname" | ||
115 | exit | ||
116 | ;; | ||
117 | esac | ||
118 | |||
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 | ||
124 | fi | ||
125 | else | ||
126 | mkdir -p $builddir | ||
127 | fi | ||
139 | 128 | ||
140 | cleardir () { | 129 | # download source tarball |
141 | # $1 is the name of the build dir | 130 | if test ! -f "$dlwhere/$file"; then |
142 | # $2 is the arch | 131 | getfile "$file" "$url" |
143 | # delete the build dirs and the source dirs | 132 | fi |
144 | echo "Cleaning up build folder" | ||
145 | rm -rf $1/build-gcc-$2 $1/build-binu-$2 | ||
146 | } | ||
147 | 133 | ||
148 | buildone () { | 134 | # download patch |
135 | if test -n "$patch"; then | ||
136 | if test ! -f "$dlwhere/$patch"; then | ||
137 | getfile "$patch" "$patch_url" | ||
138 | fi | ||
139 | fi | ||
149 | 140 | ||
150 | arch=$1 | 141 | cd $builddir |
151 | gccpatch="" # default is no gcc patch | ||
152 | gccver="4.0.3" # default gcc version | ||
153 | binutils="2.16.1" # The binutils version to use | ||
154 | gccconfigure="" #default is nothing added to configure | ||
155 | binutilsconf="" #default is nothing added to configure | ||
156 | gcctarget="" #default make target | ||
157 | gccinstalltarget="install" #default install target | ||
158 | 142 | ||
159 | system=`uname -s` | 143 | echo "ROCKBOXDEV: extracting $file" |
160 | gccurl="http://www.rockbox.org/gcc" | 144 | tar xjf $dlwhere/$file |
161 | |||
162 | case $arch in | ||
163 | [Ss]) | ||
164 | target="sh-elf" | ||
165 | gccpatch="gcc-4.0.3-rockbox-1.diff" | ||
166 | ;; | ||
167 | [Mm]) | ||
168 | target="m68k-elf" | ||
169 | gccver="3.4.6" | ||
170 | case $system in | ||
171 | CYGWIN* | Darwin | FreeBSD | Interix | SunOS) | ||
172 | gccpatch="gcc-3.4.6.patch" | ||
173 | ;; | ||
174 | Linux) | ||
175 | machine=`uname -m` | ||
176 | case $machine in | ||
177 | x86_64) | ||
178 | gccpatch="gcc-3.4.6-amd64.patch" | ||
179 | ;; | ||
180 | esac | ||
181 | ;; | ||
182 | *) | ||
183 | echo "Unknown host system $system detected - check necessity of" \ | ||
184 | "patch for ${target}-gcc $gccver and add it." | ||
185 | echo "Press enter to continue..." | ||
186 | read ignore | ||
187 | ;; | ||
188 | esac | ||
189 | ;; | ||
190 | [Aa]) | ||
191 | target="arm-elf" | ||
192 | gccpatch="rockbox-multilibs-arm-elf-gcc-4.0.3_3.diff" | ||
193 | ;; | ||
194 | [Ee]) | ||
195 | target="arm-elf-eabi" | ||
196 | gccpatch="rockbox-multilibs-noexceptions-arm-elf-eabi-gcc-4.4.2_1.diff" | ||
197 | gccver="4.4.4" | ||
198 | # needed to build a bare-metal gcc-4.4.x | ||
199 | gcctarget="all-gcc all-target-libgcc" | ||
200 | gccinstalltarget="install-gcc install-target-libgcc" | ||
201 | binutils="2.20.1" | ||
202 | ;; | ||
203 | [Ii]) | ||
204 | target="mipsel-elf" | ||
205 | gccver="4.1.2" | ||
206 | binutils="2.17" | ||
207 | gccconfigure="--disable-libssp" | ||
208 | binutilsconf="--disable-werror" | ||
209 | # necessary to make binutils build on gcc 4.3+ | ||
210 | case $system in | ||
211 | Interix) | ||
212 | gccpatch="gcc-4.1.2-interix.diff" | ||
213 | ;; | ||
214 | *) | ||
215 | ;; | ||
216 | esac | ||
217 | ;; | ||
218 | *) | ||
219 | echo "An unsupported architecture option: $arch" | ||
220 | exit | ||
221 | ;; | ||
222 | esac | ||
223 | 145 | ||
224 | bindir="$prefix/$target/bin" | 146 | # do we have a patch? |
225 | if test -n $pathadd; then | 147 | if test -n "$patch"; then |
226 | pathadd="$pathadd:$bindir" | 148 | echo "ROCKBOXDEV: applying patch $patch" |
227 | else | ||
228 | pathadd="$bindir" | ||
229 | fi | ||
230 | 149 | ||
231 | echo "" | 150 | # apply the patch |
232 | echo "In case you encounter a slow internet connection, you can use an alternative mirror." | 151 | (cd $builddir/$toolname-$version && patch -p1 < "$dlwhere/$patch") |
233 | echo "A list of other GNU mirrors is available here: http://www.gnu.org/prep/ftp.html" | ||
234 | echo "" | ||
235 | echo "Usage: GNU_MIRROR=[URL] ./rockboxdev.sh" | ||
236 | echo "" | ||
237 | echo "Example:" | ||
238 | echo "$ GNU_MIRROR=http://mirrors.kernel.org/gnu ./rockboxdev.sh" | ||
239 | echo "" | ||
240 | 152 | ||
241 | if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then | 153 | # check if the patch applied cleanly |
242 | echo "binutils $binutils already downloaded" | 154 | if [ $? -gt 0 ]; then |
243 | else | 155 | echo "ROCKBOXDEV: failed to apply patch $patch" |
244 | getfile binutils-$binutils.tar.bz2 $GNU_MIRROR/binutils | 156 | exit |
245 | fi | 157 | fi |
158 | fi | ||
246 | 159 | ||
247 | if test -f "$dlwhere/gcc-core-$gccver.tar.bz2"; then | 160 | # kludge to avoid having to install GMP and MPFR for new gcc |
248 | echo "gcc $gccver already downloaded" | 161 | if test -n "$needs_gmp"; then |
249 | else | 162 | if test ! -d gmp; then |
250 | getfile gcc-core-$gccver.tar.bz2 $GNU_MIRROR/gcc/gcc-$gccver | 163 | echo "ROCKBOXDEV: Getting GMP" |
251 | fi | 164 | getfile "gmp-5.0.1.tar.bz2" "$GNU_MIRROR/gmp" |
165 | tar xjf $dlwhere/gmp-5.0.1.tar.bz2 | ||
166 | ln -s gmp-5.0.1.tar.bz2 gmp | ||
167 | fi | ||
168 | |||
169 | if test ! -d mpfr; then | ||
170 | echo "ROCKBOXDEV: Getting MPFR" | ||
171 | getfile "mpfr-2.4.2.tar.bz2" "$GNU_MIRROR/mpfr" | ||
172 | tar xjf $dlwhere/mpfr-2.4.2.tar.bz2 | ||
173 | ln -s mpfr-2.4.2 mpfr | ||
174 | fi | ||
175 | fi | ||
252 | 176 | ||
253 | if test -n "$gccpatch"; then | 177 | echo "ROCKBOXDEV: mkdir build-$toolname" |
254 | if test -f "$dlwhere/$gccpatch"; then | 178 | mkdir build-$toolname |
255 | echo "$gccpatch already downloaded" | ||
256 | else | ||
257 | getfile "$gccpatch" "$gccurl" | ||
258 | fi | ||
259 | fi | ||
260 | 179 | ||
261 | ########################################################################### | 180 | echo "ROCKBOXDEV: cd build-$toolname" |
262 | # If there's already a build dir, we don't overwrite or delete it | 181 | cd build-$toolname |
263 | if test -d $builddir; then | ||
264 | if test ! -w $builddir; then | ||
265 | echo "ERROR: No write permissions for the build directory!" | ||
266 | exit | ||
267 | fi | ||
268 | else | ||
269 | mkdir -p $builddir | ||
270 | fi | ||
271 | 182 | ||
272 | cd $builddir | 183 | echo "ROCKBOXDEV: $toolname/configure" |
184 | ../$toolname-$version/configure --target=$target --prefix=$prefix --enable-languages=c --disable-libssp --disable-docs $configure_params | ||
273 | 185 | ||
274 | ########################################################################### | 186 | echo "ROCKBOXDEV: $toolname/make" |
275 | # Create a summary file for each toolchain, containing info about the version | 187 | $make -j8 |
276 | # and a remainder to append the compiler path to PATH | ||
277 | 188 | ||
278 | summary="summary-$1" | 189 | echo "ROCKBOXDEV: $toolname/make install" |
190 | $make install | ||
279 | 191 | ||
280 | echo "============================ Summary ============================" > $summary | 192 | rm -rf $builddir |
281 | echo "target: $target" >> $summary | 193 | } |
282 | echo "gcc version: $gccver" >> $summary | 194 | |
283 | if test -n "$gccpatch"; then | 195 | ############################################################################## |
284 | echo "gcc patch: $gccpatch" >> $summary | 196 | # Code: |
285 | fi | 197 | |
286 | echo "binutils: $binutils" >> $summary | 198 | # Verify required tools |
287 | echo "installation target: $prefix/$target" >> $summary | 199 | for t in $reqtools; do |
288 | echo "" >> $summary | 200 | tool=`findtool $t` |
289 | echo "When done, append $bindir to PATH" >> $summary | 201 | if test -z "$tool"; then |
290 | echo "=================================================================" >> $summary | 202 | echo "ROCKBOXDEV: \"$t\" is required for this script to work." |
291 | 203 | echo "ROCKBOXDEV: Please install \"$t\" and re-run the script." | |
292 | cat $summary | 204 | exit |
293 | |||
294 | echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir" | ||
295 | bunzip2 < $dlwhere/binutils-$binutils.tar.bz2 | tar xf - | ||
296 | echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir" | ||
297 | bunzip2 < $dlwhere/gcc-core-$gccver.tar.bz2 | tar xf - | ||
298 | |||
299 | if test -n "$gccpatch"; then | ||
300 | echo "ROCKBOXDEV: applying gcc patch" | ||
301 | # apply the patch and hope it runs well - don't be dependant on the | ||
302 | # exact gcc version, thus strip the gcc folder | ||
303 | (cd $builddir/gcc-$gccver && patch -p1 < "$dlwhere/$gccpatch") | ||
304 | if [ $? -gt 0 ]; then # check if the applied cleanly | ||
305 | echo "ROCKBOXDEV: failed to apply the gcc patch" | ||
306 | exit | ||
307 | fi | 205 | fi |
206 | done | ||
207 | |||
208 | echo "Download directory : $dlwhere (set RBDEV_DOWNLOAD to change)" | ||
209 | echo "Install prefix : $prefix (set RBDEV_PREFIX to change)" | ||
210 | echo "Build dir : $builddir (set RBDEV_BUILD to change)" | ||
211 | echo "" | ||
212 | |||
213 | # Verify download directory | ||
214 | if test -d "$dlwhere"; then | ||
215 | if ! test -w "$dlwhere"; then | ||
216 | echo "ROCKBOXDEV: No write permission for $dlwhere" | ||
217 | exit | ||
218 | fi | ||
219 | else | ||
220 | mkdir $dlwhere | ||
221 | if test $? -ne 0; then | ||
222 | echo "ROCKBOXDEV: Failed creating directory $dlwhere" | ||
223 | exit | ||
224 | fi | ||
308 | fi | 225 | fi |
309 | 226 | ||
310 | echo "ROCKBOXDEV: mkdir build-binu-$1" | 227 | # Verify the prefix dir |
311 | mkdir build-binu-$1 | 228 | if test ! -d $prefix; then |
312 | echo "ROCKBOXDEV: cd build-binu-$1" | 229 | mkdir -p $prefix |
313 | cd build-binu-$1 | 230 | if test $? -ne 0; then |
314 | echo "ROCKBOXDEV: binutils/configure" | 231 | echo "ROCKBOXDEV: Failed creating directory $prefix" |
315 | # we undefine _FORTIFY_SOURCE to make the binutils built run fine on recent | 232 | exit |
316 | # Ubuntu installations | 233 | fi |
317 | CFLAGS=-U_FORTIFY_SOURCE ../binutils-$binutils/configure --target=$target --prefix=$prefix/$target $binutilsconf | 234 | fi |
318 | echo "ROCKBOXDEV: binutils/make" | 235 | if test ! -w $prefix; then |
319 | # We add -r when building binutils to fix compilation on OSX - Apple's make has | 236 | echo "ROCKBOXDEV: No write permission for $prefix" |
320 | # extra built-ins which cause problems. | 237 | exit |
321 | $make -r | 238 | fi |
322 | echo "ROCKBOXDEV: binutils/make install to $prefix/$target" | ||
323 | $make install | ||
324 | cd .. # get out of build-binu-$1 | ||
325 | PATH="$bindir:${PATH}" | ||
326 | SHELL=/bin/sh # seems to be needed by the gcc build in some cases | ||
327 | |||
328 | echo "ROCKBOXDEV: mkdir build-gcc-$1" | ||
329 | mkdir build-gcc-$1 | ||
330 | echo "ROCKBOXDEV: cd build-gcc-$1" | ||
331 | cd build-gcc-$1 | ||
332 | echo "ROCKBOXDEV: gcc/configure" | ||
333 | # we undefine _FORTIFY_SOURCE to make the gcc build go through fine on | ||
334 | # recent Ubuntu installations | ||
335 | CFLAGS=-U_FORTIFY_SOURCE ../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c $gccconfigure | ||
336 | echo "ROCKBOXDEV: gcc/make" | ||
337 | $make $gcctarget | ||
338 | echo "ROCKBOXDEV: gcc/make install to $prefix/$target" | ||
339 | $make $gccinstalltarget | ||
340 | cd .. # get out of build-gcc | ||
341 | cd .. # get out of $builddir | ||
342 | |||
343 | } # buildone() | ||
344 | 239 | ||
345 | echo "" | ||
346 | echo "Select target arch:" | 240 | echo "Select target arch:" |
347 | echo "s - sh (Archos models)" | 241 | echo "s - sh (Archos models)" |
348 | echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)" | 242 | echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)" |
349 | echo "a - arm (ipods, iriver H10, Sansa, etc)" | 243 | echo "a - arm (ipods, iriver H10, Sansa, etc)" |
350 | echo "e - arm-eabi (same as above, new testing toolchain)" | 244 | echo "e - arm-eabi (same as above, new gcc toolchain)" |
351 | echo "i - mips (Jz4740 and ATJ-based players)" | 245 | echo "i - mips (Jz4740 and ATJ-based players)" |
352 | echo "separate multiple targets with spaces" | 246 | echo "separate multiple targets with spaces" |
353 | echo "(Example: \"s m a\" will build sh, m86k and arm)" | 247 | echo "(Example: \"s m a\" will build sh, m86k and arm)" |
354 | echo "" | 248 | echo "" |
355 | 249 | ||
356 | selarch=`input` | 250 | selarch=`input` |
251 | system=`uname -s` | ||
252 | |||
253 | # add target dir to path to ensure the new binutils are used in gcc build | ||
254 | PATH="$prefix/bin:${PATH}" | ||
357 | 255 | ||
358 | for arch in $selarch | 256 | for arch in $selarch |
359 | do | 257 | do |
360 | echo "" | 258 | echo "" |
361 | case $arch in | 259 | case $arch in |
362 | [Ss]) | 260 | [Ss]) |
363 | buildone $arch | 261 | build "binutils" "sh-elf" "2.16.1" |
364 | cleardir $builddir $arch | 262 | build "gcc" "sh-elf" "4.0.3" "gcc-4.0.3-rockbox-1.diff" |
365 | ;; | 263 | ;; |
366 | [Ii]) | 264 | |
367 | buildone $arch | 265 | [Ii]) |
368 | cleardir $builddir $arch | 266 | build "binutils" "mips-elf" "2.17" "" "--disable-werror" |
369 | ;; | 267 | patch="" |
370 | [Mm]) | 268 | if [ "$system" = "Interix" ]; then |
371 | buildone $arch | 269 | patch="gcc-4.1.2-interix.diff" |
372 | cleardir $builddir $arch | 270 | fi |
373 | ;; | 271 | build "gcc" "mips-elf" "4.1.2" "$patch" |
374 | [Aa]) | 272 | ;; |
375 | buildone $arch | 273 | |
376 | cleardir $builddir $arch | 274 | [Mm]) |
377 | ;; | 275 | build "binutils" "m68k-elf" "2.16.1" |
378 | [Ee]) | 276 | patch="" |
379 | buildone $arch | 277 | case $system in |
380 | cleardir $builddir $arch | 278 | CYGWIN* | Darwin | FreeBSD | Interix | SunOS) |
381 | ;; | 279 | patch="gcc-3.4.6.patch" |
382 | *) | 280 | ;; |
383 | echo "An unsupported architecture option: $arch" | 281 | Linux) |
384 | exit | 282 | machine=`uname -m` |
385 | ;; | 283 | if [ "$machine" = "x86_64" ]; then |
386 | esac | 284 | patch="gcc-3.4.6-amd64.patch" |
387 | done | 285 | fi |
286 | ;; | ||
287 | esac | ||
288 | build "gcc" "m68k-elf" "3.4.6" "$patch" | ||
289 | ;; | ||
290 | |||
291 | [Aa]) | ||
292 | build "binutils" "arm-elf" "2.16.1" | ||
293 | build "gcc" "arm-elf" "4.0.3" "rockbox-multilibs-arm-elf-gcc-4.0.3_3.diff" | ||
294 | ;; | ||
295 | |||
296 | [Ee]) | ||
297 | build "binutils" "arm-elf-eabi" "2.20.1" | ||
298 | build "gcc" "arm-elf-eabi" "4.4.4" "rockbox-multilibs-noexceptions-arm-elf-eabi-gcc-4.4.2_1.diff" "" "needs_gmp" | ||
299 | ;; | ||
388 | 300 | ||
389 | # show the summaries: | 301 | *) |
390 | cat $builddir/summary-* | 302 | echo "ROCKBOXDEV: Unsupported architecture option: $arch" |
391 | rm $builddir/summary-* | 303 | exit |
304 | ;; | ||
305 | esac | ||
306 | done | ||
392 | 307 | ||
393 | echo "" | 308 | echo "" |
394 | echo "Done!" | 309 | echo "ROCKBOXDEV: Done!" |
395 | echo "" | 310 | echo "" |
396 | echo "Make your PATH include $pathadd" | 311 | echo "ROCKBOXDEV: Make sure your PATH includes $prefix/bin" |
397 | echo "" | 312 | echo "" |