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 366

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

powered by: WebSVN 2.1.0

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