132 lines
3.4 KiB
Bash
Executable File
132 lines
3.4 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
set -x
|
|
|
|
KERNEL_VERSION='5.4'
|
|
BINUTILS_VERSION='2.31.1'
|
|
GCC_VERSION='8.4.1-20200305'
|
|
GLIBC_VERSION='2.27-alt13'
|
|
|
|
KERNEL_SOURCE="/usr/src/kernel/sources/kernel-source-${KERNEL_VERSION}.tar"
|
|
BINUTILS_SOURCE="/usr/src/binutils-source/binutils-${BINUTILS_VERSION}.tar"
|
|
GCC_SOURCE="/usr/src/gcc-source/gcc-${GCC_VERSION}.tar"
|
|
GLIBC_SOURCE="/usr/src/glibc-source/glibc-${GLIBC_VERSION}.tar"
|
|
|
|
|
|
TARGET=aarch64-linux-gnu
|
|
|
|
GCC_MAJOR_VERSION="${GCC_VERSION%%.*}"
|
|
|
|
BUILDDIR="`pwd`/build"
|
|
SRCDIR="`pwd`/src"
|
|
INSTALLDIR="`pwd`/inst/altcross-gcc-${GCC_VERSION}"
|
|
SYSROOT=/$TARGET/libc
|
|
SYSROOTDIR="$INSTALLDIR/$SYSROOT"
|
|
|
|
mkdir -p -m755 "$SRCDIR"
|
|
cd "$SRCDIR"
|
|
|
|
tar xf "$KERNEL_SOURCE"
|
|
tar xf "$BINUTILS_SOURCE"
|
|
tar xf "$GCC_SOURCE"
|
|
tar xf "$GLIBC_SOURCE"
|
|
|
|
cd "gcc-${GCC_VERSION}"
|
|
sed -i contrib/download_prerequisites -e '/base_url=/s/ftp/http/'
|
|
./contrib/download_prerequisites
|
|
|
|
mkdir -p -m755 "$INSTALLDIR/bin"
|
|
export PATH="$INSTALLDIR/bin:/usr/lib/ccache:$PATH"
|
|
unset LD_LIBRARY_PATH
|
|
|
|
mkdir -p -m755 \
|
|
"$BUILDDIR/obj_binutils" \
|
|
"$BUILDDIR/obj_gcc" \
|
|
"$BUILDDIR/obj_glibc" \
|
|
"$BUILDDIR/obj_kernel" \
|
|
|
|
make -j$(nproc) \
|
|
-C "$SRCDIR/kernel-source-${KERNEL_VERSION}" \
|
|
O="$BUILDDIR/obj_kernel" \
|
|
ARCH=arm64 \
|
|
INSTALL_HDR_PATH="$SYSROOTDIR/usr" \
|
|
headers_install
|
|
|
|
# binutils
|
|
|
|
cd "$BUILDDIR/obj_binutils"
|
|
../../src/binutils-${BINUTILS_VERSION}/configure \
|
|
--target="$TARGET" \
|
|
--prefix= \
|
|
--with-sysroot="$SYSROOT" \
|
|
--with-build-sysroot="$SYSROOTDIR" \
|
|
--disable-multilib
|
|
|
|
make -j$(nproc)
|
|
make -j$(nproc) install DESTDIR="$INSTALLDIR"
|
|
|
|
# gcc
|
|
cd "$BUILDDIR/obj_gcc"
|
|
../../src/gcc-${GCC_VERSION}/configure \
|
|
--prefix= \
|
|
--target=$TARGET \
|
|
--enable-languages=c,c++ \
|
|
--enable-version-specific-runtime-libs \
|
|
--with-sysroot="$SYSROOT" \
|
|
--with-build-sysroot="$SYSROOTDIR" \
|
|
--with-gcc-major-version-only \
|
|
--disable-multilib
|
|
|
|
# compiler only
|
|
make -j$(nproc) all-gcc
|
|
make -j$(nproc) install-gcc DESTDIR="$INSTALLDIR"
|
|
|
|
|
|
# glibc
|
|
|
|
cd "$BUILDDIR/obj_glibc"
|
|
../../src/glibc-${GLIBC_VERSION}/configure \
|
|
--prefix=/usr \
|
|
--target=$TARGET \
|
|
--host=$TARGET \
|
|
--build="$MACHTYPE" \
|
|
--with-sysroot="$SYSROOT" \
|
|
--with-build-sysroot="$SYSROOTDIR" \
|
|
--with-headers="$SYSROOTDIR"/usr/include \
|
|
--with-lib="$SYSROOTDIR"/usr/lib \
|
|
--disable-multilib \
|
|
--disable-crypt \
|
|
libc_cv_forced_unwind=yes
|
|
|
|
# glibc: headers + C runtime bits
|
|
make -j$(nproc) install-bootstrap-headers=yes install-headers DESTDIR="$SYSROOTDIR"
|
|
make -j$(nproc) csu/subdir_lib
|
|
install -d -m755 "$SYSROOTDIR"/usr/lib
|
|
install csu/crt1.o csu/crti.o csu/crtn.o "$SYSROOTDIR"/usr/lib
|
|
$TARGET-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o "$SYSROOTDIR"/usr/lib/libc.so
|
|
touch "$SYSROOTDIR"/usr/include/gnu/stubs.h "$SYSROOTDIR"/usr/include/bits/stdio_lim.h
|
|
|
|
# GCC: runtime (libgcc)
|
|
cd "$BUILDDIR/obj_gcc"
|
|
make -j$(nproc) all-target-libgcc
|
|
make -j$(nproc) install-target-libgcc DESTDIR="$INSTALLDIR"
|
|
|
|
# finish off glibc
|
|
cd "$BUILDDIR/obj_glibc"
|
|
make -j$(nproc)
|
|
make install DESTDIR="$SYSROOTDIR"
|
|
|
|
# finish off GCC
|
|
cd "$BUILDDIR/obj_gcc"
|
|
make -j$(nproc)
|
|
make -j$(nproc) install DESTDIR="$INSTALLDIR"
|
|
|
|
# set /lib64/ld-linux-aarch64.so.1 as ELF interpreter
|
|
$INSTALLDIR/bin/${TARGET}-gcc -dumpspecs > $BUILDDIR/specs
|
|
sed -e 's;/lib/ld-linux-aarch64;/lib64/ld-linux-aarch64;g' -i $BUILDDIR/specs
|
|
mv $BUILDDIR/specs "$INSTALLDIR/lib/gcc/$TARGET/${GCC_MAJOR_VERSION}/"
|
|
|
|
# relocate libgcc_s
|
|
mv $INSTALLDIR/lib/gcc/$TARGET/lib64/libgcc_s.so* "$INSTALLDIR/lib/gcc/$TARGET/${GCC_MAJOR_VERSION}/"
|
|
rmdir "$INSTALLDIR/lib/gcc/$TARGET/lib64"
|