OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [toolchain_install_scripts/] [crossbuild.sh] - Blame information for rev 607

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 136 julius
#!/bin/sh
2
 
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
8
 
9
# this is where this script will store downloaded files and check for already
10
# downloaded files
11
dlwhere="${CROSSBUILD_DOWNLOAD:-$PWD/crossbuild-dl}"
12
 
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
# This dir should be an absolute path
16
builddir="${CROSSBUILD_BUILD:-$PWD/crossbuild-build}"
17
 
18
# will append the target string to the prefix dir mentioned here
19
# Note that the user running this script must be able to do make install in
20
# this given prefix directory. Also make sure that this given root dir
21
# exists.
22
prefix="${CROSSBUILD_PREFIX:-/usr/local}"
23
 
24
# This script needs to use GNU Make. On Linux systems, GNU Make is invoked
25
# by running the "make" command, on most BSD systems, GNU Make is invoked
26
# by running the "gmake" command. Set the "make" variable accordingly.
27
if [ -f "`which gmake 2>/dev/null`" ]; then
28
    make="gmake"
29
else
30
    make="make"
31
fi
32
 
33
##############################################################################
34
# Variables:
35
 
36
target="or32-elf"
37
 
38
gccver="4.2.2"
39
gcc="gcc-core-$gccver.tar.bz2"
40
gcc_url="http://mirrors.kernel.org/gnu/gcc/gcc-$gccver";
41
gcc_patch="gcc-$gccver-or32-fp.patch.bz2"
42 390 julius
gcc_patch_url="ftp://ocuser:oc@opencores.org/toolchain"
43 136 julius
 
44
gdbver="6.8"
45
gdb="gdb-$gdbver.tar.bz2"
46
gdb_url="http://mirrors.kernel.org/gnu/gdb";
47
gdb_patch="or32-gdb-$gdbver-patch-2.5.bz2"
48
gdb_patch_url=$gcc_patch_url
49
 
50
binutilsver="2.18.50" # snapshot
51
binutils="binutils-$binutilsver.tar.bz2"
52
binutils_url="http://mirrors.kernel.org/sources.redhat.com/binutils/snapshots"
53
binutils_patch="binutils-$binutilsver.or32_fixed_patch-v2.2.bz2"
54
binutils_patch_url=$gcc_patch_url
55
 
56
simver="0.4.0"
57
sim="or1ksim-$simver.tar.bz2"
58
sim_url=$gcc_patch_url
59
 
60
# These are the tools this script requires and depends upon.
61
reqtools="gcc bzip2 make patch"
62
 
63
##############################################################################
64
# Functions:
65
 
66
findtool(){
67
  file="$1"
68
 
69
  IFS=":"
70
  for path in $PATH
71
  do
72
    # echo "Checks for $file in $path" >&2
73
    if test -f "$path/$file"; then
74
      echo "$path/$file"
75
      return
76
    fi
77
  done
78
}
79
 
80
getfile() {
81
  # $1 file
82
  # $2 URL
83
 
84
  tool=`findtool curl`
85
  if test -z "$tool"; then
86
    tool=`findtool wget`
87
    if test -n "$tool"; then
88
      # wget download
89
      echo "CROSSBUILD: Downloading $2/$1 using wget"
90
      $tool -O "$dlwhere/$1" "$2/$1"
91
    fi
92
  else
93
     # curl download
94
      echo "CROSSBUILD: Downloading $2/$1 using curl"
95
     $tool -Lo "$dlwhere/$1" "$2/$1"
96
  fi
97
 
98
  if [ $? -ne 0 ] ; then
99
      echo "CROSSBUILD: couldn't download the file!"
100
      echo "CROSSBUILD: check your internet connection"
101
      exit
102
  fi
103
 
104
  if test -z "$tool"; then
105
    echo "CROSSBUILD: No downloader tool found!"
106
    echo "CROSSBUILD: Please install curl or wget and re-run the script"
107
    exit
108
  fi
109
}
110
 
111
build() {
112
    toolname="$1"
113
    version="$2"
114
    file="$3"
115
    file_url="$4"
116
    patch="$5"
117
    patch_url="$6"
118
    configure_prefix="$7"
119
    configure_params="$8"
120
 
121
    if test -f "$dlwhere/$file"; then
122
        echo "CROSSBUILD: $file already downloaded"
123
    else
124
        getfile "$file" "$file_url"
125
    fi
126
 
127
    if test -n "$patch"; then
128
        if test -f "$dlwhere/$patch"; then
129
            echo "CROSSBUILD: $patch already downloaded"
130
        else
131
            getfile "$patch" "$patch_url"
132
        fi
133
    fi
134
 
135
    cd $builddir
136
 
137
    echo "CROSSBUILD: extracting $file"
138
    tar xjf $dlwhere/$file
139
 
140
    # do we have a patch?
141
    if test -n "$patch"; then
142
        echo "CROSSBUILD: applying patch $patch"
143
 
144
        # apply the patch
145
        (cd $builddir/$toolname-$version && bzcat "$dlwhere/$patch" | patch -p1)
146
 
147
        # check if the patch applied cleanly
148
        if [ $? -gt 0 ]; then
149
            echo "CROSSBUILD: failed to apply patch $patch"
150
            exit
151
        fi
152
    fi
153
 
154
    echo "CROSSBUILD: mkdir build-$toolname"
155
    mkdir build-$toolname
156
    echo "CROSSBUILD: cd build-$toolname"
157
    cd build-$toolname
158
    echo "CROSSBUILD: $toolname/configure"
159
    echo "CROSSBUILD: "../$toolname-$version/configure --target=$target --prefix=$configure_prefix "$configure_params"
160
    ../$toolname-$version/configure --target=$target --prefix=$configure_prefix $configure_params
161
    echo "CROSSBUILD: $toolname/make"
162
    $make -j8
163
    echo "CROSSBUILD: $toolname/make install"
164
    $make install
165
}
166
 
167
##############################################################################
168
# Code:
169
 
170
for t in $reqtools; do
171
  tool=`findtool $t`
172
  if test -z "$tool"; then
173
    echo "CROSSBUILD: \"$t\" is required for this script to work."
174
    echo "CROSSBUILD: Please install \"$t\" and re-run the script."
175
    exit
176
  fi
177
done
178
 
179
# Verify build directory or create it
180
if test -d $builddir; then
181
    if test ! -w $builddir; then
182
        echo "CROSSBUILD: ERROR: No write permissions for the build directory!"
183
        exit
184
    fi
185
else
186
    mkdir -p $builddir
187
fi
188
 
189
# Verify download directory or create it
190
if test -d "$dlwhere"; then
191
  if ! test -w "$dlwhere"; then
192
    echo "CROSSBUILD: $dlwhere exists, but doesn't seem to be writable for you"
193
    exit
194
  fi
195
else
196
  mkdir -p $dlwhere
197
  if test $? -ne 0; then
198
    echo "CROSSBUILD: $dlwhere is missing and we failed to create it!"
199
    exit
200
  fi
201
  echo "CROSSBUILD: $dlwhere has been created"
202
fi
203
 
204
# Verify installation directory
205
if test ! -d $prefix; then
206
  mkdir -p $prefix
207
  if test $? -ne 0; then
208
    echo "CROSSBUILD: $prefix is missing and we failed to create it!"
209
    exit
210
  fi
211
fi
212
if test ! -w $prefix; then
213
  echo "CROSSBUILD: ERROR: This script is set to install in $prefix but has no write permissions for it"
214
  echo "CROSSBUILD: Please fix this and re-run this script"
215
  exit
216
fi
217
 
218
echo "CROSSBUILD: Download dir: $dlwhere"
219
echo "CROSSBUILD: Build dir   : $builddir"
220
echo "CROSSBUILD: Install dir : $prefix"
221
 
222
### start the builds
223
 
224
build "binutils" "$binutilsver" "$binutils" "$binutils_url" "$binutils_patch" "$binutils_patch_url" "$prefix" "--disable-checking"
225
 
226
PATH="$prefix/bin:${PATH}" # add binutils to $PATH for gcc build
227
 
228
build "gcc" "$gccver" "$gcc" "$gcc_url" "$gcc_patch" "$gcc_patch_url" "$prefix" "--enable-languages=c --disable-libssp --with-local-prefix=$prefix/$target"
229
 
230
build "gdb" "$gdbver" "$gdb" "$gdb_url" "$gdb_patch" "$gdb_patch_url" "$prefix" "--disable-werror"
231
 
232
build "or1ksim" "$simver" "$sim" "$sim_url" "" "" "$prefix/or1ksim" "--enable-ethphy"
233
 
234
### builds done
235
 
236
echo "CROSSBUILD: Deleting build folder"
237
rm -rf $builddir
238
 
239
echo ""
240
echo "CROSSBUILD: Done!"
241
echo ""
242
echo "CROSSBUILD: Now add $prefix/bin and $prefix/or1ksim/bin to your \$PATH."
243
echo ""

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.