Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # this is where this script will store downloaded files and check for already |
| 4 | # downloaded files |
| 5 | dlwhere="$HOME/tmp" |
| 6 | |
| 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" |
| 12 | |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 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="$HOME/build-rbdev" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 16 | |
| 17 | ############################################################################## |
| 18 | |
| 19 | findtool(){ |
| 20 | file="$1" |
| 21 | |
| 22 | IFS=":" |
| 23 | for path in $PATH |
| 24 | do |
| 25 | # echo "checks for $file in $path" >&2 |
| 26 | if test -f "$path/$file"; then |
| 27 | echo "$path/$file" |
| 28 | return |
| 29 | fi |
| 30 | done |
| 31 | } |
| 32 | |
| 33 | input() { |
| 34 | read response |
| 35 | echo $response |
| 36 | } |
| 37 | |
| 38 | #$1 file |
| 39 | #$2 URL"root |
| 40 | getfile() { |
| 41 | tool=`findtool curl` |
| 42 | if test -z "$tool"; then |
| 43 | tool=`findtool wget` |
| 44 | if test -n "$tool"; then |
| 45 | # wget download |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 46 | echo "ROCKBOXDEV: downloads $2/$1 using wget" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 47 | $tool -O $dlwhere/$1 $2/$1 |
| 48 | fi |
| 49 | else |
| 50 | # curl download |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 51 | echo "ROCKBOXDEV: downloads $2/$1 using curl" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 52 | $tool -Lo $dlwhere/$1 $2/$1 |
| 53 | fi |
| 54 | if test -z "$tool"; then |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 55 | echo "ROCKBOXDEV: couldn't find downloader tool to use!" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 56 | exit |
| 57 | fi |
| 58 | |
| 59 | |
| 60 | } |
| 61 | |
Daniel Stenberg | 9a3902f | 2006-05-29 22:23:00 +0000 | [diff] [blame] | 62 | ########################################################################### |
| 63 | # Verify download directory or create it |
| 64 | if test -d "$dlwhere"; then |
| 65 | if ! test -w "$dlwhere"; then |
| 66 | echo "$dlwhere exists, but doesn't seem to be writable for you" |
| 67 | exit |
| 68 | fi |
| 69 | else |
| 70 | mkdir $dlwhere |
| 71 | if test $? -ne 0; then |
| 72 | echo "$dlwhere is missing and we failed to create it!" |
| 73 | exit |
| 74 | fi |
| 75 | echo "$dlwhere has been created to store downloads in" |
| 76 | fi |
| 77 | |
| 78 | echo "Download directory: $dlwhere (edit script to change dir)" |
| 79 | echo "Install prefix: $prefix/[target] (edit script to change dir)" |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 80 | echo "Build dir: $builddir (edit script to change dir)" |
Daniel Stenberg | 9a3902f | 2006-05-29 22:23:00 +0000 | [diff] [blame] | 81 | |
| 82 | ########################################################################### |
| 83 | # Verify that we can write in the prefix dir, as otherwise we will hardly |
| 84 | # be able to install there! |
| 85 | if test ! -w $prefix; then |
| 86 | echo "WARNING: this script is set to install in $prefix but has no" |
| 87 | echo "WARNING: write permission to do so!" |
| 88 | fi |
| 89 | |
| 90 | |
| 91 | ########################################################################### |
| 92 | # If there's already a build dir, we don't overwrite it |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 93 | if test -d $builddir; then |
| 94 | echo "you have a $builddir dir already, please remove and rerun" |
Daniel Stenberg | 9a3902f | 2006-05-29 22:23:00 +0000 | [diff] [blame] | 95 | exit |
| 96 | fi |
| 97 | |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 98 | cleardir () { |
| 99 | # $1 is the name of the build dir |
| 100 | # delete the build dirs and the source dirs |
| 101 | rm -rf $1/build-gcc $1/build-binu $1/gcc* $1/binutils* |
| 102 | } |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 103 | |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 104 | buildone () { |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 105 | |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 106 | gccpatch="" # default is no gcc patch |
| 107 | gccver="4.0.3" # default gcc version |
| 108 | binutils="2.16.1" # The binutils version to use |
| 109 | |
Daniel Stenberg | b91b410 | 2006-08-13 18:27:31 +0000 | [diff] [blame] | 110 | system=`uname -s` |
| 111 | |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 112 | case $1 in |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 113 | [Ss]) |
| 114 | target="sh-elf" |
Daniel Stenberg | 7d1cd16 | 2006-05-25 23:44:51 +0000 | [diff] [blame] | 115 | gccurl="http://www.rockbox.org/twiki/pub/Main/CrossCompiler" |
| 116 | gccpatch="gcc-4.0.3-rockbox-1.diff" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 117 | ;; |
| 118 | [Mm]) |
| 119 | target="m68k-elf" |
| 120 | gccver="3.4.6" |
Daniel Stenberg | b91b410 | 2006-08-13 18:27:31 +0000 | [diff] [blame] | 121 | case $system in |
| 122 | CYGWIN* | Darwin) |
| 123 | gccurl="http://www.rockbox.org/twiki/pub/Main/CrossCompiler" |
| 124 | gccpatch="gcc-3.4.6.patch" |
| 125 | ;; |
| 126 | Linux) |
| 127 | ;; |
| 128 | *) |
| 129 | ;; |
| 130 | esac |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 131 | ;; |
| 132 | [Aa]) |
| 133 | target="arm-elf" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 134 | ;; |
| 135 | *) |
| 136 | echo "unsupported" |
| 137 | exit |
| 138 | ;; |
| 139 | esac |
| 140 | |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 141 | bindir="$prefix/$target/bin" |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 142 | if test -n $pathadd; then |
| 143 | pathadd="$pathadd:$bindir" |
| 144 | else |
| 145 | pathadd="$bindir" |
Daniel Stenberg | 7d1cd16 | 2006-05-25 23:44:51 +0000 | [diff] [blame] | 146 | fi |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 147 | |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 148 | mkdir $builddir |
| 149 | cd $builddir |
Daniel Stenberg | 9a3902f | 2006-05-29 22:23:00 +0000 | [diff] [blame] | 150 | |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 151 | summary="summary-$1" |
| 152 | |
| 153 | echo "== Summary ==" > $summary |
| 154 | echo "Target: $target" >> $summary |
| 155 | echo "gcc $gccver" >> $summary |
| 156 | if test -n "$gccpatch"; then |
| 157 | echo "gcc patch $gccpatch" >> $summary |
| 158 | fi |
| 159 | echo "binutils $binutils" >> $summary |
| 160 | echo "install in $prefix/$target" >> $summary |
| 161 | echo "when complete, make your PATH include $bindir" >> $summary |
| 162 | |
| 163 | cat $summary |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 164 | |
| 165 | if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then |
| 166 | echo "binutils $binutils already downloaded" |
| 167 | else |
| 168 | getfile binutils-$binutils.tar.bz2 ftp://ftp.gnu.org/pub/gnu/binutils |
| 169 | fi |
| 170 | |
| 171 | if test -f "$dlwhere/gcc-$gccver.tar.bz2"; then |
| 172 | echo "gcc $gccver already downloaded" |
| 173 | else |
| 174 | getfile gcc-$gccver.tar.bz2 ftp://ftp.gnu.org/pub/gnu/gcc/gcc-$gccver |
| 175 | fi |
| 176 | |
Daniel Stenberg | 7d1cd16 | 2006-05-25 23:44:51 +0000 | [diff] [blame] | 177 | if test -n "$gccpatch"; then |
| 178 | if test -f "$dlwhere/$gccpatch"; then |
| 179 | echo "$gccpatch already downloaded" |
| 180 | else |
| 181 | getfile "$gccpatch" "$gccurl" |
| 182 | fi |
| 183 | fi |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 184 | |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 185 | echo "ROCKBOXDEV: extracting binutils-$binutils in $builddir" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 186 | tar xjf $dlwhere/binutils-$binutils.tar.bz2 |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 187 | echo "ROCKBOXDEV: extracting gcc-$gccver in $builddir" |
Linus Nielsen Feltzing | ad7fe4f | 2006-05-30 10:21:13 +0000 | [diff] [blame] | 188 | tar xjf $dlwhere/gcc-$gccver.tar.bz2 |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 189 | |
Daniel Stenberg | 7d1cd16 | 2006-05-25 23:44:51 +0000 | [diff] [blame] | 190 | if test -n "$gccpatch"; then |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 191 | echo "ROCKBOXDEV: applying gcc patch" |
Daniel Stenberg | 7d1cd16 | 2006-05-25 23:44:51 +0000 | [diff] [blame] | 192 | patch -p0 < "$dlwhere/$gccpatch" |
| 193 | fi |
| 194 | |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 195 | echo "ROCKBOXDEV: mkdir build-binu" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 196 | mkdir build-binu |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 197 | echo "ROCKBOXDEV: cd build-binu" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 198 | cd build-binu |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 199 | echo "ROCKBOXDEV: binutils/configure" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 200 | ../binutils-$binutils/configure --target=$target --prefix=$prefix/$target |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 201 | echo "ROCKBOXDEV: binutils/make" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 202 | make |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 203 | echo "ROCKBOXDEV: binutils/make install to $prefix/$target" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 204 | make install |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 205 | cd .. # get out of build-binu |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 206 | PATH="${PATH}:$bindir" |
| 207 | SHELL=/bin/sh # seems to be needed by the gcc build in some cases |
| 208 | |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 209 | echo "ROCKBOXDEV: mkdir build-gcc" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 210 | mkdir build-gcc |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 211 | echo "ROCKBOXDEV: cd build-gcc" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 212 | cd build-gcc |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 213 | echo "ROCKBOXDEV: gcc/configure" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 214 | ../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 215 | echo "ROCKBOXDEV: gcc/make" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 216 | make |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 217 | echo "ROCKBOXDEV: gcc/make install to $prefix/$target" |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 218 | make install |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 219 | cd .. # get out of build-gcc |
| 220 | cd .. # get out of $builddir |
| 221 | |
| 222 | # end of buildone() function |
| 223 | } |
| 224 | |
| 225 | echo "" |
| 226 | echo "Select target arch:" |
Daniel Stenberg | 19fe37d | 2006-08-10 06:46:56 +0000 | [diff] [blame] | 227 | echo "s - sh (Archos models)" |
| 228 | echo "m - m68k (iriver h1x0/h3x0, ifp7x0 and iaudio)" |
| 229 | echo "a - arm (ipods, iriver H10, Sansa, etc)" |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 230 | echo "all - all three compilers" |
| 231 | |
| 232 | arch=`input` |
| 233 | |
| 234 | case $arch in |
| 235 | [Ss]) |
| 236 | buildone $arch |
| 237 | ;; |
| 238 | [Mm]) |
| 239 | buildone $arch |
| 240 | ;; |
| 241 | [Aa]) |
| 242 | buildone $arch |
| 243 | ;; |
| 244 | all) |
| 245 | echo "build ALL compilers!" |
| 246 | buildone s |
| 247 | cleardir $builddir |
| 248 | |
| 249 | buildone m |
| 250 | cleardir $builddir |
| 251 | |
| 252 | buildone a |
| 253 | |
| 254 | # show the summaries: |
| 255 | cat $builddir/summary-* |
| 256 | ;; |
| 257 | *) |
| 258 | echo "unsupported architecture option" |
| 259 | exit |
| 260 | ;; |
| 261 | esac |
Daniel Stenberg | cce0d65 | 2006-05-15 13:26:59 +0000 | [diff] [blame] | 262 | |
| 263 | echo "done" |
Daniel Stenberg | 9a3902f | 2006-05-29 22:23:00 +0000 | [diff] [blame] | 264 | echo "" |
Daniel Stenberg | 2731afa | 2006-05-30 08:38:02 +0000 | [diff] [blame] | 265 | echo "Make your PATH include $pathadd" |