2001-04-10 23:31:50 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2002-12-13 17:58:51 +00:00
|
|
|
# This is my script for building a complete cross-compiler toolchain.
|
|
|
|
# It is based partly on Ray Kelm's script, which in turn was built on
|
|
|
|
# Mo Dejong's script for doing the same, but with some added fixes.
|
|
|
|
# The intent with this script is to build a cross-compiled version
|
|
|
|
# of the current MinGW environment.
|
2001-04-10 23:31:50 +00:00
|
|
|
#
|
2002-12-13 17:58:51 +00:00
|
|
|
# Updated by Sam Lantinga <slouken@libsdl.org>
|
2001-04-10 23:31:50 +00:00
|
|
|
|
|
|
|
# what flavor are we building?
|
|
|
|
|
|
|
|
TARGET=i386-mingw32msvc
|
|
|
|
|
|
|
|
# where does it go?
|
|
|
|
|
|
|
|
PREFIX=/usr/local/cross-tools
|
|
|
|
|
|
|
|
# you probably don't need to change anything from here down
|
|
|
|
|
|
|
|
TOPDIR=`pwd`
|
2002-12-13 17:58:51 +00:00
|
|
|
SRCDIR="$TOPDIR/source"
|
2001-04-10 23:31:50 +00:00
|
|
|
|
2002-12-13 17:58:51 +00:00
|
|
|
# These are the files from the MinGW 1.1 release
|
2001-04-10 23:31:50 +00:00
|
|
|
|
2002-12-13 17:58:51 +00:00
|
|
|
MINGW_URL=http://unc.dl.sourceforge.net/sourceforge/mingw
|
2003-08-15 21:26:44 +00:00
|
|
|
GCC=gcc-3.2.3-20030504-1
|
|
|
|
GCC_ARCHIVE=$GCC-src.tar.gz
|
2002-12-13 17:58:51 +00:00
|
|
|
GCC_PATCH=""
|
2003-08-15 21:26:44 +00:00
|
|
|
BINUTILS=binutils-2.13.90-20030111-1
|
2004-01-15 04:04:55 +00:00
|
|
|
BINUTILS_PATCH=binutils-2.13.90-20030111-1-flex.diff
|
2002-12-13 17:58:51 +00:00
|
|
|
BINUTILS_ARCHIVE=$BINUTILS-src.tar.gz
|
2004-01-15 04:04:55 +00:00
|
|
|
MINGW=mingw-runtime-3.2
|
2002-12-13 17:58:51 +00:00
|
|
|
MINGW_ARCHIVE=$MINGW.tar.gz
|
2004-01-15 04:04:55 +00:00
|
|
|
W32API=w32api-2.4
|
2002-12-13 17:58:51 +00:00
|
|
|
W32API_ARCHIVE=$W32API.tar.gz
|
2001-04-10 23:31:50 +00:00
|
|
|
|
2002-12-13 17:58:51 +00:00
|
|
|
# These are the files from the SDL website
|
2002-12-12 05:13:56 +00:00
|
|
|
|
2004-01-15 04:04:55 +00:00
|
|
|
TANIWHA_URL=http://quakeforge.net/~taniwha
|
2002-12-13 17:58:51 +00:00
|
|
|
SDL_URL=http://www.libsdl.org/extras/win32/common
|
|
|
|
OPENGL_ARCHIVE=opengl-devel.tar.gz
|
|
|
|
DIRECTX_ARCHIVE=directx-devel.tar.gz
|
2001-04-10 23:31:50 +00:00
|
|
|
|
|
|
|
# need install directory first on the path so gcc can find binutils
|
|
|
|
|
|
|
|
PATH="$PREFIX/bin:$PATH"
|
|
|
|
|
|
|
|
#
|
|
|
|
# download a file from a given url, only if it is not present
|
|
|
|
#
|
|
|
|
|
|
|
|
download_file()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$SRCDIR"
|
2001-04-10 23:31:50 +00:00
|
|
|
if test ! -f $1 ; then
|
|
|
|
echo "Downloading $1"
|
2002-12-13 17:58:51 +00:00
|
|
|
wget "$2/$1"
|
2001-04-10 23:31:50 +00:00
|
|
|
if test ! -f $1 ; then
|
|
|
|
echo "Could not download $1"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Found $1 in the srcdir $SRCDIR"
|
|
|
|
fi
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR"
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
download_files()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
mkdir -p "$SRCDIR"
|
2001-04-10 23:31:50 +00:00
|
|
|
|
|
|
|
# Make sure wget is installed
|
|
|
|
if test "x`which wget`" = "x" ; then
|
|
|
|
echo "You need to install wget."
|
|
|
|
exit 1
|
|
|
|
fi
|
2002-12-13 17:58:51 +00:00
|
|
|
download_file "$GCC_ARCHIVE" "$MINGW_URL"
|
|
|
|
download_file "$BINUTILS_ARCHIVE" "$MINGW_URL"
|
2004-01-15 04:04:55 +00:00
|
|
|
download_file "$BINUTILS_PATCH" "$TANIWHA_URL"
|
2002-12-13 17:58:51 +00:00
|
|
|
download_file "$MINGW_ARCHIVE" "$MINGW_URL"
|
|
|
|
download_file "$W32API_ARCHIVE" "$MINGW_URL"
|
|
|
|
download_file "$OPENGL_ARCHIVE" "$SDL_URL"
|
|
|
|
download_file "$DIRECTX_ARCHIVE" "$SDL_URL"
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install_libs()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
echo "Installing cross libs and includes"
|
|
|
|
mkdir -p "$PREFIX/$TARGET"
|
|
|
|
cd "$PREFIX/$TARGET"
|
|
|
|
gzip -dc "$SRCDIR/$MINGW_ARCHIVE" | tar xf -
|
|
|
|
gzip -dc "$SRCDIR/$W32API_ARCHIVE" | tar xf -
|
|
|
|
gzip -dc "$SRCDIR/$OPENGL_ARCHIVE" | tar xf -
|
|
|
|
gzip -dc "$SRCDIR/$DIRECTX_ARCHIVE" | tar xf -
|
|
|
|
cd "$TOPDIR"
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extract_binutils()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$SRCDIR"
|
|
|
|
rm -rf "$BINUTILS"
|
2001-04-10 23:31:50 +00:00
|
|
|
echo "Extracting binutils"
|
2002-12-13 17:58:51 +00:00
|
|
|
gzip -dc "$SRCDIR/$BINUTILS_ARCHIVE" | tar xf -
|
2004-01-15 04:04:55 +00:00
|
|
|
patch -p0 < binutils-2.13.90-20030111-1-flex.diff
|
2003-08-15 21:26:44 +00:00
|
|
|
mv binutils-2.13.90-20030111-1-src binutils-2.13.90-20030111-1
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR"
|
2002-12-12 05:13:56 +00:00
|
|
|
}
|
|
|
|
|
2001-04-10 23:31:50 +00:00
|
|
|
configure_binutils()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR"
|
|
|
|
rm -rf "binutils-$TARGET"
|
|
|
|
mkdir "binutils-$TARGET"
|
|
|
|
cd "binutils-$TARGET"
|
2001-04-10 23:31:50 +00:00
|
|
|
echo "Configuring binutils"
|
2002-12-13 17:58:51 +00:00
|
|
|
"$SRCDIR/$BINUTILS/configure" --prefix="$PREFIX" --target=$TARGET &> configure.log
|
|
|
|
cd "$TOPDIR"
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
build_binutils()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR/binutils-$TARGET"
|
2001-04-10 23:31:50 +00:00
|
|
|
echo "Building binutils"
|
|
|
|
make &> make.log
|
|
|
|
if test $? -ne 0; then
|
2002-12-13 17:58:51 +00:00
|
|
|
echo "make failed - log available: binutils-$TARGET/make.log"
|
2001-04-10 23:31:50 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR"
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install_binutils()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR/binutils-$TARGET"
|
2001-04-10 23:31:50 +00:00
|
|
|
echo "Installing binutils"
|
|
|
|
make install &> make-install.log
|
|
|
|
if test $? -ne 0; then
|
2002-12-13 17:58:51 +00:00
|
|
|
echo "install failed - log available: binutils-$TARGET/make-install.log"
|
2001-04-10 23:31:50 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR"
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extract_gcc()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$SRCDIR"
|
|
|
|
rm -rf "$GCC"
|
2001-04-10 23:31:50 +00:00
|
|
|
echo "Extracting gcc"
|
2002-12-13 17:58:51 +00:00
|
|
|
gzip -dc "$SRCDIR/$GCC_ARCHIVE" | tar xf -
|
|
|
|
cd "$TOPDIR"
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
patch_gcc()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
if [ "$GCC_PATCH" != "" ]; then
|
|
|
|
echo "Patching gcc"
|
|
|
|
cd "$SRCDIR/$GCC"
|
|
|
|
patch -p1 < "$SRCDIR/$GCC_PATCH"
|
|
|
|
cd "$TOPDIR"
|
|
|
|
fi
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
configure_gcc()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR"
|
|
|
|
rm -rf "gcc-$TARGET"
|
|
|
|
mkdir "gcc-$TARGET"
|
|
|
|
cd "gcc-$TARGET"
|
2001-04-10 23:31:50 +00:00
|
|
|
echo "Configuring gcc"
|
2002-12-13 17:58:51 +00:00
|
|
|
"$SRCDIR/$GCC/configure" -v \
|
|
|
|
--prefix="$PREFIX" --target=$TARGET \
|
|
|
|
--with-headers="$PREFIX/$TARGET/include" \
|
|
|
|
--with-gnu-as --with-gnu-ld \
|
|
|
|
--without-newlib --disable-multilib &> configure.log
|
|
|
|
cd "$TOPDIR"
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
build_gcc()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR/gcc-$TARGET"
|
2001-04-10 23:31:50 +00:00
|
|
|
echo "Building gcc"
|
|
|
|
make LANGUAGES="c c++" &> make.log
|
|
|
|
if test $? -ne 0; then
|
2002-12-13 17:58:51 +00:00
|
|
|
echo "make failed - log available: gcc-$TARGET/make.log"
|
2001-04-10 23:31:50 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR"
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install_gcc()
|
|
|
|
{
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR/gcc-$TARGET"
|
2001-04-10 23:31:50 +00:00
|
|
|
echo "Installing gcc"
|
|
|
|
make LANGUAGES="c c++" install &> make-install.log
|
|
|
|
if test $? -ne 0; then
|
2002-12-13 17:58:51 +00:00
|
|
|
echo "install failed - log available: gcc-$TARGET/make-install.log"
|
2001-04-10 23:31:50 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2002-12-13 17:58:51 +00:00
|
|
|
cd "$TOPDIR"
|
|
|
|
}
|
|
|
|
|
|
|
|
final_tweaks()
|
|
|
|
{
|
|
|
|
echo "Finalizing installation"
|
|
|
|
|
|
|
|
# remove gcc build headers
|
|
|
|
rm -rf "$PREFIX/$TARGET/sys-include"
|
|
|
|
|
|
|
|
# make cc and c++ symlinks to gcc and g++
|
|
|
|
if [ ! -f "$PREFIX/$TARGET/bin/g++" ]; then
|
|
|
|
ln "$PREFIX/bin/$TARGET-g++" "$PREFIX/$TARGET/bin/g++"
|
|
|
|
fi
|
|
|
|
if [ ! -f "$PREFIX/$TARGET/bin/cc" ]; then
|
|
|
|
ln -s "gcc" "$PREFIX/$TARGET/bin/cc"
|
|
|
|
fi
|
|
|
|
if [ ! -f "$PREFIX/$TARGET/bin/c++" ]; then
|
|
|
|
ln -s "g++" "$PREFIX/$TARGET/bin/c++"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# strip all the binaries
|
|
|
|
ls "$PREFIX"/bin/* "$PREFIX/$TARGET"/bin/* | egrep -v '.dll$' |
|
|
|
|
while read file; do
|
|
|
|
strip "$file"
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Installation complete!"
|
2001-04-10 23:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
download_files
|
|
|
|
|
|
|
|
install_libs
|
|
|
|
|
|
|
|
extract_binutils
|
|
|
|
configure_binutils
|
|
|
|
build_binutils
|
|
|
|
install_binutils
|
|
|
|
|
|
|
|
extract_gcc
|
|
|
|
patch_gcc
|
|
|
|
configure_gcc
|
|
|
|
build_gcc
|
|
|
|
install_gcc
|
|
|
|
|
2002-12-13 17:58:51 +00:00
|
|
|
final_tweaks
|