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 801

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

powered by: WebSVN 2.1.0

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