2021-06-07 09:54:02 +00:00
#!/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
2021-06-09 13:36:23 +00:00
GCC_MAJOR_VERSION = " ${ GCC_VERSION %%.* } "
2021-06-07 09:54:02 +00:00
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 "
2021-06-09 13:36:36 +00:00
export PATH = " $INSTALLDIR /bin:/usr/lib/ccache: $PATH "
2021-06-07 09:54:02 +00:00
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++ \
2021-06-09 13:36:23 +00:00
--enable-version-specific-runtime-libs \
2021-06-07 09:54:02 +00:00
--with-sysroot= " $SYSROOT " \
--with-build-sysroot= " $SYSROOTDIR " \
2021-06-07 14:26:25 +00:00
--with-gcc-major-version-only \
2021-06-07 09:54:02 +00:00
--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 "
2021-06-09 13:36:23 +00:00
2021-06-10 11:33:12 +00:00
# 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 } / "
2021-06-09 13:36:23 +00:00
# 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 "