Created
December 4, 2013 03:18
-
-
Save pefoley2/7781803 to your computer and use it in GitHub Desktop.
canada!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -e | |
set -o pipefail | |
TOPDIR=`pwd` | |
BUILD=`/usr/share/gnuconfig/config.guess` | |
HOST=$1 | |
TARGET=$2 | |
HOST_DIR=$TOPDIR/$HOST | |
TARGET_DIR=$TOPDIR/$TARGET | |
CROSS_DIR=$TOPDIR/cross-$HOST-$TARGET | |
export HOSTARCH=`echo $HOST | sed 's/-.*//'` | |
# TARGET_ARCH is used in make's deafult rules | |
export TARGETARCH=`echo $TARGET | sed 's/-.*//'` | |
if test -z "$HOST" -o -z "$TARGET"; then | |
echo "Error: must specify host and target" | |
echo "Usage: ./canadian.sh alpha-linux powerpc-linux" | |
exit 1 | |
fi | |
GCC=`wget -q http://ftp.gnu.org/pub/gnu/gcc -O - | sed -e '/folder/!d' -e 's/.*="gcc-//' -e 's/\/".*//' | tail -1` | |
MPFR=`wget -q http://ftp.gnu.org/pub/gnu/mpfr -O - | sed -e '/tar.xz"/!d' -e 's/.*mpfr-//' -e 's/\.tar.*//' | tail -1` | |
MPC=`wget -q http://ftp.gnu.org/pub/gnu/mpc -O - | sed -e '/tar.gz"/!d' -e 's/.*mpc-//' -e 's/\.tar.*//' | tail -1` | |
GMP=`wget -q ftp://ftp.gmplib.org/pub/ -O - | sed -e '/gmp-/!d' -e 's/.*gmp-//' -e 's#/.*##' | tail -1` | |
BINUTILS=`wget -q http://ftp.gnu.org/pub/gnu/binutils -O - | sed -e '/tar.bz2</!d' -e 's/.*binutils-//' -e 's/\.tar.*//' | tail -1` | |
GLIBC=`wget -q http://ftp.gnu.org/pub/gnu/glibc/?C=M -O - | sed -e '/xz"/!d' -e 's/.*glibc-//' -e 's/\.tar.*//' -e '/ports/d' | tail -1` | |
LINUX=`wget -q http://kernel.org/pub/linux/kernel/v3.x -O - | sed -e '/tar.xz"/!d' -e 's/.*linux-//' -e 's/\.tar.*//' | sort | tail -1` | |
wget -qN -P tarballs http://ftp.gnu.org/pub/gnu/gcc/gcc-$GCC/gcc-$GCC.tar.bz2 \ | |
http://ftp.gnu.org/pub/gnu/binutils/binutils-$BINUTILS.tar.bz2 \ | |
http://ftp.gnu.org/pub/gnu/mpfr/mpfr-$MPFR.tar.xz \ | |
http://ftp.gnu.org/pub/gnu/mpc/mpc-$MPC.tar.gz \ | |
ftp://ftp.gmplib.org/pub/gmp-$GMP/gmp-$GMP.tar.xz \ | |
http://ftp.gnu.org/pub/gnu/glibc/glibc-$GLIBC.tar.xz \ | |
http://kernel.org/pub/linux/kernel/v3.x/linux-$LINUX.tar.xz | |
OLDTAR=`find tarballs/* -not \( -name gcc-$GCC.tar.bz2 -o -name \ | |
binutils-$BINUTILS.tar.bz2 -o -name glibc-$GLIBC.tar.xz \ | |
-o -name mpc-$MPC.tar.gz -o -name mpfr-$MPFR.tar.xz \ | |
-o -name gmp-$GMP.tar.xz -o -name linux-$LINUX.tar.xz \)` | |
[ -z "$OLDTAR" ] || rm -rf src $OLDTAR | |
unpack() | |
{ | |
mkdir -p src/{gcc/{gmp,mpc,mpfr},binutils,glibc,linux} | |
tar xf tarballs/gcc-$GCC.tar.bz2 --strip-component=1 -C src/gcc | |
tar xf tarballs/gmp-$GMP.tar.xz --strip-component=1 -C src/gcc/gmp | |
tar xf tarballs/mpc-$MPC.tar.gz --strip-component=1 -C src/gcc/mpc | |
tar xf tarballs/mpfr-$MPFR.tar.xz --strip-component=1 -C src/gcc/mpfr | |
tar xf tarballs/binutils-$BINUTILS.tar.bz2 --strip-component=1 -C src/binutils | |
tar xf tarballs/glibc-$GLIBC.tar.xz --strip-component=1 -C src/glibc | |
tar xf tarballs/linux-$LINUX.tar.xz --strip-component=1 -C src/linux | |
for p in mpfr gmp; do | |
patch -p0 <patches/$p.patch | |
done | |
} | |
conf() | |
{ | |
src=$1 | |
shift | |
work=$1 | |
shift | |
mkdir -p $DIR/{work,logs}/$work | |
cd $DIR/work/$work | |
test -e Makefile || PATH="$CROSS_PATH" $TOPDIR/src/$src/configure \ | |
--build=$BUILD $@ |& tee $DIR/logs/$work/config.log | |
} | |
build() | |
{ | |
work=$1 | |
shift | |
PATH="$CROSS_PATH" make -j4 -C $DIR/work/$work $@ \ | |
|& tee $DIR/logs/$work/build.log | |
} | |
install() | |
{ | |
work=$1 | |
shift | |
PATH="$CROSS_PATH" make -j4 -C $DIR/work/$work $@ \ | |
|& tee $DIR/logs/$work/install.log | |
} | |
gen() | |
{ | |
if [ "$1" = "$HOST" ]; then | |
TRIPLE=$1 | |
DIR=$HOST_DIR | |
ARCH=$HOSTARCH | |
HOST_ARGS="--host=$HOST" | |
TARGET_ARGS="--target=$HOST" | |
CROSS_PATH="$PATH:$DIR/install/bin" | |
elif [ "$1" = "$TARGET" ]; then | |
TRIPLE=$1 | |
DIR=$TARGET_DIR | |
ARCH=$TARGETARCH | |
HOST_ARGS="--host=$TARGET" | |
TARGET_ARGS="--target=$TARGET" | |
CROSS_PATH="$PATH:$DIR/install/bin" | |
else | |
TRIPLE=$TARGET | |
DIR=$CROSS_DIR | |
ARCH=$TARGETARCH | |
HOST_ARGS="--host=$TARGET" | |
TARGET_ARGS="--host=$HOST --target=$TARGET" | |
CROSS_PATH="$PATH:$HOST_DIR/install/bin:$TARGET_DIR/install/bin" | |
fi | |
conf binutils binutils $TARGET_ARGS --prefix=$DIR/install --disable-nls | |
build binutils | |
install binutils install | |
conf gcc gcc $TARGET_ARGS --prefix=$DIR/install --disable-nls \ | |
--disable-shared --enable-languages=c | |
build gcc all-gcc | |
install gcc install-gcc | |
mkdir -p $DIR/{work,logs}/linux | |
ARCH=$ARCH make -j4 -C $TOPDIR/src/linux O=$DIR/work/linux headers_install \ | |
INSTALL_HDR_PATH=$DIR/install/$TRIPLE |& tee $DIR/logs/linux/build.log | |
conf glibc glibc $HOST_ARGS --prefix=$DIR/install/$TRIPLE \ | |
--with-headers=$DIR/install/$TRIPLE/include \ | |
--includedir=$DIR/install/$TRIPLE/sys-include \ | |
libc_cv_forced_unwind=yes libc_cv_ssp=no #HACK | |
install glibc install-headers | |
touch $DIR/install/$TRIPLE/sys-include/gnu/stubs.h #HACK | |
build gcc all-target-libgcc | |
install gcc install-target-libgcc | |
build glibc | |
install glibc install | |
conf gcc gcc2 $TARGET_ARGS --prefix=$DIR/install --disable-nls | |
build gcc2 | |
install gcc2 install | |
} | |
test -d src || unpack | |
gen $HOST | |
gen $TARGET | |
gen canadian |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment