summaryrefslogtreecommitdiffstats
path: root/tools/rockboxdev.sh
blob: b6419cf54d169317e75467c8ea8d850de62aff94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/bin/sh

# this is where this script will store downloaded files and check for already
# downloaded files
dlwhere="$HOME/tmp"

# will append the target string to the prefix dir mentioned here
# Note that the user running this script must be able to do make install in
# this given prefix directory. Also make sure that this given root dir
# exists.
prefix="/usr/local"

# The binutils version to use
binutils="2.16.1"

##############################################################################

findtool(){
  file="$1"

  IFS=":"
  for path in $PATH
  do
    # echo "checks for $file in $path" >&2
    if test -f "$path/$file"; then
      echo "$path/$file"
      return
    fi
  done
}

input() {
    read response
    echo $response
}

#$1 file
#$2 URL"root
getfile() {
  tool=`findtool curl`
  if test -z "$tool"; then
    tool=`findtool wget`
    if test -n "$tool"; then
      # wget download
      echo "download $2/$1 using wget"
      $tool -O $dlwhere/$1 $2/$1
    fi
  else
     # curl download
      echo "download $2/$1 using curl"
     $tool -Lo $dlwhere/$1 $2/$1
  fi
  if test -z "$tool"; then 
    echo "couldn't find downloader tool to use!"
    exit
  fi
  

}

echo "Pick target arch:"
echo "s. sh"
echo "m. m68k"
echo "a. arm"

arch=`input`

case $arch in
  [Ss])
    target="sh-elf"
    gccver="4.0.3"
    gccurl="http://www.rockbox.org/twiki/pub/Main/CrossCompiler"
    gccpatch="gcc-4.0.3-rockbox-1.diff"
    ;;
  [Mm])
    target="m68k-elf"
    gccver="3.4.6"
    ;;
  [Aa])
    target="arm-elf"
    gccver="4.0.3"
    ;;
  *)
    echo "unsupported"
    exit
    ;;
esac

# Verify download directory or create it
if test -d "$dlwhere"; then
  if test -w "$dlwhere"; then
    echo "Download directory $dlwhere seems to exist and is writable"
  else
    echo "$dlwhere exists, but doesn't seem to be writable for you"
    exit
  fi
else
  mkdir $dlwhere
  if test $? -ne 0; then
    echo "$dlwhere is missing and we failed to create it!"
    exit
  fi
  echo "$dlwhere has been created to store downloads in"
fi

if test -d build-rbdev; then
  echo "you have a build-rbdev dir already, please remove and rerun"
  exit
fi

bindir="$prefix/$target/bin"
echo "Summary:"
echo "Target: $target"
echo "gcc $gccver"
if test -n "$gccpatch"; then
  echo "gcc patch $gccpatch"
fi
echo "binutils $binutils"
echo "install in $prefix/$target"
echo ""
echo "Set your PATH to point to $bindir"


if test -f "$dlwhere/binutils-$binutils.tar.bz2"; then
  echo "binutils $binutils already downloaded"
else
  getfile binutils-$binutils.tar.bz2 ftp://ftp.gnu.org/pub/gnu/binutils
fi

if test -f "$dlwhere/gcc-$gccver.tar.bz2"; then
  echo "gcc $gccver already downloaded"
else
  getfile gcc-$gccver.tar.bz2 ftp://ftp.gnu.org/pub/gnu/gcc/gcc-$gccver
fi

if test -n "$gccpatch"; then
  if test -f "$dlwhere/$gccpatch"; then
    echo "$gccpatch already downloaded"
  else
    getfile "$gccpatch" "$gccurl"
  fi
fi

mkdir build-rbdev
cd build-rbdev
echo "extracting binutils"
tar xjf $dlwhere/binutils-$binutils.tar.bz2
echo "extracting gcc"
tar xf $dlwhere/gcc-$gccver.tar.bz2

if test -n "$gccpatch"; then
  echo "applying gcc patch"
  patch -p0 < "$dlwhere/$gccpatch"
fi

mkdir build-binu
cd build-binu
../binutils-$binutils/configure --target=$target --prefix=$prefix/$target
make
make install
PATH="${PATH}:$bindir"
SHELL=/bin/sh # seems to be needed by the gcc build in some cases

cd ../
mkdir build-gcc
cd build-gcc
../gcc-$gccver/configure --target=$target --prefix=$prefix/$target --enable-languages=c
make
make install

echo "done"