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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 366 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
releasever="or32-1.0rc1"
39
 
40
binutilsver="2.20.1"
41
binutils="binutils-$binutilsver.tar.bz2"
42 369 julius
binutils_url="http://mirrors.kernel.org/sources.redhat.com/binutils/releases"
43 366 julius
binutils_patch="binutils-$binutilsver-$releasever.patch.bz2"
44
binutils_patch_url="ftp://ocuser:oc@orsoc.se/toolchain"
45
 
46
newlibver="1.18.0"
47
newlib="newlib-$newlibver.tar.gz"
48
newlib_url="http://mirrors.kernel.org/sourceware/newlib"
49
newlib_patch="newlib-$newlibver-$releasever.patch.bz2"
50
newlib_patch_url="ftp://ocuser:oc@orsoc.se/toolchain"
51
 
52
gccver="4.5.1"
53
gcc="gcc-$gccver.tar.bz2"
54
gcc_url="http://mirrors.kernel.org/gnu/gcc/gcc-$gccver";
55
gcc_patch="gcc-$gccver-$releasever.patch.bz2"
56
gcc_patch_url="ftp://ocuser:oc@orsoc.se/toolchain"
57
 
58
gdbver="7.2"
59
gdb="gdb-$gdbver.tar.bz2"
60
gdb_url="http://mirrors.kernel.org/gnu/gdb";
61
gdb_patch="gdb-$gdbver-$releasever.patch.bz2"
62
gdb_patch_url="ftp://ocuser:oc@orsoc.se/toolchain"
63
 
64
# Options passed to all GNU tools during configure
65
or32configure="--disable-checking --enable-fast-install=N/A --disable-libssp --enable-languages=c,c++ --with-or1ksim=$prefix/or1ksim --with-newlib"
66
 
67
simver="0.5.0rc1"
68
sim="or1ksim-$simver.tar.bz2"
69
sim_url="ftp://ocuser:oc@orsoc.se/toolchain"
70
 
71
linuxver="2.6.34"
72
linux="linux-$linuxver.tar.bz2"
73
linux_url="http://www.kernel.org/pub/linux/kernel/v2.6"
74
linux_patch="linux-$linuxver-or32.patch.bz2"
75
linux_patch_url="ftp://ocuser:oc@orsoc.se/toolchain"
76
 
77
uclibcver="0.9.31"
78
uclibc="uClibc-$uclibcver.tar.bz2"
79
uclibc_url="http://www.uclibc.org/downloads"
80
uclibc_patch="uClibc-$uclibcver-or32.patch.bz2"
81 367 julius
uclibc_patch_url="ftp://ocuser:oc@orsoc.se/toolchain"
82 366 julius
uclibc_config="extra/Configs/defconfigs/or32"
83
 
84
# These are the tools this script requires and depends upon.
85 370 julius
reqtools="gcc bzip2 make patch file"
86 366 julius
 
87
##############################################################################
88
# Functions:
89
 
90
findtool(){
91
  file="$1"
92
 
93
  IFS=":"
94
  for path in $PATH
95
  do
96
    # echo "Checks for $file in $path" >&2
97
    if test -f "$path/$file"; then
98
      echo "$path/$file"
99
      return
100
    fi
101
  done
102
}
103
 
104
getfile() {
105
  # $1 file
106
  # $2 URL
107
 
108
  tool=`findtool curl`
109
  if test -z "$tool"; then
110
    tool=`findtool wget`
111
    if test -n "$tool"; then
112
      # wget download
113
      echo "CROSSBUILD: Downloading $2/$1 using wget"
114
      $tool -O "$dlwhere/$1" "$2/$1"
115
    fi
116
  else
117
     # curl download
118
      echo "CROSSBUILD: Downloading $2/$1 using curl"
119
     $tool -Lo "$dlwhere/$1" "$2/$1"
120
  fi
121
 
122
  if [ $? -ne 0 ] ; then
123
      echo "CROSSBUILD: couldn't download the file!"
124
      echo "CROSSBUILD: check your internet connection"
125
      exit
126
  fi
127
 
128
  if test -z "$tool"; then
129
    echo "CROSSBUILD: No downloader tool found!"
130
    echo "CROSSBUILD: Please install curl or wget and re-run the script"
131
    exit
132
  fi
133
}
134
 
135
extract_tool() {
136
    toolname="$1"
137
    version="$2"
138
    file="$3"
139
 
140
    cd $builddir
141
 
142
#    if [ ! -d $toolname-$version ]; then
143
        echo "CROSSBUILD: extracting $file"
144
        if [ `file $dlwhere/$file | grep -c bzip2` -ne 0 ]; then
145
            tar xjf $dlwhere/$file
146
        fi
147
        if [ `file $dlwhere/$file | grep -c gzip` -ne 0 ]; then
148
            tar xzf $dlwhere/$file
149
        fi
150
 #   else
151
#       echo "CROSSBUILD: $file already extracted"
152
#    fi
153
 
154
}
155
 
156
patch_tool() {
157
    toolname="$1"
158
    version="$2"
159
    patch="$3"
160
 
161
    # do we have a patch?
162
    if test -n "$patch"; then
163
        echo "CROSSBUILD: applying patch $patch"
164
 
165
        # apply the patch
166
        (cd $builddir/$toolname-$version && bzcat "$dlwhere/$patch" | patch -p1)
167
 
168
        # check if the patch applied cleanly
169
        if [ $? -gt 0 ]; then
170
            echo "CROSSBUILD: failed to apply patch $patch"
171
            exit
172
        fi
173
    fi
174
 
175
}
176
 
177
 
178
download_extract_patch () {
179
    toolname="$1"
180
    version="$2"
181
    file="$3"
182
    file_url="$4"
183
    patch="$5"
184
    patch_url="$6"
185
 
186
    if test -f "$dlwhere/$file"; then
187
        echo "CROSSBUILD: $file already downloaded"
188
    else
189
        getfile "$file" "$file_url"
190
    fi
191
 
192
    if test -n "$patch"; then
193
        if test -f "$dlwhere/$patch"; then
194
            echo "CROSSBUILD: $patch already downloaded"
195
        else
196
            getfile "$patch" "$patch_url"
197
        fi
198
    fi
199
 
200
    extract_tool "$toolname" "$version" "$file"
201
 
202
    patch_tool "$toolname" "$version" "$patch"
203
 
204
 }
205
 
206
build_gnu_tool() {
207
    toolname="$1"
208
    version="$2"
209
    file="$3"
210
    file_url="$4"
211
    patch="$5"
212
    patch_url="$6"
213
    configure_prefix="$7"
214
    configure_params="$8"
215
 
216
    download_extract_patch "$toolname" "$version" "$file" "$file_url" "$patch" \
217
        "$patch_url"
218
 
219
    cd $builddir
220
 
221
    echo "CROSSBUILD: mkdir build-$toolname"
222
    mkdir -p build-$toolname
223
    echo "CROSSBUILD: cd build-$toolname"
224
    cd build-$toolname
225
    echo "CROSSBUILD: $toolname/configure"
226
    echo "CROSSBUILD: "../$toolname-$version/configure --target=$target \
227
        --prefix=$configure_prefix \
228
        --with-pkgversion=$releasever-built-`date +%Y%m%d` \
229
        --with-bugurl=http://www.opencores.org/ \
230
        "$configure_params"
231
    ../$toolname-$version/configure --target=$target \
232
        --prefix=$configure_prefix \
233
        --with-pkgversion=$releasever-built-`date +%Y%m%d` \
234
        --with-bugurl=http://www.opencores.org/ \
235
        $configure_params
236
    echo "CROSSBUILD: $toolname/make"
237
    $make
238
    echo "CROSSBUILD: $toolname/make install"
239
    $make install
240
}
241
 
242
# For now, just prep the GCC path, extract newlib, link in newlib and libgloss
243
# paths.
244
prepare_gcc() {
245
    prepare_gccver="$1"
246
    file="$2"
247
    newlibver="$3"
248
    file_url="$4"
249
    patch="$5"
250
    patch_url="$6"
251
 
252
    download_extract_patch "newlib" "$newlibver" "$file" "$file_url" "$patch" \
253
        "$patch_url"
254
 
255
    cd $builddir
256
 
257
    echo "CROSSBUILD: creating GCC source directory"
258
 
259
    mkdir -p gcc-$prepare_gccver
260
 
261
    echo "CROSSBUILD: linking newlib and libgloss into GCC source directory"
262
    if [ ! -L gcc-$prepare_gccver/newlib ]; then
263
        ln -s $PWD/newlib-$newlibver/newlib $PWD/gcc-$prepare_gccver/newlib
264
    fi
265
 
266
    if [ ! -L gcc-$prepare_gccver/libgloss ]; then
267
        ln -s $PWD/newlib-$newlibver/libgloss $PWD/gcc-$prepare_gccver/libgloss
268
    fi
269
    echo "CROSSBUILD: newlib and libgloss linked into GCC source directory"
270
}
271
 
272
# Move newlib libraries and includes to own sysroot
273
post_gcc_install() {
274
 
275
    mkdir -p ${prefix}/or32-elf/newlib
276
    rm -rf ${prefix}/or32-elf/newlib-include
277
 
278
    if [ -d ${prefix}/or32-elf/include ]
279
    then
280
        mv ${prefix}/or32-elf/include \
281
            ${prefix}/or32-elf/newlib-include
282
    fi
283
 
284
    if [ -d ${prefix}/or32-elf/lib ]
285
    then
286
        afiles=`ls -1 ${prefix}/or32-elf/lib | grep '\.a' | head -1`
287
 
288
        if [ "x$afiles" != "x" ]
289
        then
290
            mv ${prefix}/or32-elf/lib/*.a ${prefix}/or32-elf/newlib
291
        fi
292
    fi
293
 
294
    if [ -f ${prefix}/or32-elf/lib/crt0.o ]
295
    then
296
        mv ${prefix}/or32-elf/lib/crt0.o ${prefix}/or32-elf/newlib
297
    fi
298
}
299
 
300
# Download, patch kernel, install headers to $prefix/$target
301
install_linux_headers() {
302
    file="$linux"
303
    file_url="$linux_url"
304
    patch="$linux_patch"
305
    patch_url="$linux_patch_url"
306
    toolname="linux"
307
    version=$linuxver
308
 
309
    download_extract_patch "$toolname" "$version" "$file" "$file_url" "$patch" \
310
        "$patch_url"
311
 
312
    cd $builddir/linux-$linuxver
313
 
314
    echo "CROSSBUILD: defconfig kernel"
315
    $make ARCH=or32 defconfig
316
    echo "CROSSBUILD: installing headers to $prefix/or32-elf"
317
    $make INSTALL_HDR_PATH=$prefix/$target headers_install
318
}
319
 
320
build_uclibc () {
321
    file="$uclibc"
322 370 julius
    file_url="$uclibc_url"
323 366 julius
    patch="$uclibc_patch"
324
    patch_url="$uclibc_patch_url"
325
    toolname="uClibc"
326
    version=$uclibcver
327
 
328
    download_extract_patch "$toolname" "$version" "$file" "$file_url" "$patch" \
329
        "$patch_url"
330
 
331
    cd $builddir
332
 
333
    cd uClibc-$uclibcver
334
    # Substitute appropriate paths for kernel headers and install path
335
    echo "CROSSBUILD: configuring .config for install path"
336
    # Create a single variable with all paths expanded
337
    kheaders="KERNEL_HEADERS=\\\"$prefix\\/$target\\/include\\\""
338
    # In-place SED
339
    sed -i -e "s|KERNEL_HEADERS.*|$kheaders|g" $uclibc_config
340
    develprefix="DEVEL_PREFIX=\\\"$prefix\\/$target\\\""
341
    sed -i -e "s|DEVEL_PREFIX.*|$develprefix|g" $uclibc_config
342
 
343
    echo "CROSSBUILD: defconfig uClibc"
344
    $make ARCH=or32 defconfig
345
    echo "CROSSBUILD: building uClibc"
346
    $make
347
    echo "CROSSBUILD: installing uClibc"
348
    $make ARCH=or32 all
349
    $make install
350
 # TODO - maybe move uClibc's libc.a where GCC can find it ($prefix/$target/lib)
351
    echo "CROSSBUILD: uClibc build complete"
352
 
353
}
354
 
355
##############################################################################
356
# Code:
357
 
358
for t in $reqtools; do
359
  tool=`findtool $t`
360
  if test -z "$tool"; then
361
    echo "CROSSBUILD: \"$t\" is required for this script to work."
362
    echo "CROSSBUILD: Please install \"$t\" and re-run the script."
363
    exit
364
  fi
365
done
366
 
367
# Verify build directory or create it
368
if test -d $builddir; then
369
    if test ! -w $builddir; then
370
        echo "CROSSBUILD: ERROR: No write permissions for the build directory!"
371
        exit
372
    fi
373
else
374
    mkdir -p $builddir
375
fi
376
 
377
# Verify download directory or create it
378
if test -d "$dlwhere"; then
379
  if ! test -w "$dlwhere"; then
380
    echo "CROSSBUILD: $dlwhere exists, but doesn't seem to be writable for you"
381
    exit
382
  fi
383
else
384
  mkdir -p $dlwhere
385
  if test $? -ne 0; then
386
    echo "CROSSBUILD: $dlwhere is missing and we failed to create it!"
387
    exit
388
  fi
389
  echo "CROSSBUILD: $dlwhere has been created"
390
fi
391
 
392
# Verify installation directory
393
if test ! -d $prefix; then
394
  mkdir -p $prefix
395
  if test $? -ne 0; then
396
    echo "CROSSBUILD: $prefix is missing and we failed to create it!"
397
    exit
398
  fi
399
fi
400
if test ! -w $prefix; then
401
  echo "CROSSBUILD: ERROR: This script is set to install in $prefix but has no write permissions for it"
402
  echo "CROSSBUILD: Please fix this and re-run this script"
403
  exit
404
fi
405
 
406
echo "CROSSBUILD: Download dir: $dlwhere"
407
echo "CROSSBUILD: Build dir   : $builddir"
408
echo "CROSSBUILD: Install dir : $prefix"
409
 
410
### start the builds
411
 
412 371 julius
build_gnu_tool "or1ksim" "$simver" "$sim" "$sim_url" "" "" "$prefix/or1ksim" "--enable-ethphy"
413 366 julius
 
414
build_gnu_tool "binutils" "$binutilsver" "$binutils" "$binutils_url" "$binutils_patch" "$binutils_patch_url" "$prefix" "$or32configure"
415
 
416
PATH="$prefix/bin:${PATH}" # add binutils to $PATH for gcc build
417
 
418
prepare_gcc "$gccver" "$newlib" "$newlibver" "$newlib_url" "$newlib_patch" "$newlib_patch_url"
419
 
420
build_gnu_tool "gcc" "$gccver" "$gcc" "$gcc_url" "$gcc_patch" "$gcc_patch_url" "$prefix" "$or32configure"
421
 
422
post_gcc_install
423
 
424
build_gnu_tool "gdb" "$gdbver" "$gdb" "$gdb_url" "$gdb_patch" "$gdb_patch_url" "$prefix" "$or32configure"
425
 
426
install_linux_headers
427
 
428
build_uclibc
429
 
430
### builds done
431
 
432
#echo "CROSSBUILD: Deleting build folder"
433
#rm -rf $builddir
434
 
435
echo ""
436
echo "CROSSBUILD: Done!"
437
echo ""
438
echo "CROSSBUILD: Remove temporary build directory, $builddir, manually"
439
echo ""
440
echo "CROSSBUILD: Now add $prefix/bin and $prefix/or1ksim/bin to your \$PATH."
441
echo ""

powered by: WebSVN 2.1.0

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