#!/bin/sh
|
#!/bin/sh
|
|
|
# Abort execution as soon as an error is encountered
|
# Abort execution as soon as an error is encountered
|
# That way the script do not let the user think the process completed correctly
|
# That way the script do not let the user think the process completed correctly
|
# and leave the opportunity to fix the problem and restart compilation where
|
# and leave the opportunity to fix the problem and restart compilation where
|
# it stopped
|
# it stopped
|
set -e
|
set -e
|
|
|
# this is where this script will store downloaded files and check for already
|
# this is where this script will store downloaded files and check for already
|
# downloaded files
|
# downloaded files
|
dlwhere="${CROSSBUILD_DOWNLOAD:-$PWD/crossbuild-dl}"
|
dlwhere="${CROSSBUILD_DOWNLOAD:-$PWD/crossbuild-dl}"
|
|
|
# This directory is used to extract all files and to build everything in. It
|
# This directory is used to extract all files and to build everything in. It
|
# must not exist before this script is invoked (as a security measure).
|
# must not exist before this script is invoked (as a security measure).
|
# This dir should be an absolute path
|
# This dir should be an absolute path
|
builddir="${CROSSBUILD_BUILD:-$PWD/crossbuild-build}"
|
builddir="${CROSSBUILD_BUILD:-$PWD/crossbuild-build}"
|
|
|
# will append the target string to the prefix dir mentioned here
|
# 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
|
# 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
|
# this given prefix directory. Also make sure that this given root dir
|
# exists.
|
# exists.
|
prefix="${CROSSBUILD_PREFIX:-/usr/local}"
|
prefix="${CROSSBUILD_PREFIX:-/usr/local}"
|
|
|
# This script needs to use GNU Make. On Linux systems, GNU Make is invoked
|
# This script needs to use GNU Make. On Linux systems, GNU Make is invoked
|
# by running the "make" command, on most BSD systems, GNU Make is invoked
|
# by running the "make" command, on most BSD systems, GNU Make is invoked
|
# by running the "gmake" command. Set the "make" variable accordingly.
|
# by running the "gmake" command. Set the "make" variable accordingly.
|
if [ -f "`which gmake 2>/dev/null`" ]; then
|
if [ -f "`which gmake 2>/dev/null`" ]; then
|
make="gmake"
|
make="gmake"
|
else
|
else
|
make="make"
|
make="make"
|
fi
|
fi
|
|
|
##############################################################################
|
##############################################################################
|
# Variables:
|
# Variables:
|
|
|
target="or32-elf"
|
target="or32-elf"
|
|
|
gccver="4.2.2"
|
gccver="4.2.2"
|
gcc="gcc-core-$gccver.tar.bz2"
|
gcc="gcc-core-$gccver.tar.bz2"
|
gcc_url="http://mirrors.kernel.org/gnu/gcc/gcc-$gccver";
|
gcc_url="http://mirrors.kernel.org/gnu/gcc/gcc-$gccver";
|
gcc_patch="gcc-$gccver-or32-fp.patch.bz2"
|
gcc_patch="gcc-$gccver-or32-fp.patch.bz2"
|
gcc_patch_url="ftp://ocuser:oc@orsoc.se/toolchain"
|
gcc_patch_url="ftp://ocuser:oc@opencores.org/toolchain"
|
|
|
gdbver="6.8"
|
gdbver="6.8"
|
gdb="gdb-$gdbver.tar.bz2"
|
gdb="gdb-$gdbver.tar.bz2"
|
gdb_url="http://mirrors.kernel.org/gnu/gdb";
|
gdb_url="http://mirrors.kernel.org/gnu/gdb";
|
gdb_patch="or32-gdb-$gdbver-patch-2.5.bz2"
|
gdb_patch="or32-gdb-$gdbver-patch-2.5.bz2"
|
gdb_patch_url=$gcc_patch_url
|
gdb_patch_url=$gcc_patch_url
|
|
|
binutilsver="2.18.50" # snapshot
|
binutilsver="2.18.50" # snapshot
|
binutils="binutils-$binutilsver.tar.bz2"
|
binutils="binutils-$binutilsver.tar.bz2"
|
binutils_url="http://mirrors.kernel.org/sources.redhat.com/binutils/snapshots"
|
binutils_url="http://mirrors.kernel.org/sources.redhat.com/binutils/snapshots"
|
binutils_patch="binutils-$binutilsver.or32_fixed_patch-v2.2.bz2"
|
binutils_patch="binutils-$binutilsver.or32_fixed_patch-v2.2.bz2"
|
binutils_patch_url=$gcc_patch_url
|
binutils_patch_url=$gcc_patch_url
|
|
|
simver="0.4.0"
|
simver="0.4.0"
|
sim="or1ksim-$simver.tar.bz2"
|
sim="or1ksim-$simver.tar.bz2"
|
sim_url=$gcc_patch_url
|
sim_url=$gcc_patch_url
|
|
|
# These are the tools this script requires and depends upon.
|
# These are the tools this script requires and depends upon.
|
reqtools="gcc bzip2 make patch"
|
reqtools="gcc bzip2 make patch"
|
|
|
##############################################################################
|
##############################################################################
|
# Functions:
|
# Functions:
|
|
|
findtool(){
|
findtool(){
|
file="$1"
|
file="$1"
|
|
|
IFS=":"
|
IFS=":"
|
for path in $PATH
|
for path in $PATH
|
do
|
do
|
# echo "Checks for $file in $path" >&2
|
# echo "Checks for $file in $path" >&2
|
if test -f "$path/$file"; then
|
if test -f "$path/$file"; then
|
echo "$path/$file"
|
echo "$path/$file"
|
return
|
return
|
fi
|
fi
|
done
|
done
|
}
|
}
|
|
|
getfile() {
|
getfile() {
|
# $1 file
|
# $1 file
|
# $2 URL
|
# $2 URL
|
|
|
tool=`findtool curl`
|
tool=`findtool curl`
|
if test -z "$tool"; then
|
if test -z "$tool"; then
|
tool=`findtool wget`
|
tool=`findtool wget`
|
if test -n "$tool"; then
|
if test -n "$tool"; then
|
# wget download
|
# wget download
|
echo "CROSSBUILD: Downloading $2/$1 using wget"
|
echo "CROSSBUILD: Downloading $2/$1 using wget"
|
$tool -O "$dlwhere/$1" "$2/$1"
|
$tool -O "$dlwhere/$1" "$2/$1"
|
fi
|
fi
|
else
|
else
|
# curl download
|
# curl download
|
echo "CROSSBUILD: Downloading $2/$1 using curl"
|
echo "CROSSBUILD: Downloading $2/$1 using curl"
|
$tool -Lo "$dlwhere/$1" "$2/$1"
|
$tool -Lo "$dlwhere/$1" "$2/$1"
|
fi
|
fi
|
|
|
if [ $? -ne 0 ] ; then
|
if [ $? -ne 0 ] ; then
|
echo "CROSSBUILD: couldn't download the file!"
|
echo "CROSSBUILD: couldn't download the file!"
|
echo "CROSSBUILD: check your internet connection"
|
echo "CROSSBUILD: check your internet connection"
|
exit
|
exit
|
fi
|
fi
|
|
|
if test -z "$tool"; then
|
if test -z "$tool"; then
|
echo "CROSSBUILD: No downloader tool found!"
|
echo "CROSSBUILD: No downloader tool found!"
|
echo "CROSSBUILD: Please install curl or wget and re-run the script"
|
echo "CROSSBUILD: Please install curl or wget and re-run the script"
|
exit
|
exit
|
fi
|
fi
|
}
|
}
|
|
|
build() {
|
build() {
|
toolname="$1"
|
toolname="$1"
|
version="$2"
|
version="$2"
|
file="$3"
|
file="$3"
|
file_url="$4"
|
file_url="$4"
|
patch="$5"
|
patch="$5"
|
patch_url="$6"
|
patch_url="$6"
|
configure_prefix="$7"
|
configure_prefix="$7"
|
configure_params="$8"
|
configure_params="$8"
|
|
|
if test -f "$dlwhere/$file"; then
|
if test -f "$dlwhere/$file"; then
|
echo "CROSSBUILD: $file already downloaded"
|
echo "CROSSBUILD: $file already downloaded"
|
else
|
else
|
getfile "$file" "$file_url"
|
getfile "$file" "$file_url"
|
fi
|
fi
|
|
|
if test -n "$patch"; then
|
if test -n "$patch"; then
|
if test -f "$dlwhere/$patch"; then
|
if test -f "$dlwhere/$patch"; then
|
echo "CROSSBUILD: $patch already downloaded"
|
echo "CROSSBUILD: $patch already downloaded"
|
else
|
else
|
getfile "$patch" "$patch_url"
|
getfile "$patch" "$patch_url"
|
fi
|
fi
|
fi
|
fi
|
|
|
cd $builddir
|
cd $builddir
|
|
|
echo "CROSSBUILD: extracting $file"
|
echo "CROSSBUILD: extracting $file"
|
tar xjf $dlwhere/$file
|
tar xjf $dlwhere/$file
|
|
|
# do we have a patch?
|
# do we have a patch?
|
if test -n "$patch"; then
|
if test -n "$patch"; then
|
echo "CROSSBUILD: applying patch $patch"
|
echo "CROSSBUILD: applying patch $patch"
|
|
|
# apply the patch
|
# apply the patch
|
(cd $builddir/$toolname-$version && bzcat "$dlwhere/$patch" | patch -p1)
|
(cd $builddir/$toolname-$version && bzcat "$dlwhere/$patch" | patch -p1)
|
|
|
# check if the patch applied cleanly
|
# check if the patch applied cleanly
|
if [ $? -gt 0 ]; then
|
if [ $? -gt 0 ]; then
|
echo "CROSSBUILD: failed to apply patch $patch"
|
echo "CROSSBUILD: failed to apply patch $patch"
|
exit
|
exit
|
fi
|
fi
|
fi
|
fi
|
|
|
echo "CROSSBUILD: mkdir build-$toolname"
|
echo "CROSSBUILD: mkdir build-$toolname"
|
mkdir build-$toolname
|
mkdir build-$toolname
|
echo "CROSSBUILD: cd build-$toolname"
|
echo "CROSSBUILD: cd build-$toolname"
|
cd build-$toolname
|
cd build-$toolname
|
echo "CROSSBUILD: $toolname/configure"
|
echo "CROSSBUILD: $toolname/configure"
|
echo "CROSSBUILD: "../$toolname-$version/configure --target=$target --prefix=$configure_prefix "$configure_params"
|
echo "CROSSBUILD: "../$toolname-$version/configure --target=$target --prefix=$configure_prefix "$configure_params"
|
../$toolname-$version/configure --target=$target --prefix=$configure_prefix $configure_params
|
../$toolname-$version/configure --target=$target --prefix=$configure_prefix $configure_params
|
echo "CROSSBUILD: $toolname/make"
|
echo "CROSSBUILD: $toolname/make"
|
$make -j8
|
$make -j8
|
echo "CROSSBUILD: $toolname/make install"
|
echo "CROSSBUILD: $toolname/make install"
|
$make install
|
$make install
|
}
|
}
|
|
|
##############################################################################
|
##############################################################################
|
# Code:
|
# Code:
|
|
|
for t in $reqtools; do
|
for t in $reqtools; do
|
tool=`findtool $t`
|
tool=`findtool $t`
|
if test -z "$tool"; then
|
if test -z "$tool"; then
|
echo "CROSSBUILD: \"$t\" is required for this script to work."
|
echo "CROSSBUILD: \"$t\" is required for this script to work."
|
echo "CROSSBUILD: Please install \"$t\" and re-run the script."
|
echo "CROSSBUILD: Please install \"$t\" and re-run the script."
|
exit
|
exit
|
fi
|
fi
|
done
|
done
|
|
|
# Verify build directory or create it
|
# Verify build directory or create it
|
if test -d $builddir; then
|
if test -d $builddir; then
|
if test ! -w $builddir; then
|
if test ! -w $builddir; then
|
echo "CROSSBUILD: ERROR: No write permissions for the build directory!"
|
echo "CROSSBUILD: ERROR: No write permissions for the build directory!"
|
exit
|
exit
|
fi
|
fi
|
else
|
else
|
mkdir -p $builddir
|
mkdir -p $builddir
|
fi
|
fi
|
|
|
# Verify download directory or create it
|
# Verify download directory or create it
|
if test -d "$dlwhere"; then
|
if test -d "$dlwhere"; then
|
if ! test -w "$dlwhere"; then
|
if ! test -w "$dlwhere"; then
|
echo "CROSSBUILD: $dlwhere exists, but doesn't seem to be writable for you"
|
echo "CROSSBUILD: $dlwhere exists, but doesn't seem to be writable for you"
|
exit
|
exit
|
fi
|
fi
|
else
|
else
|
mkdir -p $dlwhere
|
mkdir -p $dlwhere
|
if test $? -ne 0; then
|
if test $? -ne 0; then
|
echo "CROSSBUILD: $dlwhere is missing and we failed to create it!"
|
echo "CROSSBUILD: $dlwhere is missing and we failed to create it!"
|
exit
|
exit
|
fi
|
fi
|
echo "CROSSBUILD: $dlwhere has been created"
|
echo "CROSSBUILD: $dlwhere has been created"
|
fi
|
fi
|
|
|
# Verify installation directory
|
# Verify installation directory
|
if test ! -d $prefix; then
|
if test ! -d $prefix; then
|
mkdir -p $prefix
|
mkdir -p $prefix
|
if test $? -ne 0; then
|
if test $? -ne 0; then
|
echo "CROSSBUILD: $prefix is missing and we failed to create it!"
|
echo "CROSSBUILD: $prefix is missing and we failed to create it!"
|
exit
|
exit
|
fi
|
fi
|
fi
|
fi
|
if test ! -w $prefix; then
|
if test ! -w $prefix; then
|
echo "CROSSBUILD: ERROR: This script is set to install in $prefix but has no write permissions for it"
|
echo "CROSSBUILD: ERROR: This script is set to install in $prefix but has no write permissions for it"
|
echo "CROSSBUILD: Please fix this and re-run this script"
|
echo "CROSSBUILD: Please fix this and re-run this script"
|
exit
|
exit
|
fi
|
fi
|
|
|
echo "CROSSBUILD: Download dir: $dlwhere"
|
echo "CROSSBUILD: Download dir: $dlwhere"
|
echo "CROSSBUILD: Build dir : $builddir"
|
echo "CROSSBUILD: Build dir : $builddir"
|
echo "CROSSBUILD: Install dir : $prefix"
|
echo "CROSSBUILD: Install dir : $prefix"
|
|
|
### start the builds
|
### start the builds
|
|
|
build "binutils" "$binutilsver" "$binutils" "$binutils_url" "$binutils_patch" "$binutils_patch_url" "$prefix" "--disable-checking"
|
build "binutils" "$binutilsver" "$binutils" "$binutils_url" "$binutils_patch" "$binutils_patch_url" "$prefix" "--disable-checking"
|
|
|
PATH="$prefix/bin:${PATH}" # add binutils to $PATH for gcc build
|
PATH="$prefix/bin:${PATH}" # add binutils to $PATH for gcc build
|
|
|
build "gcc" "$gccver" "$gcc" "$gcc_url" "$gcc_patch" "$gcc_patch_url" "$prefix" "--enable-languages=c --disable-libssp --with-local-prefix=$prefix/$target"
|
build "gcc" "$gccver" "$gcc" "$gcc_url" "$gcc_patch" "$gcc_patch_url" "$prefix" "--enable-languages=c --disable-libssp --with-local-prefix=$prefix/$target"
|
|
|
build "gdb" "$gdbver" "$gdb" "$gdb_url" "$gdb_patch" "$gdb_patch_url" "$prefix" "--disable-werror"
|
build "gdb" "$gdbver" "$gdb" "$gdb_url" "$gdb_patch" "$gdb_patch_url" "$prefix" "--disable-werror"
|
|
|
build "or1ksim" "$simver" "$sim" "$sim_url" "" "" "$prefix/or1ksim" "--enable-ethphy"
|
build "or1ksim" "$simver" "$sim" "$sim_url" "" "" "$prefix/or1ksim" "--enable-ethphy"
|
|
|
### builds done
|
### builds done
|
|
|
echo "CROSSBUILD: Deleting build folder"
|
echo "CROSSBUILD: Deleting build folder"
|
rm -rf $builddir
|
rm -rf $builddir
|
|
|
echo ""
|
echo ""
|
echo "CROSSBUILD: Done!"
|
echo "CROSSBUILD: Done!"
|
echo ""
|
echo ""
|
echo "CROSSBUILD: Now add $prefix/bin and $prefix/or1ksim/bin to your \$PATH."
|
echo "CROSSBUILD: Now add $prefix/bin and $prefix/or1ksim/bin to your \$PATH."
|
echo ""
|
echo ""
|
|
|